feat 推送排班到sap

This commit is contained in:
2025-07-15 16:33:23 +08:00
parent 928b0f9236
commit cedc984e56

View File

@@ -142,42 +142,40 @@ public class WorkGridScheduleService : IWorkGridScheduleService
await _dbContext.InsertAsync(toInserts);
await _operateLog.LogAsync(OperateLogType.WorkGrid, $"新增网格({workGrid.Name}){request.Date.ToString("yyyy-M-d")}的{request.PeriodType.GetDescription()}人员:{request.UserCodes.Join(",")}");
if (workGrid.Code.ToString() == "4cc354b4-a727-4120-86b7-a160590bedb3")
//推送到SAP
var items = toInserts.Select(x => new SyncWorkShiftDayItem
{
//推送到SAP
var items = toInserts.Select(x => new SyncWorkShiftDayItem
{
UserCode = x.UserCode,
Begin = x.Date.ToString("yyyyMMdd"),
End = x.Date.ToString("yyyyMMdd"),
Plan = request.PeriodType == WorkGridTimePeriodEnumType.Day ? "JK03" : "JK04",
Operate = "INS"
}).ToList();
UserCode = x.UserCode,
Begin = x.Date.ToString("yyyyMMdd"),
End = x.Date.ToString("yyyyMMdd"),
Plan = request.PeriodType == WorkGridTimePeriodEnumType.Day ? "JK03" : "JK04",
Operate = "INS"
}).ToList();
var response = await _jinkoJipApi.SyncWorkShiftAsync(new SyncWorkShiftRequest { Items = items });
response.Message.IsPresent().ThrowIfTrue("JIP接口返回错误:" + response.Message);
if (response == null || response.Items == null || response.Items.Count == 0)
{
throw new UserFriendlyException("JIP接口返回数据异常,请联系管理员");
}
if (response.Items.Any(x => x.Result != "S"))
{
var errorMessages = response.Items.Where(x => x.Result != "S")
.Select(x => $"{x.UserCode}排班新增失败:{x.Message}").Join("\r\n");
throw new UserFriendlyException(errorMessages);
}
var response = await _jinkoJipApi.SyncWorkShiftAsync(new SyncWorkShiftRequest { Items = items });
response.Message.IsPresent().ThrowIfTrue("JIP接口返回错误:" + response.Message);
if (response == null || response.Items == null || response.Items.Count == 0)
{
throw new UserFriendlyException("JIP接口返回数据异常,请联系管理员");
}
foreach (var workGridSchedule in toInserts)
{
var msg = response.Items.FirstOrDefault(x => x.UserCode == workGridSchedule.UserCode)?.Message;
await _dbContext.Updateable<WorkGridScheduleEntity>()
.SetColumns(x => x.SyncResult == msg)
.Where(x => x.WorkGridCode == workGrid.Code)
.Where(x => x.UserCode == workGridSchedule.UserCode)
.Where(x => x.Date == workGridSchedule.Date)
.Where(x => x.PeriodType == workGridSchedule.PeriodType)
.ExecuteCommandAsync();
}
if (response.Items.Any(x => x.Result != "S"))
{
var errorMessages = response.Items.Where(x => x.Result != "S")
.Select(x => $"{x.UserCode}排班新增失败:{x.Message}").Join("\r\n");
throw new UserFriendlyException(errorMessages);
}
foreach (var workGridSchedule in toInserts)
{
var msg = response.Items.FirstOrDefault(x => x.UserCode == workGridSchedule.UserCode)?.Message;
await _dbContext.Updateable<WorkGridScheduleEntity>()
.SetColumns(x => x.SyncResult == msg)
.Where(x => x.WorkGridCode == workGrid.Code)
.Where(x => x.UserCode == workGridSchedule.UserCode)
.Where(x => x.Date == workGridSchedule.Date)
.Where(x => x.PeriodType == workGridSchedule.PeriodType)
.ExecuteCommandAsync();
}
//todo sub pub
@@ -245,40 +243,36 @@ public class WorkGridScheduleService : IWorkGridScheduleService
if (data.Any())
{
if (workGrid.Code.ToString() == "4cc354b4-a727-4120-86b7-a160590bedb3")
//推送到SAP
var items = data.Select(x => new SyncWorkShiftDayItem
{
//推送到SAP
var items = data.Select(x => new SyncWorkShiftDayItem
{
UserCode = x.UserCode,
Begin = x.Date.ToString("yyyyMMdd"),
End = x.Date.ToString("yyyyMMdd"),
Plan = request.PeriodType == WorkGridTimePeriodEnumType.Day ? "JK03" : "JK04",
Operate = "DEL"
}).ToList();
UserCode = x.UserCode,
Begin = x.Date.ToString("yyyyMMdd"),
End = x.Date.ToString("yyyyMMdd"),
Plan = request.PeriodType == WorkGridTimePeriodEnumType.Day ? "JK03" : "JK04",
Operate = "DEL"
}).ToList();
var response = await _jinkoJipApi.SyncWorkShiftAsync(new SyncWorkShiftRequest { Items = items });
response.Message.IsPresent().ThrowIfTrue("JIP接口返回错误:" + response.Message);
if (response == null || response.Items == null || response.Items.Count == 0)
{
throw new UserFriendlyException("JIP接口返回数据异常,请联系管理员");
}
if (response.Items.Any(x => x.Result != "S"))
{
var errorMessages = response.Items.Where(x => x.Result != "S")
.Select(x => $"{x.UserCode}排班删除失败:{x.Message}").Join("\r\n");
throw new UserFriendlyException(errorMessages);
}
foreach (var workGridSchedule in data)
{
workGridSchedule.SyncResult = response.Items.FirstOrDefault(x => x.UserCode == workGridSchedule.UserCode)?.Message;
}
await _dbContext.UpdateAsync(data);
var response = await _jinkoJipApi.SyncWorkShiftAsync(new SyncWorkShiftRequest { Items = items });
response.Message.IsPresent().ThrowIfTrue("JIP接口返回错误:" + response.Message);
if (response == null || response.Items == null || response.Items.Count == 0)
{
throw new UserFriendlyException("JIP接口返回数据异常,请联系管理员");
}
if (response.Items.Any(x => x.Result != "S"))
{
var errorMessages = response.Items.Where(x => x.Result != "S")
.Select(x => $"{x.UserCode}排班删除失败:{x.Message}").Join("\r\n");
throw new UserFriendlyException(errorMessages);
}
foreach (var workGridSchedule in data)
{
workGridSchedule.SyncResult = response.Items.FirstOrDefault(x => x.UserCode == workGridSchedule.UserCode)?.Message;
}
await _dbContext.UpdateAsync(data);
await _dbContext.DeleteAsync(data);
await _operateLog.LogAsync(OperateLogType.WorkGrid, $"移除网格({workGrid.Name}){request.Date.ToString("yyyy-M-d")}的{request.PeriodType.GetDescription()}人员:{request.UserCodes.Join(",")}");