cjy 3 months ago
commit e23c623a53

@ -1442,4 +1442,9 @@ public class SeaExportRes
/// 航线人员名称 /// 航线人员名称
/// </summary> /// </summary>
public string Laner { get; set; } public string Laner { get; set; }
/// <summary>
/// 拆票或合票标志 1-拆票 2-合票
/// </summary>
public int SplitOrMergeFlag { get; set; }
} }

@ -1,7 +1,9 @@
using DS.Module.Core; using DS.Module.Core;
using DS.Module.Core.Condition;
using DS.Module.Core.Data; using DS.Module.Core.Data;
using DS.Module.SqlSugar; using DS.Module.SqlSugar;
using DS.Module.UserModule; using DS.Module.UserModule;
using DS.WMS.Core.Op.Dtos;
using DS.WMS.Core.Op.Entity; using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.TaskPlat.Dtos; using DS.WMS.Core.TaskPlat.Dtos;
using DS.WMS.Core.TaskPlat.Entity; using DS.WMS.Core.TaskPlat.Entity;
@ -9,6 +11,7 @@ using DS.WMS.Core.TaskPlat.Interface;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using SqlSugar; using SqlSugar;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -324,6 +327,21 @@ namespace DS.WMS.Core.TaskPlat.Method
/// <returns>涉及当前登陆人的匹配结果</returns> /// <returns>涉及当前登陆人的匹配结果</returns>
public async Task<DataResult<MatchTaskResultDto>> MatchTask(List<long>? taskIdList = null) public async Task<DataResult<MatchTaskResultDto>> MatchTask(List<long>? 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(); MatchTaskResultDto result = new MatchTaskResultDto();
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId); var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
@ -335,50 +353,53 @@ namespace DS.WMS.Core.TaskPlat.Method
&& x.STATUS == TaskStatusEnum.Create.ToString() && x.STATUS == TaskStatusEnum.Create.ToString()
&& !string.IsNullOrEmpty(x.MBL_NO)) && !string.IsNullOrEmpty(x.MBL_NO))
.WhereIF(taskIdList != null && taskIdList.Count > 0, x => taskIdList!.Contains(x.Id)) .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 .ToListAsync(x => new TaskBaseInfo
{ {
Id = x.Id, Id = x.Id,
MBL_NO = x.MBL_NO, MBL_NO = x.MBL_NO,
TASK_TYPE = x.TASK_TYPE, TASK_TYPE = x.TASK_TYPE,
TASK_TYPE_NAME = x.TASK_TYPE_NAME, 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 allotSetList = await allocationService.Value.GetAllList(); var allotSetCache = await allocationService.Value.GetAllList();
if (!allotSetCache.Succeeded || allotSetCache.Data?.Any() != true)
{
return DataResult<MatchTaskResultDto>.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<MatchTaskResultDto>.Success("操作成功!", result, MultiLanguageConst.DataUpdateSuccess); return DataResult<MatchTaskResultDto>.Success("操作成功!", result, MultiLanguageConst.DataUpdateSuccess);
} }
// 需要查询的订单的提单号的集合,用于一次性将需要查询的订单查询出来; // 需要查询的订单的提单号的集合,用于一次性将需要查询的订单查询出来;
HashSet<string> waitQuerySeaExportWithMblnoList = new();
// 后续如果需要查询舱位可以再补充字段如List<string> waitQuerySlotWithMblnoList = new(); // 后续如果需要查询舱位可以再补充字段如List<string> waitQuerySlotWithMblnoList = new();
HashSet<string> waitQuerySeaExportWithMblnoList = new();
// 分配规则
Dictionary<string, List<TaskAllocationtSetDto>> allotTargetList = new();
List<(TaskBaseInfo task, TaskAllocationtSetDto allotSet, List<RecvUserInfo> allotUserList)> allotData = new(); foreach (var taskItem in taskList)
foreach (var item in taskList)
{ {
// 查找配置规则 List<TaskAllocationtSetDto> taskItemAllotSetList = allotSetList.Where(x => x.TaskTypeCode == taskItem.TASK_TYPE).ToList();
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();
// 如果某种任务没有配置接收对象,则该任务跳过分配 foreach (var allotSetItem in taskItemAllotSetList)
if (targetAllotSet == null) continue;
}
allotData.Add((item, targetAllotSet!, new List<RecvUserInfo>()));
// 如果配置的下面四种接收对象,则需要查询订单
if (targetAllotSet.IsAllotCustomerService
|| targetAllotSet.IsAllotSale
|| targetAllotSet.IsAllotOperator
|| targetAllotSet.IsAllotVouchingClerk)
{ {
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 == 0 && waitQuerySeaExportWithMblnoList.Contains(x.MBLNO))
|| (x.SplitOrMergeFlag == 1 && waitQuerySeaExportWithMblnoList.Contains(x.BookingNo)) || (x.SplitOrMergeFlag == 1 && waitQuerySeaExportWithMblnoList.Contains(x.BookingNo))
)).Select(x => new )).Select<SeaExportRes>().ToListAsync();
{ List<(TaskBaseInfo, List<RecvUserInfo>)> allotData = new();
x.Id, foreach (var taskItem in taskList)
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)
{ {
// 如果某条任务配置的接收目标为销售、操作、单证、客服中的一项,则需要查订单 var recvUserList = new List<RecvUserInfo>();
if (item.allotSet.IsAllotCustomerService
|| item.allotSet.IsAllotOperator List<TaskAllocationtSetDto> taskItemAllotSetList = allotSetList.Where(x => x.TaskTypeCode == taskItem.TASK_TYPE).ToList();
|| item.allotSet.IsAllotSale
|| item.allotSet.IsAllotVouchingClerk) var taskItemAllotList = new List<TaskAllocationtSetDto>();
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<ConditionContent>(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 if (allotSetItem.IsAllotCustomerService
* VouchingClerk=Doc+DocName || allotSetItem.IsAllotSale
* Sale=SaleId+Sale || allotSetItem.IsAllotOperator
* CustomerService=CustomerService+CustomerServiceName / ForeignCustomerService+ForeignCustomerServiceName || allotSetItem.IsAllotVouchingClerk)
*/
if (item.allotSet.IsAllotCustomerService)
{ {
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));
} }
} }
// 拓展:如果某条任务配置的接收目标为...中的一项,则需要查... if (recvUserList.Count != 0)
} {
recvUserList = recvUserList.DistinctBy(x => x.RecvUserId).ToList();
allotData = allotData.Where(x => x.allotUserList.Any()).ToList();
foreach (var item in allotData) allotData.Add((taskItem, recvUserList));
{ await SetTaskOwner([taskItem.Id], recvUserList);
await SetTaskOwner([item.task.Id], item.allotUserList); }
} }
var userId = long.Parse(user.UserId); return DataResult<MatchTaskResultDto>.Success("操作成功!", result, MultiLanguageConst.DataUpdateSuccess);
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<MatchTaskResultDto>.Success(result, MultiLanguageConst.DataUpdateSuccess);
} }
} }
} }

Loading…
Cancel
Save