From 1ddebd466682d2146f735392f04caaa42a0a3e96 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 23 Feb 2024 20:46:38 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E8=AE=BE=E5=A4=87=E5=88=86=E7=BB=84?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E9=80=BB=E8=BE=91=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implements/DeviceGroupService.cs | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs index 7f1e5345..7ffdc0d4 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceGroupService.cs @@ -3,9 +3,9 @@ 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.DataAccess.Dto; -using Kurisu.SqlSugar.Attributes; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; using Mapster; @@ -55,6 +55,15 @@ public class DeviceGroupService : IDeviceGroupService 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(); @@ -67,6 +76,23 @@ public class DeviceGroupService : IDeviceGroupService entity.ThrowIfNull("设备组不存在,无法更新"); entity.Editable.ThrowIfFalse("不可编辑当前组"); + if (entity.PCode.HasValue) + { + 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("存在下级分组类型不一致,无法修改"); + } + } + var nextDevices = await GetDevicesAsync(entity.Code); if (!entity.Type.HasValue) {