refactor 优化,注释
This commit is contained in:
@@ -1,14 +0,0 @@
|
|||||||
namespace Dlhis.Basic.Api.Dto;
|
|
||||||
|
|
||||||
public class PermissionUsersInfoDto
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 拥有权限的用户
|
|
||||||
/// </summary>
|
|
||||||
public List<string> UserNos { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 用户对应的 [ 厂区--设备Code ]
|
|
||||||
/// </summary>
|
|
||||||
public Dictionary<string, List<UserTenantDeviceCodeDto>> PermissionInfos { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
namespace Dlhis.Basic.Api.Dto;
|
|
||||||
|
|
||||||
public class UserTenantDeviceCodeDto
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 租户
|
|
||||||
/// </summary>
|
|
||||||
public string Tenant { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 设备权限
|
|
||||||
/// </summary>
|
|
||||||
public List<Guid> Codes { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using Dlhis.Basic.Device.Dtos;
|
using Dlhis.Basic.Device.Dtos;
|
||||||
using Dlhis.Basic.Device.Filters;
|
|
||||||
using Dlhis.Basic.Device.Request;
|
using Dlhis.Basic.Device.Request;
|
||||||
using Dlhis.Basic.Device.Response;
|
using Dlhis.Basic.Device.Response;
|
||||||
using Dlhis.Basic.Device.Services;
|
using Dlhis.Basic.Device.Services;
|
||||||
@@ -31,7 +30,6 @@ public class DevicePermissionsController : ControllerBase
|
|||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("assign")]
|
[HttpPost("assign")]
|
||||||
[AssignPermissionLimit]
|
|
||||||
[Transactional]
|
[Transactional]
|
||||||
[CrossTenant]
|
[CrossTenant]
|
||||||
public async Task<DevicePermissionAssignResponse> AssignAsync(DevicePermissionSaveRequest request)
|
public async Task<DevicePermissionAssignResponse> AssignAsync(DevicePermissionSaveRequest request)
|
||||||
@@ -44,7 +42,6 @@ public class DevicePermissionsController : ControllerBase
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
[HttpPost("assign-unique")]
|
[HttpPost("assign-unique")]
|
||||||
[AssignPermissionLimit]
|
|
||||||
[Transactional]
|
[Transactional]
|
||||||
[CrossTenant]
|
[CrossTenant]
|
||||||
public async Task<DevicePermissionAssignResponse> AssignToUniqueAsync(DevicePermissionsAssignToDeviceRequest request)
|
public async Task<DevicePermissionAssignResponse> AssignToUniqueAsync(DevicePermissionsAssignToDeviceRequest request)
|
||||||
@@ -52,14 +49,14 @@ public class DevicePermissionsController : ControllerBase
|
|||||||
return await _devicePermissionService.AssignToUniqueAsync(request);
|
return await _devicePermissionService.AssignToUniqueAsync(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
[AllowAnonymous]
|
// [AllowAnonymous]
|
||||||
[HttpPost("assign-unique-import")]
|
// [HttpPost("assign-unique-import")]
|
||||||
[Transactional]
|
// [Transactional]
|
||||||
[IgnoreTenant]
|
// [IgnoreTenant]
|
||||||
public async Task AssignToUniqueImportAsync(IFormFile file)
|
// public async Task AssignToUniqueImportAsync(IFormFile file)
|
||||||
{
|
// {
|
||||||
await _devicePermissionService.AssignToUniqueImportAsync(file);
|
// await _devicePermissionService.AssignToUniqueImportAsync(file);
|
||||||
}
|
// }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当前类型的权限分配
|
/// 当前类型的权限分配
|
||||||
|
|||||||
@@ -39,16 +39,3 @@ public class AssignTypeDeviceCode
|
|||||||
|
|
||||||
public List<Guid> OriginalCodes { get; set; }
|
public List<Guid> OriginalCodes { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UserTenantDeviceCodeDto
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 租户
|
|
||||||
/// </summary>
|
|
||||||
public string Tenant { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 设备权限
|
|
||||||
/// </summary>
|
|
||||||
public IEnumerable<Guid> Codes { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
using Kurisu.AspNetCore.Authentication.Abstractions;
|
|
||||||
using Kurisu.AspNetCore.Cache;
|
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
|
||||||
|
|
||||||
namespace Dlhis.Basic.Device.Filters;
|
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Method)]
|
|
||||||
public class AssignPermissionLimitAttribute : Attribute, IAsyncActionFilter
|
|
||||||
{
|
|
||||||
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
|
|
||||||
{
|
|
||||||
// var currentUser = context.HttpContext.RequestServices.GetRequiredService<ICurrentUser>();
|
|
||||||
// var redisCache = context.HttpContext.RequestServices.GetRequiredService<RedisCache>();
|
|
||||||
//
|
|
||||||
// var currentTenantId = currentUser.GetStringTenantId();
|
|
||||||
//
|
|
||||||
// await using var handler = await redisCache.LockAsync($"permission:generate:{currentTenantId}", expiry: TimeSpan.FromMinutes(3));
|
|
||||||
// handler.Acquired.ThrowIfFalse("请勿频繁分配");
|
|
||||||
await next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -56,11 +56,10 @@ public class DeviceGetAssignmentUniquesRequest
|
|||||||
public DeviceAssignmentTypeEnumType UniqueType { get; set; }
|
public DeviceAssignmentTypeEnumType UniqueType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 权限值
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Guid UniqueValue { get; set; }
|
public Guid UniqueValue { get; set; }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设备类型
|
/// 设备类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using Dlhis.Basic.Device.Dtos;
|
using Dlhis.Basic.Device.Dtos;
|
||||||
using Dlhis.Basic.Device.Request;
|
using Dlhis.Basic.Device.Request;
|
||||||
using Dlhis.Basic.Device.Response;
|
|
||||||
using Dlhis.Basic.Organization.Dto;
|
using Dlhis.Basic.Organization.Dto;
|
||||||
using Dlhis.Entity.Sys.Entities;
|
using Dlhis.Entity.Sys.Entities;
|
||||||
using Dlhis.Entity.Sys.Enums;
|
using Dlhis.Entity.Sys.Enums;
|
||||||
@@ -12,22 +11,42 @@ namespace Dlhis.Basic.Device.Services;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IDevicePermissionAnalyzeService : IScopeDependency
|
public interface IDevicePermissionAnalyzeService : IScopeDependency
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获取存储的设备权限(原始数据)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
Task<List<DevicePermissionEntity>> GetDevicePermissionsAsync(DevicePermissionSaveRequest request);
|
Task<List<DevicePermissionEntity>> GetDevicePermissionsAsync(DevicePermissionSaveRequest request);
|
||||||
|
|
||||||
Task<DevicePermissionAssignResponse> GenerateDeviceTasksAsync(Func<Task> func, List<string> userNos, string source);
|
/// <summary>
|
||||||
|
/// 获取设备权限codes(原始数据)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
Task<List<Guid>> GetAssignmentsAsync(DeviceGetAssignmentsRequest request);
|
Task<List<Guid>> GetAssignmentsAsync(DeviceGetAssignmentsRequest request);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取设备分配的人(按人员)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
Task<List<GainfoDto>> GetAssignmentUniqueAsync(DeviceGetAssignmentUniquesRequest request);
|
Task<List<GainfoDto>> GetAssignmentUniqueAsync(DeviceGetAssignmentUniquesRequest request);
|
||||||
|
|
||||||
Task<List<Guid>> GetAssignDeviceCodesAsync(string userNo);
|
/// <summary>
|
||||||
|
/// 获取人员所有权限codes
|
||||||
|
/// </summary>
|
||||||
Task<Dictionary<string, List<UserTenantDeviceCodeDto>>> GetUserAssignDeviceCodesInTenantAsync(
|
/// <param name="userNo"></param>
|
||||||
List<string> userNos,
|
/// <returns></returns>
|
||||||
DeviceAssignmentTypeEnumType? ignoreUniqueType = null,
|
Task<List<Guid>> GetUserPermissionDeviceCodesAsync(string userNo);
|
||||||
string ignoreAssignValue = null, AssignTypeEnumType? ignoreAssignType = null);
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取人员权限(人员--(厂区--分配方式--设备codes))
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userNos"></param>
|
||||||
|
/// <param name="ignoreUniqueType"></param>
|
||||||
|
/// <param name="ignoreAssignValue"></param>
|
||||||
|
/// <param name="ignoreAssignType"></param>
|
||||||
|
/// <returns></returns>
|
||||||
Task<Dictionary<string, List<TenantAssignTypeDeviceCode>>> GetUserAssignDeviceCodesWithTypeInTenantAsync(
|
Task<Dictionary<string, List<TenantAssignTypeDeviceCode>>> GetUserAssignDeviceCodesWithTypeInTenantAsync(
|
||||||
List<string> userNos,
|
List<string> userNos,
|
||||||
DeviceAssignmentTypeEnumType? ignoreUniqueType = null,
|
DeviceAssignmentTypeEnumType? ignoreUniqueType = null,
|
||||||
|
|||||||
@@ -4,11 +4,29 @@ using Kurisu.AspNetCore.DataAccess.Dto;
|
|||||||
|
|
||||||
namespace Dlhis.Basic.Device.Services;
|
namespace Dlhis.Basic.Device.Services;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 例外人员权限分配
|
||||||
|
/// </summary>
|
||||||
public interface IDevicePermissionManuallyService : IScopeDependency
|
public interface IDevicePermissionManuallyService : IScopeDependency
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获取例外分配分页
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="requestDto"></param>
|
||||||
|
/// <returns></returns>
|
||||||
Task<Pagination<DevicePermissionManuallyResponse>> GetPageAsync(PageDto requestDto);
|
Task<Pagination<DevicePermissionManuallyResponse>> GetPageAsync(PageDto requestDto);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加例外
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
Task AddAsync(DevicePermissionManuallyAddRequest request);
|
Task AddAsync(DevicePermissionManuallyAddRequest request);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除例外
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
Task DeleteAsync(long id);
|
Task DeleteAsync(long id);
|
||||||
}
|
}
|
||||||
@@ -22,11 +22,7 @@ public interface IDevicePermissionService : IScopeDependency
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<DevicePermissionAssignResponse> AssignToUniqueAsync(DevicePermissionsAssignToDeviceRequest request);
|
Task<DevicePermissionAssignResponse> AssignToUniqueAsync(DevicePermissionsAssignToDeviceRequest request);
|
||||||
|
|
||||||
|
//Task AssignToUniqueImportAsync(IFormFile file);
|
||||||
Task AssignToUniqueImportAsync(IFormFile file);
|
|
||||||
|
|
||||||
|
|
||||||
Task<Dictionary<string, IEnumerable<UserTenantDeviceCodeDto>>> GetUserDevicePermissionsAsync(string code);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 生成下发任务(主动生成)
|
/// 生成下发任务(主动生成)
|
||||||
|
|||||||
@@ -5,15 +5,45 @@ using Kurisu.AspNetCore.DataAccess.Dto;
|
|||||||
|
|
||||||
namespace Dlhis.Basic.Device.Services;
|
namespace Dlhis.Basic.Device.Services;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备时段码服务
|
||||||
|
/// </summary>
|
||||||
public interface IDeviceTimePeriodService : IScopeDependency
|
public interface IDeviceTimePeriodService : IScopeDependency
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 时段码配置
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
Task<Pagination<DeviceTimePeriodPageResponse>> GetPageAsync(DeviceTimePeriodPageRequest request);
|
Task<Pagination<DeviceTimePeriodPageResponse>> GetPageAsync(DeviceTimePeriodPageRequest request);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 保存时段码
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
Task SaveAsync(DeviceTimePeriodSaveRequest request);
|
Task SaveAsync(DeviceTimePeriodSaveRequest request);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取时段码配置
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="assignType"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
Task<List<DeviceTimePeriodResponse>> GetListAsync(DeviceTimePeriodAssignEnumType assignType, Guid value);
|
Task<List<DeviceTimePeriodResponse>> GetListAsync(DeviceTimePeriodAssignEnumType assignType, Guid value);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除时段码
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
Task DeleteCardTypeAsync(DeviceTimePeriodDeleteCardTypeRequest request);
|
Task DeleteCardTypeAsync(DeviceTimePeriodDeleteCardTypeRequest request);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生成时段码
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="func"></param>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
Task GenerateDeviceTimePeriodTasksAsync(Func<Task> func, string source);
|
Task GenerateDeviceTimePeriodTasksAsync(Func<Task> func, string source);
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,6 @@ using System.Collections.Concurrent;
|
|||||||
using Dlhis.Basic.DataPermissions;
|
using Dlhis.Basic.DataPermissions;
|
||||||
using Dlhis.Basic.Device.Dtos;
|
using Dlhis.Basic.Device.Dtos;
|
||||||
using Dlhis.Basic.Device.Request;
|
using Dlhis.Basic.Device.Request;
|
||||||
using Dlhis.Basic.Device.Response;
|
|
||||||
using Dlhis.Basic.Organization.Dto;
|
using Dlhis.Basic.Organization.Dto;
|
||||||
using Dlhis.Entity.Basic.Entity;
|
using Dlhis.Entity.Basic.Entity;
|
||||||
using Dlhis.Entity.Basic.Enums;
|
using Dlhis.Entity.Basic.Enums;
|
||||||
@@ -11,7 +10,6 @@ using Dlhis.Entity.Device.Enums;
|
|||||||
using Dlhis.Entity.Sys.Entities;
|
using Dlhis.Entity.Sys.Entities;
|
||||||
using Dlhis.Entity.Sys.Enums;
|
using Dlhis.Entity.Sys.Enums;
|
||||||
using Kurisu.AspNetCore.Authentication.Abstractions;
|
using Kurisu.AspNetCore.Authentication.Abstractions;
|
||||||
using Kurisu.AspNetCore.DataAccess.Entity;
|
|
||||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
|
|
||||||
@@ -34,8 +32,9 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
|||||||
|
|
||||||
public async Task<List<DevicePermissionEntity>> GetDevicePermissionsAsync(DevicePermissionSaveRequest request)
|
public async Task<List<DevicePermissionEntity>> GetDevicePermissionsAsync(DevicePermissionSaveRequest request)
|
||||||
{
|
{
|
||||||
var currentTenantId = await GetCurrentFactoryAsync(request);
|
var currentTenantId = await GetCurrentFactoryAsync(request.UniqueType, request.Codes);
|
||||||
|
|
||||||
|
//获取当前查询的配置
|
||||||
var setting = _dbContext.GetQueryableSetting();
|
var setting = _dbContext.GetQueryableSetting();
|
||||||
|
|
||||||
var query = _dbContext.Queryable<DevicePermissionEntity>().Where(x => x.AssignType == request.AssignType
|
var query = _dbContext.Queryable<DevicePermissionEntity>().Where(x => x.AssignType == request.AssignType
|
||||||
@@ -43,6 +42,8 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
|||||||
&& x.UniqueType == request.UniqueType
|
&& x.UniqueType == request.UniqueType
|
||||||
&& x.Type == request.Type
|
&& x.Type == request.Type
|
||||||
&& x.TenantId == currentTenantId);
|
&& x.TenantId == currentTenantId);
|
||||||
|
|
||||||
|
//根据数据权限进行过滤
|
||||||
if (setting.GetEnableDataPermission<DevicePermissionEntity>())
|
if (setting.GetEnableDataPermission<DevicePermissionEntity>())
|
||||||
{
|
{
|
||||||
(bool enableDeviceFilter, List<Guid> deviceCodes) = _myDataPermissionService.GetMyDeviceCodes();
|
(bool enableDeviceFilter, List<Guid> deviceCodes) = _myDataPermissionService.GetMyDeviceCodes();
|
||||||
@@ -54,102 +55,32 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
|||||||
}
|
}
|
||||||
|
|
||||||
return await query.ToListAsync();
|
return await query.ToListAsync();
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<string> GetCurrentFactoryAsync(DevicePermissionSaveRequest request)
|
|
||||||
{
|
|
||||||
var currentTenantId = _currentUser.GetStringTenantId();
|
|
||||||
|
|
||||||
var r = request.UniqueType switch
|
//获取当前的操作人的基地
|
||||||
|
async Task<string> GetCurrentFactoryAsync(DeviceAssignmentTypeEnumType uniqueType, List<Guid> codes)
|
||||||
{
|
{
|
||||||
DeviceAssignmentTypeEnumType.Device => await _dbContext.Queryable<DeviceEntity>().Where(x => request.Codes.Contains(x.Code)).Where(x => x.TenantId != currentTenantId).AnyAsync(),
|
var internalCurrentTenantId = _currentUser.GetStringTenantId();
|
||||||
DeviceAssignmentTypeEnumType.Group => await _dbContext.Queryable<DeviceGroupEntity>().Where(x => request.Codes.Contains(x.Code)).Where(x => x.TenantId != currentTenantId).AnyAsync(),
|
|
||||||
_ => false
|
|
||||||
};
|
|
||||||
|
|
||||||
r.ThrowIfTrue("存在设备或者设备组不属于当前厂区,操作失败!");
|
var r = uniqueType switch
|
||||||
|
|
||||||
return currentTenantId;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public async Task<DevicePermissionAssignResponse> GenerateDeviceTasksAsync(Func<Task> func, List<string> userNos, string source)
|
|
||||||
{
|
|
||||||
var before = await GetUserAssignDeviceCodesInTenantAsync(userNos);
|
|
||||||
|
|
||||||
//业务处理
|
|
||||||
_dbContext.Client.QueryFilter.Restore();
|
|
||||||
await func();
|
|
||||||
_dbContext.Client.QueryFilter.ClearAndBackup<ITenantId>();
|
|
||||||
|
|
||||||
var current = await GetUserAssignDeviceCodesInTenantAsync(userNos);
|
|
||||||
|
|
||||||
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Enable).ToListAsync();
|
|
||||||
|
|
||||||
var waitAddTasks = new List<DeviceTaskEntity>();
|
|
||||||
var waitDeleteTasks = new List<DeviceTaskEntity>();
|
|
||||||
|
|
||||||
foreach (var userNo in userNos)
|
|
||||||
{
|
|
||||||
var beforeTenantDeviceCodes = before[userNo].ToList();
|
|
||||||
var currentTenantDeviceCodes = current[userNo].ToList();
|
|
||||||
|
|
||||||
var tenants = new HashSet<string>();
|
|
||||||
foreach (var item in beforeTenantDeviceCodes)
|
|
||||||
tenants.Add(item.Tenant);
|
|
||||||
foreach (var item in currentTenantDeviceCodes)
|
|
||||||
tenants.Add(item.Tenant);
|
|
||||||
|
|
||||||
foreach (var tenant in tenants)
|
|
||||||
{
|
{
|
||||||
var currentCodes = currentTenantDeviceCodes.FirstOrDefault(x => x.Tenant == tenant)?.Codes?.ToList() ?? new List<Guid>();
|
DeviceAssignmentTypeEnumType.Device => await _dbContext.Queryable<DeviceEntity>().Where(x => codes.Contains(x.Code)).Where(x => x.TenantId != internalCurrentTenantId).AnyAsync(),
|
||||||
var beforeCodes = beforeTenantDeviceCodes.FirstOrDefault(x => x.Tenant == tenant)?.Codes?.ToList() ?? new List<Guid>();
|
DeviceAssignmentTypeEnumType.Group => await _dbContext.Queryable<DeviceGroupEntity>().Where(x => codes.Contains(x.Code)).Where(x => x.TenantId != internalCurrentTenantId).AnyAsync(),
|
||||||
|
_ => false
|
||||||
|
};
|
||||||
|
|
||||||
//被删除
|
r.ThrowIfTrue("存在设备或者设备组不属于当前厂区,操作失败!");
|
||||||
var deletedItems = beforeCodes.Where(x => !currentCodes.Contains(x)).ToList();
|
|
||||||
//新增
|
|
||||||
var addItems = currentCodes.Where(x => !beforeCodes.Contains(x)).ToList();
|
|
||||||
|
|
||||||
if (!deletedItems.Any() && !addItems.Any())
|
return internalCurrentTenantId;
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var deviceCodes = devices.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();
|
|
||||||
|
|
||||||
//下发任务创建
|
|
||||||
deletedItems.ForEach(x => waitDeleteTasks.Add(new DeviceTaskEntity
|
|
||||||
{
|
|
||||||
DeviceUniqueNo = devices.First(item => item.Code == x).UniqueNo,
|
|
||||||
Status = DeviceTaskStatusEnumType.Wait,
|
|
||||||
Type = DeviceTaskEnumType.Delete,
|
|
||||||
DeviceType = devices.First(item => item.Code == x).Type,
|
|
||||||
UserNo = userNo,
|
|
||||||
Version = 0,
|
|
||||||
TenantId = tenant,
|
|
||||||
Source = source
|
|
||||||
}));
|
|
||||||
|
|
||||||
addItems.ForEach(x => waitAddTasks.Add(new DeviceTaskEntity
|
|
||||||
{
|
|
||||||
DeviceUniqueNo = devices.First(item => item.Code == x).UniqueNo,
|
|
||||||
Status = DeviceTaskStatusEnumType.Wait,
|
|
||||||
Type = DeviceTaskEnumType.Add,
|
|
||||||
DeviceType = devices.First(item => item.Code == x).Type,
|
|
||||||
UserNo = userNo,
|
|
||||||
Version = 0,
|
|
||||||
TenantId = tenant,
|
|
||||||
Source = source
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await ChunkInsertAsync(waitAddTasks);
|
public async Task<List<Guid>> GetUserPermissionDeviceCodesAsync(string userNo)
|
||||||
await ChunkInsertAsync(waitDeleteTasks);
|
{
|
||||||
|
var result = await GetUserAssignDeviceCodesWithTypeInTenantAsync(new List<string> { userNo });
|
||||||
return new DevicePermissionAssignResponse(waitAddTasks.Count, waitDeleteTasks.Count);
|
return result.Count == 0
|
||||||
|
? new List<Guid>()
|
||||||
|
: result[userNo].SelectMany(x => x.AssignTypes.SelectMany(p => p.Codes)).Distinct().ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -344,33 +275,6 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ChunkInsertAsync<T>(List<T> batch) where T : class, new()
|
|
||||||
{
|
|
||||||
foreach (var tasks in batch.Chunk(500))
|
|
||||||
{
|
|
||||||
await _dbContext.InsertAsync(tasks.ToList());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public async Task<Dictionary<string, List<UserTenantDeviceCodeDto>>> GetUserAssignDeviceCodesInTenantAsync(
|
|
||||||
List<string> userNos,
|
|
||||||
DeviceAssignmentTypeEnumType? ignoreUniqueType = null,
|
|
||||||
string ignoreAssignValue = null, AssignTypeEnumType? ignoreAssignType = null)
|
|
||||||
{
|
|
||||||
var result = await GetUserAssignDeviceCodesWithTypeInTenantAsync(userNos, ignoreUniqueType, ignoreAssignValue, ignoreAssignType);
|
|
||||||
|
|
||||||
return result.ToDictionary(x => x.Key, x => x.Value.GroupBy(p => p.Tenant).Select(item =>
|
|
||||||
{
|
|
||||||
return new UserTenantDeviceCodeDto
|
|
||||||
{
|
|
||||||
Tenant = item.Key,
|
|
||||||
Codes = item.SelectMany(p => p.AssignTypes).SelectMany(p => p.Codes).Distinct().ToList(),
|
|
||||||
};
|
|
||||||
}).ToList());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public async Task<List<Guid>> GetAssignmentsAsync(DeviceGetAssignmentsRequest request)
|
public async Task<List<Guid>> GetAssignmentsAsync(DeviceGetAssignmentsRequest request)
|
||||||
{
|
{
|
||||||
var r = await GetDevicePermissionsAsync(new DevicePermissionSaveRequest
|
var r = await GetDevicePermissionsAsync(new DevicePermissionSaveRequest
|
||||||
@@ -405,10 +309,4 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
|||||||
Factory = x.Factory
|
Factory = x.Factory
|
||||||
}).ToListAsync();
|
}).ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<Guid>> GetAssignDeviceCodesAsync(string userNo)
|
|
||||||
{
|
|
||||||
var result = await GetUserAssignDeviceCodesInTenantAsync(new List<string> { userNo });
|
|
||||||
return result.First().Value.SelectMany(x => x.Codes).ToList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -156,81 +156,64 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
return new DevicePermissionAssignResponse(tasksToAdd.Count, tasksToDelete.Count);
|
return new DevicePermissionAssignResponse(tasksToAdd.Count, tasksToDelete.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
// /// <inheritdoc />
|
||||||
public async Task AssignToUniqueImportAsync(IFormFile file)
|
// public async Task AssignToUniqueImportAsync(IFormFile file)
|
||||||
{
|
// {
|
||||||
var deviceNo = Path.GetFileNameWithoutExtension(file.FileName);
|
// var deviceNo = Path.GetFileNameWithoutExtension(file.FileName);
|
||||||
|
//
|
||||||
var device = await _dbContext.Queryable<DeviceEntity>().Where(x => x.UniqueNo == deviceNo).SingleAsync();
|
// var device = await _dbContext.Queryable<DeviceEntity>().Where(x => x.UniqueNo == deviceNo).SingleAsync();
|
||||||
device.ThrowIfNull("设备不存在");
|
// device.ThrowIfNull("设备不存在");
|
||||||
|
//
|
||||||
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
|
// ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
|
||||||
using (var package = new ExcelPackage(file.OpenReadStream()))
|
// using (var package = new ExcelPackage(file.OpenReadStream()))
|
||||||
{
|
// {
|
||||||
ExcelWorksheet worksheet = package.Workbook.Worksheets[0];
|
// ExcelWorksheet worksheet = package.Workbook.Worksheets[0];
|
||||||
int rowCount = worksheet.Dimension.Rows; // 获取行数
|
// int rowCount = worksheet.Dimension.Rows; // 获取行数
|
||||||
int colCount = worksheet.Dimension.Columns; // 获取列数
|
// int colCount = worksheet.Dimension.Columns; // 获取列数
|
||||||
|
//
|
||||||
var list = new List<string>();
|
// var list = new List<string>();
|
||||||
for (int i = 1; i < rowCount; i++)
|
// for (int i = 1; i < rowCount; i++)
|
||||||
{
|
// {
|
||||||
var userCode = worksheet.Cells[i + 1, 2].GetCellValue<string>();
|
// var userCode = worksheet.Cells[i + 1, 2].GetCellValue<string>();
|
||||||
list.Add(userCode);
|
// list.Add(userCode);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
foreach (var items in list.Chunk(500))
|
// foreach (var items in list.Chunk(500))
|
||||||
{
|
// {
|
||||||
var gainfoNos = await _dbContext.Queryable<GainfoEntity>().Where(x => items.Contains(x.Code)).Select(x => x.No).ToListAsync();
|
// var gainfoNos = await _dbContext.Queryable<GainfoEntity>().Where(x => items.Contains(x.Code)).Select(x => x.No).ToListAsync();
|
||||||
|
//
|
||||||
var permissions = gainfoNos.Select(x => new DevicePermissionEntity
|
// var permissions = gainfoNos.Select(x => new DevicePermissionEntity
|
||||||
{
|
// {
|
||||||
AssignType = AssignTypeEnumType.User,
|
// AssignType = AssignTypeEnumType.User,
|
||||||
AssignValue = x,
|
// AssignValue = x,
|
||||||
UniqueType = DeviceAssignmentTypeEnumType.Device,
|
// UniqueType = DeviceAssignmentTypeEnumType.Device,
|
||||||
UniqueValue = device.Code,
|
// UniqueValue = device.Code,
|
||||||
Type = device.Type,
|
// Type = device.Type,
|
||||||
TenantId = device.TenantId,
|
// TenantId = device.TenantId,
|
||||||
IsDeleted = false
|
// IsDeleted = false
|
||||||
}).ToList();
|
// }).ToList();
|
||||||
|
//
|
||||||
await _dbContext.InsertAsync(permissions);
|
// await _dbContext.InsertAsync(permissions);
|
||||||
|
//
|
||||||
var tasks = permissions.Select(x => new DeviceTaskEntity
|
// var tasks = permissions.Select(x => new DeviceTaskEntity
|
||||||
{
|
// {
|
||||||
Type = DeviceTaskEnumType.Add,
|
// Type = DeviceTaskEnumType.Add,
|
||||||
DeviceType = x.Type,
|
// DeviceType = x.Type,
|
||||||
UserId = null,
|
// UserId = null,
|
||||||
UserNo = x.AssignValue,
|
// UserNo = x.AssignValue,
|
||||||
DeviceUniqueNo = device.UniqueNo,
|
// DeviceUniqueNo = device.UniqueNo,
|
||||||
Status = DeviceTaskStatusEnumType.Wait,
|
// Status = DeviceTaskStatusEnumType.Wait,
|
||||||
Version = 0,
|
// Version = 0,
|
||||||
ResultMessage = null,
|
// ResultMessage = null,
|
||||||
Source = "人员分配到设备import",
|
// Source = "人员分配到设备import",
|
||||||
Priority = 0,
|
// Priority = 0,
|
||||||
TenantId = device.TenantId,
|
// TenantId = device.TenantId,
|
||||||
}).ToList();
|
// }).ToList();
|
||||||
|
//
|
||||||
await _dbContext.InsertAsync(tasks);
|
// await _dbContext.InsertAsync(tasks);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public async Task<Dictionary<string, IEnumerable<UserTenantDeviceCodeDto>>> GetUserDevicePermissionsAsync(string code)
|
|
||||||
{
|
|
||||||
var userNo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == code).Select(x => x.No).SingleAsync();
|
|
||||||
var result = await _devicePermissionAnalyzeService.GetUserAssignDeviceCodesWithTypeInTenantAsync(new List<string> { userNo });
|
|
||||||
|
|
||||||
return result.ToDictionary(x => x.Key, x => x.Value.GroupBy(p => p.Tenant).Select(item =>
|
|
||||||
{
|
|
||||||
return new UserTenantDeviceCodeDto
|
|
||||||
{
|
|
||||||
Tenant = item.Key,
|
|
||||||
Codes = item.SelectMany(p => p.AssignTypes).SelectMany(p => p.Codes).Distinct().ToList(),
|
|
||||||
};
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public async Task<Pagination<DeviceGainfoResponse>> GetGainfoPageByDeviceAsync(DeviceWithGainfoRequest request)
|
public async Task<Pagination<DeviceGainfoResponse>> GetGainfoPageByDeviceAsync(DeviceWithGainfoRequest request)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -190,9 +190,10 @@ public class DeviceTimePeriodService : IDeviceTimePeriodService
|
|||||||
DeviceUniqueNo = deviceUniqueNo,
|
DeviceUniqueNo = deviceUniqueNo,
|
||||||
Status = DeviceTaskStatusEnumType.Wait,
|
Status = DeviceTaskStatusEnumType.Wait,
|
||||||
Version = 0,
|
Version = 0,
|
||||||
|
ResultMessage = null,
|
||||||
Source = source,
|
Source = source,
|
||||||
Priority = 90,
|
Priority = 90,
|
||||||
TenantId = device.TenantId
|
TenantId = device.TenantId,
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Dlhis.Basic.Device.Filters;
|
using Dlhis.Basic.Device.Response;
|
||||||
using Dlhis.Basic.Device.Response;
|
|
||||||
using Dlhis.Basic.Organization.Request;
|
using Dlhis.Basic.Organization.Request;
|
||||||
using Dlhis.Basic.Organization.Response;
|
using Dlhis.Basic.Organization.Response;
|
||||||
using Dlhis.Basic.Organization.Services;
|
using Dlhis.Basic.Organization.Services;
|
||||||
@@ -75,7 +74,6 @@ public class GainfoGroupsController : ControllerBase
|
|||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("assign")]
|
[HttpPost("assign")]
|
||||||
[AssignPermissionLimit]
|
|
||||||
[Transactional]
|
[Transactional]
|
||||||
[CrossTenant]
|
[CrossTenant]
|
||||||
public async Task<DevicePermissionAssignResponse> AssignGainfosAsync(GainfoAssignRequest request)
|
public async Task<DevicePermissionAssignResponse> AssignGainfosAsync(GainfoAssignRequest request)
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ public class GainfoPermissionService : IGainfoPermissionService
|
|||||||
//获取人员的设备权限
|
//获取人员的设备权限
|
||||||
if (deviceCodes.IsEmpty())
|
if (deviceCodes.IsEmpty())
|
||||||
{
|
{
|
||||||
deviceCodes = await _devicePermissionAnalyzeService.GetAssignDeviceCodesAsync(gainfo!.No);
|
deviceCodes = await _devicePermissionAnalyzeService.GetUserPermissionDeviceCodesAsync(gainfo!.No);
|
||||||
}
|
}
|
||||||
|
|
||||||
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => deviceCodes.Contains(x.Code)).ToListAsync();
|
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => deviceCodes.Contains(x.Code)).ToListAsync();
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Dlhis.Basic.BusinessShift.Services;
|
using Dlhis.Basic.BusinessShift.Services;
|
||||||
using Dlhis.Basic.Device.Filters;
|
|
||||||
using Dlhis.Basic.Places.Request;
|
using Dlhis.Basic.Places.Request;
|
||||||
using Dlhis.Basic.Places.Response;
|
using Dlhis.Basic.Places.Response;
|
||||||
using Dlhis.Basic.Places.Services;
|
using Dlhis.Basic.Places.Services;
|
||||||
@@ -124,7 +123,6 @@ public class BusinessPlacesController : ControllerBase
|
|||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("device/assign")]
|
[HttpPost("device/assign")]
|
||||||
[AssignPermissionLimit]
|
|
||||||
[Transactional]
|
[Transactional]
|
||||||
[CrossTenant]
|
[CrossTenant]
|
||||||
public async Task Assign(DispositionDeviceRequest request)
|
public async Task Assign(DispositionDeviceRequest request)
|
||||||
|
|||||||
Reference in New Issue
Block a user