diff --git a/Src/Dlhis.Basic/Organization/Services/IIdentityUserSyncService.cs b/Src/Dlhis.Basic/Organization/Services/IIdentityUserSyncService.cs index a4a2a58a..1ce716c9 100644 --- a/Src/Dlhis.Basic/Organization/Services/IIdentityUserSyncService.cs +++ b/Src/Dlhis.Basic/Organization/Services/IIdentityUserSyncService.cs @@ -3,4 +3,6 @@ namespace Dlhis.Basic.Organization.Services; public interface IIdentityUserSyncService : IScopeDependency { Task SyncAccountAsync(string userName, string name, string idNo, string tenant); + + Task LockAccountAsync(string userName); } \ No newline at end of file diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoUpdateService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoUpdateService.cs index 7663e18d..db93dc9e 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoUpdateService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoUpdateService.cs @@ -233,7 +233,6 @@ public class GainfoUpdateService : IGainfoUpdateService await _dbContext.Client.Ado.BeginTranAsync(); try { - var info = GainfoSapToGainfo(item); await _dbContext.Updateable().SetColumns(g => new GainfoSapEntity { PERNR = item.PERNR, @@ -261,13 +260,32 @@ public class GainfoUpdateService : IGainfoUpdateService //获取当前在职人员 var gainfo = await _dbContext.Queryable().Where(x => x.Code == item.ename).SingleAsync(); - var workplace = _tenants.FirstOrDefault(x => x.Name == item.ZZ_GZDJDNM)?.Code ?? item.ZZ_GZDJDNM; - var factory = _tenants.LastOrDefault(x => x.Name == item.ZZ_GZDCQNM)?.Code ?? item.ZZ_GZDCQNM; - + //默认人员存在 if (gainfo != null) { + var workplace = _tenants.FirstOrDefault(x => x.Name == item.ZZ_GZDJDNM)?.Code ?? item.ZZ_GZDJDNM; + var factory = _tenants.LastOrDefault(x => x.Name == item.ZZ_GZDCQNM)?.Code ?? item.ZZ_GZDCQNM; + if (item.isowner == "T") { + var change = string.Empty; + + if (gainfo.Factory != factory || gainfo.Workplace != workplace || gainfo.DepartmentNo != item.appellation) + { + if (gainfo.Factory != factory) + { + change = $"{gainfo.Factory}->{factory}"; + } + + if (gainfo.DepartmentNo != item.appellation) + { + change += $"{gainfo.DepartmentNo}->{item.appellation}"; + } + + await _identityUserSyncService.SyncAccountAsync(gainfo.Code, gainfo.Name, gainfo.IdNo, factory); + await _gainfoPermissionService.ResetPermissionsAsync(gainfo.No, DeviceTaskEnumType.Delete, null, $"异动生成({change})"); + } + await _dbContext.Updateable().SetColumns(g => new GainfoEntity { InternalNo = item.PERNR, @@ -288,14 +306,9 @@ public class GainfoUpdateService : IGainfoUpdateService ModifiedTime = DateTime.Now }).Where(x => x.Code == item.ename).ExecuteCommandAsync(); - if (gainfo.Factory != factory) + if (change.IsPresent()) { - await _identityUserSyncService.SyncAccountAsync(gainfo.Code, gainfo.Name, gainfo.IdNo, factory); - } - - if (gainfo.Factory != factory || gainfo.Workplace != workplace || gainfo.DepartmentNo != item.appellation) - { - await _gainfoPermissionService.ResetPermissionsAsync(gainfo.No, DeviceTaskEnumType.Delete, null, "异动生成"); + await _gainfoPermissionService.ResetPermissionsAsync(gainfo.No, DeviceTaskEnumType.Add, null, $"异动生成({change})"); } } else @@ -317,42 +330,7 @@ public class GainfoUpdateService : IGainfoUpdateService gainfo.Id = gainfo.IdentityUserId; await _dbContext.DeleteReallyAsync(gainfo); - } - } - else - { - if (item.isowner == "T") - { - await _dbContext.InsertAsync(info); - await _identityUserSyncService.SyncAccountAsync(info.Code, info.Name, info.IdNo, factory); - } - else - { - if (!await _dbContext.Queryable().AnyAsync(x => x.Code == item.ename)) - { - await _dbContext.Client.Insertable(info).AS("GainfoLeave").ExecuteCommandAsync(); - } - else - { - await _dbContext.Updateable().SetColumns(g => new GainfoLeaveEntity - { - 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, - }).Where(x => x.Code == item.ename).ExecuteCommandAsync(); - } + await _identityUserSyncService.LockAccountAsync(gainfo.Code); } } @@ -361,7 +339,7 @@ public class GainfoUpdateService : IGainfoUpdateService catch (Exception ex) { await _dbContext.Client.Ado.RollbackTranAsync(); - _logger.LogError(ex, "离职任务生成失败:{message}", ex.Message); + _logger.LogError(ex, "更新人员失败:{message}", ex.Message); } } diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/IdentityUserSyncService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/IdentityUserSyncService.cs index 2ccbdfb8..1202760e 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/IdentityUserSyncService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/IdentityUserSyncService.cs @@ -72,6 +72,19 @@ public class IdentityUserSyncService : IIdentityUserSyncService } } + /// + public async Task LockAccountAsync(string userName) + { + var user = await _identityDbContext.Queryable().Where(x => x.UserName == userName).SingleAsync(); + if (user != null) + { + user.LockoutEnabled = true; + user.LockoutEnd = new DateTime(2099, 12, 31); + + await _identityDbContext.UpdateAsync(user); + } + } + //************************************************************************** help method ************************************************************************************** private async Task AddUserClaim(IDbContext dbContext, int userId, string type, string value)