diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoUpdateService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoUpdateService.cs index 77538da1..b5c60de7 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoUpdateService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoUpdateService.cs @@ -230,67 +230,66 @@ public class GainfoUpdateService : IGainfoUpdateService private async Task UpdatePersonAsync(GainfoSapEntity item) { - var info = GainfoSapToGainfo(item); - await _dbContext.Updateable().SetColumns(g => new GainfoSapEntity + await _dbContext.Client.Ado.BeginTranAsync(); + try { - PERNR = item.PERNR, - gname = item.gname, - phone = item.phone, - appellation = item.appellation, - isowner = item.isowner, - remark = item.remark, - email = item.email, - WERKS = item.WERKS, - KOSTL = item.KOSTL, - STELL = item.STELL, - Z_ZJ = item.Z_ZJ, - ZZ_ZD = item.ZZ_ZD, - MNTXT = item.MNTXT, - MASSN = item.MASSN, - ZSTATUS = item.ZSTATUS, - ZLZRQ = item.ZLZRQ, - STELL_NM = item.STELL_NM, - createdate = item.createdate, - ZZ_GZDJDNM = item.ZZ_GZDJDNM, - ZZ_GZDCQNM = item.ZZ_GZDCQNM, - }).Where(x => x.ename == item.ename).ExecuteCommandAsync(); - - //获取当前在职人员 - 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) - { - if (item.isowner == "T") + var info = GainfoSapToGainfo(item); + await _dbContext.Updateable().SetColumns(g => new GainfoSapEntity { - await _dbContext.Updateable().SetColumns(g => new GainfoEntity + PERNR = item.PERNR, + gname = item.gname, + phone = item.phone, + appellation = item.appellation, + isowner = item.isowner, + remark = item.remark, + email = item.email, + WERKS = item.WERKS, + KOSTL = item.KOSTL, + STELL = item.STELL, + Z_ZJ = item.Z_ZJ, + ZZ_ZD = item.ZZ_ZD, + MNTXT = item.MNTXT, + MASSN = item.MASSN, + ZSTATUS = item.ZSTATUS, + ZLZRQ = item.ZLZRQ, + STELL_NM = item.STELL_NM, + createdate = item.createdate, + ZZ_GZDJDNM = item.ZZ_GZDJDNM, + ZZ_GZDCQNM = item.ZZ_GZDCQNM, + }).Where(x => x.ename == item.ename).ExecuteCommandAsync(); + + //获取当前在职人员 + 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) + { + if (item.isowner == "T") { - 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 _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, + }).Where(x => x.Code == item.ename).ExecuteCommandAsync(); - await _identityUserSyncService.SyncAccountAsync(gainfo.Code, gainfo.Name, gainfo.IdNo, factory); - await _gainfoPermissionService.ResetPermissionsAsync(gainfo.No, DeviceTaskEnumType.Update, null, "人员数据变更"); - } - else - { - await _dbContext.Client.Ado.BeginTranAsync(); - try + await _identityUserSyncService.SyncAccountAsync(gainfo.Code, gainfo.Name, gainfo.IdNo, factory); + } + else { await _gainfoPermissionService.ResetPermissionsAsync(gainfo.No, DeviceTaskEnumType.Delete, null, "人员离职生成"); @@ -309,51 +308,51 @@ public class GainfoUpdateService : IGainfoUpdateService gainfo.Id = gainfo.IdentityUserId; await _dbContext.DeleteReallyAsync(gainfo); - - await _dbContext.Client.Ado.CommitTranAsync(); } - catch (Exception ex) - { - await _dbContext.Client.Ado.RollbackTranAsync(); - _logger.LogError(ex, "离职任务生成失败:{message}", ex.Message); - } - } - } - 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)) + if (item.isowner == "T") { - await _dbContext.Client.Insertable(info).AS("GainfoLeave").ExecuteCommandAsync(); + await _dbContext.InsertAsync(info); + await _identityUserSyncService.SyncAccountAsync(info.Code, info.Name, info.IdNo, factory); } else { - await _dbContext.Updateable().SetColumns(g => new GainfoLeaveEntity + if (!await _dbContext.Queryable().AnyAsync(x => x.Code == item.ename)) { - 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 _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 _dbContext.Client.Ado.CommitTranAsync(); + } + catch (Exception ex) + { + await _dbContext.Client.Ado.RollbackTranAsync(); + _logger.LogError(ex, "离职任务生成失败:{message}", ex.Message); } }