From d3dbff92483ca2ec7f60fe8548a6a0791c8fcf0d Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 13 Dec 2024 17:30:14 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BA=BA=E5=91=98=E7=A6=BB=E8=81=8C?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/GainfoUpdateService.cs | 71 +++++++------------ 1 file changed, 25 insertions(+), 46 deletions(-) diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoUpdateService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoUpdateService.cs index 15fded70..b50fce1d 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoUpdateService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoUpdateService.cs @@ -2,6 +2,8 @@ using Dlhis.Basic.Organization.Comparers; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Basic.Enums; +using Dlhis.Entity.Sys.Entities; +using Dlhis.Entity.Sys.Enums; using Dlhis.Jip.Api.Dto; using Dlhis.Sys.Api; using Dlhis.Sys.Api.Response; @@ -173,7 +175,6 @@ public class GainfoUpdateService : IGainfoUpdateService { await _dbContext.InsertAsync(info); await _identityUserSyncService.SyncAccountAsync(info.Code, info.Name, info.IdNo, info.Factory); - }, new List { info.No }); } else @@ -258,34 +259,6 @@ public class GainfoUpdateService : IGainfoUpdateService if (gainfo != null) { if (item.isowner == "T") - { - await _devicePermissionAnalyzeService.GenerateDeviceTasksAsync(async () => - { - await _dbContext.Updateable().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(); - - await _identityUserSyncService.SyncAccountAsync(gainfo.Code, gainfo.Name, gainfo.IdNo, factory); - - }, new List { gainfo.No }); - } - else { await _devicePermissionAnalyzeService.GenerateDeviceTasksAsync(async () => { @@ -310,27 +283,37 @@ public class GainfoUpdateService : IGainfoUpdateService }).Where(x => x.Code == item.ename).ExecuteCommandAsync(); await _identityUserSyncService.SyncAccountAsync(gainfo.Code, gainfo.Name, gainfo.IdNo, factory); - }, new List { gainfo.No }); - - + } + else + { + await _dbContext.Client.Ado.BeginTranAsync(); try { - //先写入离职表 - gainfo.IdentityUserId = (int)gainfo.Id; //记录原始id - gainfo.Id = 0; - gainfo.ResignationDate = item.ZLZRQ; - - if (!await _dbContext.Queryable().AnyAsync(x => x.Code == item.ename)) + await _devicePermissionAnalyzeService.GenerateDeviceTasksAsync(async () => { - await _dbContext.Client.Insertable(gainfo).AS("GainfoLeave").ExecuteCommandAsync(); - } + //先写入离职表 + gainfo.IdentityUserId = (int)gainfo.Id; //记录原始id + gainfo.Id = 0; + gainfo.ResignationDate = item.ZLZRQ; - gainfo.Id = gainfo.IdentityUserId; - await _dbContext.DeleteReallyAsync(gainfo); + if (!await _dbContext.Queryable().AnyAsync(x => x.Code == item.ename)) + { + await _dbContext.Client.Insertable(gainfo).AS("GainfoLeave").ExecuteCommandAsync(); + } + + await _dbContext.Deleteable().Where(x => x.UserNo != gainfo.No).ExecuteCommandAsync(); + await _dbContext.Deleteable().Where(x => x.AssignType == AssignTypeEnumType.User && x.AssignValue == gainfo.No).ExecuteCommandAsync(); + + gainfo.Id = gainfo.IdentityUserId; + await _dbContext.DeleteReallyAsync(gainfo); + }, new List { gainfo.No }); + + await _dbContext.Client.Ado.CommitTranAsync(); } catch (Exception ex) { + await _dbContext.Client.Ado.RollbackTranAsync(); _logger.LogError(ex, "离职任务生成失败:{message}", ex.Message); } } @@ -389,8 +372,6 @@ public class GainfoUpdateService : IGainfoUpdateService 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 = await _dbContext.Queryable().ToListAsync(); return gainfos.Select(x => new SapPersonItem @@ -426,8 +407,6 @@ public class GainfoUpdateService : IGainfoUpdateService { return data.Select(person => { - //var position = _positions.FirstOrDefault(x => x.No == person.PLANS); - var rzrq = person.ZRZRQ; var lzrq = person.ZLZRQ; var rmk = $"入职时间:{rzrq.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture)} ";