test .
This commit is contained in:
@@ -134,6 +134,14 @@ public class DevicePermissionsController : ControllerBase
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("temp-userPermissionCodes")]
|
||||
[IgnoreTenant]
|
||||
public async Task<object> GetAssignDeviceCodesAsync(List<string> userCodes)
|
||||
{
|
||||
return await _devicePermissionService.GetUserDeviceCodesByNoAsync(userCodes);
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("test-userPermissionCodes")]
|
||||
[IgnoreTenant]
|
||||
public async Task<Dictionary<string, List<TenantAssignTypeDeviceCode>>> GetTestAssignDeviceCodesAsync(string userNo)
|
||||
|
||||
@@ -63,4 +63,6 @@ public interface IDevicePermissionService : IScopeDependency
|
||||
Task<List<string>> GetDeviceNotInUsersAsync(string deviceUniqueNo);
|
||||
|
||||
Task<int> GenerateDeleteDeviceTasksAsync(string deviceUniqueNo);
|
||||
|
||||
Task<object> GetUserDeviceCodesByNoAsync(List<string> userCodes);
|
||||
}
|
||||
@@ -342,6 +342,41 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
return deviceCodes.Concat(manuallyDeviceCodes).Distinct().ToList();
|
||||
}
|
||||
|
||||
public async Task<object> GetUserDeviceCodesByNoAsync(List<string> userCodes)
|
||||
{
|
||||
var users = await _dbContext.Queryable<GainfoEntity>().Where(x => userCodes.Contains(x.Code)).Select(x => new { x.No, x.Code, x.Name }).ToListAsync();
|
||||
var userNos = users.Select(x => x.No).ToList();
|
||||
|
||||
//例外处理: 特殊手动分配的设备权限
|
||||
var manuallyDeviceCodes = await _dbContext.Queryable<DevicePermissionManuallyEntity>()
|
||||
.Where(x => userNos.Contains(x.UserNo))
|
||||
.Select(x => new { x.UserNo, x.DeviceCode })
|
||||
.ToListAsync();
|
||||
|
||||
var result = await _devicePermissionAnalyzeService.GetUserAssignDeviceCodesWithTypeInTenantAsync(userNos);
|
||||
|
||||
var userWithDeviceCodes = result.ToDictionary(x => x.Key, x =>
|
||||
{
|
||||
var codes = x.Value.SelectMany(x => x.AssignTypes.SelectMany(p => p.Codes)).Distinct().ToList();
|
||||
var userManuallyDeviceCodes = manuallyDeviceCodes.Where(p => p.UserNo == x.Key).Select(p => p.DeviceCode).ToList();
|
||||
return codes.Concat(userManuallyDeviceCodes).Distinct().ToList();
|
||||
});
|
||||
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>().ToListAsync();
|
||||
|
||||
var finialResult = new List<object>();
|
||||
foreach (var item in userWithDeviceCodes)
|
||||
{
|
||||
var userNo = item.Key;
|
||||
var user = users.First(x => x.No == userNo);
|
||||
|
||||
var details = devices.Where(x => item.Value.Contains(x.Code)).Select(x => new { UserCode = user.Code, UserName = user.Name, DeviceUniqueNo = x.UniqueNo, DeviceDeployPlace = x.DeployPlace });
|
||||
finialResult.AddRange(details);
|
||||
}
|
||||
|
||||
return finialResult;
|
||||
}
|
||||
|
||||
|
||||
public async Task<int> ResetVisitorsByDeviceAsync(string deviceUniqueNo)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user