diff --git a/Admin.Bodk.Customer/Admin.Bodk.Customer.csproj b/Admin.Bodk.Customer/Admin.Bodk.Customer.csproj new file mode 100644 index 0000000..5ecefcf --- /dev/null +++ b/Admin.Bodk.Customer/Admin.Bodk.Customer.csproj @@ -0,0 +1,17 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + diff --git a/Admin.Bodk.Customer/CustomerService.cs b/Admin.Bodk.Customer/CustomerService.cs new file mode 100644 index 0000000..c08707d --- /dev/null +++ b/Admin.Bodk.Customer/CustomerService.cs @@ -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; +/// +/// 设备管理服务 +/// +[ApiDescriptionSettings(Order = 2)] +public class CustomerService: IDynamicApiController, ITransient +{ + private readonly SqlSugarRepository _customer; + public CustomerService(SqlSugarRepository customer) + { + _customer = customer; + } + /// + /// 获取客户列表 + /// + /// + /// + [DisplayName("获取客户列表")] + public async Task> 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); + } + + /// + /// 增加客户 + /// + /// + /// + [UnitOfWork] + [ApiDescriptionSettings(Name = "Add"), HttpPost] + [DisplayName("增加客户")] + public async Task AddCustomer(CustomerDot input) + { + if(input is null) throw Oops.Oh("参数不能为空"); + var customer = input.Adapt(); + var newEquipment = await _customer.AsInsertable(customer).ExecuteReturnEntityAsync(); + return newEquipment.Id; + } +} \ No newline at end of file diff --git a/Admin.Bodk.Customer/Entities/Customer.cs b/Admin.Bodk.Customer/Entities/Customer.cs new file mode 100644 index 0000000..2e2f438 --- /dev/null +++ b/Admin.Bodk.Customer/Entities/Customer.cs @@ -0,0 +1,38 @@ + +using System.ComponentModel.DataAnnotations; +using Admin.NET.Core; +using Nest; +using SqlSugar; +using Yitter.IdGenerator; + +namespace Admin.Bodk.Customer.Entities; +/// +/// 客户表 +/// +[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 +} \ No newline at end of file diff --git a/Admin.Bodk.Customer/Modules/Dot.cs b/Admin.Bodk.Customer/Modules/Dot.cs new file mode 100644 index 0000000..d2ab908 --- /dev/null +++ b/Admin.Bodk.Customer/Modules/Dot.cs @@ -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; } +} \ No newline at end of file diff --git a/Admin.Bodk.Device/Entities/equipment/M9.cs b/Admin.Bodk.Device/Entities/equipment/M9.cs new file mode 100644 index 0000000..eff1f69 --- /dev/null +++ b/Admin.Bodk.Device/Entities/equipment/M9.cs @@ -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; +/// +/// M9数据表 +/// +[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 +{ + /// + /// 设备名称 + /// + public string HostName { get; set; } + /// + /// 网口、串口 + /// + public string DomainName { get; set; } + /// + /// 设备IP + /// + public List IPInterfaces { get; set; } + +} + +public class IPInterfaces +{ + public string InterfaceName { get; set; } + public string IPAddresses { get; set; } +} \ No newline at end of file diff --git a/Admin.Bodk.Device/Services/M9Service.cs b/Admin.Bodk.Device/Services/M9Service.cs new file mode 100644 index 0000000..52c4fc4 --- /dev/null +++ b/Admin.Bodk.Device/Services/M9Service.cs @@ -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; + +/// +/// M9相关接口 +/// +[ApiDescriptionSettings(Order = 2)] +public class M9Service: IDynamicApiController, ITransient +{ + private readonly SqlSugarRepository _m9; + private readonly string _baseUri = "http://192.168.88.111:8080/"; + ApiService _apiService = new ApiService(); + public M9Service(SqlSugarRepository m9) + { + _m9 = m9; + } + + /// + /// 增加Ip + /// + /// + /// + [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(); + m9Input.InterfaceName = Interface.InterfaceName; + m9Input.IPAddresses = Interface.IPAddresses; + try + { + Console.WriteLine("开始插入数据"); + await _m9.AsInsertable(m9Input).ExecuteReturnEntityAsync(); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + } + + /// + /// 读取coils + /// + /// + /// + [UnitOfWork] + [ApiDescriptionSettings(Name = "ReadCoils"), HttpGet] + [DisplayName("读取coils")] + public async Task 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); + } + } + + /// + /// 写入coils + /// + [UnitOfWork] + [ApiDescriptionSettings(Name = "WriteCoils"), HttpGet] + [DisplayName("写入coils")] + public async Task 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); + } + } + + /// + /// 读取HoldingRegisters + /// + [UnitOfWork] + [ApiDescriptionSettings(Name = "ReadHoldingRegisters"), HttpGet] + [DisplayName("读取HoldingRegisters")] + public async Task 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); + } + } + + /// + /// 写入HoldingRegisters + /// + [UnitOfWork] + [ApiDescriptionSettings(Name = "WriteHoldingRegisters"), HttpGet] + [DisplayName("写入HoldingRegisters")] + public async Task 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); + } + } +} \ No newline at end of file diff --git a/Admin.Bodk.Device/Services/StorageService.cs b/Admin.Bodk.Device/Services/StorageService.cs index 1631cfb..788bfe3 100644 --- a/Admin.Bodk.Device/Services/StorageService.cs +++ b/Admin.Bodk.Device/Services/StorageService.cs @@ -1,7 +1,4 @@ -// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 -// -// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 - + using System.ComponentModel; using Bodk.Device.Storage; using Bodk.Device.Storage.EventArgs; diff --git a/Admin.Bodk.Device/Startup.cs b/Admin.Bodk.Device/Startup.cs index 2d2f15f..554d523 100644 --- a/Admin.Bodk.Device/Startup.cs +++ b/Admin.Bodk.Device/Startup.cs @@ -1,7 +1,4 @@ -// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 -// -// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 - + using Bodk.Device.Storage; using Bodk.Device.Storage.EventArgs; using Furion; diff --git a/Admin.NET.Core/SeedData/SysConfigSeedData.cs b/Admin.NET.Core/SeedData/SysConfigSeedData.cs index 7c865e3..db6bda3 100644 --- a/Admin.NET.Core/SeedData/SysConfigSeedData.cs +++ b/Admin.NET.Core/SeedData/SysConfigSeedData.cs @@ -1,6 +1,3 @@ -// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 -// -// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 namespace Admin.NET.Core; diff --git a/Admin.NET.Core/Service/Result.cs b/Admin.NET.Core/Service/Result.cs new file mode 100644 index 0000000..25a1b9c --- /dev/null +++ b/Admin.NET.Core/Service/Result.cs @@ -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 : ResultData + { + /// + /// 操作结果的数据。 + /// + public T Data { get; set; } + /// + /// 使用默认值初始化 Result 类的新实例。 + /// + public ResultData() : this(true, "OK") { } + /// + /// 使用指定值初始化 Result 类的新实例。 + /// + public ResultData(bool state, string msg) : this(state, msg, default(T)) { } + /// + /// 使用指定值初始化 Result 类的新实例,包括数据。 + /// + public ResultData(bool isSuccess, string msg, T data) + { + this.IsSuccess = isSuccess; Message = msg; Data = data; + } + } +} diff --git a/Admin.NET.Core/Service/Server/ApiService.cs b/Admin.NET.Core/Service/Server/ApiService.cs index ae31c4a..1d4a20f 100644 --- a/Admin.NET.Core/Service/Server/ApiService.cs +++ b/Admin.NET.Core/Service/Server/ApiService.cs @@ -1,4 +1,7 @@ +using Admin.Bodk.Device; +using Newtonsoft.Json; + namespace Admin.NET.Core.Service; public class ApiService @@ -10,11 +13,19 @@ public class ApiService _httpClient = new HttpClient(); } - public async Task GetApiResponseAsync(string url) + public async Task GetApiResponseAsync(string url) { HttpResponseMessage response = await _httpClient.GetAsync(url); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(); - return responseBody; + var result = JsonConvert.DeserializeObject(responseBody); + if (result.IsSuccess) + { + return result; + } + else + { + throw Oops.Oh(result.Message); + } } } \ No newline at end of file diff --git a/Admin.NET.Web.Entry/Admin.NET.Web.Entry.csproj b/Admin.NET.Web.Entry/Admin.NET.Web.Entry.csproj index 34fdd04..44e0318 100644 --- a/Admin.NET.Web.Entry/Admin.NET.Web.Entry.csproj +++ b/Admin.NET.Web.Entry/Admin.NET.Web.Entry.csproj @@ -40,6 +40,7 @@ + diff --git a/Admin.NET.Web.Entry/Admin.NET.db b/Admin.NET.Web.Entry/Admin.NET.db index 53eb8f1..3530dac 100644 Binary files a/Admin.NET.Web.Entry/Admin.NET.db and b/Admin.NET.Web.Entry/Admin.NET.db differ diff --git a/Admin.NET.sln b/Admin.NET.sln index b8055ea..cfe547d 100644 --- a/Admin.NET.sln +++ b/Admin.NET.sln @@ -28,6 +28,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bodk.Device.Storage", "Bodk EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bodk.Extensions.Modbus", "Bodk.Extensions.Modbus\Bodk.Extensions.Modbus.csproj", "{14C3AEEE-38F2-45FC-9123-13B075F49E2C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Admin.Bodk.Customer", "Admin.Bodk.Customer\Admin.Bodk.Customer.csproj", "{6A073364-6552-4CDB-861A-4BD8B51E0FF6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -70,6 +72,10 @@ Global {14C3AEEE-38F2-45FC-9123-13B075F49E2C}.Debug|Any CPU.Build.0 = Debug|Any CPU {14C3AEEE-38F2-45FC-9123-13B075F49E2C}.Release|Any CPU.ActiveCfg = Release|Any CPU {14C3AEEE-38F2-45FC-9123-13B075F49E2C}.Release|Any CPU.Build.0 = Release|Any CPU + {6A073364-6552-4CDB-861A-4BD8B51E0FF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6A073364-6552-4CDB-861A-4BD8B51E0FF6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6A073364-6552-4CDB-861A-4BD8B51E0FF6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6A073364-6552-4CDB-861A-4BD8B51E0FF6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE