fix 恢复同步逻辑

This commit is contained in:
2025-11-17 11:41:45 +08:00
parent f153d6e3a4
commit 37794743fd
3 changed files with 1 additions and 74 deletions

View File

@@ -60,8 +60,7 @@ public class SyncController : ControllerBase
[IgnoreTenant] [IgnoreTenant]
public async Task GetBusinessTripsAsync(CodeRequest request) public async Task GetBusinessTripsAsync(CodeRequest request)
{ {
await _sapBusinessTripService.HandleDirtyDataAsync(request.Code); await _sapBusinessTripService.HandlerBusinessTripsByFactoryAsync(request.Code);
//await _sapBusinessTripService.HandlerBusinessTripsByFactoryAsync(request.Code);
} }
[HttpGet("/api/sync/test")] [HttpGet("/api/sync/test")]

View File

@@ -3,6 +3,4 @@ namespace Dlhis.Basic.Organization.Services;
public interface ISapBusinessTripService : IScopeDependency public interface ISapBusinessTripService : IScopeDependency
{ {
Task HandlerBusinessTripsByFactoryAsync(string factory); Task HandlerBusinessTripsByFactoryAsync(string factory);
Task HandleDirtyDataAsync(string factory);
} }

View File

@@ -204,74 +204,4 @@ public class SapBusinessTripService : ISapBusinessTripService
.Select(x => x.DeviceCode) .Select(x => x.DeviceCode)
.ToListAsync(); .ToListAsync();
} }
public async Task HandleDirtyDataAsync(string factory)
{
var tripGroup = await GetTripGroupAsync(factory);
var deviceCodes = await GetTripGroupUnderDeviceCodesAsync(tripGroup.Code);
//确保是真实脏数据
var yesterday = DateTime.Now.Date.AddDays(-2);
try
{
var dirtyData = await _dbContext.Queryable<BusinessTripEntity>()
.Where(x => x.Destination == factory)
.Where(x => !SqlFunc.IsNullOrEmpty(x.Destination))
.Where(x => x.Status == BusinessTripStatusEnumType.Generated)
.Where(x => x.BeginDate < yesterday)
.Select(x => new
{
num = SqlFunc.RowNumber(SqlFunc.Desc(x.BeginDate), x.Code),
x.Id, x.Code, x.BeginDate
}).MergeTable()
.Where(x => x.num == 1)
.ToListAsync();
foreach (var item in dirtyData)
{
try
{
var currentGainfo = await _dbContext.Queryable<GainfoLeaveEntity>()
.Where(x => x.Code == item.Code)
.Select(x => new { x.No, x.Code })
.SingleAsync();
if (currentGainfo == null)
{
continue;
// currentGainfo = await _dbContext.Queryable<GainfoEntity>()
// .Where(x => x.Code == item.Code)
// .Select(x => new { x.No, x.Code })
// .SingleAsync();
}
await _dbContext.Updateable<DevicePermissionEntity>()
.SetColumns(x => x.IsDeleted == true)
.Where(x => x.AssignType == AssignTypeEnumType.User)
.Where(x => x.AssignValue == currentGainfo.No)
.Where(x => x.UniqueType == DeviceAssignmentTypeEnumType.Group)
.Where(x => x.UniqueValue == tripGroup.Code)
.Where(x => x.Type == tripGroup.Type)
.Where(x => x.TenantId == factory)
.ExecuteCommandAsync();
await _dbContext.Updateable<BusinessTripEntity>()
.SetColumns(x => x.Status == BusinessTripStatusEnumType.Deleted)
.Where(x => x.Id == item.Id)
.ExecuteCommandAsync();
await _gainfoPermissionService.ResetPermissionsAsync(currentGainfo.No, DeviceTaskEnumType.Delete, deviceCodes, "出差遗留脏数据删除");
}
catch (Exception e)
{
_logger.LogError(e, "处理出差遗留脏数据删除失败:工号{code}", item.Code);
}
}
}
catch (Exception e)
{
_logger.LogError(e, "处理{factory}遗留出差数据失败:{message}", factory, e.Message);
}
}
} }