fix 优化分组
This commit is contained in:
@@ -29,7 +29,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dlhis.Canteen", "Src\Dlhis.
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dlhis.Sys.Api", "Src\Dlhis.Sys.Api\Dlhis.Sys.Api.csproj", "{85A345C7-913E-4C1B-BE1C-600DE408A02F}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dlhis.Sys.Api", "Src\Dlhis.Sys.Api\Dlhis.Sys.Api.csproj", "{85A345C7-913E-4C1B-BE1C-600DE408A02F}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dlhis.Basic.Api", "Src\Dlhis.Basic.Api\Dlhis.Basic.Api.csproj", "{1F337648-8A22-4601-A842-0F634FBA2825}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dlhis.Basic.Api", "Src\Dlhis.Basic.Api\Dlhis.Basic.Api.csproj", "{1F337648-8A22-4601-A842-0F634FBA2825}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public class DeviceGroupSaveRequest
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 上级分组
|
/// 上级分组
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Guid? PCode { get; set; }
|
public Guid PCode { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设备组名称
|
/// 设备组名称
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Dlhis.Entity.Device.Enums;
|
using Dlhis.Entity.Device.Enums;
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
|
using Microsoft.AspNetCore.Server.IISIntegration;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Dlhis.Basic.Device.Response;
|
namespace Dlhis.Basic.Device.Response;
|
||||||
@@ -50,6 +51,15 @@ public class DeviceGroupTreeResponse
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool Editable { get; set; }
|
||||||
|
|
||||||
|
public bool IsDefault { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否允许设置下级
|
||||||
|
/// </summary>
|
||||||
|
public bool AbleSetNext => IsDefault;
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public string TenantId { get; set; }
|
public string TenantId { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using Dlhis.Basic.Device.Response;
|
|||||||
using Dlhis.Entity.Basic.Entity;
|
using Dlhis.Entity.Basic.Entity;
|
||||||
using Dlhis.Entity.Device.Entities;
|
using Dlhis.Entity.Device.Entities;
|
||||||
using Dlhis.Entity.Device.Enums;
|
using Dlhis.Entity.Device.Enums;
|
||||||
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
using Kurisu.Core.User.Abstractions;
|
using Kurisu.Core.User.Abstractions;
|
||||||
using Kurisu.SqlSugar.Services;
|
using Kurisu.SqlSugar.Services;
|
||||||
@@ -46,19 +45,13 @@ public class DeviceGroupService : IDeviceGroupService
|
|||||||
//检查父级节点
|
//检查父级节点
|
||||||
await CheckPCodeExistsDeviceAsync(request.PCode);
|
await CheckPCodeExistsDeviceAsync(request.PCode);
|
||||||
|
|
||||||
|
var pGrp = await _dbContext.Queryable<DeviceGroupEntity>().Where(x => x.Code == request.PCode).FirstAsync();
|
||||||
|
pGrp.AbleSetNext.ThrowIfFalse($"分组{pGrp.Name}不可添加下级");
|
||||||
|
(pGrp != null && pGrp.Type != request.Type).ThrowIfTrue("分组类型必须与上级类型保持一致");
|
||||||
|
|
||||||
if (!request.Id.HasValue)
|
if (!request.Id.HasValue)
|
||||||
{
|
{
|
||||||
if (request.PCode.HasValue)
|
|
||||||
{
|
|
||||||
var pGrp = await _dbContext.Queryable<DeviceGroupEntity>().Where(x => x.Code == request.PCode).FirstAsync();
|
|
||||||
if (pGrp != null && pGrp.Type != request.Type)
|
|
||||||
{
|
|
||||||
throw new UserFriendlyException("分组类型必须与上级类型保持一致");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var entity = request.Adapt<DeviceGroupEntity>();
|
var entity = request.Adapt<DeviceGroupEntity>();
|
||||||
entity.Editable = true;
|
|
||||||
entity.Code = Guid.NewGuid();
|
entity.Code = Guid.NewGuid();
|
||||||
|
|
||||||
await _dbContext.InsertAsync(entity);
|
await _dbContext.InsertAsync(entity);
|
||||||
@@ -69,31 +62,18 @@ public class DeviceGroupService : IDeviceGroupService
|
|||||||
entity.ThrowIfNull("设备组不存在,无法更新");
|
entity.ThrowIfNull("设备组不存在,无法更新");
|
||||||
entity.Editable.ThrowIfFalse("不可编辑当前组");
|
entity.Editable.ThrowIfFalse("不可编辑当前组");
|
||||||
|
|
||||||
if (entity.PCode.HasValue)
|
if (request.Type != entity.Type)
|
||||||
{
|
{
|
||||||
var pGrp = await _dbContext.Queryable<DeviceGroupEntity>().Where(x => x.Code == request.PCode).FirstAsync();
|
//检查下级分组type不一致
|
||||||
if (pGrp != null && pGrp.Type != request.Type)
|
var existsDiffNextGroups = await _dbContext.Queryable<DeviceGroupEntity>()
|
||||||
{
|
.Where(x => x.PCode == entity.Code)
|
||||||
throw new UserFriendlyException("分组类型必须与上级类型保持一致");
|
.Where(x => x.Type != request.Type)
|
||||||
}
|
.AnyAsync();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var nGrp = await _dbContext.Queryable<DeviceGroupEntity>().Where(x => x.PCode == entity.Code).FirstAsync();
|
|
||||||
if (nGrp != null && nGrp.Type != request.Type)
|
|
||||||
{
|
|
||||||
throw new UserFriendlyException("存在下级分组类型不一致,无法修改");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var nextDevices = await GetDevicesAsync(entity.Code);
|
existsDiffNextGroups.ThrowIfTrue("存在下级分组类型不一致,无法修改");
|
||||||
if (!entity.Type.HasValue)
|
|
||||||
{
|
var nextDevices = await GetDevicesAsync(entity.Code);
|
||||||
(request.Type.HasValue && nextDevices.Any(x => x.Type != request.Type)).ThrowIfTrue($"分组设备存在非{request.Type.Value.GetDescription()}类型的设备设备");
|
nextDevices.Any(x => x.Type != request.Type).ThrowIfTrue("分组设备类型不匹配,无法修改类型");
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
(request.Type.HasValue && request.Type != entity.Type && nextDevices.Any()).ThrowIfTrue("分组设备类型不匹配,无法修改类型");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
request.Adapt(entity);
|
request.Adapt(entity);
|
||||||
@@ -185,10 +165,7 @@ public class DeviceGroupService : IDeviceGroupService
|
|||||||
{
|
{
|
||||||
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => request.DeviceCodes.Contains(x.Code)).ToListAsync();
|
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => request.DeviceCodes.Contains(x.Code)).ToListAsync();
|
||||||
//检查分组的分类控制
|
//检查分组的分类控制
|
||||||
if (group.Type.HasValue)
|
devices.Any(x => x.Type != group.Type).ThrowIfTrue("存在设备类型有误,无法分配到当前分组");
|
||||||
{
|
|
||||||
devices.Any(x => x.Type != group.Type).ThrowIfTrue("存在设备类型有误,无法分配到当前分组");
|
|
||||||
}
|
|
||||||
|
|
||||||
//重新赋值到请求参数中
|
//重新赋值到请求参数中
|
||||||
request.DeviceCodes = devices.Select(x => x.Code).ToList();
|
request.DeviceCodes = devices.Select(x => x.Code).ToList();
|
||||||
|
|||||||
@@ -24,10 +24,20 @@ public class GainfoGroupTreeResponse
|
|||||||
public string Remark { get; set; }
|
public string Remark { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否编辑
|
/// 是否可编辑
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Editable { get; set; }
|
public bool Editable { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否为业务默认分组
|
||||||
|
/// </summary>
|
||||||
|
public bool IsDefault { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否允许设置下级
|
||||||
|
/// </summary>
|
||||||
|
public bool AbleSetNext => IsDefault;
|
||||||
|
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public string TenantId { get; set; }
|
public string TenantId { get; set; }
|
||||||
|
|||||||
@@ -59,14 +59,12 @@ public class GainfoGroupService : IGainfoGroupService
|
|||||||
{
|
{
|
||||||
var entity = request.Adapt<GainfoGroupEntity>();
|
var entity = request.Adapt<GainfoGroupEntity>();
|
||||||
entity.Code = Guid.NewGuid();
|
entity.Code = Guid.NewGuid();
|
||||||
entity.Editable = true;
|
|
||||||
await _dbContext.InsertAsync(entity);
|
await _dbContext.InsertAsync(entity);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var entity = await _dbContext.Queryable<GainfoGroupEntity>().Where(x => x.Id == request.Id).SingleAsync();
|
var entity = await _dbContext.Queryable<GainfoGroupEntity>().Where(x => x.Id == request.Id).SingleAsync();
|
||||||
request.Adapt(entity);
|
request.Adapt(entity);
|
||||||
entity.Editable = true;
|
|
||||||
await _dbContext.UpdateAsync(entity);
|
await _dbContext.UpdateAsync(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ public class DeviceGroupEntity : SugarBaseEntity, ITenantId, ISoftDeleted
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设备组功能类型
|
/// 设备组功能类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(IsNullable = true, ColumnDescription = "设备组功能类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))]
|
[SugarColumn(IsNullable = false, ColumnDescription = "设备组功能类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))]
|
||||||
public DeviceTypeEnumType? Type { get; set; }
|
public DeviceTypeEnumType Type { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 上级设备组code
|
/// 上级设备组code
|
||||||
@@ -40,9 +40,15 @@ public class DeviceGroupEntity : SugarBaseEntity, ITenantId, ISoftDeleted
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否可编辑
|
/// 是否可编辑
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnDescription = "是否可编辑")]
|
[SugarColumn(ColumnDataType = "bit", DefaultValue = "1", ColumnDescription = "是否可编辑")]
|
||||||
public bool Editable { get; set; }
|
public bool Editable { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 可设置下级
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnDataType = "bit", DefaultValue = "1")]
|
||||||
|
public bool AbleSetNext { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 备注
|
/// 备注
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ public class CreateDefinitelyGroupJob
|
|||||||
Type = type,
|
Type = type,
|
||||||
Name = grp,
|
Name = grp,
|
||||||
Editable = false,
|
Editable = false,
|
||||||
|
AbleSetNext = false,
|
||||||
Remark = _remark,
|
Remark = _remark,
|
||||||
|
|
||||||
CreatedBy = 1,
|
CreatedBy = 1,
|
||||||
@@ -130,6 +131,7 @@ public class CreateDefinitelyGroupJob
|
|||||||
Type = type,
|
Type = type,
|
||||||
Name = workplaceName,
|
Name = workplaceName,
|
||||||
Editable = false,
|
Editable = false,
|
||||||
|
AbleSetNext = false,
|
||||||
Remark = _remark,
|
Remark = _remark,
|
||||||
|
|
||||||
CreatedBy = 1,
|
CreatedBy = 1,
|
||||||
@@ -153,6 +155,7 @@ public class CreateDefinitelyGroupJob
|
|||||||
Type = type,
|
Type = type,
|
||||||
Name = factoryName,
|
Name = factoryName,
|
||||||
Editable = false,
|
Editable = false,
|
||||||
|
AbleSetNext = true,
|
||||||
Remark = _remark,
|
Remark = _remark,
|
||||||
|
|
||||||
CreatedBy = 1,
|
CreatedBy = 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user