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