fix: 人员同步按最新数据处理

This commit is contained in:
2026-05-27 11:47:12 +08:00
parent 05f0dfb312
commit cbd375fbb4
2 changed files with 15 additions and 12 deletions

View File

@@ -8,7 +8,6 @@ using Dlhis.Entity.Device.Entities;
using Dlhis.Entity.Device.Enums; using Dlhis.Entity.Device.Enums;
using Dlhis.Entity.Sys.Enums; using Dlhis.Entity.Sys.Enums;
using Kurisu.AspNetCore.DataAccess.Dto; using Kurisu.AspNetCore.DataAccess.Dto;
using Kurisu.AspNetCore.DataAccess.Extensions;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions; using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.AspNetCore.Utils.Extensions;

View File

@@ -469,7 +469,7 @@ public class GainfoUpdateService : IGainfoUpdateService
var lastMap = last var lastMap = last
.Where(x => !string.IsNullOrWhiteSpace(x.ZWORKCODE)) .Where(x => !string.IsNullOrWhiteSpace(x.ZWORKCODE))
.GroupBy(x => x.ZWORKCODE) .GroupBy(x => x.ZWORKCODE)
.ToDictionary(x => x.Key, x => x.ToList()); .ToDictionary(x => x.Key, x => x.First());
var modifiedPersons = new List<SapPersonItem>(); var modifiedPersons = new List<SapPersonItem>();
foreach (var person in sapList) foreach (var person in sapList)
@@ -480,16 +480,14 @@ public class GainfoUpdateService : IGainfoUpdateService
continue; continue;
} }
if (!lastMap.TryGetValue(person.ZWORKCODE, out var historyPersons) || historyPersons.Count <= 0) if (!lastMap.TryGetValue(person.ZWORKCODE, out var latestHistory))
{ {
modifiedPersons.Add(person); modifiedPersons.Add(person);
continue; continue;
} }
var exactHistory = historyPersons.FirstOrDefault(x => comparer.Equals(person, x)); if (comparer.Equals(person, latestHistory))
if (exactHistory != null)
{ {
historyPersons.Remove(exactHistory);
continue; continue;
} }
@@ -500,13 +498,13 @@ public class GainfoUpdateService : IGainfoUpdateService
{ {
var first = modifiedPersons[0]; var first = modifiedPersons[0];
var historyCandidates = !string.IsNullOrWhiteSpace(first.ZWORKCODE) var historyCandidates = !string.IsNullOrWhiteSpace(first.ZWORKCODE)
&& lastMap.TryGetValue(first.ZWORKCODE, out var currentHistoryPersons) && lastMap.TryGetValue(first.ZWORKCODE, out var currentHistoryPerson)
? currentHistoryPersons ? currentHistoryPerson
: new List<SapPersonItem>(); : null;
var hasHistory = historyCandidates.Count > 0; var hasHistory = historyCandidates != null;
var diffType = hasHistory ? "Update" : "Insert"; var diffType = hasHistory ? "Update" : "Insert";
var diffMessage = hasHistory var diffMessage = hasHistory
? string.Join("; ", GetFirstDiffFields(first, historyCandidates[0])) ? string.Join("; ", GetFirstDiffFields(first, historyCandidates))
: "历史记录不存在"; : "历史记录不存在";
_logger.LogWarning("SAP首条差异 DiffType:{diffType}, ZWORKCODE:{workCode}, HasHistory:{hasHistory}, Diffs:{diffs}", _logger.LogWarning("SAP首条差异 DiffType:{diffType}, ZWORKCODE:{workCode}, HasHistory:{hasHistory}, Diffs:{diffs}",
diffType, first.ZWORKCODE, hasHistory, diffMessage); diffType, first.ZWORKCODE, hasHistory, diffMessage);
@@ -535,7 +533,13 @@ public class GainfoUpdateService : IGainfoUpdateService
var items = await _dbContext.Queryable<GainfoSapEntity>() var items = await _dbContext.Queryable<GainfoSapEntity>()
.Where(x => chunk.Contains(x.ename)) .Where(x => chunk.Contains(x.ename))
.ToListAsync(); .ToListAsync();
gainfos.AddRange(items); var latestItems = items
.OrderByDescending(x => x.logdate)
.ThenByDescending(x => x.id)
.GroupBy(x => x.ename)
.Select(x => x.First())
.ToList();
gainfos.AddRange(latestItems);
} }
return gainfos.Select(ToSapPersonItem).ToList(); return gainfos.Select(ToSapPersonItem).ToList();