肖正
6 months ago
14 changed files with 390 additions and 13 deletions
@ -0,0 +1,17 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>net8.0</TargetFramework> |
||||
|
<ImplicitUsings>enable</ImplicitUsings> |
||||
|
<Nullable>enable</Nullable> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="SqlSugarCore" Version="5.1.4.146-preview10" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\Admin.NET.Core\Admin.NET.Core.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
@ -0,0 +1,54 @@ |
|||||
|
|
||||
|
using System.ComponentModel; |
||||
|
using Admin.Bodk.Customer.Modules; |
||||
|
using Admin.NET.Core; |
||||
|
using Furion.DatabaseAccessor; |
||||
|
using Furion.DependencyInjection; |
||||
|
using Furion.DynamicApiController; |
||||
|
using Furion.FriendlyException; |
||||
|
using Mapster; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using SqlSugar; |
||||
|
|
||||
|
namespace Admin.Bodk.Customer; |
||||
|
/// <summary>
|
||||
|
/// 设备管理服务
|
||||
|
/// </summary>
|
||||
|
[ApiDescriptionSettings(Order = 2)] |
||||
|
public class CustomerService: IDynamicApiController, ITransient |
||||
|
{ |
||||
|
private readonly SqlSugarRepository<Entities.Customer> _customer; |
||||
|
public CustomerService(SqlSugarRepository<Entities.Customer> customer) |
||||
|
{ |
||||
|
_customer = customer; |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 获取客户列表
|
||||
|
/// </summary>
|
||||
|
/// <param name="input"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[DisplayName("获取客户列表")] |
||||
|
public async Task<SqlSugarPagedList<Entities.Customer>> PostCustomerList(CustomerInput input) |
||||
|
{ |
||||
|
return await _customer.AsQueryable() |
||||
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Name), |
||||
|
m => m.Name != null && m.Name.Contains(input.Name)) |
||||
|
.ToPagedListAsync(input.Page, input.PageSize); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 增加客户
|
||||
|
/// </summary>
|
||||
|
/// <param name="input"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[UnitOfWork] |
||||
|
[ApiDescriptionSettings(Name = "Add"), HttpPost] |
||||
|
[DisplayName("增加客户")] |
||||
|
public async Task<long> AddCustomer(CustomerDot input) |
||||
|
{ |
||||
|
if(input is null) throw Oops.Oh("参数不能为空"); |
||||
|
var customer = input.Adapt<Entities.Customer>(); |
||||
|
var newEquipment = await _customer.AsInsertable(customer).ExecuteReturnEntityAsync(); |
||||
|
return newEquipment.Id; |
||||
|
} |
||||
|
} |
@ -0,0 +1,38 @@ |
|||||
|
|
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using Admin.NET.Core; |
||||
|
using Nest; |
||||
|
using SqlSugar; |
||||
|
using Yitter.IdGenerator; |
||||
|
|
||||
|
namespace Admin.Bodk.Customer.Entities; |
||||
|
/// <summary>
|
||||
|
/// 客户表
|
||||
|
/// </summary>
|
||||
|
[SugarTable(null, "客户表")] |
||||
|
[SysTable] |
||||
|
public class Customer: EntityTenant, IRepositorySettings |
||||
|
{ |
||||
|
[SugarColumn(ColumnDescription = "主键", IsPrimaryKey = true, IsIdentity = false)] |
||||
|
public long Id { get; set; } = YitIdHelper.NextId(); |
||||
|
|
||||
|
[SugarColumn(ColumnDescription = "客户名称", Length = 32)] |
||||
|
[Required, MaxLength(32)] |
||||
|
public virtual string? Name { get; set; } |
||||
|
|
||||
|
[SugarColumn(ColumnDescription = "性别")] |
||||
|
[Required] |
||||
|
public virtual Sex Sex { get; set; } |
||||
|
|
||||
|
[SugarColumn(ColumnDescription = "身份证号码", Length = 32,IsNullable = true)] |
||||
|
public virtual string IdNo { get; set; } |
||||
|
|
||||
|
[SugarColumn(ColumnDescription = "手机号码", Length = 32,IsNullable = true)] |
||||
|
public virtual string PhoneNo { get; set; } |
||||
|
} |
||||
|
|
||||
|
public enum Sex |
||||
|
{ |
||||
|
Man = 1, |
||||
|
Woman = 0 |
||||
|
} |
@ -0,0 +1,22 @@ |
|||||
|
using Admin.Bodk.Customer.Entities; |
||||
|
using Admin.NET.Core; |
||||
|
|
||||
|
namespace Admin.Bodk.Customer.Modules; |
||||
|
|
||||
|
public class Dot |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public class CustomerInput:BasePageInput |
||||
|
{ |
||||
|
public string Name { get; set; } |
||||
|
} |
||||
|
|
||||
|
public class CustomerDot:BasePageInput |
||||
|
{ |
||||
|
public string Name { get; set; } |
||||
|
public Sex Sex { get; set; } |
||||
|
public string IdNo { get; set; } |
||||
|
public string PhoneNo { get; set; } |
||||
|
} |
@ -0,0 +1,56 @@ |
|||||
|
|
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using Admin.NET.Core; |
||||
|
using Nest; |
||||
|
using SqlSugar; |
||||
|
using Yitter.IdGenerator; |
||||
|
|
||||
|
namespace Admin.Bodk.Device.Entities.equipment; |
||||
|
/// <summary>
|
||||
|
/// M9数据表
|
||||
|
/// </summary>
|
||||
|
[SugarTable(null, "M9数据表")] |
||||
|
[SysTable] |
||||
|
public class M9: EntityTenant, IRepositorySettings |
||||
|
{ |
||||
|
// 是否主键,是否自增
|
||||
|
[SugarColumn(ColumnDescription = "主键", IsPrimaryKey = true, IsIdentity = false)] |
||||
|
public long Id { get; set; } = YitIdHelper.NextId(); |
||||
|
|
||||
|
[SugarColumn(ColumnDescription = "设备名称", Length = 32)] |
||||
|
[Required, MaxLength(32)] |
||||
|
public virtual string HostName { get; set; } |
||||
|
|
||||
|
[SugarColumn(ColumnDescription = "网口、串口", Length = 32, IsNullable = true)] |
||||
|
public virtual string DomainName { get; set; } |
||||
|
|
||||
|
[SugarColumn(ColumnDescription = "网口名称", Length = 32)] |
||||
|
[Required] |
||||
|
public virtual string InterfaceName { get; set; } |
||||
|
|
||||
|
[SugarColumn(ColumnDescription = "设备IP", Length = 32)] |
||||
|
[Required] |
||||
|
public virtual string IPAddresses { get; set; } |
||||
|
} |
||||
|
public class M9Input: BasePageInput |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 设备名称
|
||||
|
/// </summary>
|
||||
|
public string HostName { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 网口、串口
|
||||
|
/// </summary>
|
||||
|
public string DomainName { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 设备IP
|
||||
|
/// </summary>
|
||||
|
public List<IPInterfaces> IPInterfaces { get; set; } |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public class IPInterfaces |
||||
|
{ |
||||
|
public string InterfaceName { get; set; } |
||||
|
public string IPAddresses { get; set; } |
||||
|
} |
@ -0,0 +1,138 @@ |
|||||
|
|
||||
|
using System.ComponentModel; |
||||
|
using Admin.Bodk.Device.Entities.equipment; |
||||
|
using Admin.NET.Core; |
||||
|
using Admin.NET.Core.Service; |
||||
|
using Furion.DatabaseAccessor; |
||||
|
using Furion.DependencyInjection; |
||||
|
using Furion.DynamicApiController; |
||||
|
using Furion.FriendlyException; |
||||
|
using Mapster; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
|
||||
|
namespace Admin.Bodk.Device.Services; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// M9相关接口
|
||||
|
/// </summary>
|
||||
|
[ApiDescriptionSettings(Order = 2)] |
||||
|
public class M9Service: IDynamicApiController, ITransient |
||||
|
{ |
||||
|
private readonly SqlSugarRepository<M9> _m9; |
||||
|
private readonly string _baseUri = "http://192.168.88.111:8080/"; |
||||
|
ApiService _apiService = new ApiService(); |
||||
|
public M9Service(SqlSugarRepository<M9> m9) |
||||
|
{ |
||||
|
_m9 = m9; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 增加Ip
|
||||
|
/// </summary>
|
||||
|
/// <param name="input"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[UnitOfWork] |
||||
|
[ApiDescriptionSettings(Name = "AddIp"), HttpGet] |
||||
|
[DisplayName("增加Ip")] |
||||
|
public async Task AddEquipment([FromBody] M9Input input) |
||||
|
{ |
||||
|
if(input is null) throw Oops.Oh("参数不能为空"); |
||||
|
if (input.IPInterfaces is null || input.IPInterfaces.Count == 0) throw Oops.Oh("IP不能为空"); |
||||
|
foreach (var Interface in input.IPInterfaces) |
||||
|
{ |
||||
|
M9 m9Input = input.Adapt<M9>(); |
||||
|
m9Input.InterfaceName = Interface.InterfaceName; |
||||
|
m9Input.IPAddresses = Interface.IPAddresses; |
||||
|
try |
||||
|
{ |
||||
|
Console.WriteLine("开始插入数据"); |
||||
|
await _m9.AsInsertable(m9Input).ExecuteReturnEntityAsync(); |
||||
|
} |
||||
|
catch (Exception e) |
||||
|
{ |
||||
|
Console.WriteLine(e); |
||||
|
throw; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 读取coils
|
||||
|
/// </summary>
|
||||
|
/// <param name="input"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[UnitOfWork] |
||||
|
[ApiDescriptionSettings(Name = "ReadCoils"), HttpGet] |
||||
|
[DisplayName("读取coils")] |
||||
|
public async Task<ResultData> GetReadCoils(string slaveId, string startAddress, string numCoils) |
||||
|
{ |
||||
|
string url = $"{_baseUri}api/modbus/read-coils?slaveId={slaveId}&startAddress={startAddress}&numCoils={numCoils}"; |
||||
|
try |
||||
|
{ |
||||
|
return await _apiService.GetApiResponseAsync(url); |
||||
|
} |
||||
|
catch (HttpRequestException e) |
||||
|
{ |
||||
|
throw Oops.Oh(e.Message); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 写入coils
|
||||
|
/// </summary>
|
||||
|
[UnitOfWork] |
||||
|
[ApiDescriptionSettings(Name = "WriteCoils"), HttpGet] |
||||
|
[DisplayName("写入coils")] |
||||
|
public async Task<ResultData> WriteCoils(string slaveId, string startAddress) |
||||
|
{ |
||||
|
string url = $"{_baseUri}api/modbus/write-coils?slaveId={slaveId}&startAddress={startAddress}"; |
||||
|
try |
||||
|
{ |
||||
|
return await _apiService.GetApiResponseAsync(url); |
||||
|
} |
||||
|
catch (HttpRequestException e) |
||||
|
{ |
||||
|
throw Oops.Oh(e.Message); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 读取HoldingRegisters
|
||||
|
/// </summary>
|
||||
|
[UnitOfWork] |
||||
|
[ApiDescriptionSettings(Name = "ReadHoldingRegisters"), HttpGet] |
||||
|
[DisplayName("读取HoldingRegisters")] |
||||
|
public async Task<ResultData> ReadHoldingRegisters(string slaveId, string startAddress, string numRegisters) |
||||
|
{ |
||||
|
string url = $"{_baseUri}api/modbus/read-holding-registers?slaveId={slaveId}" + |
||||
|
$"&startAddress={startAddress}&numRegisters={numRegisters}"; |
||||
|
try |
||||
|
{ |
||||
|
return await _apiService.GetApiResponseAsync(url); |
||||
|
} |
||||
|
catch (HttpRequestException e) |
||||
|
{ |
||||
|
throw Oops.Oh(e.Message); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 写入HoldingRegisters
|
||||
|
/// </summary>
|
||||
|
[UnitOfWork] |
||||
|
[ApiDescriptionSettings(Name = "WriteHoldingRegisters"), HttpGet] |
||||
|
[DisplayName("写入HoldingRegisters")] |
||||
|
public async Task<ResultData> WriteHoldingRegisters(string slaveId, string startAddress) |
||||
|
{ |
||||
|
string url = $"{_baseUri}api/modbus/write-holding-registers?slaveId={slaveId}" + |
||||
|
$"&startAddress={startAddress}"; |
||||
|
try |
||||
|
{ |
||||
|
return await _apiService.GetApiResponseAsync(url); |
||||
|
} |
||||
|
catch (HttpRequestException e) |
||||
|
{ |
||||
|
throw Oops.Oh(e.Message); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,43 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Admin.Bodk.Device |
||||
|
{ |
||||
|
public class ResultData |
||||
|
{ |
||||
|
public bool IsSuccess { get; set; } = true; |
||||
|
public string Message { get; set; } = ""; |
||||
|
|
||||
|
public ResultData() : this(true, "操作成功") { } |
||||
|
public ResultData(bool state, string msg) |
||||
|
{ |
||||
|
IsSuccess = state; |
||||
|
Message = msg; |
||||
|
} |
||||
|
} |
||||
|
public class ResultData<T> : ResultData |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 操作结果的数据。
|
||||
|
/// </summary>
|
||||
|
public T Data { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 使用默认值初始化 Result 类的新实例。
|
||||
|
/// </summary>
|
||||
|
public ResultData() : this(true, "OK") { } |
||||
|
/// <summary>
|
||||
|
/// 使用指定值初始化 Result 类的新实例。
|
||||
|
/// </summary>
|
||||
|
public ResultData(bool state, string msg) : this(state, msg, default(T)) { } |
||||
|
/// <summary>
|
||||
|
/// 使用指定值初始化 Result 类的新实例,包括数据。
|
||||
|
/// </summary>
|
||||
|
public ResultData(bool isSuccess, string msg, T data) |
||||
|
{ |
||||
|
this.IsSuccess = isSuccess; Message = msg; Data = data; |
||||
|
} |
||||
|
} |
||||
|
} |
Binary file not shown.
Loading…
Reference in new issue