修改派车任务,增加派车后单独同步东胜功能

optimize
jianghaiqing 11 months ago
parent fcef329e5b
commit 25d92513de

@ -109,5 +109,12 @@ namespace Myshipping.Application
/// <param name="model">请求详情</param>
/// <returns>返回回执</returns>
Task<TaskManageOrderResultDto> SaveTruckByPage(TruckPageDto model);
/// <summary>
/// 发送完派车后手工同步东胜
/// </summary>
/// <param name="info">派车详情</param>
/// <returns>返回回执</returns>
Task<TaskManageOrderResultDto> SendTruckAfterDispatch(TaskTruckDto info);
}
}

@ -1478,5 +1478,128 @@ namespace Myshipping.Application
return result;
}
/// <summary>
/// 发送完派车后手工同步东胜
/// </summary>
/// <param name="info">派车详情</param>
/// <returns>返回回执</returns>
[HttpPost("/TaskManageTruck/SendTruckAfterDispatch")]
public async Task<TaskManageOrderResultDto> SendTruckAfterDispatch([FromBody] TaskTruckDto info)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
/*
1
2
3
*/
var entity = _taskTruckRepository.AsQueryable().First(a => a.PK_ID == info.PK_ID);
if (entity == null)
throw Oops.Oh($"派车信息获取失败,派车信息不存在或已作废");
if(entity.Status != BookingTruckStatus.SEND_DISPATCH.ToString())
throw Oops.Oh($"同步东胜只能用于已派车的任务");
//保存集装箱列表信息
var saveRlt = InnerSaveAfterDispatch(info).GetAwaiter().GetResult();
var truckModel = _taskTruckRepository.AsQueryable().First(a => a.PK_ID == info.PK_ID);
var truckCtnList = _taskTruckContaRepository.AsQueryable().Where(a => a.P_ID == info.PK_ID).ToList();
BookingTruckDto model = truckModel.Adapt<BookingTruckDto>();
if (truckCtnList.Count > 0)
model.ContaList = truckCtnList.Adapt<List<BookingTruckCtnDto>>();
if (truckModel.BookingTruckId.HasValue)
model.Id = truckModel.BookingTruckId.Value;
//回调同步东胜
var service = _namedServiceProvider.GetService(nameof(BookingTruckService));
var rlt = await service.TruckDispatchCompleteCallBack(model);
if (!rlt.succ)
{
throw Oops.Oh(rlt.msg);
}
result.succ = true;
result.msg = "同步成功";
result.ext = rlt;
}
catch(Exception ex)
{
result.succ = false;
result.msg = $"{ex.Message}";
}
return result;
}
/// <summary>
/// 保存内部方法
/// </summary>
/// <param name="info">派车信息</param>
/// <returns>返回派车Id</returns>
[SqlSugarUnitOfWork]
private async Task<string> InnerSaveAfterDispatch(TaskTruckDto info)
{
TaskTruckInfo entity = info.Adapt<TaskTruckInfo>();
if (entity == null)
throw Oops.Oh($"派车信息不能为空");
if (!entity.KGS.HasValue)
throw Oops.Oh($"吨数不能为空");
List<TaskTruckCtn> entityCtnList = info.ContaList.Adapt<List<TaskTruckCtn>>();
if (entityCtnList != null && entityCtnList.Count > 0)
{
//保存时默认统计箱型箱量
entity.CntrTotal = string.Join(";", entityCtnList.GroupBy(a => a.CTNALL)
.Select(a =>
{
return $"{a.Key}*{a.ToList().Sum(b => b.CTNNUM.HasValue ? b.CTNNUM.Value : 1)}";
}).ToArray());
}
var model = _taskTruckRepository.AsQueryable().First(a => a.PK_ID == entity.PK_ID);
if (model == null)
throw Oops.Oh($"派车信息获取失败,派车信息不存在或已作废");
model.UpdatedTime = DateTime.Now;
model.UpdatedUserId = UserManager.UserId;
model.UpdatedUserName = UserManager.Name;
model.CntrTotal = entity.CntrTotal;
await _taskTruckRepository.AsUpdateable(model).UpdateColumns(it => new
{
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName,
it.CntrTotal
}).ExecuteCommandAsync();
await _taskTruckContaRepository.DeleteAsync(x => x.P_ID == model.PK_ID);
if (entityCtnList != null && entityCtnList.Count > 0)
{
entityCtnList.ForEach(async ctn =>
{
ctn.P_ID = entity.PK_ID;
ctn.PK_ID = IDGen.NextID().ToString();
await _taskTruckContaRepository.InsertAsync(ctn);
});
}
return entity.PK_ID;
}
}
}

Loading…
Cancel
Save