diff --git a/Myshipping.Application/Service/DataSync/DataSyncService.cs b/Myshipping.Application/Service/DataSync/DataSyncService.cs index 1f73a3b5..43195535 100644 --- a/Myshipping.Application/Service/DataSync/DataSyncService.cs +++ b/Myshipping.Application/Service/DataSync/DataSyncService.cs @@ -266,7 +266,7 @@ namespace Myshipping.Application public async Task SyncCustomer(List model) { var userlist = await _repUser.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToListAsync(); - var mlist = await _djycustomer.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToListAsync(); + var mlist = await _djycustomer.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToListAsync(); var shiplist = await _codeForwarder.AsQueryable().ToListAsync(); foreach (var item in model) { @@ -421,10 +421,10 @@ namespace Myshipping.Application public async Task SyncVesselDateList(List model) { - var mapcarrier = _mapcarrier.Where(x => x.Module == "HeChuan").ToList(); + var mapcarrier = _mapcarrier.Where(x => x.Module == "HeChuan").ToList(); var userlist = _repUser.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToList(); - var mlist = _vesselinfo.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID).ToList(); - var orderlist= _rep.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false).ToList(); + var mlist = _vesselinfo.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID).ToList(); + var orderlist = _rep.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false).ToList(); foreach (var item in model) { @@ -435,7 +435,7 @@ namespace Myshipping.Application { throw Oops.Bah("BSNO未录入"); } - + var m = mlist.Where(x => x.BSNO == item.BSNO).FirstOrDefault(); var entity = item.Adapt(); entity.Vessel = item.Vessel.ToUpper().Trim(); @@ -494,7 +494,7 @@ namespace Myshipping.Application if (!string.IsNullOrEmpty(item.CARRIER) && !string.IsNullOrEmpty(item.Vessel) && (!string.IsNullOrEmpty(item.Voyno) || !string.IsNullOrWhiteSpace(item.VoynoInside))) { - var order = orderlist.Where(x => x.CARRIERID == item.CARRIERID && x.VESSEL == item.Vessel) + var order = orderlist.Where(x => x.CARRIERID == item.CARRIERID && x.VESSEL == item.Vessel) .WhereIF(!string.IsNullOrEmpty(item.Voyno), x => x.VOYNO == item.Voyno) .WhereIF(!string.IsNullOrEmpty(item.VoynoInside), x => x.VOYNOINNER == item.VoynoInside).ToList(); @@ -602,7 +602,7 @@ namespace Myshipping.Application var userlist = await _repUser.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToListAsync(); var djycustomer = await _djycustomer.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToListAsync(); var goodsconfig = await _goodsStatusConfig.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToListAsync(); - var orderlist = await _rep.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false&& x.TenantId == UserManager.TENANT_ID).ToListAsync(); + var orderlist = await _rep.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToListAsync(); var linelist = await _repline.AsQueryable().Filter(null, true).Where(m => m.TenantId == UserManager.TENANT_ID).ToListAsync(); foreach (var model in list) @@ -616,12 +616,12 @@ namespace Myshipping.Application throw Oops.Bah("未录入创建人"); } - var user = userlist.Where(x => x.Name == model.CreatedUserName.Trim() && x.IsDeleted == false).FirstOrDefault(); + var user = userlist.Where(x => x.Name == model.CreatedUserName.Trim() && x.IsDeleted == false).FirstOrDefault(); if (user == null) { throw Oops.Bah($"未匹配到创建人{model.CreatedUserName.Trim()}请联系管理员添加相关用户"); } - var order = orderlist.Where(x => x.BSNO == model.BSNO ).FirstOrDefault(); + var order = orderlist.Where(x => x.BSNO == model.BSNO).FirstOrDefault(); if (order == null) @@ -705,7 +705,7 @@ namespace Myshipping.Application } if (!string.IsNullOrEmpty(entity.LineName)) { - var line = linelist.Where(m => m.LineName.Contains(entity.LineName)).FirstOrDefault(); + var line = linelist.Where(m => m.LineName.Contains(entity.LineName)).FirstOrDefault(); if (line == null) { await _repline.InsertAsync(new DjyTenantLine @@ -1692,12 +1692,12 @@ namespace Myshipping.Application public async Task SaveSyncVesselDate(List dto) { var infolist = _vesselinfo.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID).ToList(); - var orderlist = await _rep.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false).ToListAsync(); - + var orderlist = await _rep.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false).ToListAsync(); + foreach (var item in dto) { var model = infolist.Where(x => x.Vessel == item.Vessel && x.Voyno == item.Voyno).FirstOrDefault(); - if (model != null) + if (model != null) { model.ETA = item.ETA; model.YgtETD = item.ETD; @@ -1843,7 +1843,7 @@ namespace Myshipping.Application [SqlSugarUnitOfWork] public async Task SaveSyncGHVesselDate(List dto) { - var orderlist = await _rep.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false).ToListAsync(); + var orderlist = await _rep.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false).ToListAsync(); foreach (var item in dto) { @@ -2205,14 +2205,17 @@ namespace Myshipping.Application var usrList = _repUser.AsQueryable().Filter(null, true).Where(u => u.TenantId == tenantId && !u.IsDeleted).ToList(); Dictionary> dic = new Dictionary>(); - //遍历船名航次,查询订舱数据 + //遍历船名航次,查询船期维护人 foreach (var item in dto) { - var boUserList = _rep.AsQueryable().Filter(null, true).Where(x => x.VESSEL == item.Vessel && x.VOYNO == item.Voyno && (x.ParentId == 0 || x.ParentId == null) && !x.IsDeleted && x.TenantId == tenantId) - .Select(x => x.CreatedUserId).ToList(); - if (boUserList.Count > 0) + var veUserList = _vesselinfo.AsQueryable().Filter(null, true) + .Where(v => v.TenantId == tenantId && v.Vessel == item.Vessel && v.Voyno == item.Voyno && !v.IsDeleted) + .Select(x => x.CreatedUserId) + .ToList(); + + if (veUserList.Count > 0) { - var phoneList = usrList.Where(u => boUserList.Contains(u.Id) && u.Phone != "" && u.Phone != null).Select(x => x.Phone).ToList(); + var phoneList = usrList.Where(u => veUserList.Contains(u.Id) && u.Phone != "" && u.Phone != null).Select(x => x.Phone).ToList(); foreach (var phone in phoneList) { 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) {