From c412b0e5fadd144ddd1e277af7f2b68f077c3033 Mon Sep 17 00:00:00 2001 From: zhangxiaofeng <1939543722@qq.com> Date: Thu, 22 Aug 2024 16:01:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=88=86=E9=85=8D=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DS.WMS.Core/Op/Dtos/SeaExportRes.cs | 5 + .../TaskPlat/Method/TaskManageBaseService.cs | 218 ++++++++++-------- 2 files changed, 125 insertions(+), 98 deletions(-) diff --git a/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportRes.cs b/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportRes.cs index 3c3dc7f1..a732a449 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportRes.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportRes.cs @@ -1442,4 +1442,9 @@ public class SeaExportRes /// 航线人员名称 /// public string Laner { get; set; } + + /// + /// 拆票或合票标志 1-拆票 2-合票 + /// + public int SplitOrMergeFlag { get; set; } } \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBaseService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBaseService.cs index 1c671a0d..5cafbb5a 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBaseService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBaseService.cs @@ -1,7 +1,9 @@ using DS.Module.Core; +using DS.Module.Core.Condition; using DS.Module.Core.Data; using DS.Module.SqlSugar; using DS.Module.UserModule; +using DS.WMS.Core.Op.Dtos; using DS.WMS.Core.Op.Entity; using DS.WMS.Core.TaskPlat.Dtos; using DS.WMS.Core.TaskPlat.Entity; @@ -9,6 +11,7 @@ using DS.WMS.Core.TaskPlat.Interface; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using Newtonsoft.Json; using SqlSugar; using System.Linq.Expressions; using System.Runtime.InteropServices; @@ -324,6 +327,21 @@ namespace DS.WMS.Core.TaskPlat.Method /// 涉及当前登陆人的匹配结果 public async Task> MatchTask(List? taskIdList = null) { + /* + * + * 测试库测试用Sql: + SELECT t.SplitOrMergeFlag,t.OperatorId,t.OperatorName,t.Doc,t.DocName,t.CustomerService,t.CustomerServiceName,t.ForeignCustomerService,t.ForeignCustomerServiceName,t.Sale,t.SaleId,t. * + FROM `op_sea_export` t + where Deleted=0 and id In(1816649497120477184,1816779333432381440,1780891904372772864) + order by id desc + + + SELECT t.SplitOrMergeFlag,t.OperatorId,t.OperatorName,t.Doc,t.DocName,t.CustomerService,t.CustomerServiceName,t.ForeignCustomerService,t.ForeignCustomerServiceName,t.Sale,t.SaleId,t. * + FROM `op_sea_export` t + where Deleted=0 and id In(1813475270208917504,1813509723408961536,1816277472539447296) + order by id desc + */ + MatchTaskResultDto result = new MatchTaskResultDto(); var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId); @@ -335,50 +353,53 @@ namespace DS.WMS.Core.TaskPlat.Method && x.STATUS == TaskStatusEnum.Create.ToString() && !string.IsNullOrEmpty(x.MBL_NO)) .WhereIF(taskIdList != null && taskIdList.Count > 0, x => taskIdList!.Contains(x.Id)) + //.Where(x => x.Id == 1813475270208917504 || x.Id == 1816277472539447296 || x.Id == 1813509723408961536) .ToListAsync(x => new TaskBaseInfo { Id = x.Id, MBL_NO = x.MBL_NO, TASK_TYPE = x.TASK_TYPE, TASK_TYPE_NAME = x.TASK_TYPE_NAME, - CARRIER_ID = x.CARRIER_ID, + //CARRIER_ID = x.CARRIER_ID, }); + logger.LogInformation($"MatchTask共查询出{taskList.Count}条待匹配的记录,taskList:{string.Join(',', taskList.Select(x => x.Id))}"); + + var allotSetCache = await allocationService.Value.GetAllList(); - var allotSetList = await allocationService.Value.GetAllList(); + if (!allotSetCache.Succeeded || allotSetCache.Data?.Any() != true) + { + return DataResult.Success("操作成功!", result, MultiLanguageConst.DataUpdateSuccess); + } - if (!allotSetList.Succeeded || allotSetList.Data?.Any() != true) + var taskTypeStrList = taskList.Select(x => x.TASK_TYPE).Distinct().ToList(); + var allotSetList = allotSetCache.Data.Where(x => taskTypeStrList.Contains(x.TaskTypeCode)).ToList(); + if (allotSetList.Count == 0) { return DataResult.Success("操作成功!", result, MultiLanguageConst.DataUpdateSuccess); } // 需要查询的订单的提单号的集合,用于一次性将需要查询的订单查询出来; - HashSet waitQuerySeaExportWithMblnoList = new(); // 后续如果需要查询舱位,可以再补充字段如List waitQuerySlotWithMblnoList = new(); + HashSet waitQuerySeaExportWithMblnoList = new(); + // 分配规则 + Dictionary> allotTargetList = new(); - List<(TaskBaseInfo task, TaskAllocationtSetDto allotSet, List allotUserList)> allotData = new(); - - foreach (var item in taskList) + foreach (var taskItem in taskList) { - // 查找配置规则 - var targetAllotSet = allotSetList.Data.Where(x => x.TaskTypeCode == item.TASK_TYPE && x.CarrierId == item.CARRIER_ID).OrderBy(x => x.Id).FirstOrDefault(); - if (targetAllotSet == null) - { - targetAllotSet = allotSetList.Data.Where(x => x.TaskTypeCode == item.TASK_TYPE).OrderBy(x => x.Id).FirstOrDefault(); - - // 如果某种任务没有配置接收对象,则该任务跳过分配 - if (targetAllotSet == null) continue; - } + List taskItemAllotSetList = allotSetList.Where(x => x.TaskTypeCode == taskItem.TASK_TYPE).ToList(); - allotData.Add((item, targetAllotSet!, new List())); - - // 如果配置的下面四种接收对象,则需要查询订单 - if (targetAllotSet.IsAllotCustomerService - || targetAllotSet.IsAllotSale - || targetAllotSet.IsAllotOperator - || targetAllotSet.IsAllotVouchingClerk) + foreach (var allotSetItem in taskItemAllotSetList) { - waitQuerySeaExportWithMblnoList.Add(item.MBL_NO!); + // 这里先存下来,后面再统一查库,减少查询次数 + // 如果配置的下面四种接收对象,则需要查询订单 + if (allotSetItem.IsAllotCustomerService + || allotSetItem.IsAllotSale + || allotSetItem.IsAllotOperator + || allotSetItem.IsAllotVouchingClerk) + { + waitQuerySeaExportWithMblnoList.Add(taskItem.MBL_NO!); + } } } @@ -388,95 +409,96 @@ namespace DS.WMS.Core.TaskPlat.Method && ( (x.SplitOrMergeFlag == 0 && waitQuerySeaExportWithMblnoList.Contains(x.MBLNO)) || (x.SplitOrMergeFlag == 1 && waitQuerySeaExportWithMblnoList.Contains(x.BookingNo)) - )).Select(x => new - { - x.Id, - x.MBLNO, - x.OperatorId, - x.OperatorName, - x.Doc, - x.DocName, - x.SaleId, - x.Sale, - x.CustomerService, - x.CustomerServiceName, - x.ForeignCustomerService, - x.ForeignCustomerServiceName - }).ToListAsync(); - - foreach (var item in allotData) + )).Select().ToListAsync(); + List<(TaskBaseInfo, List)> allotData = new(); + foreach (var taskItem in taskList) { - // 如果某条任务配置的接收目标为销售、操作、单证、客服中的一项,则需要查订单 - if (item.allotSet.IsAllotCustomerService - || item.allotSet.IsAllotOperator - || item.allotSet.IsAllotSale - || item.allotSet.IsAllotVouchingClerk) + var recvUserList = new List(); + + List taskItemAllotSetList = allotSetList.Where(x => x.TaskTypeCode == taskItem.TASK_TYPE).ToList(); + + var taskItemAllotList = new List(); + foreach (var allotSetItem in taskItemAllotSetList) { - var order = seaExportList.FirstOrDefault(x => x.MBLNO == item.task.MBL_NO); - if (order == null) + // 验证条件 + if (!string.IsNullOrEmpty(allotSetItem.Condition)) { - continue; + var contitionContent = JsonConvert.DeserializeObject(allotSetItem.Condition!)!; + + TaskFlowDataContext dataContext = new(); + + if (allotSetItem.IsAllotCustomerService + || allotSetItem.IsAllotSale + || allotSetItem.IsAllotOperator + || allotSetItem.IsAllotVouchingClerk) + { + var seaExport = seaExportList.FirstOrDefault(x => (x.SplitOrMergeFlag == 0 && taskItem.MBL_NO == x.MBLNO) || (x.SplitOrMergeFlag == 1 && taskItem.MBL_NO == x.BookingNo)); + + if (seaExport == null) continue; // 这里为了效率,设置为如果订单为空,则跳过;后面如果需要判断其他表,需要把这里注释掉 + + dataContext.Set(TaskFlowDataNameConst.Business, seaExport); + } + + if (!ConditionHelper.IsPass(contitionContent, dataContext)) + continue; } - /* - * 操作Operator=订单里的:OperatorId+OperatorName - * 单证VouchingClerk=订单里的:Doc+DocName - * 销售Sale=订单里的:SaleId+Sale - * 客服CustomerService=订单里的:CustomerService+CustomerServiceName / ForeignCustomerService+ForeignCustomerServiceName - */ - - if (item.allotSet.IsAllotCustomerService) + + if (allotSetItem.IsAllotCustomerService + || allotSetItem.IsAllotSale + || allotSetItem.IsAllotOperator + || allotSetItem.IsAllotVouchingClerk) { - if (order.CustomerService != 0 && !string.IsNullOrEmpty(order.CustomerServiceName)) + var order = seaExportList.FirstOrDefault(x => (x.SplitOrMergeFlag == 0 && taskItem.MBL_NO == x.MBLNO) || (x.SplitOrMergeFlag == 1 && taskItem.MBL_NO == x.BookingNo)); + if (order == null) { - item.allotUserList.Add(new RecvUserInfo(order.CustomerService, order.CustomerServiceName)); + continue; } - if (order.ForeignCustomerService != 0 && !string.IsNullOrEmpty(order.ForeignCustomerServiceName)) + /* + * 操作Operator=订单里的:OperatorId+OperatorName + * 单证VouchingClerk=订单里的:Doc+DocName + * 销售Sale=订单里的:SaleId+Sale + * 客服CustomerService=订单里的:CustomerService+CustomerServiceName / ForeignCustomerService+ForeignCustomerServiceName + */ + + if (allotSetItem.IsAllotCustomerService) { - item.allotUserList.Add(new RecvUserInfo(order.ForeignCustomerService, order.ForeignCustomerServiceName)); + if (order.CustomerService != 0 && !string.IsNullOrEmpty(order.CustomerServiceName)) + { + recvUserList.Add(new RecvUserInfo(order.CustomerService, order.CustomerServiceName)); + } + if (order.ForeignCustomerService != 0 && !string.IsNullOrEmpty(order.ForeignCustomerServiceName)) + { + recvUserList.Add(new RecvUserInfo(order.ForeignCustomerService, order.ForeignCustomerServiceName)); + } + } + if (allotSetItem.IsAllotOperator + && order.OperatorId != 0 && !string.IsNullOrEmpty(order.OperatorName)) + { + recvUserList.Add(new RecvUserInfo(order.OperatorId, order.OperatorName)); + } + if (allotSetItem.IsAllotSale + && order.SaleId != 0 && !string.IsNullOrEmpty(order.Sale)) + { + recvUserList.Add(new RecvUserInfo(order.SaleId, order.Sale)); + } + if (allotSetItem.IsAllotVouchingClerk + && order.Doc != 0 && !string.IsNullOrEmpty(order.DocName)) + { + recvUserList.Add(new RecvUserInfo(order.Doc, order.DocName)); } - } - if (item.allotSet.IsAllotOperator - && order.OperatorId != 0 && !string.IsNullOrEmpty(order.OperatorName)) - { - item.allotUserList.Add(new RecvUserInfo(order.OperatorId, order.OperatorName)); - } - if (item.allotSet.IsAllotSale - && order.SaleId != 0 && !string.IsNullOrEmpty(order.Sale)) - { - item.allotUserList.Add(new RecvUserInfo(order.SaleId, order.Sale)); - } - if (item.allotSet.IsAllotVouchingClerk - && order.Doc != 0 && !string.IsNullOrEmpty(order.DocName)) - { - item.allotUserList.Add(new RecvUserInfo(order.Doc, order.DocName)); } } - // 拓展:如果某条任务配置的接收目标为...中的一项,则需要查... - } - - allotData = allotData.Where(x => x.allotUserList.Any()).ToList(); + if (recvUserList.Count != 0) + { + recvUserList = recvUserList.DistinctBy(x => x.RecvUserId).ToList(); - foreach (var item in allotData) - { - await SetTaskOwner([item.task.Id], item.allotUserList); + allotData.Add((taskItem, recvUserList)); + await SetTaskOwner([taskItem.Id], recvUserList); + } } - var userId = long.Parse(user.UserId); - var currentUserRelateTask = allotData.Where(x => x.allotUserList.Any(y => y.RecvUserId == userId)) - .Select(x => x.task).ToList(); - - result.LoginUserMatchTaskIdList = currentUserRelateTask.Select(x => x.Id).ToList(); - - result.LoginUserMatchTaskList = currentUserRelateTask.GroupBy(x => new { x.TASK_TYPE, x.TASK_TYPE_NAME }) - .Select(x => new MatchTaskClassifyDto() - { - TaskType = x.Key.TASK_TYPE, - TaskTypeName = x.Key.TASK_TYPE_NAME!, - Count = x.Count() - }).ToList(); - - return DataResult.Success(result, MultiLanguageConst.DataUpdateSuccess); + return DataResult.Success("操作成功!", result, MultiLanguageConst.DataUpdateSuccess); } } }