update 版本升级
This commit is contained in:
@@ -38,7 +38,7 @@ public class BusinessPlacesController : ControllerBase
|
|||||||
[HttpGet("page")]
|
[HttpGet("page")]
|
||||||
public async Task<Pagination<BusinessPlaceResponse>> GetPageAsync([FromQuery] BusinessPlacePageRequest request)
|
public async Task<Pagination<BusinessPlaceResponse>> GetPageAsync([FromQuery] BusinessPlacePageRequest request)
|
||||||
{
|
{
|
||||||
var enums = await _enumSettingApi.GetEnums();
|
//var enums = await _enumSettingApi.GetEnums();
|
||||||
return await _businessPlaceService.GetPageAsync(request);
|
return await _businessPlaceService.GetPageAsync(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class DevicesController : ControllerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取设备模板
|
/// 设备模板分页
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
@@ -47,7 +47,7 @@ public class DevicesController : ControllerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取设备分页
|
/// 设备分页
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
@@ -56,4 +56,15 @@ public class DevicesController : ControllerBase
|
|||||||
{
|
{
|
||||||
return await _deviceService.GetPageAsync(request);
|
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;
|
namespace Dlhis.Basic.Device.Request;
|
||||||
|
|
||||||
@@ -6,32 +7,29 @@ public class DeviceSaveRequest
|
|||||||
{
|
{
|
||||||
public long? Id { get; set; }
|
public long? Id { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public string Sno { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// mac地址
|
/// 设备唯一号
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Mac { get; set; }
|
[Required(ErrorMessage = "设备唯一号不能为空")]
|
||||||
|
public string UniqueNo { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 模板code
|
/// 模板code
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string TemplateCode { get; set; }
|
[Required(ErrorMessage = "模板不能为空")]
|
||||||
|
public Guid TemplateCode { get; set; }
|
||||||
/// <summary>
|
|
||||||
/// 品牌
|
|
||||||
/// </summary>
|
|
||||||
public string Brand { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 供应商信息
|
/// 供应商信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Required(ErrorMessage = "供应商信息不能为空")]
|
||||||
public string Supplier { get; set; }
|
public string Supplier { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设备功能
|
/// 设备功能
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[MinLength(1, ErrorMessage = "设备功能不能为空")]
|
||||||
|
[Required(ErrorMessage = "设备功能不能为空")]
|
||||||
public List<DeviceFuncEnumType> Funcs { get; set; }
|
public List<DeviceFuncEnumType> Funcs { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -52,6 +50,7 @@ public class DeviceSaveRequest
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 连接信息
|
/// 连接信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Required(ErrorMessage = "连接信息不能为空")]
|
||||||
public string ConnectionInfo { get; set; }
|
public string ConnectionInfo { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public class DeviceTemplateSaveRequest
|
|||||||
public string Brand { get; set; }
|
public string Brand { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 模板名称
|
/// 型号
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using Kurisu.Core.DataAccess.Dto;
|
|||||||
|
|
||||||
namespace Dlhis.Basic.Device.Services;
|
namespace Dlhis.Basic.Device.Services;
|
||||||
|
|
||||||
public interface IDeviceService
|
public interface IDeviceService : IScopeDependency
|
||||||
{
|
{
|
||||||
Task<Pagination<DeviceResponse>> GetPageAsync(DevicePageRequest request);
|
Task<Pagination<DeviceResponse>> GetPageAsync(DevicePageRequest request);
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
using Dlhis.Basic.Device.Request;
|
using Dlhis.Basic.Device.Request;
|
||||||
using Dlhis.Basic.Device.Response;
|
using Dlhis.Basic.Device.Response;
|
||||||
using Dlhis.Entity.Device.Entities;
|
using Dlhis.Entity.Device.Entities;
|
||||||
|
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
using Kurisu.Core.DataAccess.Dto;
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
using Kurisu.SqlSugar.Extensions;
|
using Kurisu.SqlSugar.Extensions;
|
||||||
using Kurisu.SqlSugar.Services;
|
using Kurisu.SqlSugar.Services;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
|
using NetTaste;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace Dlhis.Basic.Device.Services.Implements;
|
namespace Dlhis.Basic.Device.Services.Implements;
|
||||||
|
|
||||||
@@ -30,20 +34,72 @@ public class DeviceService : IDeviceService
|
|||||||
|
|
||||||
public async Task SaveAsync(DeviceSaveRequest request)
|
public async Task SaveAsync(DeviceSaveRequest request)
|
||||||
{
|
{
|
||||||
|
var template = await CheckTemplateExistsAsync(request.TemplateCode);
|
||||||
|
await CheckTemplateFieldAsync(request.TemplateCode, request.ConnectionInfo);
|
||||||
|
|
||||||
if (!request.Id.HasValue)
|
if (!request.Id.HasValue)
|
||||||
{
|
{
|
||||||
var entity = request.Adapt<DeviceEntity>();
|
var entity = request.Adapt<DeviceEntity>();
|
||||||
entity.Code = Guid.NewGuid();
|
entity.Code = Guid.NewGuid();
|
||||||
|
entity.Brand = template.Brand;
|
||||||
await _dbContext.InsertAsync(entity);
|
await _dbContext.InsertAsync(entity);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var device = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Id == request.Id).FirstAsync();
|
var entity = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Id == request.Id).FirstAsync();
|
||||||
device.ThrowIfNull("设备不存在,无法更新");
|
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.Request;
|
||||||
using Dlhis.Basic.Device.Response;
|
using Dlhis.Basic.Device.Response;
|
||||||
using Dlhis.Entity.Device.Entities;
|
using Dlhis.Entity.Device.Entities;
|
||||||
|
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
using Kurisu.Core.DataAccess.Dto;
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
using Kurisu.SqlSugar.Extensions;
|
using Kurisu.SqlSugar.Extensions;
|
||||||
using Kurisu.SqlSugar.Services;
|
using Kurisu.SqlSugar.Services;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace Dlhis.Basic.Device.Services.Implements;
|
namespace Dlhis.Basic.Device.Services.Implements;
|
||||||
|
|
||||||
@@ -30,6 +33,9 @@ public class DeviceTemplateService : IDeviceTemplateService
|
|||||||
|
|
||||||
public async Task SaveTemplateAsync(DeviceTemplateSaveRequest request)
|
public async Task SaveTemplateAsync(DeviceTemplateSaveRequest request)
|
||||||
{
|
{
|
||||||
|
CheckJsonFormat(request.Template);
|
||||||
|
await CheckDuplicateAsync(request);
|
||||||
|
|
||||||
if (!request.Id.HasValue)
|
if (!request.Id.HasValue)
|
||||||
{
|
{
|
||||||
var entity = request.Adapt<DeviceTemplateEntity>();
|
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();
|
var existsUsing = await _dbContext.Queryable<DeviceEntity>().Where(x => x.TemplateCode == templateCode).AnyAsync();
|
||||||
existsUsing.ThrowIfTrue("存在使用中的设备信息,无法修改");
|
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>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Kurisu.AspNetCore" Version="0.4.3" />
|
<PackageReference Include="Kurisu.AspNetCore" Version="0.4.5" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -16,10 +16,12 @@ public class SqlSugarPack : BaseAppPack
|
|||||||
|
|
||||||
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||||
{
|
{
|
||||||
//using var scope = app.ApplicationServices.CreateScope();
|
#if DEBUG
|
||||||
//var db = scope.ServiceProvider.GetService<ISqlSugarClient>();
|
using var scope = app.ApplicationServices.CreateScope();
|
||||||
//var tables = App.ActiveTyps.Where(x => x.IsDefined(typeof(SugarTable), false)).ToArray();
|
var db = scope.ServiceProvider.GetService<ISqlSugarClient>();
|
||||||
//db.DbMaintenance.CreateDatabase();
|
var tables = App.ActiveTyps.Where(x => x.IsDefined(typeof(SugarTable), false)).ToArray();
|
||||||
//db.CodeFirst.InitTables(tables);
|
db.DbMaintenance.CreateDatabase();
|
||||||
|
db.CodeFirst.InitTables(tables);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Kurisu.AspNetCore" Version="0.4.3" />
|
<PackageReference Include="Kurisu.AspNetCore" Version="0.4.5" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Kurisu.AspNetCore" Version="0.4.3" />
|
<PackageReference Include="Kurisu.AspNetCore" Version="0.4.5" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Kurisu.Core.DataAccess.Entity;
|
using System;
|
||||||
|
using Kurisu.Core.DataAccess.Entity;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
|
||||||
namespace Dlhis.Entity.Device.Entities;
|
namespace Dlhis.Entity.Device.Entities;
|
||||||
@@ -18,13 +19,13 @@ public class DeviceTemplateEntity : SugarBaseEntity, ITenantId
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 品牌
|
/// 品牌
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnDescription = "品牌")]
|
[SugarColumn(ColumnDescription = "品牌", UniqueGroupNameList = new string[] { "idx_DeviceTemplate_brand_name" })]
|
||||||
public string Brand { get; set; }
|
public string Brand { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 模板名称
|
/// 模板名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnDescription = "模板名称")]
|
[SugarColumn(ColumnDescription = "型号", UniqueGroupNameList = new string[] { "idx_DeviceTemplate_brand_name" })]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Dlhis.Entity.Permission.Enums;
|
using Dlhis.Entity.Permission.Enums;
|
||||||
using Kurisu.Core.DataAccess.Entity;
|
using Kurisu.Core.DataAccess.Entity;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
using SqlSugar.DbConvert;
|
||||||
|
|
||||||
namespace Dlhis.Entity.Permission.Entities;
|
namespace Dlhis.Entity.Permission.Entities;
|
||||||
|
|
||||||
@@ -8,12 +9,12 @@ namespace Dlhis.Entity.Permission.Entities;
|
|||||||
/// 菜单权限
|
/// 菜单权限
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarTable(TableName = "MenuPermission", TableDescription = "菜单权限")]
|
[SugarTable(TableName = "MenuPermission", TableDescription = "菜单权限")]
|
||||||
public class MenuPermissionEntity : SugarBaseEntity, ITenantId
|
public class MenuPermissionEntity : SugarBaseEntity, ITenantId, ISoftDeleted
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 权限类型
|
/// 权限类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnDataType = "varchar(50)", ColumnDescription = "权限类型")]
|
[SugarColumn(ColumnDataType = "varchar(50)", ColumnDescription = "权限类型", SqlParameterDbType = typeof(EnumToStringConvert))]
|
||||||
public MenuPermissionTypeEnumType UniqueType { get; set; }
|
public MenuPermissionTypeEnumType UniqueType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -30,4 +31,6 @@ public class MenuPermissionEntity : SugarBaseEntity, ITenantId
|
|||||||
|
|
||||||
|
|
||||||
public string TenantId { get; set; }
|
public string TenantId { get; set; }
|
||||||
|
|
||||||
|
public bool IsDeleted { get; set; }
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>disable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
<DockerfileContext>..\..</DockerfileContext>
|
<DockerfileContext>..\..</DockerfileContext>
|
||||||
@@ -17,8 +17,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Kurisu.AspNetCore" Version="0.4.3" />
|
<PackageReference Include="Kurisu.AspNetCore" Version="0.4.5" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -26,7 +25,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Menu\" />
|
<Folder Include="Menu\Controllers\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Dlhis.Entity.Permission.Enums;
|
||||||
|
|
||||||
|
namespace Dlhis.Permission.Menu.Request;
|
||||||
|
|
||||||
|
public class MenuPermissionAssignmentRequest
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 权限类型
|
||||||
|
/// </summary>
|
||||||
|
[EnumDataType(typeof(MenuPermissionTypeEnumType))]
|
||||||
|
public MenuPermissionTypeEnumType UniqueType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 唯一值
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
public string UniqueValue { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 权限code
|
||||||
|
/// </summary>
|
||||||
|
public List<string> Codes { get; set; } = new List<string>();
|
||||||
|
}
|
||||||
102
Src/Dlhis.Permission/Menu/Request/SaveMenuRequest.cs
Normal file
102
Src/Dlhis.Permission/Menu/Request/SaveMenuRequest.cs
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Dlhis.Entity.Permission.Enums;
|
||||||
|
|
||||||
|
namespace Dlhis.Permission.Menu.Request;
|
||||||
|
|
||||||
|
public class SaveMenuRequest : IValidatableObject
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// code
|
||||||
|
/// </summary>
|
||||||
|
public string Code { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 上级
|
||||||
|
/// </summary>
|
||||||
|
public string PCode { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Name
|
||||||
|
/// </summary>
|
||||||
|
[Required(ErrorMessage = "Name不能为空")]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 标题
|
||||||
|
/// </summary>
|
||||||
|
[Required(ErrorMessage = "标题不能为空")]
|
||||||
|
public string Title { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 图标
|
||||||
|
/// </summary>
|
||||||
|
public string Icon { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 路由地址
|
||||||
|
/// </summary>
|
||||||
|
public string Route { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 权限标识
|
||||||
|
/// </summary>
|
||||||
|
public string Permission { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否可见
|
||||||
|
/// </summary>
|
||||||
|
public bool? Visible { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否为外链
|
||||||
|
/// </summary>
|
||||||
|
public bool IsLink { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 序号
|
||||||
|
/// </summary>
|
||||||
|
public int Sequence { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 菜单类型
|
||||||
|
/// </summary>
|
||||||
|
[EnumDataType(typeof(MenuEnumType))]
|
||||||
|
public MenuEnumType MenuType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 平台
|
||||||
|
/// </summary>
|
||||||
|
[EnumDataType(typeof(PlatformEnumType))]
|
||||||
|
public PlatformEnumType Platform { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 兼容reset处理
|
||||||
|
/// </summary>
|
||||||
|
public List<SaveMenuRequest> Items { get; set; }
|
||||||
|
|
||||||
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||||
|
{
|
||||||
|
if ((MenuType == MenuEnumType.Menu || MenuType == MenuEnumType.Button) && string.IsNullOrEmpty(Permission))
|
||||||
|
{
|
||||||
|
yield return new ValidationResult("当类型为菜单或者按钮时,权限标识不能为空", new[] { nameof(Permission) });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MenuType == MenuEnumType.Folder && !string.IsNullOrEmpty(PCode))
|
||||||
|
{
|
||||||
|
yield return new ValidationResult("目录类型无需传入上级code", new[] { nameof(PCode) });
|
||||||
|
}
|
||||||
|
|
||||||
|
//自动生成code
|
||||||
|
if (string.IsNullOrEmpty(Code))
|
||||||
|
{
|
||||||
|
Code = Guid.NewGuid().ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Visible.HasValue)
|
||||||
|
{
|
||||||
|
Visible = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
81
Src/Dlhis.Permission/Menu/Response/MenuResponse.cs
Normal file
81
Src/Dlhis.Permission/Menu/Response/MenuResponse.cs
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
using Dlhis.Entity.Permission.Enums;
|
||||||
|
|
||||||
|
namespace Dlhis.Permission.Menu.Response;
|
||||||
|
|
||||||
|
public class MenuResponse
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// code
|
||||||
|
/// </summary>
|
||||||
|
public string Code { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 上级
|
||||||
|
/// </summary>
|
||||||
|
public string PCode { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 标题
|
||||||
|
/// </summary>
|
||||||
|
public string Title { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Name
|
||||||
|
/// </summary>
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 图标
|
||||||
|
/// </summary>
|
||||||
|
public string Icon { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 路由地址
|
||||||
|
/// </summary>
|
||||||
|
public string Route { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 序号
|
||||||
|
/// </summary>
|
||||||
|
public int Sequence { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 菜单类型
|
||||||
|
/// </summary>
|
||||||
|
public MenuEnumType MenuType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否外链
|
||||||
|
/// </summary>
|
||||||
|
public bool IsLink { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 权限标识
|
||||||
|
/// </summary>
|
||||||
|
public string Permission { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否可见
|
||||||
|
/// </summary>
|
||||||
|
public bool Visible { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 平台
|
||||||
|
/// </summary>
|
||||||
|
public PlatformEnumType Platform { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 手机端才会有
|
||||||
|
/// </summary>
|
||||||
|
public List<string> HotelIds { get; set; } = new List<string>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 子菜单
|
||||||
|
/// </summary>
|
||||||
|
public List<MenuResponse> Items { get; set; }
|
||||||
|
}
|
||||||
24
Src/Dlhis.Permission/Menu/Services/IMenuService.cs
Normal file
24
Src/Dlhis.Permission/Menu/Services/IMenuService.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
using Dlhis.Entity.Permission.Enums;
|
||||||
|
using Dlhis.Permission.Menu.Request;
|
||||||
|
using Dlhis.Permission.Menu.Response;
|
||||||
|
|
||||||
|
namespace Dlhis.Permission.Menu.Services;
|
||||||
|
|
||||||
|
public interface IMenuService
|
||||||
|
{
|
||||||
|
Task<List<MenuResponse>> GetListAsync(PlatformEnumType platform);
|
||||||
|
|
||||||
|
Task SaveMenuAsync(SaveMenuRequest request);
|
||||||
|
|
||||||
|
Task AssignmentAsync(MenuPermissionAssignmentRequest request);
|
||||||
|
|
||||||
|
Task<List<string>> GetAssignmentCodesAsync(MenuPermissionTypeEnumType permissionType, string uniqueData);
|
||||||
|
|
||||||
|
Task<List<string>> GetAllAssignmentPermissionsAsync();
|
||||||
|
|
||||||
|
Task<List<MenuResponse>> GetCurrentMenusAsync();
|
||||||
|
|
||||||
|
Task<bool> IsPass(IEnumerable<string> p);
|
||||||
|
|
||||||
|
Task ResetAsync(List<SaveMenuRequest> request);
|
||||||
|
}
|
||||||
191
Src/Dlhis.Permission/Menu/Services/Implements/MenuService.cs
Normal file
191
Src/Dlhis.Permission/Menu/Services/Implements/MenuService.cs
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
using Dlhis.Entity.Permission.Entities;
|
||||||
|
using Dlhis.Entity.Permission.Enums;
|
||||||
|
using Dlhis.Permission.Menu.Request;
|
||||||
|
using Dlhis.Permission.Menu.Response;
|
||||||
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
|
using Kurisu.Core.User.Abstractions;
|
||||||
|
using Kurisu.SqlSugar.Services;
|
||||||
|
using Mapster;
|
||||||
|
|
||||||
|
namespace Dlhis.Permission.Menu.Services.Implements;
|
||||||
|
|
||||||
|
public class MenuService : IMenuService
|
||||||
|
{
|
||||||
|
private readonly IDbContext _dbContext;
|
||||||
|
private readonly ICurrentUser _currentUser;
|
||||||
|
|
||||||
|
public MenuService(IDbContext dbContext, ICurrentUser currentUser)
|
||||||
|
{
|
||||||
|
_dbContext = dbContext;
|
||||||
|
_currentUser = currentUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<MenuResponse>> GetListAsync(PlatformEnumType platform)
|
||||||
|
{
|
||||||
|
var result = await _dbContext.Queryable<MenuEntity>()
|
||||||
|
.Where(x => x.Platform == platform)
|
||||||
|
.OrderBy(x => x.Sequence)
|
||||||
|
.Select<MenuResponse>()
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
var top = result.Where(x => x.PCode.IsEmpty()).ToList();
|
||||||
|
foreach (var menu in top)
|
||||||
|
{
|
||||||
|
RecursionGetNext(menu, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return top;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SaveMenuAsync(SaveMenuRequest request)
|
||||||
|
{
|
||||||
|
await CheckAsync(request);
|
||||||
|
|
||||||
|
if (!request.Id.HasValue)
|
||||||
|
{
|
||||||
|
var entity = request.Adapt<MenuEntity>();
|
||||||
|
await _dbContext.InsertAsync(entity);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var entity = await _dbContext.Queryable<MenuEntity>().Where(x => x.Id == request.Id).FirstAsync();
|
||||||
|
await ChangeIfCodeEditAsync(entity.Code, request.Code);
|
||||||
|
|
||||||
|
request.Adapt(entity);
|
||||||
|
|
||||||
|
await _dbContext.UpdateAsync(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private async Task ChangeIfCodeEditAsync(string beforeCode, string pcode)
|
||||||
|
{
|
||||||
|
if (beforeCode != pcode)
|
||||||
|
{
|
||||||
|
//修改下级的PCode为当前的code
|
||||||
|
var menus = await _dbContext.Queryable<MenuEntity>().Where(x => x.PCode == beforeCode).ToListAsync();
|
||||||
|
menus.ForEach(x =>
|
||||||
|
{
|
||||||
|
x.PCode = pcode;
|
||||||
|
});
|
||||||
|
|
||||||
|
//修改权限code为当前的code,避免权限丢失
|
||||||
|
var permissions = await _dbContext.Queryable<MenuPermissionEntity>().Where(x => x.Code == beforeCode).ToListAsync();
|
||||||
|
permissions.ForEach(x =>
|
||||||
|
{
|
||||||
|
x.Code = pcode;
|
||||||
|
});
|
||||||
|
|
||||||
|
await _dbContext.UpdateAsync(menus);
|
||||||
|
await _dbContext.UpdateAsync(permissions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task AssignmentAsync(MenuPermissionAssignmentRequest request)
|
||||||
|
{
|
||||||
|
(request.UniqueType == MenuPermissionTypeEnumType.Role).ThrowIfTrue("暂不支持角色分配");
|
||||||
|
|
||||||
|
//清空覆盖
|
||||||
|
var permissionsToDelete = await _dbContext.Queryable<MenuPermissionEntity>()
|
||||||
|
.Where(x => x.UniqueType == request.UniqueType)
|
||||||
|
.Where(x => x.UniqueValue == request.UniqueValue)
|
||||||
|
.ToListAsync();
|
||||||
|
//触发日志记录
|
||||||
|
await _dbContext.DeleteAsync(permissionsToDelete);
|
||||||
|
|
||||||
|
var permissions = request.Codes.Select(x => new MenuPermissionEntity
|
||||||
|
{
|
||||||
|
Code = x,
|
||||||
|
UniqueType = request.UniqueType,
|
||||||
|
UniqueValue = request.UniqueValue
|
||||||
|
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
|
||||||
|
await _dbContext.InsertAsync(permissions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<List<string>> GetAssignmentCodesAsync(MenuPermissionTypeEnumType permissionType, string uniqueData)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<List<string>> GetAllAssignmentPermissionsAsync()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<List<MenuResponse>> GetCurrentMenusAsync()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<bool> IsPass(IEnumerable<string> p)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task ResetAsync(List<SaveMenuRequest> request)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void RecursionGetNext(MenuResponse current, List<MenuResponse> menus)
|
||||||
|
{
|
||||||
|
var nextMenus = menus.Where(x => x.PCode == current.Code).ToList();
|
||||||
|
current.Items = nextMenus;
|
||||||
|
foreach (var menu in nextMenus)
|
||||||
|
{
|
||||||
|
RecursionGetNext(menu, menus);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task CheckAsync(SaveMenuRequest request)
|
||||||
|
{
|
||||||
|
//检查重复code
|
||||||
|
var exists = await _dbContext.Queryable<MenuEntity>()
|
||||||
|
.Where(x => x.Code == request.Code)
|
||||||
|
.WhereIF(request.Id.HasValue, x => x.Id != request.Id).AnyAsync();
|
||||||
|
exists.ThrowIfTrue($"{request.Title}存在重复code");
|
||||||
|
|
||||||
|
//检查name
|
||||||
|
exists = await _dbContext.Queryable<MenuEntity>()
|
||||||
|
.Where(x => x.Name == request.Name)
|
||||||
|
.WhereIF(request.Id.HasValue, x => x.Id != request.Id).AnyAsync();
|
||||||
|
exists.ThrowIfTrue($"{request.Title}存在重复name");
|
||||||
|
|
||||||
|
//判断权限重复
|
||||||
|
if (request.Permission.IsPresent())
|
||||||
|
{
|
||||||
|
exists = await _dbContext.Queryable<MenuEntity>()
|
||||||
|
.Where(x => x.Permission == request.Permission && (request.MenuType == MenuEnumType.Menu || request.MenuType == MenuEnumType.Button))
|
||||||
|
.WhereIF(request.Id.HasValue, x => x.Id != request.Id).AnyAsync();
|
||||||
|
exists.ThrowIfTrue($"{request.Title}存在重复权限标识");
|
||||||
|
}
|
||||||
|
|
||||||
|
//request.PCode
|
||||||
|
var menu = await _dbContext.Queryable<MenuEntity>().Where(x => x.Code == request.PCode).FirstAsync();
|
||||||
|
(menu == null && request.MenuType != MenuEnumType.Folder).ThrowIfTrue($"{request.Title}上级不存在");
|
||||||
|
|
||||||
|
if (request.MenuType == MenuEnumType.Folder)
|
||||||
|
{
|
||||||
|
request.PCode = null;
|
||||||
|
}
|
||||||
|
else if (request.MenuType == MenuEnumType.Menu)
|
||||||
|
{
|
||||||
|
if (menu.MenuType != MenuEnumType.Folder)
|
||||||
|
{
|
||||||
|
throw new Exception($"{request.Title}菜单上级需要为目录");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//button
|
||||||
|
if (menu.MenuType != MenuEnumType.Menu)
|
||||||
|
{
|
||||||
|
throw new Exception($"{request.Title}按钮上级需要为菜单");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Kurisu.AspNetCore" Version="0.4.3" />
|
<PackageReference Include="Kurisu.AspNetCore" Version="0.4.5" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Reference in New Issue
Block a user