Browse Source

用户接口

master
肖正 6 months ago
parent
commit
41696234d9
  1. 17
      Admin.Bodk.Customer/Admin.Bodk.Customer.csproj
  2. 54
      Admin.Bodk.Customer/CustomerService.cs
  3. 38
      Admin.Bodk.Customer/Entities/Customer.cs
  4. 22
      Admin.Bodk.Customer/Modules/Dot.cs
  5. 56
      Admin.Bodk.Device/Entities/equipment/M9.cs
  6. 138
      Admin.Bodk.Device/Services/M9Service.cs
  7. 5
      Admin.Bodk.Device/Services/StorageService.cs
  8. 5
      Admin.Bodk.Device/Startup.cs
  9. 3
      Admin.NET.Core/SeedData/SysConfigSeedData.cs
  10. 43
      Admin.NET.Core/Service/Result.cs
  11. 15
      Admin.NET.Core/Service/Server/ApiService.cs
  12. 1
      Admin.NET.Web.Entry/Admin.NET.Web.Entry.csproj
  13. BIN
      Admin.NET.Web.Entry/Admin.NET.db
  14. 6
      Admin.NET.sln

17
Admin.Bodk.Customer/Admin.Bodk.Customer.csproj

@ -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>

54
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;
/// <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;
}
}

38
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;
/// <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
}

22
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; }
}

56
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;
/// <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; }
}

138
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;
/// <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);
}
}
}

5
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;

5
Admin.Bodk.Device/Startup.cs

@ -1,7 +1,4 @@
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证

using Bodk.Device.Storage;
using Bodk.Device.Storage.EventArgs;
using Furion;

3
Admin.NET.Core/SeedData/SysConfigSeedData.cs

@ -1,6 +1,3 @@
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
namespace Admin.NET.Core;

43
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<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;
}
}
}

15
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<string> GetApiResponseAsync(string url)
public async Task<ResultData> GetApiResponseAsync(string url)
{
HttpResponseMessage response = await _httpClient.GetAsync(url);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
return responseBody;
var result = JsonConvert.DeserializeObject<ResultData>(responseBody);
if (result.IsSuccess)
{
return result;
}
else
{
throw Oops.Oh(result.Message);
}
}
}

1
Admin.NET.Web.Entry/Admin.NET.Web.Entry.csproj

@ -40,6 +40,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Admin.Bodk.Customer\Admin.Bodk.Customer.csproj" />
<ProjectReference Include="..\Admin.Bodk.Device\Admin.Bodk.Device.csproj" />
<ProjectReference Include="..\Admin.NET.Web.Core\Admin.NET.Web.Core.csproj" />
</ItemGroup>

BIN
Admin.NET.Web.Entry/Admin.NET.db

Binary file not shown.

6
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

Loading…
Cancel
Save