fix 根据档案号,设备组查询设备

This commit is contained in:
2024-03-11 18:04:00 +08:00
parent 90e5728fd3
commit 59122c408f
3 changed files with 37 additions and 38 deletions

View File

@@ -3,9 +3,6 @@ using Dlhis.Basic.Organization.Response;
using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Device.Entities;
using Dlhis.Entity.Device.Enums;
using Dlhis.Entity.Sys.Entities;
using Dlhis.Entity.Sys.Enums;
using Dm.filter.rw;
using Kurisu.SqlSugar.Services;
namespace Dlhis.Basic.Organization.Services.Implements;
@@ -52,48 +49,46 @@ public class GainfoPermissions : IGainfoPermissions
.ToListAsync();
}
public async Task GetDevicesUnderGroupByUserNoAsync(string userNo, string deviceGroupCode)
{;
public async Task<List<KeyValue<string>>> GetDevicesUnderGroupByUserNoAsync(string userNo, string deviceGroupCode)
{
var deviceGroups = await _dbContext.Queryable<DeviceGroupEntity>().ToListAsync();
var currentGroup = deviceGroups.Where(x => x.Code.ToString() == deviceGroupCode).First();
var groups = new List<Guid>();
if(!currentGroup.PCode.HasValue)
{
RecursionGetNext(currentGroup, deviceGroups, groups);
}
else
{
groups.Add((Guid)currentGroup.PCode);
}
var groups = RecursionGetNext(currentGroup, deviceGroups).ToList();
var gs = await _dbContext.Queryable<DevicePermissionEntity>()
.Where(x => groups.Contains(x.UniqueValue))
.Where(x => x.UniqueType == DeviceAssignmentTypeEnumType.Group)
.Where(x => x.AssignType == AssignTypeEnumType.User)
.Where(x => x.AssignValue == userNo)
.Select(x => x.UniqueValue)
.ToListAsync();
//用户所有deviceCode权限
var deviceCodes = await _devicePermissionService.GetAssignDeviceCodesAsync(userNo);
var lst = new List<Guid>();
foreach (var gcode in gs)
var result = await _dbContext.Queryable<DeviceGroupRelationshipEntity>()
.LeftJoin<DeviceEntity>((x, d) => x.DeviceCode == d.Code)
.Where(x => groups.Contains(x.GroupCode))
.Where(x => deviceCodes.Contains(x.DeviceCode))
.Select((x, d) => new { x.DeviceCode, d.DeployPlace })
.Distinct()
.ToListAsync();
return result.Select(x => new KeyValue<string>
{
var devices = await _dbContext.Queryable<DeviceGroupRelationshipEntity>()
.Where(x => x.GroupCode == gcode)
.Select(x => x.DeviceCode)
.ToListAsync();
}
Key = x.DeviceCode.ToString(),
Value = x.DeployPlace
})
.ToList();
}
private void RecursionGetNext(DeviceGroupEntity current, List<DeviceGroupEntity> deviceGroups,List<Guid> res)
private IEnumerable<Guid> RecursionGetNext(DeviceGroupEntity current, List<DeviceGroupEntity> deviceGroups)
{
var next = deviceGroups.Where(x => x.PCode == current.Code).ToList();
foreach (var item in next)
{
RecursionGetNext(item, deviceGroups,res);
RecursionGetNext(item, deviceGroups);
}
res.Add(current.Code);
yield return current.Code;
}
}
public class KeyValue<T>
{
public string Key { get; set; }
public T Value { get; set; }
}