fix 人员同步,下发任务创建
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Dtos;
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Basic.Device.Services;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
|
||||
@@ -57,7 +58,7 @@ public class DevicePermissionsController : ControllerBase
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 就餐设备唯一号权限
|
||||
/// 获取就餐设备唯一号权限
|
||||
/// </summary>
|
||||
/// <param name="userNo"></param>
|
||||
/// <returns></returns>
|
||||
@@ -67,4 +68,20 @@ public class DevicePermissionsController : ControllerBase
|
||||
{
|
||||
return await _devicePermissionService.GetCanteenDeviceUniqueNosByUserNoAsync(userNo);
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpGet("all-permission")]
|
||||
[IgnoreTenant]
|
||||
public async Task<PermissionUsersInfoDto> GetPermissionUsersInfoAsync()
|
||||
{
|
||||
return await _devicePermissionService.GetPermissionUsersInfoAsync();
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[IgnoreTenant]
|
||||
[HttpPost("re-permission")]
|
||||
public async Task<int> ReGeneratePermissionUsersInfoAsync(PermissionUsersInfoDto beforeDto)
|
||||
{
|
||||
return await _devicePermissionService.ReGeneratePermissionUsersInfoAsync(beforeDto);
|
||||
}
|
||||
}
|
||||
|
||||
15
Src/Dlhis.Basic/Device/Dtos/PermissionUsersInfoDto.cs
Normal file
15
Src/Dlhis.Basic/Device/Dtos/PermissionUsersInfoDto.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace Dlhis.Basic.Device.Dtos
|
||||
{
|
||||
public class PermissionUsersInfoDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 拥有权限的用户
|
||||
/// </summary>
|
||||
public List<string> UserNos { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户对应的 [ 厂区--设备Code ]
|
||||
/// </summary>
|
||||
public Dictionary<string, List<UserTenantDeviceCodeDto>> PermissionInfos { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Dtos;
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Entity.Sys.Enums;
|
||||
@@ -64,4 +65,11 @@ public interface IDevicePermissionService : IScopeDependency
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task<Pagination<AssigmentByCodeResponse>> GetAssigmentByCodeAsync(AssigmentByCodeRequest request);
|
||||
|
||||
|
||||
|
||||
Task<PermissionUsersInfoDto> GetPermissionUsersInfoAsync();
|
||||
|
||||
|
||||
Task<int> ReGeneratePermissionUsersInfoAsync(PermissionUsersInfoDto beforeDto);
|
||||
}
|
||||
|
||||
@@ -161,6 +161,97 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<PermissionUsersInfoDto> GetPermissionUsersInfoAsync()
|
||||
{
|
||||
//获取所有人的权限
|
||||
var userNos = await GetPermissionUserNosAsync();
|
||||
var permissions = await GetAssignDeviceCodesInternalAsync(userNos);
|
||||
|
||||
return new PermissionUsersInfoDto
|
||||
{
|
||||
UserNos = userNos,
|
||||
PermissionInfos = permissions
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public async Task<int> ReGeneratePermissionUsersInfoAsync(PermissionUsersInfoDto beforeDto)
|
||||
{
|
||||
var userNos = beforeDto.UserNos;
|
||||
var before = beforeDto.PermissionInfos.ToDictionary(x => x.Key, x => x.Value, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
//获取业务处理后所有人的权限
|
||||
var nextUserNos = await GetPermissionUserNosAsync();
|
||||
if (nextUserNos.Any())
|
||||
userNos = userNos.Concat(nextUserNos).Distinct(StringComparer.OrdinalIgnoreCase).ToList();
|
||||
|
||||
var current = await GetAssignDeviceCodesInternalAsync(userNos);
|
||||
|
||||
var deivces = await _dbContext.Queryable<DeviceEntity>().ToListAsync();
|
||||
var waitTasks = new List<DeviceTaskEntity>();
|
||||
|
||||
foreach (var userNo in userNos)
|
||||
{
|
||||
before.TryGetValue(userNo, out var beforeTenantDeviceCodes);
|
||||
beforeTenantDeviceCodes ??= new();
|
||||
|
||||
current.TryGetValue(userNo, out var currentTenantDeviceCodes);
|
||||
currentTenantDeviceCodes ??= new();
|
||||
|
||||
var tenants = beforeTenantDeviceCodes.Select(x => x.Tenant).Concat(currentTenantDeviceCodes.Select(x => x.Tenant)).Distinct().ToList();
|
||||
|
||||
foreach (var tenant in tenants)
|
||||
{
|
||||
var currentCodes = currentTenantDeviceCodes.FirstOrDefault(x => x.Tenant == tenant)?.Codes ?? new();
|
||||
var beforeCodes = beforeTenantDeviceCodes.FirstOrDefault(x => x.Tenant == tenant)?.Codes ?? new();
|
||||
|
||||
//被删除
|
||||
var deletedItems = beforeCodes.Where(x => !currentCodes.Contains(x)).ToList();
|
||||
//新增
|
||||
var addItems = currentCodes.Where(x => !beforeCodes.Contains(x)).ToList();
|
||||
|
||||
if (!deletedItems.Any() && !addItems.Any())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var deviceCodes = deivces.Where(x => deletedItems.Contains(x.Code) || addItems.Contains(x.Code)).Select(x => x.Code).ToList();
|
||||
deletedItems = deletedItems.Where(x => deviceCodes.Contains(x)).ToList();
|
||||
addItems = addItems.Where(x => deviceCodes.Contains(x)).ToList();
|
||||
|
||||
//下发任务创建
|
||||
var toDeleted = deletedItems.Select(x => new DeviceTaskEntity
|
||||
{
|
||||
DeviceUniqueNo = deivces.First(item => item.Code == x).UniqueNo,
|
||||
Status = DeviceTaskStatusEnumType.Wait,
|
||||
Type = DeviceTaskEnumType.Delete,
|
||||
UserNo = userNo,
|
||||
Version = 0,
|
||||
TenantId = tenant,
|
||||
}).ToList();
|
||||
|
||||
var toAdd = addItems.Select(x => new DeviceTaskEntity
|
||||
{
|
||||
DeviceUniqueNo = deivces.First(item => item.Code == x).UniqueNo,
|
||||
Status = DeviceTaskStatusEnumType.Wait,
|
||||
Type = DeviceTaskEnumType.Add,
|
||||
UserNo = userNo,
|
||||
Version = 0,
|
||||
TenantId = tenant,
|
||||
}).ToList();
|
||||
|
||||
waitTasks.AddRange(toDeleted.Concat(toAdd).ToList());
|
||||
}
|
||||
}
|
||||
|
||||
if (waitTasks.Any())
|
||||
{
|
||||
await _dbContext.InsertAsync(waitTasks);
|
||||
}
|
||||
|
||||
return waitTasks.Count;
|
||||
}
|
||||
|
||||
public async Task GenerateDeviceTasksAsync(string userNo, DeviceTaskEnumType taskType)
|
||||
{
|
||||
var deviceCodes = await GetAssignDeviceCodesAsync(userNo);
|
||||
@@ -193,7 +284,6 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
await _dbContext.InsertAsync(tasks);
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<string>> GetCanteenDeviceUniqueNosByUserNoAsync(string userNo)
|
||||
{
|
||||
var all = await GetAssignDeviceCodesAsync(userNo);
|
||||
@@ -305,40 +395,6 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
return userNos.Concat(userNosByGroup).Concat(userNosByDepartment).Concat(userNosByWerk).Distinct().ToList();
|
||||
}
|
||||
|
||||
|
||||
private static List<Guid> GetAssignmentsInternal(
|
||||
List<DevicePermissionEntity> devicePermissions, List<DeviceGroupEntity> deviceGroups,
|
||||
DeviceAssignmentTypeEnumType uniqueType, AssignTypeEnumType assignType, string assignValue)
|
||||
{
|
||||
var devicePermissionCodes = devicePermissions
|
||||
.Where(x => x.UniqueType == uniqueType)
|
||||
.Where(x => x.AssignType == assignType)
|
||||
.Where(x => x.AssignValue == assignValue)
|
||||
.Select(x => x.UniqueValue).ToList();
|
||||
|
||||
//处理获取设备组的情况,递归到最下级获取设备code
|
||||
if (uniqueType == DeviceAssignmentTypeEnumType.Group)
|
||||
{
|
||||
var tops = deviceGroups.Where(x => !x.PCode.HasValue).ToList();
|
||||
tops.ForEach(x =>
|
||||
{
|
||||
RecursionGetNext(x, deviceGroups, devicePermissionCodes, devicePermissionCodes.Contains(x.Code));
|
||||
});
|
||||
}
|
||||
|
||||
return devicePermissionCodes.Distinct().ToList();
|
||||
|
||||
void RecursionGetNext(DeviceGroupEntity current, List<DeviceGroupEntity> deviceGroups, List<Guid> result, bool add)
|
||||
{
|
||||
var next = deviceGroups.Where(x => x.PCode == current.Code).ToList();
|
||||
foreach (var item in next)
|
||||
{
|
||||
if (add) result.Add(item.Code);
|
||||
RecursionGetNext(item, deviceGroups, result, result.Contains(item.Code));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static List<UserTenantDeviceCodeDto> GetAssignCodesInternal(
|
||||
List<DevicePermissionEntity> devicePermissions, List<DeviceGroupEntity> deviceGroups,
|
||||
DeviceAssignmentTypeEnumType uniqueType, AssignTypeEnumType assignType, string assignValue)
|
||||
@@ -400,7 +456,7 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
var deviceGroups = await _dbContext.Queryable<DeviceGroupEntity>().ToListAsync();
|
||||
var deviceRelationships = await _dbContext.Queryable<DeviceGroupRelationshipEntity>().ToListAsync();
|
||||
|
||||
var result = new Dictionary<string, List<UserTenantDeviceCodeDto>>(gainfos.Count);
|
||||
var result = new Dictionary<string, List<UserTenantDeviceCodeDto>>(gainfos.Count, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
foreach (var gainfo in gainfos)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user