From 25d92513de0f28c49b157606dabe4b4356f177f6 Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Mon, 25 Dec 2023 14:08:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B4=BE=E8=BD=A6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=B4=BE=E8=BD=A6=E5=90=8E?= =?UTF-8?q?=E5=8D=95=E7=8B=AC=E5=90=8C=E6=AD=A5=E4=B8=9C=E8=83=9C=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Interface/ITaskManageTruckService.cs | 7 + .../TaskManagePlat/TaskManageTruckService.cs | 123 ++++++++++++++++++ 2 files changed, 130 insertions(+) diff --git a/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageTruckService.cs b/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageTruckService.cs index 703a2e68..3c528e86 100644 --- a/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageTruckService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageTruckService.cs @@ -109,5 +109,12 @@ namespace Myshipping.Application /// 请求详情 /// 返回回执 Task SaveTruckByPage(TruckPageDto model); + + /// + /// 发送完派车后手工同步东胜 + /// + /// 派车详情 + /// 返回回执 + Task SendTruckAfterDispatch(TaskTruckDto info); } } diff --git a/Myshipping.Application/Service/TaskManagePlat/TaskManageTruckService.cs b/Myshipping.Application/Service/TaskManagePlat/TaskManageTruckService.cs index 1234e369..31ece7a6 100644 --- a/Myshipping.Application/Service/TaskManagePlat/TaskManageTruckService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/TaskManageTruckService.cs @@ -1478,5 +1478,128 @@ namespace Myshipping.Application return result; } + /// + /// 发送完派车后手工同步东胜 + /// + /// 派车详情 + /// 返回回执 + [HttpPost("/TaskManageTruck/SendTruckAfterDispatch")] + public async Task 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(); + + if (truckCtnList.Count > 0) + model.ContaList = truckCtnList.Adapt>(); + + 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; + } + + /// + /// 保存内部方法 + /// + /// 派车信息 + /// 返回派车Id + [SqlSugarUnitOfWork] + private async Task InnerSaveAfterDispatch(TaskTruckDto info) + { + TaskTruckInfo entity = info.Adapt(); + + if (entity == null) + throw Oops.Oh($"派车信息不能为空"); + + if (!entity.KGS.HasValue) + throw Oops.Oh($"吨数不能为空"); + + List entityCtnList = info.ContaList.Adapt>(); + + 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; + } } }