|
|
@ -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 (!allotSetList.Succeeded || allotSetList.Data?.Any() != true)
|
|
|
|
if (!allotSetCache.Succeeded || allotSetCache.Data?.Any() != true)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return DataResult<MatchTaskResultDto>.Success("操作成功!", result, MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果某种任务没有配置接收对象,则该任务跳过分配
|
|
|
|
|
|
|
|
if (targetAllotSet == null) continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
allotData.Add((item, targetAllotSet!, new List<RecvUserInfo>()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var allotSetItem in taskItemAllotSetList)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 这里先存下来,后面再统一查库,减少查询次数
|
|
|
|
// 如果配置的下面四种接收对象,则需要查询订单
|
|
|
|
// 如果配置的下面四种接收对象,则需要查询订单
|
|
|
|
if (targetAllotSet.IsAllotCustomerService
|
|
|
|
if (allotSetItem.IsAllotCustomerService
|
|
|
|
|| targetAllotSet.IsAllotSale
|
|
|
|
|| allotSetItem.IsAllotSale
|
|
|
|
|| targetAllotSet.IsAllotOperator
|
|
|
|
|| allotSetItem.IsAllotOperator
|
|
|
|
|| targetAllotSet.IsAllotVouchingClerk)
|
|
|
|
|| allotSetItem.IsAllotVouchingClerk)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
waitQuerySeaExportWithMblnoList.Add(item.MBL_NO!);
|
|
|
|
waitQuerySeaExportWithMblnoList.Add(taskItem.MBL_NO!);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -388,31 +409,46 @@ 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();
|
|
|
|
|
|
|
|
foreach (var taskItem in taskList)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
x.Id,
|
|
|
|
var recvUserList = new List<RecvUserInfo>();
|
|
|
|
x.MBLNO,
|
|
|
|
|
|
|
|
x.OperatorId,
|
|
|
|
List<TaskAllocationtSetDto> taskItemAllotSetList = allotSetList.Where(x => x.TaskTypeCode == taskItem.TASK_TYPE).ToList();
|
|
|
|
x.OperatorName,
|
|
|
|
|
|
|
|
x.Doc,
|
|
|
|
var taskItemAllotList = new List<TaskAllocationtSetDto>();
|
|
|
|
x.DocName,
|
|
|
|
foreach (var allotSetItem in taskItemAllotSetList)
|
|
|
|
x.SaleId,
|
|
|
|
{
|
|
|
|
x.Sale,
|
|
|
|
// 验证条件
|
|
|
|
x.CustomerService,
|
|
|
|
if (!string.IsNullOrEmpty(allotSetItem.Condition))
|
|
|
|
x.CustomerServiceName,
|
|
|
|
{
|
|
|
|
x.ForeignCustomerService,
|
|
|
|
var contitionContent = JsonConvert.DeserializeObject<ConditionContent>(allotSetItem.Condition!)!;
|
|
|
|
x.ForeignCustomerServiceName
|
|
|
|
|
|
|
|
}).ToListAsync();
|
|
|
|
TaskFlowDataContext dataContext = new();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in allotData)
|
|
|
|
if (allotSetItem.IsAllotCustomerService
|
|
|
|
{
|
|
|
|
|| allotSetItem.IsAllotSale
|
|
|
|
// 如果某条任务配置的接收目标为销售、操作、单证、客服中的一项,则需要查订单
|
|
|
|
|| allotSetItem.IsAllotOperator
|
|
|
|
if (item.allotSet.IsAllotCustomerService
|
|
|
|
|| allotSetItem.IsAllotVouchingClerk)
|
|
|
|
|| item.allotSet.IsAllotOperator
|
|
|
|
{
|
|
|
|
|| item.allotSet.IsAllotSale
|
|
|
|
var seaExport = seaExportList.FirstOrDefault(x => (x.SplitOrMergeFlag == 0 && taskItem.MBL_NO == x.MBLNO) || (x.SplitOrMergeFlag == 1 && taskItem.MBL_NO == x.BookingNo));
|
|
|
|
|| item.allotSet.IsAllotVouchingClerk)
|
|
|
|
|
|
|
|
{
|
|
|
|
if (seaExport == null) continue; // 这里为了效率,设置为如果订单为空,则跳过;后面如果需要判断其他表,需要把这里注释掉
|
|
|
|
var order = seaExportList.FirstOrDefault(x => x.MBLNO == item.task.MBL_NO);
|
|
|
|
|
|
|
|
|
|
|
|
dataContext.Set(TaskFlowDataNameConst.Business, seaExport);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!ConditionHelper.IsPass(contitionContent, dataContext))
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (allotSetItem.IsAllotCustomerService
|
|
|
|
|
|
|
|
|| allotSetItem.IsAllotSale
|
|
|
|
|
|
|
|
|| allotSetItem.IsAllotOperator
|
|
|
|
|
|
|
|
|| allotSetItem.IsAllotVouchingClerk)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var order = seaExportList.FirstOrDefault(x => (x.SplitOrMergeFlag == 0 && taskItem.MBL_NO == x.MBLNO) || (x.SplitOrMergeFlag == 1 && taskItem.MBL_NO == x.BookingNo));
|
|
|
|
if (order == null)
|
|
|
|
if (order == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
@ -424,59 +460,45 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
* 客服CustomerService=订单里的:CustomerService+CustomerServiceName / ForeignCustomerService+ForeignCustomerServiceName
|
|
|
|
* 客服CustomerService=订单里的:CustomerService+CustomerServiceName / ForeignCustomerService+ForeignCustomerServiceName
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
if (item.allotSet.IsAllotCustomerService)
|
|
|
|
if (allotSetItem.IsAllotCustomerService)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (order.CustomerService != 0 && !string.IsNullOrEmpty(order.CustomerServiceName))
|
|
|
|
if (order.CustomerService != 0 && !string.IsNullOrEmpty(order.CustomerServiceName))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
item.allotUserList.Add(new RecvUserInfo(order.CustomerService, order.CustomerServiceName));
|
|
|
|
recvUserList.Add(new RecvUserInfo(order.CustomerService, order.CustomerServiceName));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (order.ForeignCustomerService != 0 && !string.IsNullOrEmpty(order.ForeignCustomerServiceName))
|
|
|
|
if (order.ForeignCustomerService != 0 && !string.IsNullOrEmpty(order.ForeignCustomerServiceName))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
item.allotUserList.Add(new RecvUserInfo(order.ForeignCustomerService, order.ForeignCustomerServiceName));
|
|
|
|
recvUserList.Add(new RecvUserInfo(order.ForeignCustomerService, order.ForeignCustomerServiceName));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (item.allotSet.IsAllotOperator
|
|
|
|
if (allotSetItem.IsAllotOperator
|
|
|
|
&& order.OperatorId != 0 && !string.IsNullOrEmpty(order.OperatorName))
|
|
|
|
&& order.OperatorId != 0 && !string.IsNullOrEmpty(order.OperatorName))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
item.allotUserList.Add(new RecvUserInfo(order.OperatorId, order.OperatorName));
|
|
|
|
recvUserList.Add(new RecvUserInfo(order.OperatorId, order.OperatorName));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (item.allotSet.IsAllotSale
|
|
|
|
if (allotSetItem.IsAllotSale
|
|
|
|
&& order.SaleId != 0 && !string.IsNullOrEmpty(order.Sale))
|
|
|
|
&& order.SaleId != 0 && !string.IsNullOrEmpty(order.Sale))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
item.allotUserList.Add(new RecvUserInfo(order.SaleId, order.Sale));
|
|
|
|
recvUserList.Add(new RecvUserInfo(order.SaleId, order.Sale));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (item.allotSet.IsAllotVouchingClerk
|
|
|
|
if (allotSetItem.IsAllotVouchingClerk
|
|
|
|
&& order.Doc != 0 && !string.IsNullOrEmpty(order.DocName))
|
|
|
|
&& order.Doc != 0 && !string.IsNullOrEmpty(order.DocName))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
item.allotUserList.Add(new RecvUserInfo(order.Doc, order.DocName));
|
|
|
|
recvUserList.Add(new RecvUserInfo(order.Doc, order.DocName));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 拓展:如果某条任务配置的接收目标为...中的一项,则需要查...
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
allotData = allotData.Where(x => x.allotUserList.Any()).ToList();
|
|
|
|
if (recvUserList.Count != 0)
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in allotData)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await SetTaskOwner([item.task.Id], item.allotUserList);
|
|
|
|
recvUserList = recvUserList.DistinctBy(x => x.RecvUserId).ToList();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
allotData.Add((taskItem, recvUserList));
|
|
|
|
|
|
|
|
await SetTaskOwner([taskItem.Id], recvUserList);
|
|
|
|
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);
|
|
|
|
return DataResult<MatchTaskResultDto>.Success("操作成功!", result, MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|