fix 优化分组
This commit is contained in:
@@ -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<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.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>();
|
||||
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<DeviceGroupEntity>().Where(x => x.Code == request.PCode).FirstAsync();
|
||||
if (pGrp != null && pGrp.Type != request.Type)
|
||||
{
|
||||
throw new UserFriendlyException("分组类型必须与上级类型保持一致");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var nGrp = await _dbContext.Queryable<DeviceGroupEntity>().Where(x => x.PCode == entity.Code).FirstAsync();
|
||||
if (nGrp != null && nGrp.Type != request.Type)
|
||||
{
|
||||
throw new UserFriendlyException("存在下级分组类型不一致,无法修改");
|
||||
}
|
||||
}
|
||||
//检查下级分组type不一致
|
||||
var existsDiffNextGroups = await _dbContext.Queryable<DeviceGroupEntity>()
|
||||
.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<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();
|
||||
|
||||
Reference in New Issue
Block a user