feat 按设备,设备组,营业点维度添加人员
This commit is contained in:
@@ -6,16 +6,13 @@ using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Entity.Sys.Entities;
|
||||
using Dlhis.Entity.Sys.Enums;
|
||||
using Dlhis.Scheduled.Api;
|
||||
using Kurisu.AspNetCore.Authentication.Abstractions;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.Entity;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using SqlSugar;
|
||||
using GeneratePermissionIdRequest = Dlhis.Scheduled.Api.Request.GeneratePermissionIdRequest;
|
||||
|
||||
namespace Dlhis.Basic.Device.Services.Implements;
|
||||
|
||||
@@ -23,27 +20,16 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly RedisCache _redisCache;
|
||||
private readonly IHangfireApi _hangfireApi;
|
||||
|
||||
public DevicePermissionService(IDbContext dbContext,
|
||||
ICurrentUser currentUser,
|
||||
RedisCache redisCache,
|
||||
IHangfireApi hangfireApi)
|
||||
ICurrentUser currentUser)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_currentUser = currentUser;
|
||||
_redisCache = redisCache;
|
||||
_hangfireApi = hangfireApi;
|
||||
}
|
||||
|
||||
public async Task AssignAsync(DevicePermissionSaveRequest request)
|
||||
{
|
||||
var currentTenantId = _currentUser.GetStringTenantId();
|
||||
|
||||
await using var handler = await _redisCache.LockAsync($"permission:generate:{currentTenantId}");
|
||||
handler.Acquired.ThrowIfFalse("请勿频繁分配设备权限");
|
||||
|
||||
var tenantId = request.AssignType == AssignTypeEnumType.Department ? request.TenantId : _currentUser.GetStringTenantId();
|
||||
|
||||
await GenerateDeviceTasksAsync(async () =>
|
||||
@@ -75,6 +61,43 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
}, null);
|
||||
}
|
||||
|
||||
public async Task AssignToUniqueAsync(DevicePermissionsAssignToDeviceRequest request)
|
||||
{
|
||||
var tenantId = request.AssignType == AssignTypeEnumType.Department ? request.TenantId : _currentUser.GetStringTenantId();
|
||||
|
||||
await GenerateDeviceTasksAsync(async () =>
|
||||
{
|
||||
//删除当前匹配的基地权限
|
||||
var p = await _dbContext.Queryable<DevicePermissionEntity>()
|
||||
.Where(x => x.UniqueType == request.UniqueType)
|
||||
.Where(x => x.UniqueValue == request.UniqueValue)
|
||||
.Where(x => x.AssignType == request.AssignType)
|
||||
.Where(x => request.Values.Contains(x.AssignValue))
|
||||
.Where(x => x.TenantId == tenantId)
|
||||
.ToListAsync();
|
||||
|
||||
await _dbContext.DeleteReallyAsync(p);
|
||||
|
||||
if (!request.IsDelete)
|
||||
{
|
||||
//保存配置的权限
|
||||
if (request.Values.IsPresent())
|
||||
{
|
||||
var devicePermissions = request.Values.Select(v => new DevicePermissionEntity
|
||||
{
|
||||
AssignType = request.AssignType,
|
||||
AssignValue = v,
|
||||
UniqueType = request.UniqueType,
|
||||
UniqueValue = request.UniqueValue,
|
||||
TenantId = tenantId
|
||||
}).ToList();
|
||||
|
||||
await _dbContext.InsertAsync(devicePermissions);
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
|
||||
public async Task GeneratePermissionsAsync(long id)
|
||||
{
|
||||
var assignment = await _dbContext.Queryable<DevicePermissionAssignmentEntity>().SingleAsync(x => x.Id == id);
|
||||
|
||||
Reference in New Issue
Block a user