fix 优化同步速度

This commit is contained in:
2024-12-25 15:10:10 +08:00
parent 27ea53134c
commit 3586a456d2
2 changed files with 48 additions and 51 deletions

View File

@@ -125,12 +125,12 @@ public class MyDataPermissionService : IDataPermissionService
{
var codes = new List<Guid>();
var disableFilter = _currentUser.GetRole() is "admin" or "tenant-admin";
if (!disableFilter)
var hasAllPermission = _currentUser.GetRole() is "admin" or "tenant-admin";
if (!hasAllPermission)
{
codes = _getDataPermissions.GetData<DeviceGroupEntity>().FirstOrDefault().Value ?? new List<Guid>();
}
return (!disableFilter, codes);
return (!hasAllPermission, codes);
}
}

View File

@@ -1,7 +1,7 @@
using Dlhis.Basic.Device.Services;
using Dlhis.Basic.Organization.Comparers;
using Dlhis.Basic.Organization.Comparers;
using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Basic.Enums;
using Dlhis.Entity.Device.Enums;
using Dlhis.Entity.Sys.Entities;
using Dlhis.Entity.Sys.Enums;
using Dlhis.Jip.Api.Dto;
@@ -18,7 +18,7 @@ public class GainfoUpdateService : IGainfoUpdateService
private readonly ILogger<GainfoUpdateService> _logger;
private readonly ITenantApi _tenantApi;
private readonly IJinkoSapService _jinkoSapService;
private readonly IDevicePermissionAnalyzeService _devicePermissionAnalyzeService;
private readonly IGainfoPermissionService _gainfoPermissionService;
private readonly IIdentityUserSyncService _identityUserSyncService;
private List<TenantResponse> _tenants;
@@ -27,7 +27,7 @@ public class GainfoUpdateService : IGainfoUpdateService
ILogger<GainfoUpdateService> logger,
ITenantApi tenantApi,
IJinkoSapService jinkoSapService,
IDevicePermissionAnalyzeService devicePermissionAnalyzeService,
IGainfoPermissionService gainfoPermissionService,
IIdentityUserSyncService identityUserSyncService)
{
_dbContext = dbContext;
@@ -35,7 +35,7 @@ public class GainfoUpdateService : IGainfoUpdateService
_logger = logger;
_tenantApi = tenantApi;
_jinkoSapService = jinkoSapService;
_devicePermissionAnalyzeService = devicePermissionAnalyzeService;
_gainfoPermissionService = gainfoPermissionService;
_identityUserSyncService = identityUserSyncService;
}
@@ -171,11 +171,10 @@ public class GainfoUpdateService : IGainfoUpdateService
if (item.isowner == "T")
{
await _devicePermissionAnalyzeService.GenerateDeviceTasksAsync(async () =>
{
await _dbContext.InsertAsync(info);
await _identityUserSyncService.SyncAccountAsync(info.Code, info.Name, info.IdNo, info.Factory);
}, new List<string> { info.No }, "入职生成");
await _dbContext.InsertAsync(info);
await _identityUserSyncService.SyncAccountAsync(info.Code, info.Name, info.IdNo, info.Factory);
await _gainfoPermissionService.ResetPermissionsAsync(info.No, DeviceTaskEnumType.Add, null, "入职生成");
}
else
{
@@ -260,55 +259,53 @@ public class GainfoUpdateService : IGainfoUpdateService
{
if (item.isowner == "T")
{
await _devicePermissionAnalyzeService.GenerateDeviceTasksAsync(async () =>
await _dbContext.Updateable<GainfoEntity>().SetColumns(g => new GainfoEntity
{
await _dbContext.Updateable<GainfoEntity>().SetColumns(g => new GainfoEntity
{
InternalNo = item.PERNR,
Name = item.gname,
PositionNo = item.STELL,
Grade = item.ZZ_ZD,
Title = item.Z_ZJ,
Phone = item.phone,
DepartmentNo = item.appellation,
Remark = item.remark,
Degree = item.email,
Werks = item.WERKS,
CostId = item.KOSTL,
EntryDate = item.createdate,
ResignationDate = item.ZLZRQ,
Workplace = workplace,
Factory = factory,
CardType = SafeParseCardType(item.ZZ_KLX)
}).Where(x => x.Code == item.ename).ExecuteCommandAsync();
InternalNo = item.PERNR,
Name = item.gname,
PositionNo = item.STELL,
Grade = item.ZZ_ZD,
Title = item.Z_ZJ,
Phone = item.phone,
DepartmentNo = item.appellation,
Remark = item.remark,
Degree = item.email,
Werks = item.WERKS,
CostId = item.KOSTL,
EntryDate = item.createdate,
ResignationDate = item.ZLZRQ,
Workplace = workplace,
Factory = factory,
CardType = SafeParseCardType(item.ZZ_KLX)
}).Where(x => x.Code == item.ename).ExecuteCommandAsync();
await _identityUserSyncService.SyncAccountAsync(gainfo.Code, gainfo.Name, gainfo.IdNo, factory);
}, new List<string> { gainfo.No }, "人员数据变更");
await _identityUserSyncService.SyncAccountAsync(gainfo.Code, gainfo.Name, gainfo.IdNo, factory);
await _gainfoPermissionService.ResetPermissionsAsync(info.No, DeviceTaskEnumType.Update, null, "人员数据变更");
}
else
{
await _dbContext.Client.Ado.BeginTranAsync();
try
{
await _devicePermissionAnalyzeService.GenerateDeviceTasksAsync(async () =>
await _gainfoPermissionService.ResetPermissionsAsync(info.No, DeviceTaskEnumType.Delete, null, "人员离职生成");
//先写入离职表
gainfo.IdentityUserId = (int)gainfo.Id; //记录原始id
gainfo.Id = 0;
gainfo.ResignationDate = item.ZLZRQ;
if (!await _dbContext.Queryable<GainfoLeaveEntity>().AnyAsync(x => x.Code == item.ename))
{
//先写入离职表
gainfo.IdentityUserId = (int)gainfo.Id; //记录原始id
gainfo.Id = 0;
gainfo.ResignationDate = item.ZLZRQ;
await _dbContext.Client.Insertable(gainfo).AS("GainfoLeave").ExecuteCommandAsync();
}
if (!await _dbContext.Queryable<GainfoLeaveEntity>().AnyAsync(x => x.Code == item.ename))
{
await _dbContext.Client.Insertable(gainfo).AS("GainfoLeave").ExecuteCommandAsync();
}
await _dbContext.Deleteable<GainfoGroupRelationshipEntity>().Where(x => x.UserNo == gainfo.No).ExecuteCommandAsync();
await _dbContext.Deleteable<DevicePermissionEntity>().Where(x => x.AssignType == AssignTypeEnumType.User && x.AssignValue == gainfo.No).ExecuteCommandAsync();
gainfo.Id = gainfo.IdentityUserId;
await _dbContext.DeleteReallyAsync(gainfo);
}, new List<string> { gainfo.No }, "人员离职生成");
await _dbContext.Deleteable<GainfoGroupRelationshipEntity>().Where(x => x.UserNo == gainfo.No).ExecuteCommandAsync();
await _dbContext.Deleteable<DevicePermissionEntity>().Where(x => x.AssignType == AssignTypeEnumType.User && x.AssignValue == gainfo.No).ExecuteCommandAsync();
gainfo.Id = gainfo.IdentityUserId;
await _dbContext.DeleteReallyAsync(gainfo);
await _dbContext.Client.Ado.CommitTranAsync();
}
catch (Exception ex)