diff --git a/Dlhis.Jinko.Face.sln b/Dlhis.Jinko.Face.sln
index ff1fecaa..0f893f5a 100644
--- a/Dlhis.Jinko.Face.sln
+++ b/Dlhis.Jinko.Face.sln
@@ -29,7 +29,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dlhis.Canteen", "Src\Dlhis.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dlhis.Sys.Api", "Src\Dlhis.Sys.Api\Dlhis.Sys.Api.csproj", "{85A345C7-913E-4C1B-BE1C-600DE408A02F}"
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
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
diff --git a/Src/Dlhis.Basic/Device/Request/DeviceGroupSaveRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceGroupSaveRequest.cs
index f16286ff..73bf5281 100644
--- a/Src/Dlhis.Basic/Device/Request/DeviceGroupSaveRequest.cs
+++ b/Src/Dlhis.Basic/Device/Request/DeviceGroupSaveRequest.cs
@@ -10,7 +10,7 @@ public class DeviceGroupSaveRequest
///
/// 上级分组
///
- public Guid? PCode { get; set; }
+ public Guid PCode { get; set; }
///
/// 设备组名称
diff --git a/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs b/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs
index 24e19c85..a1e7456a 100644
--- a/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs
+++ b/Src/Dlhis.Basic/Device/Response/DeviceGroupTreeResponse.cs
@@ -1,5 +1,6 @@
using Dlhis.Entity.Device.Enums;
using Kurisu.AspNetCore.Utils.Extensions;
+using Microsoft.AspNetCore.Server.IISIntegration;
using Newtonsoft.Json;
namespace Dlhis.Basic.Device.Response;
@@ -50,6 +51,15 @@ public class DeviceGroupTreeResponse
}
}
+ public bool Editable { get; set; }
+
+ public bool IsDefault { get; set; }
+
+ ///
+ /// 是否允许设置下级
+ ///
+ public bool AbleSetNext => IsDefault;
+
[JsonIgnore]
public string TenantId { get; set; }
diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs
index 361d6289..23cc9137 100644
--- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs
+++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs
@@ -3,7 +3,6 @@ using Dlhis.Basic.Device.Response;
using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Device.Entities;
using Dlhis.Entity.Device.Enums;
-using Kurisu.AspNetCore.UnifyResultAndValidation;
using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.Core.User.Abstractions;
using Kurisu.SqlSugar.Services;
@@ -46,19 +45,13 @@ public class DeviceGroupService : IDeviceGroupService
//检查父级节点
await CheckPCodeExistsDeviceAsync(request.PCode);
+ var pGrp = await _dbContext.Queryable().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.PCode.HasValue)
- {
- var pGrp = await _dbContext.Queryable().Where(x => x.Code == request.PCode).FirstAsync();
- if (pGrp != null && pGrp.Type != request.Type)
- {
- throw new UserFriendlyException("分组类型必须与上级类型保持一致");
- }
- }
-
var entity = request.Adapt();
- entity.Editable = true;
entity.Code = Guid.NewGuid();
await _dbContext.InsertAsync(entity);
@@ -69,31 +62,18 @@ public class DeviceGroupService : IDeviceGroupService
entity.ThrowIfNull("设备组不存在,无法更新");
entity.Editable.ThrowIfFalse("不可编辑当前组");
- if (entity.PCode.HasValue)
+ if (request.Type != entity.Type)
{
- var pGrp = await _dbContext.Queryable().Where(x => x.Code == request.PCode).FirstAsync();
- if (pGrp != null && pGrp.Type != request.Type)
- {
- throw new UserFriendlyException("分组类型必须与上级类型保持一致");
- }
- }
- else
- {
- var nGrp = await _dbContext.Queryable().Where(x => x.PCode == entity.Code).FirstAsync();
- if (nGrp != null && nGrp.Type != request.Type)
- {
- throw new UserFriendlyException("存在下级分组类型不一致,无法修改");
- }
- }
+ //检查下级分组type不一致
+ var existsDiffNextGroups = await _dbContext.Queryable()
+ .Where(x => x.PCode == entity.Code)
+ .Where(x => x.Type != request.Type)
+ .AnyAsync();
- var nextDevices = await GetDevicesAsync(entity.Code);
- if (!entity.Type.HasValue)
- {
- (request.Type.HasValue && nextDevices.Any(x => x.Type != request.Type)).ThrowIfTrue($"分组设备存在非{request.Type.Value.GetDescription()}类型的设备设备");
- }
- else
- {
- (request.Type.HasValue && request.Type != entity.Type && nextDevices.Any()).ThrowIfTrue("分组设备类型不匹配,无法修改类型");
+ existsDiffNextGroups.ThrowIfTrue("存在下级分组类型不一致,无法修改");
+
+ var nextDevices = await GetDevicesAsync(entity.Code);
+ nextDevices.Any(x => x.Type != request.Type).ThrowIfTrue("分组设备类型不匹配,无法修改类型");
}
request.Adapt(entity);
@@ -185,10 +165,7 @@ public class DeviceGroupService : IDeviceGroupService
{
var devices = await _dbContext.Queryable().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();
diff --git a/Src/Dlhis.Basic/Organization/Response/GainfoGroupTreeResponse.cs b/Src/Dlhis.Basic/Organization/Response/GainfoGroupTreeResponse.cs
index b9219035..5b5000fd 100644
--- a/Src/Dlhis.Basic/Organization/Response/GainfoGroupTreeResponse.cs
+++ b/Src/Dlhis.Basic/Organization/Response/GainfoGroupTreeResponse.cs
@@ -24,10 +24,20 @@ public class GainfoGroupTreeResponse
public string Remark { get; set; }
///
- /// 是否编辑
+ /// 是否可编辑
///
public bool Editable { get; set; }
+ ///
+ /// 是否为业务默认分组
+ ///
+ public bool IsDefault { get; set; }
+
+ ///
+ /// 是否允许设置下级
+ ///
+ public bool AbleSetNext => IsDefault;
+
[JsonIgnore]
public string TenantId { get; set; }
diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs
index 82c91486..ea35ff11 100644
--- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs
+++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoGroupService.cs
@@ -59,14 +59,12 @@ public class GainfoGroupService : IGainfoGroupService
{
var entity = request.Adapt();
entity.Code = Guid.NewGuid();
- entity.Editable = true;
await _dbContext.InsertAsync(entity);
}
else
{
var entity = await _dbContext.Queryable().Where(x => x.Id == request.Id).SingleAsync();
request.Adapt(entity);
- entity.Editable = true;
await _dbContext.UpdateAsync(entity);
}
}
diff --git a/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs b/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs
index 9b551fbe..a56c8c97 100644
--- a/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs
+++ b/Src/Dlhis.Entity/Device/Entities/DeviceGroupEntity.cs
@@ -15,8 +15,8 @@ public class DeviceGroupEntity : SugarBaseEntity, ITenantId, ISoftDeleted
///
/// 设备组功能类型
///
- [SugarColumn(IsNullable = true, ColumnDescription = "设备组功能类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))]
- public DeviceTypeEnumType? Type { get; set; }
+ [SugarColumn(IsNullable = false, ColumnDescription = "设备组功能类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))]
+ public DeviceTypeEnumType Type { get; set; }
///
/// 上级设备组code
@@ -40,9 +40,15 @@ public class DeviceGroupEntity : SugarBaseEntity, ITenantId, ISoftDeleted
///
/// 是否可编辑
///
- [SugarColumn(ColumnDescription = "是否可编辑")]
+ [SugarColumn(ColumnDataType = "bit", DefaultValue = "1", ColumnDescription = "是否可编辑")]
public bool Editable { get; set; }
+ ///
+ /// 可设置下级
+ ///
+ [SugarColumn(ColumnDataType = "bit", DefaultValue = "1")]
+ public bool AbleSetNext { get; set; }
+
///
/// 备注
///
diff --git a/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs b/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs
index 553f4138..9daadce1 100644
--- a/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs
+++ b/Src/Dlhis.ScheduledTask/CommonJobs/CreateDefinitelyGroupJob.cs
@@ -106,6 +106,7 @@ public class CreateDefinitelyGroupJob
Type = type,
Name = grp,
Editable = false,
+ AbleSetNext = false,
Remark = _remark,
CreatedBy = 1,
@@ -130,6 +131,7 @@ public class CreateDefinitelyGroupJob
Type = type,
Name = workplaceName,
Editable = false,
+ AbleSetNext = false,
Remark = _remark,
CreatedBy = 1,
@@ -153,6 +155,7 @@ public class CreateDefinitelyGroupJob
Type = type,
Name = factoryName,
Editable = false,
+ AbleSetNext = true,
Remark = _remark,
CreatedBy = 1,