fix 处理设备分组优化
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using Dlhis.DataPermission.Model;
|
||||||
using Dlhis.Entity.Basic.Entity;
|
using Dlhis.Entity.Basic.Entity;
|
||||||
using Dlhis.Entity.Device.Entities;
|
using Dlhis.Entity.Device.Entities;
|
||||||
using Dlhis.Entity.Sys.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();
|
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 data = db.Queryable<DeviceGroupEntity>().ToList();
|
||||||
//开始递归处理
|
//开始递归处理
|
||||||
var tops = data.Where(x => !x.PCode.HasValue).ToList();
|
var tops = data.Where(x => !x.PCode.HasValue).ToList();
|
||||||
tops.ForEach(x => { DeviceGroupRecursionGetNext(x, data, deviceGroupCodes, deviceGroupCodes.Contains(x.Code)); });
|
tops.ForEach(x => { DeviceGroupRecursionGetNext(x, data, deviceGroupCodes, deviceGroupCodes.Contains(x.Code)); });
|
||||||
deviceGroupCodes = deviceGroupCodes.Distinct().ToList();
|
deviceGroupCodes = deviceGroupCodes.Distinct().ToList();
|
||||||
deviceCodes = db.Queryable<DeviceGroupRelationshipEntity>().Where(x => deviceGroupCodes.Contains(x.GroupCode)).Select(x => x.DeviceCode).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (deviceGroupCodeProperty != null && deviceGroupCodes.Any())
|
if (deviceCodeProperty != null)
|
||||||
{
|
{
|
||||||
dict.Add(deviceGroupCodeProperty.Name, deviceGroupCodes);
|
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)
|
if (deviceCodeProperty != null)
|
||||||
|
|||||||
@@ -43,11 +43,12 @@ public class DeviceGroupService : IDeviceGroupService
|
|||||||
.Select<DeviceGroupTreeResponse>()
|
.Select<DeviceGroupTreeResponse>()
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
var others = await _dbContext.Queryable<DeviceGroupEntity>()
|
var others = await _dbContext.Client.Queryable<DeviceGroupEntity>()
|
||||||
.Where(x => x.Type == type)
|
.Where(x => x.Type == type)
|
||||||
.Where(x => x.Name == "*共用区域" || x.Name == "*非共用区域" || x.Name == "*通用考勤设备组" || x.Name == "*专用考勤设备组")
|
.Where(x => x.Name == "*共用区域" || x.Name == "*非共用区域" || x.Name == "*通用考勤设备组" || x.Name == "*专用考勤设备组")
|
||||||
.Select<DeviceGroupTreeResponse>()
|
.Select<DeviceGroupTreeResponse>()
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
deviceGroups.AddRange(others);
|
deviceGroups.AddRange(others);
|
||||||
|
|
||||||
var tops = deviceGroups.Where(x => !x.PCode.HasValue).ToList();
|
var tops = deviceGroups.Where(x => !x.PCode.HasValue).ToList();
|
||||||
@@ -167,7 +168,7 @@ public class DeviceGroupService : IDeviceGroupService
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <returns></returns>
|
/// <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();
|
var pGrp = await _dbContext.Queryable<DeviceGroupEntity>().Where(x => x.Code == request.PCode).FirstAsync();
|
||||||
if (pGrp != null)
|
if (pGrp != null)
|
||||||
@@ -178,7 +179,6 @@ public class DeviceGroupService : IDeviceGroupService
|
|||||||
}
|
}
|
||||||
|
|
||||||
(pGrp != null && pGrp.Type != request.Type).ThrowIfTrue("分组类型必须与上级类型保持一致");
|
(pGrp != null && pGrp.Type != request.Type).ThrowIfTrue("分组类型必须与上级类型保持一致");
|
||||||
return pGrp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Attributes;
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Attributes;
|
||||||
|
|
||||||
namespace Dlhis.Basic.DataPermissions;
|
namespace Dlhis.DataPermission.Model;
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Property)]
|
[AttributeUsage(AttributeTargets.Property)]
|
||||||
public class DeviceCodeAttribute : BaseDataPermissionAttribute
|
public class DeviceCodeAttribute : BaseDataPermissionAttribute
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Attributes;
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Attributes;
|
||||||
|
|
||||||
namespace Dlhis.Basic.DataPermissions;
|
namespace Dlhis.DataPermission.Model;
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Property)]
|
[AttributeUsage(AttributeTargets.Property)]
|
||||||
public class DeviceGroupCodeAttribute : BaseDataPermissionAttribute
|
public class DeviceGroupCodeAttribute : BaseDataPermissionAttribute
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Dlhis.Basic.DataPermissions;
|
using Dlhis.DataPermission.Model;
|
||||||
using Dlhis.Entity.Device.Enums;
|
using Dlhis.Entity.Device.Enums;
|
||||||
using Kurisu.AspNetCore.DataAccess.Entity;
|
using Kurisu.AspNetCore.DataAccess.Entity;
|
||||||
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
||||||
|
|||||||
Reference in New Issue
Block a user