fix 优化代码风格和触发数据迁移任务下发
This commit is contained in:
@@ -5,14 +5,12 @@ using Dlhis.Entity.Device.Entities;
|
|||||||
using Dlhis.Entity.Device.Enums;
|
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 Dlhis.Scheduled.Api;
|
|
||||||
using Kurisu.AspNetCore.Authentication.Abstractions;
|
using Kurisu.AspNetCore.Authentication.Abstractions;
|
||||||
using Kurisu.AspNetCore.DataAccess.Entity;
|
using Kurisu.AspNetCore.DataAccess.Entity;
|
||||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||||
using Kurisu.AspNetCore.Utils;
|
using Kurisu.AspNetCore.Utils;
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using GeneratePermissionIdRequest = Dlhis.Scheduled.Api.Request.GeneratePermissionIdRequest;
|
|
||||||
|
|
||||||
namespace Dlhis.Basic.Device.Services.Implements;
|
namespace Dlhis.Basic.Device.Services.Implements;
|
||||||
|
|
||||||
@@ -21,71 +19,50 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
private readonly IDbContext _dbContext;
|
private readonly IDbContext _dbContext;
|
||||||
private readonly ICurrentUser _currentUser;
|
private readonly ICurrentUser _currentUser;
|
||||||
private readonly RedisCache _redisCache;
|
private readonly RedisCache _redisCache;
|
||||||
private readonly IHangfireApi _hangfireApi;
|
|
||||||
|
|
||||||
public DevicePermissionService(IDbContext dbContext, ICurrentUser currentUser, RedisCache redisCache, IHangfireApi hangfireApi)
|
public DevicePermissionService(IDbContext dbContext, ICurrentUser currentUser, RedisCache redisCache)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
_currentUser = currentUser;
|
_currentUser = currentUser;
|
||||||
_redisCache = redisCache;
|
_redisCache = redisCache;
|
||||||
_hangfireApi = hangfireApi;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AssignAsync(DevicePermissionSaveRequest request)
|
public async Task AssignAsync(DevicePermissionSaveRequest request)
|
||||||
{
|
{
|
||||||
var currentTenantId = _currentUser.GetStringTenantId();
|
var currentTenantId = _currentUser.GetStringTenantId();
|
||||||
|
|
||||||
using (var handler = await _redisCache.LockAsync($"permission:generate:{currentTenantId}"))
|
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 () =>
|
||||||
{
|
{
|
||||||
handler.Acquired.ThrowIfFalse("请勿频繁分配设备权限");
|
//删除当前匹配的基地权限
|
||||||
|
var p = await _dbContext.Queryable<DevicePermissionEntity>()
|
||||||
|
.Where(x => x.AssignType == request.AssignType)
|
||||||
|
.Where(x => x.AssignValue == request.AssignValue)
|
||||||
|
.Where(x => x.UniqueType == request.UniqueType)
|
||||||
|
.Where(x => x.TenantId == tenantId)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
var tenantId = request.AssignType == AssignTypeEnumType.Department ? request.TenantId : _currentUser.GetStringTenantId();
|
await _dbContext.DeleteReallyAsync(p);
|
||||||
|
|
||||||
await GenerateDeviceTasksAsync(async () =>
|
//保存配置的权限
|
||||||
|
if (request.Codes.IsPresent())
|
||||||
{
|
{
|
||||||
//删除当前匹配的基地权限
|
var devicePermissions = request.Codes.Select(code => new DevicePermissionEntity
|
||||||
var p = await _dbContext.Queryable<DevicePermissionEntity>()
|
|
||||||
.Where(x => x.AssignType == request.AssignType)
|
|
||||||
.Where(x => x.AssignValue == request.AssignValue)
|
|
||||||
.Where(x => x.UniqueType == request.UniqueType)
|
|
||||||
.Where(x => x.TenantId == tenantId)
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
await _dbContext.DeleteReallyAsync(p);
|
|
||||||
|
|
||||||
//保存配置的权限
|
|
||||||
if (request.Codes.IsPresent())
|
|
||||||
{
|
{
|
||||||
var devicePermissions = request.Codes.Select(code => new DevicePermissionEntity
|
AssignType = request.AssignType,
|
||||||
{
|
AssignValue = request.AssignValue,
|
||||||
AssignType = request.AssignType,
|
UniqueType = request.UniqueType,
|
||||||
AssignValue = request.AssignValue,
|
UniqueValue = code,
|
||||||
UniqueType = request.UniqueType,
|
TenantId = tenantId
|
||||||
UniqueValue = code,
|
}).ToList();
|
||||||
TenantId = tenantId
|
|
||||||
}).ToList();
|
|
||||||
|
|
||||||
await _dbContext.InsertAsync(devicePermissions);
|
await _dbContext.InsertAsync(devicePermissions);
|
||||||
}
|
}
|
||||||
}, null);
|
}, null);
|
||||||
}
|
|
||||||
|
|
||||||
// var tenantId = request.AssignType == AssignTypeEnumType.Department ? request.TenantId : _currentUser.GetStringTenantId();
|
|
||||||
// request.TenantId = tenantId;
|
|
||||||
//
|
|
||||||
// var json = request.ToJson();
|
|
||||||
// var id = await _dbContext.InsertReturnIdentityAsync(new DevicePermissionAssignmentEntity
|
|
||||||
// {
|
|
||||||
// Assignment = json,
|
|
||||||
// IsHandler = false,
|
|
||||||
// Result = null,
|
|
||||||
// TenantId = currentTenantId
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// await _hangfireApi.GeneratePermissionsAsync(new GeneratePermissionIdRequest()
|
|
||||||
// {
|
|
||||||
// Id = id
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task GeneratePermissionsAsync(long id)
|
public async Task GeneratePermissionsAsync(long id)
|
||||||
@@ -334,12 +311,12 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var deivces = await _dbContext.Queryable<DeviceEntity>()
|
var devices = await _dbContext.Queryable<DeviceEntity>()
|
||||||
.Where(x => x.Enable)
|
.Where(x => x.Enable)
|
||||||
.Where(x => deviceCodes.Contains(x.Code))
|
.Where(x => deviceCodes.Contains(x.Code))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
var tasks = deivces.Select(x => new DeviceTaskEntity
|
var tasks = devices.Select(x => new DeviceTaskEntity
|
||||||
{
|
{
|
||||||
DeviceUniqueNo = x.UniqueNo,
|
DeviceUniqueNo = x.UniqueNo,
|
||||||
Status = DeviceTaskStatusEnumType.Wait,
|
Status = DeviceTaskStatusEnumType.Wait,
|
||||||
@@ -347,6 +324,7 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
DeviceType = x.Type,
|
DeviceType = x.Type,
|
||||||
UserNo = userNo,
|
UserNo = userNo,
|
||||||
CancellationId = 0,
|
CancellationId = 0,
|
||||||
|
Priority = 0,
|
||||||
Version = 0,
|
Version = 0,
|
||||||
TenantId = x.TenantId
|
TenantId = x.TenantId
|
||||||
}).ToList();
|
}).ToList();
|
||||||
@@ -428,7 +406,7 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
.Where(x => x.AssignType == assignType)
|
.Where(x => x.AssignType == assignType)
|
||||||
.Where(x => x.AssignValue == assignValue)
|
.Where(x => x.AssignValue == assignValue)
|
||||||
.GroupBy(x => x.TenantId)
|
.GroupBy(x => x.TenantId)
|
||||||
.Select(x => new UserTenantDeviceCodeDto { Tenant = x.Key, Codes = x.Select(x => x.UniqueValue).ToList() })
|
.Select(x => new UserTenantDeviceCodeDto { Tenant = x.Key, Codes = x.Select(p => p.UniqueValue).ToList() })
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
//处理获取设备分组的情况
|
//处理获取设备分组的情况
|
||||||
@@ -450,9 +428,9 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
};
|
};
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
void RecursionGetNext(DeviceGroupEntity current, List<DeviceGroupEntity> deviceGroups, List<UserTenantDeviceCodeDto> result, bool add)
|
void RecursionGetNext(DeviceGroupEntity current, List<DeviceGroupEntity> internalDeviceGroups, List<UserTenantDeviceCodeDto> result, bool add)
|
||||||
{
|
{
|
||||||
var next = deviceGroups.Where(x => x.PCode == current.Code).ToList();
|
var next = internalDeviceGroups.Where(x => x.PCode == current.Code).ToList();
|
||||||
foreach (var item in next)
|
foreach (var item in next)
|
||||||
{
|
{
|
||||||
if (add)
|
if (add)
|
||||||
@@ -460,7 +438,7 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
result.Add(new UserTenantDeviceCodeDto { Tenant = item.TenantId, Codes = new List<Guid> { item.Code } });
|
result.Add(new UserTenantDeviceCodeDto { Tenant = item.TenantId, Codes = new List<Guid> { item.Code } });
|
||||||
}
|
}
|
||||||
|
|
||||||
RecursionGetNext(item, deviceGroups, result, result.SelectMany(x => x.Codes).Contains(item.Code));
|
RecursionGetNext(item, internalDeviceGroups, result, result.SelectMany(x => x.Codes).Contains(item.Code));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -169,16 +169,18 @@ public class GainfoPermissionService : IGainfoPermissionService
|
|||||||
var tasks = devices.Select(x => new DeviceTaskEntity
|
var tasks = devices.Select(x => new DeviceTaskEntity
|
||||||
{
|
{
|
||||||
UserId = gainfo!.Id,
|
UserId = gainfo!.Id,
|
||||||
Source = null,
|
|
||||||
DeviceUniqueNo = x.UniqueNo,
|
DeviceUniqueNo = x.UniqueNo,
|
||||||
Status = DeviceTaskStatusEnumType.Wait,
|
Status = DeviceTaskStatusEnumType.Wait,
|
||||||
|
Version = 0,
|
||||||
|
CancellationId = 0,
|
||||||
UserNo = request.UserNo,
|
UserNo = request.UserNo,
|
||||||
Type = request.IsLeave
|
Type = request.IsLeave
|
||||||
? DeviceTaskEnumType.Delete
|
? DeviceTaskEnumType.Delete
|
||||||
: DeviceTaskEnumType.Add,
|
: DeviceTaskEnumType.Add,
|
||||||
DeviceType = x.Type,
|
DeviceType = x.Type,
|
||||||
TenantId = gainfo.Factory,
|
TenantId = gainfo.Factory,
|
||||||
Priority = 10
|
Priority = 10,
|
||||||
|
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
await _dbContext.InsertAsync(tasks);
|
await _dbContext.InsertAsync(tasks);
|
||||||
@@ -193,6 +195,8 @@ public class GainfoPermissionService : IGainfoPermissionService
|
|||||||
.Select<DeviceGroupTreeResponse>()
|
.Select<DeviceGroupTreeResponse>()
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//**********************************************************************************************************************************************
|
||||||
|
|
||||||
private static IEnumerable<Guid> RecursionGetNext(DeviceGroupEntity current, List<DeviceGroupEntity> deviceGroups)
|
private static IEnumerable<Guid> RecursionGetNext(DeviceGroupEntity current, List<DeviceGroupEntity> deviceGroups)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
using Dlhis.Basic.Organization.Request;
|
using Dlhis.Basic.Device.Services;
|
||||||
|
using Dlhis.Basic.Organization.Request;
|
||||||
using Dlhis.Basic.Organization.Response;
|
using Dlhis.Basic.Organization.Response;
|
||||||
using Dlhis.Entity.Basic.Entity;
|
using Dlhis.Entity.Basic.Entity;
|
||||||
using Dlhis.Entity.Basic.Enums;
|
using Dlhis.Entity.Basic.Enums;
|
||||||
|
using Dlhis.Entity.Device.Enums;
|
||||||
using Dlhis.Scheduled.Api;
|
using Dlhis.Scheduled.Api;
|
||||||
using Dlhis.Scheduled.Api.Request;
|
using Dlhis.Scheduled.Api.Request;
|
||||||
using Dlhis.Sys.Api;
|
using Dlhis.Sys.Api;
|
||||||
@@ -23,6 +25,7 @@ public class GainfoService : IGainfoService
|
|||||||
private readonly ICurrentUser _currentUser;
|
private readonly ICurrentUser _currentUser;
|
||||||
private readonly ITenantApi _tenantApi;
|
private readonly ITenantApi _tenantApi;
|
||||||
private readonly IHangfireApi _hangfireApi;
|
private readonly IHangfireApi _hangfireApi;
|
||||||
|
private readonly IDevicePermissionService _devicePermissionService;
|
||||||
private readonly IGainfoPermissionService _gainfoPermissionService;
|
private readonly IGainfoPermissionService _gainfoPermissionService;
|
||||||
private readonly ILogger<GainfoService> _logger;
|
private readonly ILogger<GainfoService> _logger;
|
||||||
|
|
||||||
@@ -32,6 +35,7 @@ public class GainfoService : IGainfoService
|
|||||||
ICurrentUser currentUser,
|
ICurrentUser currentUser,
|
||||||
ITenantApi tenantApi,
|
ITenantApi tenantApi,
|
||||||
IHangfireApi hangfireApi,
|
IHangfireApi hangfireApi,
|
||||||
|
IDevicePermissionService devicePermissionService,
|
||||||
IGainfoPermissionService gainfoPermissionService,
|
IGainfoPermissionService gainfoPermissionService,
|
||||||
ILogger<GainfoService> logger)
|
ILogger<GainfoService> logger)
|
||||||
{
|
{
|
||||||
@@ -41,6 +45,7 @@ public class GainfoService : IGainfoService
|
|||||||
_currentUser = currentUser;
|
_currentUser = currentUser;
|
||||||
_tenantApi = tenantApi;
|
_tenantApi = tenantApi;
|
||||||
_hangfireApi = hangfireApi;
|
_hangfireApi = hangfireApi;
|
||||||
|
_devicePermissionService = devicePermissionService;
|
||||||
_gainfoPermissionService = gainfoPermissionService;
|
_gainfoPermissionService = gainfoPermissionService;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
@@ -335,8 +340,14 @@ public class GainfoService : IGainfoService
|
|||||||
ModifiedBy = 1,
|
ModifiedBy = 1,
|
||||||
ModifiedTime = DateTime.Now,
|
ModifiedTime = DateTime.Now,
|
||||||
UserCode = gainfo.Code,
|
UserCode = gainfo.Code,
|
||||||
Face = request.Face,
|
Face = request.Face
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//海宁触发权限下发
|
||||||
|
if (gainfo.Workplace == "5")
|
||||||
|
{
|
||||||
|
await _devicePermissionService.GenerateDeviceTasksAsync(gainfo.No, DeviceTaskEnumType.Add);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user