From f933bb7a608c1314e3741bcfffde2410a27f85e7 Mon Sep 17 00:00:00 2001 From: zhangxiaofeng <1939543722@qq.com> Date: Mon, 29 Jul 2024 14:03:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=8F=AF=E7=94=A8=E8=88=B1?= =?UTF-8?q?=E4=BD=8D=E5=8F=8A=E7=AE=B1=E5=AD=90=E6=96=B9=E6=B3=95=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E5=8A=9F=E8=83=BD=E9=97=AE=E9=A2=98=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/BookingSlot/BookingSlotService.cs | 138 +++++++++++------- .../BookingSlot/Dto/AvailableSlotDto.cs | 18 +++ 2 files changed, 105 insertions(+), 51 deletions(-) create mode 100644 Myshipping.Application/Service/BookingSlot/Dto/AvailableSlotDto.cs diff --git a/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs b/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs index 5fc0f8aa..525df08c 100644 --- a/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs +++ b/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs @@ -365,8 +365,10 @@ namespace Myshipping.Application TenantId = model.TenantId })); - var inputDto = new BookingSlotBaseApiDto { - DataObj = new BookingSlotBaseApiSaveDto { + var inputDto = new BookingSlotBaseApiDto + { + DataObj = new BookingSlotBaseApiSaveDto + { PORTDISCHARGEID = model.PORTDISCHARGEID, PORTDISCHARGE = model.PORTDISCHARGE, PORTLOADID = model.PORTLOADID, @@ -741,8 +743,8 @@ namespace Myshipping.Application portEnName = currStr.Split(',')[0]?.Trim(); } } - - + + if (!string.IsNullOrWhiteSpace(portEnName)) { var cachePortLoad = await _cache.GetAllCodePortLoad(); @@ -816,12 +818,12 @@ namespace Myshipping.Application if (string.IsNullOrWhiteSpace(dto.DataObj.CTN_STAT)) { - if(dto.DataObj.CtnList != null && dto.DataObj.CtnList.Count > 0) + if (dto.DataObj.CtnList != null && dto.DataObj.CtnList.Count > 0) { - dto.DataObj.CTN_STAT = string.Join(",",dto.DataObj.CtnList.GroupBy(a => a.CTNALL).Select(a => + dto.DataObj.CTN_STAT = string.Join(",", dto.DataObj.CtnList.GroupBy(a => a.CTNALL).Select(a => $"{a.Key}*{a.Select(b => b.CTNNUM).Sum()}").ToArray()); } - + } //自动转换对应标签 @@ -1047,7 +1049,7 @@ namespace Myshipping.Application await PushCompareBCInfo(bcSrcDto, bcTargetDto, id, dto.BatchNo); //触发标签自动绑定 - await GenerateSlotLabel(dto,id); + await GenerateSlotLabel(dto, id); } else if (dto.OpType == "del") { @@ -1564,31 +1566,64 @@ namespace Myshipping.Application }) .MergeTable(); - // 3. 将queryable1 左连接 queryable2,使用【总的箱量】减去【已使用的箱量】,得到【剩余的箱量】,添加【剩余的箱量】> 0 的条件,作为queryable3 - var queryable3 = queryable1.LeftJoin(queryable2, (q1, q2) => q1.id == q2.id && q1.ctnCode == q2.ctnCode) + ISugarQueryable tragerQueryable; + + if (pageInfo == null) + { + // 3. 将queryable1 左连接 queryable2,使用【总的箱量】减去【已使用的箱量】,得到【剩余的箱量】,添加【剩余的箱量】> 0 的条件,作为queryable3 + tragerQueryable = queryable1.LeftJoin(queryable2, (q1, q2) => q1.id == q2.id && q1.ctnCode == q2.ctnCode) + .Select((q1, q2) => new AvailableSlotDto + { + Id = q1.id, + CtnCode = q1.ctnCode, + CtnAll = q1.numAll, + NumResidue = SqlFunc.IsNull(q1.numAll - q2.numUse, q1.numAll) + }) + .MergeTable() + .Where(r => r.NumResidue > 0); + } + else + { + var queryable1Clone = queryable1.Clone(); + + // 3. 将queryable1 左连接 queryable2,使用【总的箱量】减去【已使用的箱量】,得到【剩余的箱量】,添加【剩余的箱量】> 0 的条件,并对Id进行去重,作为queryable3 + var queryable3 = queryable1.LeftJoin(queryable2, (q1, q2) => q1.id == q2.id && q1.ctnCode == q2.ctnCode) .Select((q1, q2) => new { q1.id, - q1.ctnCode, - q1.numAll, numResidue = SqlFunc.IsNull(q1.numAll - q2.numUse, q1.numAll) }) .MergeTable() - .Where(r => r.numResidue > 0); + .Where(r => r.numResidue > 0) + .Select(r => r.id) + .Distinct(); - // 4. 执行ToList(),得到可用的【舱位主键】、【箱型】、【箱量】列表 - RefAsync total = 0; - var canUselist = pageInfo == null - ? await queryable3.ToListAsync() - : await queryable3.ToPageListAsync(pageInfo.PageNo, pageInfo.PageSize, total); + // 4. 执行queryable3,得到【可用的舱位主键列表】 + RefAsync total = 0; + var canUseIdList = await queryable3.ToPageListAsync(pageInfo.PageNo, pageInfo.PageSize, total); + + if (pageInfo != null) + { + pageInfo.Total = total; + } + + // 5. 使用queryable1的副本queryable1Clone,左连接queryable2,添加【可用的舱位主键列表】作为条件,得到queryable4 + tragerQueryable = queryable1Clone.LeftJoin(queryable2, (q1, q2) => q1.id == q2.id && q1.ctnCode == q2.ctnCode) + .Select((q1, q2) => new AvailableSlotDto() + { + Id = q1.id, + CtnCode = q1.ctnCode, + CtnAll = q1.numAll, + NumResidue = SqlFunc.IsNull(q1.numAll - q2.numUse, q1.numAll) + }) + .MergeTable() + .Where(r => canUseIdList.Contains(r.Id)); - if (pageInfo != null) - { - pageInfo.Total = total; } + List canUselist = await tragerQueryable.ToListAsync(); // 查询舱位列表 - var baseIdList = canUselist.Select(c => c.id); + var baseIdList = canUselist.Select(c => c.Id); List baseList = await _repBase.AsQueryable() .Where(u => baseIdList.Contains(u.Id)) .ToListAsync(); @@ -1599,15 +1634,15 @@ namespace Myshipping.Application List result = baseList.Adapt>(); foreach (var item in result) { - var ctnList = canUselist.Where(c => c.id == item.Id).ToList(); + var ctnList = canUselist.Where(c => c.Id == item.Id).ToList(); if (ctnList?.Any() == true) { item.CtnList = ctnList.Select(c => new BookingSlotCtnDto() { - CTNCODE = c.ctnCode, - CTNNUM = c.numResidue, - TOTALNUM = c.numAll, - CTNALL = ctnCodeCache.FirstOrDefault(e => e.Code == c.ctnCode)?.Name ?? throw new Exception($"舱位信息中存在未收录的箱型:{c.ctnCode},需要在箱型字典中补充"), + CTNCODE = c.CtnCode, + CTNNUM = c.NumResidue, + TOTALNUM = c.CtnAll, + CTNALL = ctnCodeCache.FirstOrDefault(e => e.Code == c.CtnCode)?.Name ?? throw new Exception($"舱位信息中存在未收录的箱型:{c.CtnCode},需要在箱型字典中补充"), }).ToList(); } } @@ -1809,7 +1844,7 @@ namespace Myshipping.Application newSlotAllocation.SELLING_PRICE = generateModel.SELLING_PRICE; newSlotAllocation.SPLIT_OR_MERGE_FLAG = generateModel.SplitOrMerge; - if(generateModel.SplitOrMerge == 1 || generateModel.SplitOrMerge == 2) + if (generateModel.SplitOrMerge == 1 || generateModel.SplitOrMerge == 2) { newSlotAllocation.ALLO_BILL_NO = generateModel.NewMBlNo; } @@ -3116,7 +3151,7 @@ namespace Myshipping.Application /// 返回订舱ID private async Task GenerateBookingOrder(BookingSlotBase bookingSlotBase, List bookingSlotFileList, - BookingGenerateDto generateModel,string masterBookingSlotNo) + BookingGenerateDto generateModel, string masterBookingSlotNo) { long id = 0; @@ -3187,8 +3222,8 @@ namespace Myshipping.Application _logger.LogInformation("根据舱位生成订舱,allNum:{allNum}", allNum); //bkModel.IsSplit = selectNum != allNum; bkModel.SPLIT_OR_MERGE_FLAG = selectNum != allNum ? 1 : 0; - - if(!string.IsNullOrWhiteSpace(masterBookingSlotNo)) + + if (!string.IsNullOrWhiteSpace(masterBookingSlotNo)) bkModel.SPLIT_OR_MERGE_FLAG = 2; //拆票逻辑 @@ -3228,7 +3263,7 @@ namespace Myshipping.Application //{ // bkModel.MBLNO = custNo + "A"; - + //} //else //{ @@ -3526,7 +3561,7 @@ namespace Myshipping.Application var bkNoList = list.Select(x => x.BOOKING_ID).ToList(); var bkList = _repBookingOrder.AsQueryable().Filter(null, true).Where(a => bkNoList.Contains(a.Id) && a.TenantId == tenantId && a.IsDeleted == false).ToList(); - if(bkList.Count > 0) + if (bkList.Count > 0) { dto.BookingOrderList = bkList.Select(x => x.Id).ToList(); } @@ -3623,7 +3658,7 @@ namespace Myshipping.Application var bookingInfo = _repBookingOrder.AsQueryable().Filter(null, true).First(x => x.Id == ca.Alloc.BOOKING_ID && x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID); - CreateTask(CautionNoticeTaskEnum.WeekAt, bcSrcDto, userList, bookingInfo, slotInfo, srcWeek, targetWeek, $"提单号:{bcSrcDto.MBLNo} \r\n计费周变更了 \r\n原:{srcWeek} \r\n新:{targetWeek}",true); + CreateTask(CautionNoticeTaskEnum.WeekAt, bcSrcDto, userList, bookingInfo, slotInfo, srcWeek, targetWeek, $"提单号:{bcSrcDto.MBLNo} \r\n计费周变更了 \r\n原:{srcWeek} \r\n新:{targetWeek}", true); }); } else if (slotInfo != null) @@ -3768,10 +3803,11 @@ namespace Myshipping.Application } } }*/ - + bool isNeedWholeShip = false; - CautionNoticeTaskWholeShipDto cautionNoticeTaskWholeShipDto = new CautionNoticeTaskWholeShipDto { + CautionNoticeTaskWholeShipDto cautionNoticeTaskWholeShipDto = new CautionNoticeTaskWholeShipDto + { Carrier = slotInfo.CARRIERID, MBLNo = slotInfo.SLOT_BOOKING_NO }; @@ -3865,7 +3901,7 @@ namespace Myshipping.Application } else { - if(cautionNoticeTaskWholeShipDto.IsVesselChange) + if (cautionNoticeTaskWholeShipDto.IsVesselChange) { if (bookingSlotAllocList.Count > 0) { @@ -4046,7 +4082,7 @@ namespace Myshipping.Application /// 变更值 /// 提示信息 private void CreateTask(CautionNoticeTaskEnum cautionNoticeType, TaskBCInfoDto bcSrcDto, List userList, BookingOrder bookingInfo, - BookingSlotBase bookingSlotInfo, string srcVal, string targetVal, string notifyContent,bool isAutoSendNotice) + BookingSlotBase bookingSlotInfo, string srcVal, string targetVal, string notifyContent, bool isAutoSendNotice) { List userIdList = new List(); @@ -4149,15 +4185,15 @@ namespace Myshipping.Application try { - var model =_repBase.AsQueryable().Filter(null, true) + var model = _repBase.AsQueryable().Filter(null, true) .First(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID && x.SLOT_BOOKING_NO == slotBookingNo && x.CARRIERID == CarrierId); - if(model == null) + if (model == null) throw Oops.Bah("舱位信息不存在"); id = model.Id; } - catch(Exception ex) + catch (Exception ex) { _logger.LogInformation($"订舱编号检索舱位信息失败,原因:{ex.Message}"); } @@ -4377,7 +4413,7 @@ namespace Myshipping.Application } } - List> rltList = new List>(); + List> rltList = new List>(); list.ForEach(m => { @@ -4402,7 +4438,7 @@ namespace Myshipping.Application rltList.Add(new Tuple(m.SLOT_BOOKING_NO, 0, $"舱位提单号:{m.SLOT_BOOKING_NO} 生成合票订舱失败,原因:{ex.Message}")); } }); - + result.succ = true; result.msg = "成功"; @@ -4426,7 +4462,7 @@ namespace Myshipping.Application /// 舱位详情 /// 舱位ID /// - private async Task GenerateSlotLabel(BookingSlotBaseApiDto dto,long id) + private async Task GenerateSlotLabel(BookingSlotBaseApiDto dto, long id) { try { @@ -4440,7 +4476,7 @@ namespace Myshipping.Application List ruleList = new List(); - if(labelList.Count > 0) + if (labelList.Count > 0) { for (int i = 0; i < labelList.Count; i++) { @@ -4458,11 +4494,11 @@ namespace Myshipping.Application { var operEnum = (LabelRegexOperEnum)System.Enum.Parse(typeof(LabelRegexOperEnum), regList[j].oper); - if (regList[j].name.Equals("PORTLOADID",StringComparison.OrdinalIgnoreCase)) + if (regList[j].name.Equals("PORTLOADID", StringComparison.OrdinalIgnoreCase)) { isSucc = CheckLabel("PORTLOADID", dto.DataObj.PORTLOADID, regList[j].val, regList[j].master, operEnum); - if(isSucc) + if (isSucc) { ruleList.Add(labelList[i]); break; @@ -4557,7 +4593,7 @@ namespace Myshipping.Application } } - if(isSucc) + if (isSucc) { _logger.LogInformation($"标签对应到有效规则,{labelList[i].Name}"); } @@ -4567,7 +4603,7 @@ namespace Myshipping.Application { _logger.LogInformation($"标签对应失败,{labelList[i].Name},原因:{innEx.Message}"); } - + } else { @@ -4601,7 +4637,7 @@ namespace Myshipping.Application } #endregion - private bool CheckLabel(string name,string val,string checkVal, bool isMaster, LabelRegexOperEnum operEnum) + private bool CheckLabel(string name, string val, string checkVal, bool isMaster, LabelRegexOperEnum operEnum) { if (operEnum == LabelRegexOperEnum.equal) { @@ -4619,7 +4655,7 @@ namespace Myshipping.Application } else if (operEnum == LabelRegexOperEnum.like) { - if (!string.IsNullOrWhiteSpace(val) && val.Contains(checkVal,StringComparison.OrdinalIgnoreCase)) + if (!string.IsNullOrWhiteSpace(val) && val.Contains(checkVal, StringComparison.OrdinalIgnoreCase)) { return true; } diff --git a/Myshipping.Application/Service/BookingSlot/Dto/AvailableSlotDto.cs b/Myshipping.Application/Service/BookingSlot/Dto/AvailableSlotDto.cs new file mode 100644 index 00000000..f5d5862d --- /dev/null +++ b/Myshipping.Application/Service/BookingSlot/Dto/AvailableSlotDto.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Myshipping.Application.Service.BookingSlot.Dto +{ + public class AvailableSlotDto + { + public long Id { get; set; } + public string CtnCode { get; set; } + + public int CtnAll { get; set; } + + public int NumResidue { get; set; } + } +}