From e6254428736065b79f50ad67f62ed112900f4bd7 Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Wed, 7 Feb 2024 16:34:47 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A2=84=E7=94=A9?= =?UTF-8?q?=E8=B4=A7=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RollingNominationDispatchRequestDto.cs | 34 ++ .../Nomination/TaskRollingNominationDto.cs | 15 + .../TaskRollingNominationShowDto.cs | 11 + .../TaskManagePlat/Dtos/TaskManageMapper.cs | 5 +- .../ITaskManageRollingNominationService.cs | 32 +- .../TaskManageRollingNominationService.cs | 295 +++++++++++++++++- .../TaskManagePlat/TaskManageService.cs | 28 ++ 7 files changed, 396 insertions(+), 24 deletions(-) create mode 100644 Myshipping.Application/Service/TaskManagePlat/Dtos/Nomination/RollingNominationDispatchRequestDto.cs diff --git a/Myshipping.Application/Service/TaskManagePlat/Dtos/Nomination/RollingNominationDispatchRequestDto.cs b/Myshipping.Application/Service/TaskManagePlat/Dtos/Nomination/RollingNominationDispatchRequestDto.cs new file mode 100644 index 00000000..f1c64b26 --- /dev/null +++ b/Myshipping.Application/Service/TaskManagePlat/Dtos/Nomination/RollingNominationDispatchRequestDto.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Myshipping.Application +{ + /// + /// 生成预甩货调度请求 + /// + public class RollingNominationDispatchRequestDto + { + /// + /// 预甩货主键 + /// + public string nominationId { get; set; } + + /// + /// 是否新增(true-新增,不处理NOM_STATUS_NOTE=Load的记录 false-可以处理任意记录) + /// + public bool isAdd { get; set; } = false; + + /// + /// 预甩货可Load明细信息主键组 + /// + public string[] loadDetailIds { get; set; } + + /// + /// 预甩货调度批次主键 + /// + public string nominationBatchId { get; set; } + } +} diff --git a/Myshipping.Application/Service/TaskManagePlat/Dtos/Nomination/TaskRollingNominationDto.cs b/Myshipping.Application/Service/TaskManagePlat/Dtos/Nomination/TaskRollingNominationDto.cs index 463e32a0..ec7212a4 100644 --- a/Myshipping.Application/Service/TaskManagePlat/Dtos/Nomination/TaskRollingNominationDto.cs +++ b/Myshipping.Application/Service/TaskManagePlat/Dtos/Nomination/TaskRollingNominationDto.cs @@ -234,5 +234,20 @@ namespace Myshipping.Application /// /// public string BBYMAIL { get; set; } + + /// + /// 箱型代码 + /// + public string CtnCode { get; set; } + + /// + /// 箱型名称 + /// + public string CtnAll { get; set; } + + /// + /// 箱量 + /// + public int CtnNum { get; set; } } } diff --git a/Myshipping.Application/Service/TaskManagePlat/Dtos/Nomination/TaskRollingNominationShowDto.cs b/Myshipping.Application/Service/TaskManagePlat/Dtos/Nomination/TaskRollingNominationShowDto.cs index 8bc03053..a837a51c 100644 --- a/Myshipping.Application/Service/TaskManagePlat/Dtos/Nomination/TaskRollingNominationShowDto.cs +++ b/Myshipping.Application/Service/TaskManagePlat/Dtos/Nomination/TaskRollingNominationShowDto.cs @@ -78,6 +78,12 @@ namespace Myshipping.Application /// 批次ID /// public string BatchId { get; set; } + + /// + /// 预甩货调度主键 + /// + public string NominationDispatchId { get; set; } + /// /// 状态 /// @@ -280,5 +286,10 @@ namespace Myshipping.Application /// 箱量 /// public int CtnNum { get; set; } + + /// + /// 预甩货调度主键 + /// + public string NominationDispatchId { get; set; } } } diff --git a/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskManageMapper.cs b/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskManageMapper.cs index e6ea197f..4cc315ab 100644 --- a/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskManageMapper.cs +++ b/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskManageMapper.cs @@ -898,7 +898,10 @@ namespace Myshipping.Application .Map(dest => dest.LOADPORT_NAME, src => src.LoadPortName) .Map(dest => dest.DISCHARGEPORT_NAME, src => src.DischargePortName) .Map(dest => dest.PLACEOF_DELIVERY, src => src.PlaceOfDelivery) - .Map(dest => dest.BBYMAIL, src => src.BBYMAIL); + .Map(dest => dest.BBYMAIL, src => src.BBYMAIL) + .Map(dest => dest.CTNALL, src => src.CtnAll) + .Map(dest => dest.CTNCODE, src => src.CtnCode) + .Map(dest => dest.CTNNUM, src => src.CtnNum); config.ForType() diff --git a/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageRollingNominationService.cs b/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageRollingNominationService.cs index b3d82c05..90c34454 100644 --- a/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageRollingNominationService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageRollingNominationService.cs @@ -28,44 +28,50 @@ namespace Myshipping.Application /// /// 生成预甩货客户访问链接 /// - /// 预甩货任务主键组 + /// 预甩货调度主键组 /// 返回回执 - Task CreateShareLink(string[] taskPkIds); + Task CreateShareLink(string[] nominationDispatchIds); /// /// 取消预甩货客户访问链接 /// - /// 预甩货任务主键组 + /// 预甩货调度主键组 /// 返回回执 - Task CancelShareLink(string[] taskPkIds); + Task CancelShareLink(string[] nominationDispatchIds); /// /// 推送预甩货客户访问链接 /// - /// 预甩货任务主键组 + /// 预甩货调度主键组 /// 返回回执 - Task PushShareLink(string[] taskPkIds); + Task PushShareLink(string[] nominationDispatchId); /// /// 生成预甩货调度 /// - /// 预甩货船信息主键 - /// 预甩货可Load明细信息主键组 + /// 生成预甩货调度请求 /// 返回回执 - Task DispatchRollingNomination(string nominationShipId, string[] loadDetailIds); + Task DispatchRollingNomination(RollingNominationDispatchRequestDto model); + + /// + /// 刷新预甩货对应订舱 + /// + /// 预甩货明细任务主键组 + /// 返回回执 + Task RefreshBookingOrder(string[] detailPkIds); /// /// 查看分享链接 /// - /// 预甩任务主键 + /// 预甩货调度批次主键组 /// 返回回执 - Task GetUrl(string batchId); + Task GetUrl(string nominationDispatchId); /// /// 获取Status是load的可配载的列表 /// - /// 预甩货任务主键 + /// 预甩货主键 /// 返回回执 - Task GetLoadStatusDetailList(string taskPkId); + Task GetLoadStatusDetailList(string nominationId); } } diff --git a/Myshipping.Application/Service/TaskManagePlat/TaskManageRollingNominationService.cs b/Myshipping.Application/Service/TaskManagePlat/TaskManageRollingNominationService.cs index 1b236196..b7b8b321 100644 --- a/Myshipping.Application/Service/TaskManagePlat/TaskManageRollingNominationService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/TaskManageRollingNominationService.cs @@ -1,4 +1,5 @@ -using Furion.DynamicApiController; +using Furion.DistributedIDGenerator; +using Furion.DynamicApiController; using Furion.FriendlyException; using Mapster; using Microsoft.AspNetCore.Components; @@ -249,13 +250,23 @@ namespace Myshipping.Application /// /// 生成预甩货客户访问链接 /// - /// 预甩货任务主键组 + /// 预甩货调度主键组 /// 返回回执 [HttpPost("/TaskManageRollingNomination/CreateShareLink")] - public async Task CreateShareLink([FromQuery] string[] taskPkIds) + public async Task CreateShareLink([FromBody] string[] nominationDispatchIds) { TaskManageOrderResultDto result = new TaskManageOrderResultDto(); + try + { + + } + catch(Exception ex) + { + result.succ = false; + result.msg = $"生成预甩货客户访问链接异常,原因:{ex.Message}"; + } + return result; } #endregion @@ -264,13 +275,23 @@ namespace Myshipping.Application /// /// 取消预甩货客户访问链接 /// - /// 预甩货任务主键组 + /// 预甩货调度主键组 /// 返回回执 [HttpPost("/TaskManageRollingNomination/CancelShareLink")] - public async Task CancelShareLink(string[] taskPkIds) + public async Task CancelShareLink([FromBody] string[] nominationDispatchIds) { TaskManageOrderResultDto result = new TaskManageOrderResultDto(); + try + { + + } + catch (Exception ex) + { + result.succ = false; + result.msg = $"取消预甩货客户访问链接异常,原因:{ex.Message}"; + } + return result; } #endregion @@ -279,13 +300,23 @@ namespace Myshipping.Application /// /// 推送预甩货客户访问链接 /// - /// 预甩货任务主键组 + /// 预甩货任务主键组 /// 返回回执 [HttpPost("/TaskManageRollingNomination/PushShareLink")] - public async Task PushShareLink(string[] taskPkIds) + public async Task PushShareLink([FromBody] string[] nominationDispatchId) { TaskManageOrderResultDto result = new TaskManageOrderResultDto(); + try + { + + } + catch (Exception ex) + { + result.succ = false; + result.msg = $"推送预甩货客户访问链接异常,原因:{ex.Message}"; + } + return result; } #endregion @@ -294,14 +325,238 @@ namespace Myshipping.Application /// /// 生成预甩货调度 /// - /// 预甩货船信息主键 - /// 预甩货可Load明细信息主键组 + /// 生成预甩货调度请求 /// 返回回执 [HttpPost("/TaskManageRollingNomination/DispatchRollingNomination")] - public async Task DispatchRollingNomination(string nominationShipId, string[] loadDetailIds) + public async Task DispatchRollingNomination([FromBody] RollingNominationDispatchRequestDto model) + { + TaskManageOrderResultDto result = new TaskManageOrderResultDto(); + + try + { + /* + 1、如果调度ID不为空,标识选择新的明细替换原有的调度。 + (1)首先匹配所选的箱型箱量是否一致,装货港、卸货港必需一致,不满足不能进行生成调度。 + (2)删除原调度,生成新调度。 + 2、如果调度ID为空,标识是新增调度。 + 3、没有订舱ID或委托单位ID的数据不能生成调度。 + */ + if (model.loadDetailIds == null || model.loadDetailIds.Length == 0) + { + throw Oops.Oh($"预甩货可Load明细信息不能为空"); + } + + if (!model.isAdd && string.IsNullOrWhiteSpace(model.nominationBatchId)) + { + throw Oops.Oh($"改配调度需要提供预甩货调度批次ID"); + } + + var detailList = _taskRollingNominationDetailInfoRepository.AsQueryable() + .Where(a => model.loadDetailIds.Contains(a.PK_ID) && a.IsDeleted == false).ToList(); + + if (detailList.Count != model.loadDetailIds.Length) + { + throw Oops.Oh($"预甩货明细部分获取失败,请重新获取预甩货明细"); + } + + if (detailList.Any(a => !a.BOOKING_ID.HasValue || !a.CUSTOMERID.HasValue)) + { + throw Oops.Oh($"预甩货明细存在未对应订舱的记录,不能生成调度"); + } + + var nomId = detailList.FirstOrDefault().NOM_ID; + + var nomModel = _taskRollingNominationInfoRepository.AsQueryable() + .First(a => a.PK_ID == nomId); + + var shipmentList = detailList.Select(a => a.SHIPMENT).Distinct().ToList(); + + Dictionary batchDict = shipmentList.Select(a => new { Key = a, BatchId = IDGen.NextID().ToString() }) + .ToDictionary(a => a.Key, b => b.BatchId); + + + DateTime nowDate = DateTime.Now; + if (!model.isAdd) + { + List dispatchList = new List(); + List withDispatchDetailList = new List(); + + var withDispatchList = _taskRollingNominationDetailInfoRepository.AsQueryable().Filter(null, true) + .InnerJoin((detail, dispatch) => detail.PK_ID == dispatch.DETAIL_ID) + .Where((detail, dispatch) => detail.PK_ID == dispatch.DETAIL_ID && detail.IsDeleted == false + && dispatch.IsDeleted == false && dispatch.BATCH_ID == model.nominationBatchId) + .Select((detail, dispatch) => new { Detail = detail, Dispatch = dispatch }).ToList(); + + if (withDispatchList.Count > 0) + { + withDispatchDetailList = withDispatchList.Select(a => a.Detail) + .ToList(); + } + + if (dispatchList.Count == 0) + { + throw Oops.Oh($"预甩货调度获取失败,无法改配"); + } + + //如果原调度对应的明细含有本次提交的明细,不允许改配调度 + if (withDispatchDetailList.Any(a => + model.loadDetailIds.Any(b => b == a.PK_ID))) + { + throw Oops.Oh($"预甩货调度获取失败,提交明细已生成调度,无法改配"); + } + + //需要匹配箱型箱量 + var origCtnStat = string.Join(",", withDispatchDetailList + .GroupBy(a => a.CTNALL).OrderBy(a => a.Key) + .Select(a => $"{a.Key}*{a.Sum(b => b.CTNNUM)}").ToArray()); + + detailList = _taskRollingNominationDetailInfoRepository.AsQueryable() + .Where(a => shipmentList.Contains(a.SHIPMENT) && a.IsDeleted == false && a.NOM_ID == nomId).ToList(); + + var targetCtnStat = string.Join(",", detailList + .GroupBy(a => a.CTNALL).OrderBy(a => a.Key) + .Select(a => $"{a.Key}*{a.Sum(b => b.CTNNUM)}").ToArray()); + + //如果箱型箱量不一致不能改配 + if (!origCtnStat.Equals(targetCtnStat)) + { + throw Oops.Oh($"预甩货调度获取失败,提交明细箱型箱量于被改配调度不一致,无法改配"); + } + + var origShip = withDispatchDetailList.FirstOrDefault(); + var targetShip = detailList.FirstOrDefault(); + + var origKey = $"{origShip.PLACEOF_RECEIPT}_{origShip.LOADPORT_NAME}_{origShip.DISCHARGEPORT_NAME}_{origShip.PLACEOF_DELIVERY}"; + var targeKey = $"{targetShip.PLACEOF_RECEIPT}_{targetShip.LOADPORT_NAME}_{targetShip.DISCHARGEPORT_NAME}_{targetShip.PLACEOF_DELIVERY}"; + + //收货地、装货港、卸货港、交货地必需一致 + if (!origKey.Equals(targeKey)) + { + throw Oops.Oh($"预甩货调度获取失败,提交明细收货地、装货港、卸货港、交货地被改配调度不一致,无法改配"); + } + + //删除原调度 + withDispatchList.ForEach(async a => + { + a.Dispatch.IsDeleted = true; + a.Dispatch.UpdatedTime = nowDate; + a.Dispatch.UpdatedUserId = UserManager.UserId; + a.Dispatch.UpdatedUserName = UserManager.Name; + + await _taskRollingNominationDispatchInfoRepository.AsUpdateable(a.Dispatch) + .UpdateColumns(it => new + { + it.IsDeleted, + it.UpdatedTime, + it.UpdatedUserId, + it.UpdatedUserName + }).ExecuteCommandAsync(); + }); + + //写入新调度 + detailList.ForEach(a => + { + TaskRollingNominationDispatchInfo dispatchInfo = new TaskRollingNominationDispatchInfo + { + PK_ID = IDGen.NextID().ToString(), + CreatedTime = nowDate, + UpdatedTime = nowDate, + CreatedUserId = UserManager.UserId, + CreatedUserName = UserManager.Name, + DETAIL_ID = a.PK_ID, + NOM_ID = a.NOM_ID, + NOM_SHIP_ID = a.NOM_SHIP_ID, + IsDeleted = false, + STATUS = "WAIT", + TASK_ID = nomModel.TASK_ID, + TenantId = UserManager.TENANT_ID, + TenantName = UserManager.TENANT_NAME, + BATCH_ID = batchDict[a.SHIPMENT], + }; + + _taskRollingNominationDispatchInfoRepository.Insert(dispatchInfo); + }); + } + else + { + + var withDispatchList = _taskRollingNominationDetailInfoRepository.AsQueryable().Filter(null, true) + .InnerJoin((detail, dispatch) => detail.PK_ID == dispatch.DETAIL_ID) + .Where((detail, dispatch) => detail.PK_ID == dispatch.DETAIL_ID && detail.IsDeleted == false + && shipmentList.Contains(detail.SHIPMENT) && detail.NOM_ID == nomId + && dispatch.IsDeleted == false) + .Select((detail, dispatch) => new { Detail = detail, Dispatch = dispatch }).ToList(); + + if (withDispatchList.Count > 0) + { + throw Oops.Oh($"预甩货明细已生成调度不能重复"); + } + + detailList = _taskRollingNominationDetailInfoRepository.AsQueryable() + .Where(a => shipmentList.Contains(a.SHIPMENT) && a.IsDeleted == false && a.NOM_ID == nomId).ToList(); + + + //开始写入调度 + detailList.ForEach(a => + { + TaskRollingNominationDispatchInfo dispatchInfo = new TaskRollingNominationDispatchInfo + { + PK_ID = IDGen.NextID().ToString(), + CreatedTime = nowDate, + UpdatedTime = nowDate, + CreatedUserId = UserManager.UserId, + CreatedUserName = UserManager.Name, + DETAIL_ID= a.PK_ID, + NOM_ID= a.NOM_ID, + NOM_SHIP_ID= a.NOM_SHIP_ID, + IsDeleted= false, + STATUS = "WAIT", + TASK_ID = nomModel.TASK_ID, + TenantId = UserManager.TENANT_ID, + TenantName = UserManager.TENANT_NAME, + BATCH_ID = batchDict[a.SHIPMENT], + }; + + _taskRollingNominationDispatchInfoRepository.Insert(dispatchInfo); + }); + } + + result.succ = true; + result.msg = "成功"; + } + catch (Exception ex) + { + result.succ = false; + result.msg = $"生成预甩货调度异常,原因:{ex.Message}"; + } + + return result; + } + #endregion + + #region 刷新预甩货对应订舱 + /// + /// 刷新预甩货对应订舱 + /// + /// 预甩货明细任务主键组 + /// 返回回执 + [HttpPost("/TaskManageRollingNomination/RefreshBookingOrder")] + public async Task RefreshBookingOrder([FromBody] string[] detailPkIds) { TaskManageOrderResultDto result = new TaskManageOrderResultDto(); + try + { + /* + + */ + } + catch (Exception ex) + { + result.succ = false; + result.msg = $"刷新预甩货对应订舱异常,原因:{ex.Message}"; + } + return result; } #endregion @@ -317,6 +572,16 @@ namespace Myshipping.Application { TaskManageOrderResultDto result = new TaskManageOrderResultDto(); + try + { + + } + catch (Exception ex) + { + result.succ = false; + result.msg = $"推送预甩货客户访问链接异常,原因:{ex.Message}"; + } + return result; } #endregion @@ -332,6 +597,16 @@ namespace Myshipping.Application { TaskManageOrderResultDto result = new TaskManageOrderResultDto(); + try + { + + } + catch (Exception ex) + { + result.succ = false; + result.msg = $"推送预甩货客户访问链接异常,原因:{ex.Message}"; + } + return result; } #endregion diff --git a/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs b/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs index 8e08d736..753499f5 100644 --- a/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs @@ -809,6 +809,8 @@ namespace Myshipping.Application if (info.Main.RollingNomination.ToDetail != null && info.Main.RollingNomination.ToDetail.Count > 0) { + var ctnCodeList = _cache.GetAllCodeCtn().GetAwaiter().GetResult().ToList(); + info.Main.RollingNomination.ToDetail.ForEach(t => { var rollingNominationShip = t.Adapt(); @@ -829,10 +831,26 @@ namespace Myshipping.Application if (t.NominationList != null && t.NominationList.Count > 0) { + //这里直接批量检索订舱信息,如果有对应的提单号直接写入订舱主键 + + var billNoList = t.NominationList.Select(x => x.Shipment.ToUpper()) + .Distinct().ToArray(); + + var bookList = _bookingOrderRepository.AsQueryable().Filter(null, true) + .Where(x => billNoList.Contains(x.MBLNO) && x.IsDeleted == false && x.TenantId == taskInfo.TenantId).ToList(); + t.NominationList.ForEach(x => { var rollingNominationDetail = x.Adapt(); + if (!string.IsNullOrWhiteSpace(rollingNominationDetail.CTNALL)) + { + var ctnCode = ctnCodeList.FirstOrDefault(a => !string.IsNullOrWhiteSpace(a.Name) && + a.Name.Equals(rollingNominationDetail.CTNALL, StringComparison.OrdinalIgnoreCase)); + + rollingNominationDetail.CTNCODE = ctnCode?.Code; + } + rollingNominationDetail.PK_ID = IDGen.NextID().ToString(); rollingNominationDetail.NOM_SHIP_ID = rollingNominationShip.PK_ID; rollingNominationDetail.NOM_ID = rollingNomination.PK_ID; @@ -845,6 +863,16 @@ namespace Myshipping.Application rollingNominationDetail.TenantId = taskInfo.TenantId; rollingNominationDetail.TenantName = taskInfo.TenantName; + var bookingInfo = bookList.FirstOrDefault(x => + x.MBLNO.Equals(rollingNominationDetail.SHIPMENT, StringComparison.OrdinalIgnoreCase)); + + if (bookingInfo != null) + { + rollingNominationDetail.BOOKING_ID = bookingInfo.Id; + rollingNominationDetail.CUSTOMERID = bookingInfo.CUSTOMERID; + rollingNominationDetail.CUSTOMERNAME = bookingInfo.CUSTOMERNAME; + } + _taskRollingNominationDetailInfoRepository.Insert(rollingNominationDetail); }); From 2f53f2e7a03ef49d5de75cecaf42ff293610df9e Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Wed, 7 Feb 2024 17:22:21 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A2=84=E7=94=A9?= =?UTF-8?q?=E8=B4=A7=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TaskManageRollingNominationService.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Myshipping.Application/Service/TaskManagePlat/TaskManageRollingNominationService.cs b/Myshipping.Application/Service/TaskManagePlat/TaskManageRollingNominationService.cs index b7b8b321..7e9d5874 100644 --- a/Myshipping.Application/Service/TaskManagePlat/TaskManageRollingNominationService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/TaskManageRollingNominationService.cs @@ -547,9 +547,8 @@ namespace Myshipping.Application try { - /* - - */ + + } catch (Exception ex) { @@ -599,7 +598,21 @@ namespace Myshipping.Application try { + var withDispatchList = + _taskRollingNominationInfoRepository.AsQueryable().Filter(null, true) + .InnerJoin((nom,detail)=> nom.PK_ID == detail.NOM_ID) + .LeftJoin((nom,detail, dispatch) => + detail.PK_ID == dispatch.DETAIL_ID && dispatch.IsDeleted == false) + .Where((nom,detail, dispatch) => + nom.TASK_ID == taskPkId && detail.IsDeleted == false && string.IsNullOrWhiteSpace(dispatch.TASK_ID)) + .Select((nom, detail, dispatch) => new { Detail = detail}).ToList(); + + if (withDispatchList.Count > 0) + { + result.ext = withDispatchList.Select(a => a.Detail.Adapt()).ToList(); + } + result.succ = true; } catch (Exception ex) { From a87273b940df2fd16e738f204fc186a914e7562a Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Thu, 8 Feb 2024 14:36:42 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A2=84=E7=94=A9?= =?UTF-8?q?=E8=B4=A7=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TaskRollingNominationShowDto.cs | 20 +++ .../TaskManagePlat/Dtos/TaskManageMapper.cs | 3 +- .../ITaskManageAccessShareLinkService.cs | 18 ++ .../Interface/ITaskManageShareLinkService.cs | 7 +- .../TaskManageRollingNominationService.cs | 163 +++++++++++------- .../TaskManagePlat/TaskManageService.cs | 12 +- 6 files changed, 153 insertions(+), 70 deletions(-) create mode 100644 Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageAccessShareLinkService.cs diff --git a/Myshipping.Application/Service/TaskManagePlat/Dtos/Nomination/TaskRollingNominationShowDto.cs b/Myshipping.Application/Service/TaskManagePlat/Dtos/Nomination/TaskRollingNominationShowDto.cs index a837a51c..4f9e3d6e 100644 --- a/Myshipping.Application/Service/TaskManagePlat/Dtos/Nomination/TaskRollingNominationShowDto.cs +++ b/Myshipping.Application/Service/TaskManagePlat/Dtos/Nomination/TaskRollingNominationShowDto.cs @@ -67,6 +67,16 @@ namespace Myshipping.Application /// Load列表 /// public List LoadDetailList { get; set; } + + /// + /// 合计单票汇总合计箱型箱量 + /// + public string TotalPreBillCtnStat { get; set; } + + /// + /// 合计load汇总合计箱型箱量 + /// + public string TotalLoadCtnStat { get; set; } } /// @@ -291,5 +301,15 @@ namespace Myshipping.Application /// 预甩货调度主键 /// public string NominationDispatchId { get; set; } + + /// + /// 箱备注(主要) + /// + public string CtnNote { get; set; } + + /// + /// 明细主键 + /// + public string PKId { get; set; } } } diff --git a/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskManageMapper.cs b/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskManageMapper.cs index 4cc315ab..7d8472e3 100644 --- a/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskManageMapper.cs +++ b/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskManageMapper.cs @@ -940,7 +940,8 @@ namespace Myshipping.Application .Map(dest => dest.BBYMAIL, src => src.BBYMAIL) .Map(dest => dest.CtnCode, src => src.CTNCODE) .Map(dest => dest.CtnAll, src => src.CTNALL) - .Map(dest => dest.CtnNum, src => src.CTNNUM); + .Map(dest => dest.CtnNum, src => src.CTNNUM) + .Map(dest => dest.PKId, src => src.PK_ID); } } diff --git a/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageAccessShareLinkService.cs b/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageAccessShareLinkService.cs new file mode 100644 index 00000000..d9849d5f --- /dev/null +++ b/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageAccessShareLinkService.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Myshipping.Application +{ + public interface ITaskManageAccessShareLinkService + { + /// + /// 访问链接 + /// + /// 请求链接 + /// 返回回执 + Task AccessRollingNomination(string shareKey); + } +} diff --git a/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageShareLinkService.cs b/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageShareLinkService.cs index b4ec7c1d..6ed8e9b4 100644 --- a/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageShareLinkService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageShareLinkService.cs @@ -37,11 +37,6 @@ namespace Myshipping.Application Task ValidateShareLink(string Url); - /// - /// 访问链接 - /// - /// 请求链接 - /// 返回回执 - Task QueryShareLink(string Url); + } } diff --git a/Myshipping.Application/Service/TaskManagePlat/TaskManageRollingNominationService.cs b/Myshipping.Application/Service/TaskManagePlat/TaskManageRollingNominationService.cs index 7e9d5874..078b9453 100644 --- a/Myshipping.Application/Service/TaskManagePlat/TaskManageRollingNominationService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/TaskManageRollingNominationService.cs @@ -1,4 +1,5 @@ -using Furion.DistributedIDGenerator; +using Furion.DependencyInjection; +using Furion.DistributedIDGenerator; using Furion.DynamicApiController; using Furion.FriendlyException; using Mapster; @@ -23,7 +24,7 @@ namespace Myshipping.Application /// 预甩货通知 /// [ApiDescriptionSettings("Application", Name = "TaskManageRollingNomination", Order = 10)] - public class TaskManageRollingNominationService : ITaskManageRollingNominationService, IDynamicApiController + public class TaskManageRollingNominationService : ITaskManageRollingNominationService, IDynamicApiController, ITransient { private readonly ISysCacheService _cache; private readonly ILogger _logger; @@ -178,6 +179,8 @@ namespace Myshipping.Application && (string.IsNullOrWhiteSpace(dispatch.PK_ID) || (!string.IsNullOrWhiteSpace(dispatch.PK_ID) && dispatch.IsDeleted == false))) .Select((detail, dispatch) => new { Detail = detail, Dispatch = dispatch }).ToList(); + List> tuples = new List>(); + model.PreBillList = withDispatchList.Where(a=> a.Dispatch != null || ((a.Dispatch == null || string.IsNullOrWhiteSpace(a.Dispatch.PK_ID)) && !a.Detail.NOM_STATUS_NOTE.Equals("Load",StringComparison.OrdinalIgnoreCase))) @@ -193,9 +196,14 @@ namespace Myshipping.Application var preBillDetail = preBillArg.FirstOrDefault().Detail; var preBillDispatch = preBillArg.FirstOrDefault().Dispatch; - string ctnStat = string.Join(",", preBillArg.GroupBy(x => x.Detail.CTNALL) + var cStaticlst = preBillArg.GroupBy(x => x.Detail.CTNALL) .Select(x => - $"{x.Key}*{x.Sum(t => t.Detail.CTNNUM)}").ToArray()); + new { Key = x.Key, Num = x.Sum(t => t.Detail.CTNNUM) }).ToList(); + + string ctnStat = string.Join(",", cStaticlst.Select(x => + $"{x.Key}*{x.Num}").ToArray()); + + cStaticlst.ForEach(y => tuples.Add(new Tuple(y.Key, y.Num))); TaskRollingNominationShipPreBillShowDto preBillInfo = new TaskRollingNominationShipPreBillShowDto { @@ -220,7 +228,7 @@ namespace Myshipping.Application UserOpinionTxt = preBillDispatch?.USER_OPINION_TXT, BatchId = preBillDispatch?.BATCH_ID, BookingId = preBillDetail.BOOKING_ID, - GroupName = $"CUST_{idx + 1}", + GroupName = preBillDetail.CUSTOMERID.HasValue?$"CUST_{idx + 1}":"", }; return preBillInfo; @@ -235,6 +243,20 @@ namespace Myshipping.Application && a.Detail.NOM_STATUS_NOTE.Equals("Load", StringComparison.OrdinalIgnoreCase)) .Select(a => a.Detail.Adapt()).ToList(); } + + if(tuples.Count > 0) + { + model.TotalPreBillCtnStat = string.Join(",", tuples.GroupBy(x => x.Item1) + .Select(x => + $"{x.Key}*{x.Sum(t => t.Item2)}").ToArray()); + } + + if (model.LoadDetailList.Count > 0) + { + model.TotalLoadCtnStat = string.Join(",", model.LoadDetailList.GroupBy(x => x.CtnAll) + .Select(x => + $"{x.Key}*{x.Sum(t => t.CtnNum)}").ToArray()); + } } catch (Exception ex) { @@ -341,43 +363,43 @@ namespace Myshipping.Application 2、如果调度ID为空,标识是新增调度。 3、没有订舱ID或委托单位ID的数据不能生成调度。 */ - if (model.loadDetailIds == null || model.loadDetailIds.Length == 0) - { - throw Oops.Oh($"预甩货可Load明细信息不能为空"); - } + DateTime nowDate = DateTime.Now; - if (!model.isAdd && string.IsNullOrWhiteSpace(model.nominationBatchId)) + if (!model.isAdd) { - throw Oops.Oh($"改配调度需要提供预甩货调度批次ID"); - } + if(string.IsNullOrWhiteSpace(model.nominationBatchId)) + { + throw Oops.Oh($"改配调度需要提供预甩货调度批次ID"); + } - var detailList = _taskRollingNominationDetailInfoRepository.AsQueryable() - .Where(a => model.loadDetailIds.Contains(a.PK_ID) && a.IsDeleted == false).ToList(); + if (model.loadDetailIds == null || model.loadDetailIds.Length == 0) + { + throw Oops.Oh($"预甩货可Load明细信息不能为空"); + } - if (detailList.Count != model.loadDetailIds.Length) - { - throw Oops.Oh($"预甩货明细部分获取失败,请重新获取预甩货明细"); - } + var detailList = _taskRollingNominationDetailInfoRepository.AsQueryable() + .Where(a => model.loadDetailIds.Contains(a.PK_ID) && a.IsDeleted == false).ToList(); - if (detailList.Any(a => !a.BOOKING_ID.HasValue || !a.CUSTOMERID.HasValue)) - { - throw Oops.Oh($"预甩货明细存在未对应订舱的记录,不能生成调度"); - } + if (detailList.Count != model.loadDetailIds.Length) + { + throw Oops.Oh($"预甩货明细部分获取失败,请重新获取预甩货明细"); + } - var nomId = detailList.FirstOrDefault().NOM_ID; + if (detailList.Any(a => !a.BOOKING_ID.HasValue || !a.CUSTOMERID.HasValue)) + { + throw Oops.Oh($"预甩货明细存在未对应订舱的记录,不能生成调度"); + } - var nomModel = _taskRollingNominationInfoRepository.AsQueryable() - .First(a => a.PK_ID == nomId); + var nomId = detailList.FirstOrDefault().NOM_ID; - var shipmentList = detailList.Select(a => a.SHIPMENT).Distinct().ToList(); + var nomModel = _taskRollingNominationInfoRepository.AsQueryable() + .First(a => a.PK_ID == nomId); - Dictionary batchDict = shipmentList.Select(a => new { Key = a, BatchId = IDGen.NextID().ToString() }) - .ToDictionary(a => a.Key, b => b.BatchId); + var shipmentList = detailList.Select(a => a.SHIPMENT).Distinct().ToList(); + Dictionary batchDict = shipmentList.Select(a => new { Key = a, BatchId = IDGen.NextID().ToString() }) + .ToDictionary(a => a.Key, b => b.BatchId); - DateTime nowDate = DateTime.Now; - if (!model.isAdd) - { List dispatchList = new List(); List withDispatchDetailList = new List(); @@ -479,45 +501,62 @@ namespace Myshipping.Application } else { - - var withDispatchList = _taskRollingNominationDetailInfoRepository.AsQueryable().Filter(null, true) - .InnerJoin((detail, dispatch) => detail.PK_ID == dispatch.DETAIL_ID) - .Where((detail, dispatch) => detail.PK_ID == dispatch.DETAIL_ID && detail.IsDeleted == false - && shipmentList.Contains(detail.SHIPMENT) && detail.NOM_ID == nomId - && dispatch.IsDeleted == false) - .Select((detail, dispatch) => new { Detail = detail, Dispatch = dispatch }).ToList(); - - if (withDispatchList.Count > 0) + var withDispatchList = + _taskRollingNominationInfoRepository.AsQueryable().Filter(null, true) + .InnerJoin((nom, detail) => nom.PK_ID == detail.NOM_ID) + .LeftJoin((nom, detail, dispatch) => + detail.PK_ID == dispatch.DETAIL_ID && dispatch.IsDeleted == false) + .Where((nom, detail, dispatch) => + detail.IsDeleted == false + && detail.NOM_ID == model.nominationId) + .Select((nom, detail, dispatch) => + new { Nom = nom, Detail = detail, Dispatch = dispatch }).ToList(); + + if (withDispatchList.Any(p => p.Dispatch != null + && !string.IsNullOrWhiteSpace(p.Dispatch.PK_ID))) { throw Oops.Oh($"预甩货明细已生成调度不能重复"); } - detailList = _taskRollingNominationDetailInfoRepository.AsQueryable() - .Where(a => shipmentList.Contains(a.SHIPMENT) && a.IsDeleted == false && a.NOM_ID == nomId).ToList(); + var nomiInfo = withDispatchList.FirstOrDefault().Nom; + + var shipmentList = withDispatchList + .Select(a => a.Detail.SHIPMENT) + .Distinct().ToList(); + + Dictionary batchDict = shipmentList.Select(a => new { Key = a, BatchId = IDGen.NextID().ToString() }) + .ToDictionary(a => a.Key, b => b.BatchId); + + DateTime deadLine = nomiInfo.CONFIRM_DEAD_LINE.Value.AddHours(2); - //开始写入调度 - detailList.ForEach(a => + withDispatchList.ForEach(info => { - TaskRollingNominationDispatchInfo dispatchInfo = new TaskRollingNominationDispatchInfo - { - PK_ID = IDGen.NextID().ToString(), - CreatedTime = nowDate, - UpdatedTime = nowDate, - CreatedUserId = UserManager.UserId, - CreatedUserName = UserManager.Name, - DETAIL_ID= a.PK_ID, - NOM_ID= a.NOM_ID, - NOM_SHIP_ID= a.NOM_SHIP_ID, - IsDeleted= false, - STATUS = "WAIT", - TASK_ID = nomModel.TASK_ID, - TenantId = UserManager.TENANT_ID, - TenantName = UserManager.TENANT_NAME, - BATCH_ID = batchDict[a.SHIPMENT], - }; + var a = info.Detail; - _taskRollingNominationDispatchInfoRepository.Insert(dispatchInfo); + if (!a.NOM_STATUS_NOTE.Equals("Load", StringComparison.OrdinalIgnoreCase)) + { + TaskRollingNominationDispatchInfo dispatchInfo = new TaskRollingNominationDispatchInfo + { + PK_ID = IDGen.NextID().ToString(), + CreatedTime = nowDate, + UpdatedTime = nowDate, + CreatedUserId = UserManager.UserId, + CreatedUserName = UserManager.Name, + DETAIL_ID = a.PK_ID, + NOM_ID = a.NOM_ID, + NOM_SHIP_ID = a.NOM_SHIP_ID, + IsDeleted = false, + STATUS = "WAIT", + TASK_ID = nomiInfo.TASK_ID, + TenantId = UserManager.TENANT_ID, + TenantName = UserManager.TENANT_NAME, + BATCH_ID = batchDict[a.SHIPMENT], + CONFIRM_DEAD_LINE = deadLine + }; + + _taskRollingNominationDispatchInfoRepository.Insert(dispatchInfo); + } }); } diff --git a/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs b/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs index 7454f8d4..dc9e0e41 100644 --- a/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs @@ -112,6 +112,7 @@ namespace Myshipping.Application private readonly ISysDataUserMenu _sysDataUserMenuService; private readonly INamedServiceProvider _namedBookingOrderServiceProvider; + private readonly INamedServiceProvider _namedRollingNominationServiceProvider; const string CONST_WEB_ACCOUNT_TYPE = "CmaWeb"; const string CONST_BOOK_ORIGINAL_DOWN_URL_CODE = "bookOriginalDownUrl"; @@ -157,6 +158,7 @@ namespace Myshipping.Application IDjyWebsiteAccountConfigService webAccountConfig, ISysCacheService cache, ISysDataUserMenu sysDataUserMenuService, + INamedServiceProvider namedRollingNominationServiceProvider, ILogger logger) { _taskBaseInfoRepository = taskBaseInfoRepository; @@ -190,6 +192,7 @@ namespace Myshipping.Application _taskRollingNominationDetailInfoRepository = taskRollingNominationDetailInfoRepository; _namedBookingOrderServiceProvider = namedBookingOrderServiceProvider; + _namedRollingNominationServiceProvider = namedRollingNominationServiceProvider; _sysDataUserMenuService = sysDataUserMenuService; @@ -881,7 +884,14 @@ namespace Myshipping.Application }); } - + //异步生成调度 + var rollNominationService = _namedRollingNominationServiceProvider + .GetService(nameof(TaskManageRollingNominationService)); + + var dispatchRlt = await rollNominationService.DispatchRollingNomination(new RollingNominationDispatchRequestDto { + isAdd = true, + nominationId = rollingNomination.PK_ID + }); } #endregion