fix userIds查询
This commit is contained in:
@@ -14,7 +14,7 @@ namespace Dlhis.Entity.Sys.Entities;
|
||||
public class DataPermissionEntity : SugarBaseEntity, ITenantId
|
||||
{
|
||||
/// <summary>
|
||||
/// <EFBFBD>û<EFBFBD>UserNo
|
||||
/// identity userId
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false)]
|
||||
public string AssignValue { get; set; }
|
||||
|
||||
@@ -1,22 +1,25 @@
|
||||
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 Dlhis.Sys.DataPermission.Request;
|
||||
using Dlhis.Sys.DataPermission.Response;
|
||||
using Dlhis.Sys.Identity.Services;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Mapster;
|
||||
|
||||
namespace Dlhis.Sys.DataPermission.Services.Implements;
|
||||
|
||||
public class DataPermissionService : IDataPermissionService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly IUserService _userService;
|
||||
|
||||
public DataPermissionService(IDbContext dbContext)
|
||||
public DataPermissionService(IDbContext dbContext, IUserService userService)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -60,21 +63,45 @@ public class DataPermissionService : IDataPermissionService
|
||||
.Distinct()
|
||||
.ToListAsync();
|
||||
|
||||
var userNos = await _dbContext.Queryable<DataPermissionEntity>()
|
||||
var deviceGroups = await _dbContext.Queryable<DeviceGroupEntity>().ToListAsync();
|
||||
var nextItems = new List<Guid>();
|
||||
foreach (var code in deviceGroupCodes)
|
||||
{
|
||||
nextItems.AddRange(HandlerDeviceGroupNextCodes(code, deviceGroups));
|
||||
}
|
||||
|
||||
var values = await _dbContext.Queryable<DataPermissionEntity>()
|
||||
.Where(x => (x.UniqueValue == deviceCode && x.UniqueType == DataPermissionAssignmentEnumType.Device)
|
||||
|| (deviceGroupCodes.Contains(x.UniqueValue) && x.UniqueType == DataPermissionAssignmentEnumType.Group)
|
||||
|| (nextItems.Contains(x.UniqueValue) && x.UniqueType == DataPermissionAssignmentEnumType.Group)
|
||||
)
|
||||
.Select(x => x.AssignValue)
|
||||
.ToListAsync();
|
||||
|
||||
|
||||
return await _dbContext.Queryable<GainfoEntity>()
|
||||
.Where(x => userNos.Contains(x.No))
|
||||
.Select(x => new GainfoResponse
|
||||
var userIds = values.Adapt<List<int>>();
|
||||
var users = await _userService.GetUserByIdsAsync(userIds);
|
||||
return users.Select(x => new GainfoResponse
|
||||
{
|
||||
UserCode = x.Code,
|
||||
UserName = x.Name
|
||||
})
|
||||
.ToListAsync();
|
||||
UserCode = x.UserName,
|
||||
UserName = x.OperatorName
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
private static List<Guid> HandlerDeviceGroupNextCodes(Guid current, List<DeviceGroupEntity> data)
|
||||
{
|
||||
var result = new List<Guid> { current };
|
||||
|
||||
InternalHandlerCodes(current, data, result);
|
||||
|
||||
return result;
|
||||
|
||||
static void InternalHandlerCodes(Guid internalCurrent, List<DeviceGroupEntity> internalData, List<Guid> internalResult)
|
||||
{
|
||||
var next = internalData.Where(x => x.PCode == internalCurrent);
|
||||
foreach (var item in next)
|
||||
{
|
||||
internalResult.Add(item.Code);
|
||||
InternalHandlerCodes(item.Code, internalData, internalResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user