fix 处理设备分组优化

This commit is contained in:
2024-08-16 14:48:26 +08:00
parent e850af7d80
commit 8ae685cafb
5 changed files with 17 additions and 12 deletions

View File

@@ -1,3 +1,4 @@
using Dlhis.DataPermission.Model;
using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Device.Entities;
using Dlhis.Entity.Sys.Entities;
@@ -52,19 +53,23 @@ public class GetDataPermissionService : IGetDataPermissions, ISingletonDependenc
//先计算分组权限下的设备
var deviceGroupCodes = userDataPermissions.Where(x => x.UniqueType == DeviceAssignmentTypeEnumType.Group).Select(x => x.UniqueValue).ToList();
if (deviceGroupCodes.Any() && deviceCodeProperty != null)
if (deviceGroupCodes.Any())
{
var data = db.Queryable<DeviceGroupEntity>().ToList();
//开始递归处理
var tops = data.Where(x => !x.PCode.HasValue).ToList();
tops.ForEach(x => { DeviceGroupRecursionGetNext(x, data, deviceGroupCodes, deviceGroupCodes.Contains(x.Code)); });
deviceGroupCodes = deviceGroupCodes.Distinct().ToList();
deviceCodes = db.Queryable<DeviceGroupRelationshipEntity>().Where(x => deviceGroupCodes.Contains(x.GroupCode)).Select(x => x.DeviceCode).ToList();
}
if (deviceGroupCodeProperty != null && deviceGroupCodes.Any())
{
dict.Add(deviceGroupCodeProperty.Name, deviceGroupCodes);
if (deviceCodeProperty != null)
{
deviceCodes = db.Queryable<DeviceGroupRelationshipEntity>().Where(x => deviceGroupCodes.Contains(x.GroupCode)).Select(x => x.DeviceCode).ToList();
}
if (deviceGroupCodeProperty != null)
{
dict.Add(deviceGroupCodeProperty.Name, deviceGroupCodes);
}
}
if (deviceCodeProperty != null)

View File

@@ -43,11 +43,12 @@ public class DeviceGroupService : IDeviceGroupService
.Select<DeviceGroupTreeResponse>()
.ToListAsync();
var others = await _dbContext.Queryable<DeviceGroupEntity>()
var others = await _dbContext.Client.Queryable<DeviceGroupEntity>()
.Where(x => x.Type == type)
.Where(x => x.Name == "*共用区域" || x.Name == "*非共用区域" || x.Name == "*通用考勤设备组" || x.Name == "*专用考勤设备组")
.Select<DeviceGroupTreeResponse>()
.ToListAsync();
deviceGroups.AddRange(others);
var tops = deviceGroups.Where(x => !x.PCode.HasValue).ToList();
@@ -167,7 +168,7 @@ public class DeviceGroupService : IDeviceGroupService
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
private async Task<DeviceGroupEntity> CheckPCodeAsync(DeviceGroupSaveRequest request)
private async Task CheckPCodeAsync(DeviceGroupSaveRequest request)
{
var pGrp = await _dbContext.Queryable<DeviceGroupEntity>().Where(x => x.Code == request.PCode).FirstAsync();
if (pGrp != null)
@@ -178,7 +179,6 @@ public class DeviceGroupService : IDeviceGroupService
}
(pGrp != null && pGrp.Type != request.Type).ThrowIfTrue("分组类型必须与上级类型保持一致");
return pGrp;
}
/// <summary>

View File

@@ -1,6 +1,6 @@
using Kurisu.AspNetCore.DataAccess.SqlSugar.Attributes;
namespace Dlhis.Basic.DataPermissions;
namespace Dlhis.DataPermission.Model;
[AttributeUsage(AttributeTargets.Property)]
public class DeviceCodeAttribute : BaseDataPermissionAttribute

View File

@@ -1,6 +1,6 @@
using Kurisu.AspNetCore.DataAccess.SqlSugar.Attributes;
namespace Dlhis.Basic.DataPermissions;
namespace Dlhis.DataPermission.Model;
[AttributeUsage(AttributeTargets.Property)]
public class DeviceGroupCodeAttribute : BaseDataPermissionAttribute

View File

@@ -1,4 +1,4 @@
using Dlhis.Basic.DataPermissions;
using Dlhis.DataPermission.Model;
using Dlhis.Entity.Device.Enums;
using Kurisu.AspNetCore.DataAccess.Entity;
using Kurisu.AspNetCore.DataAccess.SqlSugar;