diff --git a/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskBCInfoDto.cs b/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskBCInfoDto.cs index 816a01e2..71861e0a 100644 --- a/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskBCInfoDto.cs +++ b/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskBCInfoDto.cs @@ -240,5 +240,9 @@ namespace Myshipping.Application /// 集装箱列表 /// public List CtnList { get; set; } + /// + /// 顺序号 + /// + public int Indx { get; set; } } } diff --git a/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs b/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs index b9b33d98..59c83998 100644 --- a/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs @@ -10,6 +10,8 @@ using Myshipping.Application.Enum; using Myshipping.Core; using Myshipping.Core.Service; using NPOI.SS.Formula.Functions; +using SqlSugar; +using StackExchange.Profiling.Internal; using System; using System.Collections.Generic; using System.IO; @@ -197,21 +199,88 @@ namespace Myshipping.Application /* 1、优先匹配提单号一致的 2、判断船名航次一致的 - 3、 */ try { + Dictionary> toDoListDict = new Dictionary>(); //获取所有待处理的BC任务 - var taskList = await _taskBCInfoRepository.AsQueryable().InnerJoin((a,b)=>a.TASK_ID == b.PK_ID) + var taskList = await _taskBCInfoRepository.AsQueryable().InnerJoin((a,b)=>a.TASK_ID == b.PK_ID) .Where((a, b)=> !a.BOOKING_ORDER_ID.HasValue && b.STATUS == TaskStatusEnum.Create.ToString()) .Select((a,b)=>new { BC = a,TSK = b }).ToListAsync(); if (taskList.Count > 0) - { - + { + taskList.ForEach(async tsk => + { + var curList = await _bookingOrderRepository.AsQueryable() + .Where(a => a.VESSEL.Contains(tsk.BC.VESSEL) && a.VOYNO.Contains(tsk.BC.VOYNO) || a.MBLNO.Contains(tsk.BC.MBL_NO) + ).ToListAsync(); + + if (curList.Count > 0) + { + toDoListDict.Add(tsk.BC.PK_ID, curList); + } + else + { + toDoListDict.Add(tsk.BC.PK_ID, new List()); + } + }); + } + + //这里最后清洗一下对应的订舱数据,只保留一条符合的数据 + if (toDoListDict.Count > 0) + { + List> tupList = new List>(); + + int num = 1; + int odNum = 1; + foreach (var kvp in toDoListDict) + { + var bcInfo = taskList.FirstOrDefault(a => a.BC.PK_ID == kvp.Key).BC.Adapt(); + + bcInfo.Indx = num; + + if (kvp.Value.Count > 0) + { + var bookingOrder = kvp.Value.Select(a => + { + if (a.MBLNO.Equals(bcInfo.MBLNo, StringComparison.OrdinalIgnoreCase)) + { + return new { Sort = 90, OBJ = a }; + } + else if (a.VESSEL.Equals(bcInfo.Vessel, StringComparison.OrdinalIgnoreCase) + && a.VOYNO.Equals(bcInfo.VoyNo, StringComparison.OrdinalIgnoreCase)) + { + return new { Sort = 80, OBJ = a }; + } + + return new { Sort = 1, OBJ = a }; + }).OrderByDescending(a => a.Sort).FirstOrDefault().OBJ.Adapt(); + + bookingOrder.Indx = odNum; + odNum++; + + tupList.Add(new Tuple( + bcInfo, + bookingOrder + )); + } + else + { + tupList.Add(new Tuple( + bcInfo, + null + )); + } + + num++; + } + + result.ext = tupList; } result.succ = true; + } catch (Exception ex) {