update 版本升级
This commit is contained in:
@@ -38,7 +38,7 @@ public class BusinessPlacesController : ControllerBase
|
||||
[HttpGet("page")]
|
||||
public async Task<Pagination<BusinessPlaceResponse>> GetPageAsync([FromQuery] BusinessPlacePageRequest request)
|
||||
{
|
||||
var enums = await _enumSettingApi.GetEnums();
|
||||
//var enums = await _enumSettingApi.GetEnums();
|
||||
return await _businessPlaceService.GetPageAsync(request);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public class DevicesController : ControllerBase
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取设备模板
|
||||
/// 设备模板分页
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
@@ -47,7 +47,7 @@ public class DevicesController : ControllerBase
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取设备分页
|
||||
/// 设备分页
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
@@ -56,4 +56,15 @@ public class DevicesController : ControllerBase
|
||||
{
|
||||
return await _deviceService.GetPageAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设备保存
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("save")]
|
||||
public async Task SaveAsync(DeviceSaveRequest request)
|
||||
{
|
||||
await _deviceService.SaveAsync(request);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
|
||||
namespace Dlhis.Basic.Device.Request;
|
||||
|
||||
@@ -6,32 +7,29 @@ public class DeviceSaveRequest
|
||||
{
|
||||
public long? Id { get; set; }
|
||||
|
||||
|
||||
public string Sno { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// mac地址
|
||||
/// 设备唯一号
|
||||
/// </summary>
|
||||
public string Mac { get; set; }
|
||||
[Required(ErrorMessage = "设备唯一号不能为空")]
|
||||
public string UniqueNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模板code
|
||||
/// </summary>
|
||||
public string TemplateCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 品牌
|
||||
/// </summary>
|
||||
public string Brand { get; set; }
|
||||
[Required(ErrorMessage = "模板不能为空")]
|
||||
public Guid TemplateCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 供应商信息
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "供应商信息不能为空")]
|
||||
public string Supplier { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备功能
|
||||
/// </summary>
|
||||
[MinLength(1, ErrorMessage = "设备功能不能为空")]
|
||||
[Required(ErrorMessage = "设备功能不能为空")]
|
||||
public List<DeviceFuncEnumType> Funcs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -52,6 +50,7 @@ public class DeviceSaveRequest
|
||||
/// <summary>
|
||||
/// 连接信息
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "连接信息不能为空")]
|
||||
public string ConnectionInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -10,7 +10,7 @@ public class DeviceTemplateSaveRequest
|
||||
public string Brand { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模板名称
|
||||
/// 型号
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using Kurisu.Core.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Basic.Device.Services;
|
||||
|
||||
public interface IDeviceService
|
||||
public interface IDeviceService : IScopeDependency
|
||||
{
|
||||
Task<Pagination<DeviceResponse>> GetPageAsync(DevicePageRequest request);
|
||||
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Kurisu.SqlSugar.Extensions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Mapster;
|
||||
using NetTaste;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Dlhis.Basic.Device.Services.Implements;
|
||||
|
||||
@@ -30,20 +34,72 @@ public class DeviceService : IDeviceService
|
||||
|
||||
public async Task SaveAsync(DeviceSaveRequest request)
|
||||
{
|
||||
var template = await CheckTemplateExistsAsync(request.TemplateCode);
|
||||
await CheckTemplateFieldAsync(request.TemplateCode, request.ConnectionInfo);
|
||||
|
||||
if (!request.Id.HasValue)
|
||||
{
|
||||
var entity = request.Adapt<DeviceEntity>();
|
||||
entity.Code = Guid.NewGuid();
|
||||
entity.Brand = template.Brand;
|
||||
await _dbContext.InsertAsync(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
var device = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Id == request.Id).FirstAsync();
|
||||
device.ThrowIfNull("设备不存在,无法更新");
|
||||
var entity = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Id == request.Id).FirstAsync();
|
||||
entity.ThrowIfNull("设备不存在,无法更新");
|
||||
|
||||
request.Adapt(device);
|
||||
request.Adapt(entity);
|
||||
entity.Brand = template.Brand;
|
||||
|
||||
await _dbContext.UpdateAsync(device);
|
||||
await _dbContext.UpdateAsync(entity);
|
||||
}
|
||||
}
|
||||
|
||||
//******************************************************** help method **********************************************************
|
||||
|
||||
/// <summary>
|
||||
/// 检查设备模板是否存在
|
||||
/// </summary>
|
||||
/// <param name="templateCode"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<DeviceTemplateEntity> CheckTemplateExistsAsync(Guid templateCode)
|
||||
{
|
||||
var entity = await _dbContext.Queryable<DeviceTemplateEntity>().Where(x => x.Code == templateCode).FirstAsync();
|
||||
entity.ThrowIfNull("设备模板不存在");
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查设备连接参数是否与模板设定一致
|
||||
/// </summary>
|
||||
/// <param name="templateCode"></param>
|
||||
/// <param name="jsonContent"></param>
|
||||
/// <returns></returns>
|
||||
private async Task CheckTemplateFieldAsync(Guid templateCode, string jsonContent)
|
||||
{
|
||||
var template = await _dbContext.Queryable<DeviceTemplateEntity>().Where(x => x.Code == templateCode).FirstAsync();
|
||||
template.ThrowIfNull("设备模板不存在");
|
||||
|
||||
try
|
||||
{
|
||||
var templateJobj = JObject.Parse(template.Template);
|
||||
var jobj = JObject.Parse(jsonContent);
|
||||
(templateJobj.Count == jobj.Count).ThrowIfFalse("连接参数字段数不一致");
|
||||
|
||||
foreach (var item in templateJobj)
|
||||
{
|
||||
jobj.ContainsKey(item.Key).ThrowIfFalse($"设备连接参数需要和模板一致.缺失{item.Key}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex) when (ex is JsonReaderException)
|
||||
{
|
||||
throw new UserFriendlyException("连接信息参数格式不正确");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Kurisu.SqlSugar.Extensions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Mapster;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Dlhis.Basic.Device.Services.Implements;
|
||||
|
||||
@@ -30,6 +33,9 @@ public class DeviceTemplateService : IDeviceTemplateService
|
||||
|
||||
public async Task SaveTemplateAsync(DeviceTemplateSaveRequest request)
|
||||
{
|
||||
CheckJsonFormat(request.Template);
|
||||
await CheckDuplicateAsync(request);
|
||||
|
||||
if (!request.Id.HasValue)
|
||||
{
|
||||
var entity = request.Adapt<DeviceTemplateEntity>();
|
||||
@@ -44,7 +50,6 @@ public class DeviceTemplateService : IDeviceTemplateService
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//**********************************************************************************************************/
|
||||
|
||||
|
||||
@@ -58,4 +63,30 @@ public class DeviceTemplateService : IDeviceTemplateService
|
||||
var existsUsing = await _dbContext.Queryable<DeviceEntity>().Where(x => x.TemplateCode == templateCode).AnyAsync();
|
||||
existsUsing.ThrowIfTrue("存在使用中的设备信息,无法修改");
|
||||
}
|
||||
|
||||
private async Task CheckDuplicateAsync(DeviceTemplateSaveRequest request)
|
||||
{
|
||||
var duplicate = await _dbContext.Queryable<DeviceTemplateEntity>().Where(x => x.Brand == request.Brand && x.Name == request.Name)
|
||||
.WhereIF(request.Id.HasValue, x => x.Id != request.Id)
|
||||
.AnyAsync();
|
||||
|
||||
duplicate.ThrowIfTrue("品牌和型号重复");
|
||||
}
|
||||
|
||||
private void CheckJsonFormat(string template)
|
||||
{
|
||||
try
|
||||
{
|
||||
var jobj = JObject.Parse(template);
|
||||
(jobj.Count == 0).ThrowIfTrue("模板至少需要一个参数");
|
||||
}
|
||||
catch (Exception ex) when (ex is JsonReaderException)
|
||||
{
|
||||
throw new UserFriendlyException("模板格式有误");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Kurisu.AspNetCore" Version="0.4.3" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
||||
<PackageReference Include="Kurisu.AspNetCore" Version="0.4.5" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -16,10 +16,12 @@ public class SqlSugarPack : BaseAppPack
|
||||
|
||||
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
//using var scope = app.ApplicationServices.CreateScope();
|
||||
//var db = scope.ServiceProvider.GetService<ISqlSugarClient>();
|
||||
//var tables = App.ActiveTyps.Where(x => x.IsDefined(typeof(SugarTable), false)).ToArray();
|
||||
//db.DbMaintenance.CreateDatabase();
|
||||
//db.CodeFirst.InitTables(tables);
|
||||
#if DEBUG
|
||||
using var scope = app.ApplicationServices.CreateScope();
|
||||
var db = scope.ServiceProvider.GetService<ISqlSugarClient>();
|
||||
var tables = App.ActiveTyps.Where(x => x.IsDefined(typeof(SugarTable), false)).ToArray();
|
||||
db.DbMaintenance.CreateDatabase();
|
||||
db.CodeFirst.InitTables(tables);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user