diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs index 1142af9d..40290280 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs @@ -182,11 +182,6 @@ public class DevicePermissionService : IDevicePermissionService var userNos = beforeDto.UserNos; var before = beforeDto.PermissionInfos.ToDictionary(x => x.Key, x => x.Value, StringComparer.OrdinalIgnoreCase); - //获取业务处理后所有人的权限 - var nextUserNos = await GetPermissionUserNosAsync(); - if (nextUserNos.Any()) - userNos = userNos.Concat(nextUserNos).Distinct(StringComparer.OrdinalIgnoreCase).ToList(); - var current = await GetAssignDeviceCodesInternalAsync(userNos); var deivces = await _dbContext.Queryable().ToListAsync(); diff --git a/Src/Dlhis.ScheduledTask/Common/Services/Implements/GainfoUpdateService.cs b/Src/Dlhis.ScheduledTask/Common/Services/Implements/GainfoUpdateService.cs index c08a520e..99be42ef 100644 --- a/Src/Dlhis.ScheduledTask/Common/Services/Implements/GainfoUpdateService.cs +++ b/Src/Dlhis.ScheduledTask/Common/Services/Implements/GainfoUpdateService.cs @@ -9,6 +9,7 @@ using Dlhis.ScheduledTask.Common.Dto; using Dlhis.ScheduledTask.Common.Comparers; using Kurisu.AspNetCore.Utils.Extensions; using Dlhis.ScheduledTask.Common.Response; +using Dlhis.Basic.Api.Dtos; namespace Dlhis.ScheduledTask.Common.Services.Implements; @@ -78,7 +79,7 @@ public class GainfoUpdateService : IGainfoUpdateService if (persons.Count > 0) { - var modifiedPersons = GetModifiedPerson(persons.OrderByDescending(x => x.ZSTATUS).ThenBy(x => x.ZRZRQ).ToList()); + var modifiedPersons = await GetModifiedPersonAsync(persons.OrderByDescending(x => x.ZSTATUS).ThenBy(x => x.ZRZRQ).ToList()); werkInfo.HandleMessage = "SAP人员差异数量" + modifiedPersons.Count; werkInfo.DiffNumber = modifiedPersons.Count; @@ -92,16 +93,8 @@ public class GainfoUpdateService : IGainfoUpdateService var tenantResult = await _tenantApi.GetTenantsInternalAsync(); _tenants = tenantResult.Data; - //var codes = modifiedPersons.Select(x => x.ZWORKCODE).ToList(); - //var userNos = await _dbContext.Queryable().Where(x => codes.Contains(x.Code)).Select(x => x.No).ToListAsync(); - //var dtoResult = await _devicePermissionApi.GetPermissionUsersInfoAsync(userNos); - //var dto = dtoResult.Data; - await SavePersonAsync(modifiedPersons); - //var rResult = await _devicePermissionApi.RePermissionUsersInfoAsync(dto); - //var r = rResult.Data; - werkInfo.PermissionChangeNumber = 0; await _dbContext.UpdateAsync(werkInfo); } @@ -134,7 +127,7 @@ public class GainfoUpdateService : IGainfoUpdateService _logger.LogInformation("获取SAP人员数量为:{count}", persons.Count); if (persons.Count > 0) { - var modifiedPersons = GetModifiedPerson(persons.OrderByDescending(x => x.ZSTATUS).ThenBy(x => x.ZRZRQ).ToList()); + var modifiedPersons = await GetModifiedPersonAsync(persons.OrderByDescending(x => x.ZSTATUS).ThenBy(x => x.ZRZRQ).ToList()); _logger.LogInformation("SAP人员差异数量为:{count}", modifiedPersons.Count); if (modifiedPersons.Count > 0) { @@ -186,8 +179,18 @@ public class GainfoUpdateService : IGainfoUpdateService i++; try { - await InsertPersonAsync(item); + var no = await InsertPersonAsync(item); _logger.LogWarning("执行新增成功 工号:{code},姓名:{name}", item.ename, item.gname); + + var rResult = await _devicePermissionApi.RePermissionUsersInfoAsync(new PermissionUsersInfoDto + { + UserNos = new List { no }, + PermissionInfos = new Dictionary> + { + [no] = new List() + } + }); + var r = rResult.Data; } catch (Exception ex) { @@ -200,8 +203,22 @@ public class GainfoUpdateService : IGainfoUpdateService i++; try { - await UpdatePersonAsync(item); - _logger.LogWarning("执行更新成功 工号:{code},姓名:{name}", item.ename, item.gname); + var no = await _dbContext.Queryable().Where(x => x.Code == item.ename).Select(x => x.No).SingleAsync(); + if (no.IsPresent()) + { + var dtoResult = await _devicePermissionApi.GetPermissionUsersInfoAsync(new List { no }); + var dto = dtoResult.Data; + + await UpdatePersonAsync(item); + _logger.LogWarning("执行更新成功 工号:{code},姓名:{name}", item.ename, item.gname); + + await _devicePermissionApi.RePermissionUsersInfoAsync(dto); + } + else + { + await UpdatePersonAsync(item); + _logger.LogWarning("执行更新成功 工号:{code},姓名:{name}", item.ename, item.gname); + } } catch (Exception ex) { @@ -211,7 +228,7 @@ public class GainfoUpdateService : IGainfoUpdateService } } - private async Task InsertPersonAsync(GainfoSapEntity item) + private async Task InsertPersonAsync(GainfoSapEntity item) { await _dbContext.InsertAsync(item); @@ -220,10 +237,12 @@ public class GainfoUpdateService : IGainfoUpdateService if (item.isowner == "T") { await _dbContext.InsertAsync(info); + return info.No; } else { await _dbContext.Client.Insertable(info).AS("GainfoLeave").ExecuteCommandAsync(); + return null; } } @@ -260,7 +279,7 @@ public class GainfoUpdateService : IGainfoUpdateService return info; } - private async Task UpdatePersonAsync(GainfoSapEntity item) + private async Task UpdatePersonAsync(GainfoSapEntity item) { var gainfoSap = await _dbContext.Queryable().Where(x => x.ename == item.ename).FirstAsync(); await _dbContext.Updateable().SetColumns(g => new GainfoSapEntity @@ -331,11 +350,14 @@ public class GainfoUpdateService : IGainfoUpdateService await _dbContext.Client.Insertable(gainfo).AS("GainfoLeave").ExecuteCommandAsync(); } } + + + return gainfo?.No; } - private List GetModifiedPerson(List sapList) + private async Task> GetModifiedPersonAsync(List sapList) { - var last = LoadData(); + var last = await LoadDataAsync(); if (last.Count <= 0) { return sapList; @@ -373,11 +395,11 @@ public class GainfoUpdateService : IGainfoUpdateService } - private List LoadData() + private async Task> LoadDataAsync() { //var pJson = "{\"id\":0,\"ano\":null,\"class\":\"C\",\"passwd\":null,\"question\":null,\"answer\":null,\"gname\":\"岳文超\",\"ename\":\"098250\",\"country\":null,\"idcls\":\"ID\",\"idno\":\"\\\"140105200112051318\n\",\"native\":\"14010\",\"sex\":\"M\",\"birthday\":\"2001-12-05T00:00:00\",\"address\":\"\",\"postcode\":null,\"occupation\":\"99\",\"appellation\":\"00210591\",\"nation\":\"01\",\"phone\":\"13773151205\",\"fax\":null,\"mobile\":null,\"email\":\"高中/中专【失效】\",\"web\":\"\",\"vip\":null,\"sec\":null,\"cropsno\":null,\"cropname\":null,\"fancy\":null,\"remark\":\"入职时间:2023-05-05 离职时间:2023-10-30 变更原因:自离【失效】\",\"amount\":0,\"days\":0,\"consume01\":0.0000,\"consume02\":0.0000,\"consume03\":0.0000,\"consume04\":0.0000,\"log_id\":\"XX\",\"log_shift\":\"1\",\"log_date\":null,\"log_ip\":\"127.0.0.1\",\"times\":0,\"logmark\":0,\"rmcode\":null,\"mkt\":null,\"src\":null,\"isowner\":\"F\",\"createdate\":\"2023-05-05T00:00:00\",\"PERNR\":\"00281800\",\"WERKS\":\"1560\",\"ZSTATUS\":\"5\",\"KOSTL\":\"156020336\",\"ZZ_ZD\":\"3\",\"Z_ZJ\":\"T0\",\"STELL\":null,\"STELL_NM\":null,\"ZLZRQ\":\"2023-10-30T00:00:00\",\"MASSN\":\"ZD\",\"MNTXT\":\"离职\",\"MASSG\":null,\"MGTXT\":null,\"logdate\":\"2024-03-14T00:02:34\",\"updatelogdate\":null,\"guestno\":null,\"ZZ_KLX\":\"3\",\"DAT01\":null,\"ZZ_COUNNM\":null,\"ZZ_GZDJDNM\":\"海宁基地\",\"ZZ_GZDCQNM\":\"海宁尖山\"}"; //var gainfos = new List() { pJson.ToObject() }; - var gainfos = _dbContext.Queryable().ToList(); + var gainfos = await _dbContext.Queryable().ToListAsync(); return gainfos.Select(x => new SapPersonItem {