(多个任务类型)根据任务类型列表+海运出口订单Id查询任务分配的人员列表

usertest
zhangxiaofeng 4 months ago
parent beb9d72872
commit eaa0940d57

@ -29,12 +29,21 @@ namespace DS.WMS.Core.TaskPlat.Interface
Task<DataResult<List<TaskAllocationtSetDto>>> GetAllList(bool isFromCache = true);
/// <summary>
/// 根据任务类型+海运出口订单Id查询任务分配的人员列表
/// (单个任务类型)根据任务类型+海运出口订单Id查询任务分配的人员列表
/// </summary>
/// <param name="taskType">任务类型</param>
/// <param name="seaExportId">海运出口订单Id</param>
/// <param name="dataContext">数据上下文(规则匹配时用到的数据来源)</param>
/// <returns>任务接收人列表</returns>
Task<DataResult<List<RecvUserInfo>>> GetAllotUserBySeaExportId(TaskBaseTypeEnum taskType, long seaExportId, TaskFlowDataContext? dataContext = null);
/// <summary>
/// (多个任务类型)根据任务类型列表+海运出口订单Id查询任务分配的人员列表
/// </summary>
/// <param name="taskTypeList">任务类型列表</param>
/// <param name="seaExportId">海运出口订单Id</param>
/// <param name="dataContext">数据上下文(规则匹配时用到的数据来源)</param>
/// <returns>指定任务类型对应的任务接收人列表</returns>
Task<DataResult<Dictionary<TaskBaseTypeEnum, List<RecvUserInfo>>>> GetAllotUserBySeaExportId(List<TaskBaseTypeEnum> taskTypeList, long seaExportId, TaskFlowDataContext? dataContext = null);
}
}

@ -3,19 +3,16 @@ using DS.Module.Core.Condition;
using DS.Module.Core.Data;
using DS.Module.SqlSugar;
using DS.Module.UserModule;
using DS.WMS.Core.Invoice.Dtos;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Sys.Interface;
using DS.WMS.Core.Sys.Method;
using DS.WMS.Core.TaskPlat.Dtos;
using DS.WMS.Core.TaskPlat.Entity;
using DS.WMS.Core.TaskPlat.Interface;
using LanguageExt.Common;
using LanguageExt.Pipes;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using SqlSugar;
using static AnyDiff.DifferenceLines;
namespace DS.WMS.Core.TaskPlat.Method
@ -195,15 +192,16 @@ namespace DS.WMS.Core.TaskPlat.Method
bool isLoad = false;
if (isFromCache)
{
var rlt = await sysCacheService.GetAllCommonCodeFromCache<TaskAllocationtSetDto>(SysCacheCategoryEnum.TaskAllocationtSet, "DS8");
// 因为设置界面还没有实现,所以先注释掉,防止改库后数据不变
//if (isFromCache)
//{
// var rlt = await sysCacheService.GetAllCommonCodeFromCache<TaskAllocationtSetDto>(SysCacheCategoryEnum.TaskAllocationtSet, "DS8");
if (rlt.Succeeded)
return rlt;
// if (rlt.Succeeded)
// return rlt;
isLoad = true;
}
// isLoad = true;
//}
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
@ -225,7 +223,7 @@ namespace DS.WMS.Core.TaskPlat.Method
}
/// <summary>
/// 根据任务类型+海运出口订单Id查询任务分配的人员列表
/// (单个任务类型)根据任务类型+海运出口订单Id查询任务分配的人员列表
/// </summary>
/// <param name="taskType">任务类型</param>
/// <param name="seaExportId">海运出口订单Id</param>
@ -271,24 +269,33 @@ namespace DS.WMS.Core.TaskPlat.Method
}
// 查出涉及到的订单
SeaExport? order = null;
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
var order = await tenantDb.Queryable<SeaExport>()
.Where(x => x.Id == seaExportId)
.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
}).FirstAsync();
if (dataContext.ContainsKey(TaskFlowDataNameConst.Business))
{
order = dataContext.Get<SeaExport>(TaskFlowDataNameConst.Business);
}
else
{
order = await tenantDb.Queryable<SeaExport>()
.Where(x => x.Id == seaExportId)
.Select(x => new SeaExport
{
Id = x.Id,
MBLNO = x.MBLNO,
OperatorId = x.OperatorId,
OperatorName = x.OperatorName,
Doc = x.Doc,
DocName = x.DocName,
SaleId = x.SaleId,
Sale = x.Sale,
CustomerService = x.CustomerService,
CustomerServiceName = x.CustomerServiceName,
ForeignCustomerService = x.ForeignCustomerService,
ForeignCustomerServiceName = x.ForeignCustomerServiceName
}).FirstAsync();
}
if (order == null)
{
return DataResult<List<RecvUserInfo>>.Success($"根据海运出口订单Id{seaExportId}未查询到海运出口订单", [], MultiLanguageConst.DataQueryNoData);
@ -334,5 +341,139 @@ namespace DS.WMS.Core.TaskPlat.Method
return DataResult<List<RecvUserInfo>>.Success($"查询成功", result, MultiLanguageConst.OperationSuccess);
}
/// <summary>
/// (多个任务类型)根据任务类型列表+海运出口订单Id查询任务分配的人员列表
/// </summary>
/// <param name="taskTypeList">任务类型列表</param>
/// <param name="seaExportId">海运出口订单Id</param>
/// <param name="dataContext">数据上下文(规则匹配时用到的数据来源)</param>
/// <returns>指定任务类型对应的任务接收人列表</returns>
public async Task<DataResult<Dictionary<TaskBaseTypeEnum, List<RecvUserInfo>>>> GetAllotUserBySeaExportId(List<TaskBaseTypeEnum> taskTypeList, long seaExportId, TaskFlowDataContext? dataContext = null)
{
var allotSetList = await GetAllList();
if (!allotSetList.Succeeded || allotSetList.Data?.Any() != true)
{
return DataResult<Dictionary<TaskBaseTypeEnum, List<RecvUserInfo>>>.Success($"未查询到任一类型的任务分配规则", [], MultiLanguageConst.DataQueryNoData);
}
if (taskTypeList == null || taskTypeList.Count == 0)
{
return DataResult<Dictionary<TaskBaseTypeEnum, List<RecvUserInfo>>>.Success($"任务列表为空", [], MultiLanguageConst.DataQueryNoData);
}
taskTypeList = taskTypeList.Distinct().ToList();
var taskTypeStrList = taskTypeList.Select(x => x.ToString());
var allotList = allotSetList.Data.Where(x => taskTypeStrList.Contains(x.TaskTypeCode)).OrderBy(x => x.Id).ToList();
if (allotList.Count == 0)
{
return DataResult<Dictionary<TaskBaseTypeEnum, List<RecvUserInfo>>>.Success($"对于任务列表:{string.Join(',', taskTypeStrList)}未配置任务分配规则", [], MultiLanguageConst.DataQueryNoData);
}
var groupAllotList = allotList.GroupBy(x => x.TaskTypeCode);
// 匹配分配规则
Dictionary<TaskBaseTypeEnum, List<TaskAllocationtSetDto>> allotTargetList = new();
foreach (var groupAllotItem in groupAllotList)
{
var itemResult = new List<TaskAllocationtSetDto>();
foreach (var allotItem in groupAllotItem)
{
if (string.IsNullOrEmpty(allotItem.Condition) || dataContext == null)
{
itemResult.Add(allotItem);
}
else
{
var contitionContent = JsonConvert.DeserializeObject<ContitionContent>(allotItem.Condition)!;
if (ConditionHelper.IsPass(contitionContent, dataContext))
{
itemResult.Add(allotItem);
}
}
}
if (itemResult.Count != 0 && Enum.TryParse(typeof(TaskBaseTypeEnum), groupAllotItem.Key, out object? type))
{
allotTargetList.Add((TaskBaseTypeEnum)type, itemResult); // 因为前面做了去重所以这里可以直接用Add
}
}
// 查出涉及到的订单
SeaExport? order = null;
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
if (dataContext.ContainsKey(TaskFlowDataNameConst.Business))
{
order = dataContext.Get<SeaExport>(TaskFlowDataNameConst.Business);
}
else
{
order = await tenantDb.Queryable<SeaExport>()
.Where(x => x.Id == seaExportId)
.Select(x => new SeaExport
{
Id = x.Id,
MBLNO = x.MBLNO,
OperatorId = x.OperatorId,
OperatorName = x.OperatorName,
Doc = x.Doc,
DocName = x.DocName,
SaleId = x.SaleId,
Sale = x.Sale,
CustomerService = x.CustomerService,
CustomerServiceName = x.CustomerServiceName,
ForeignCustomerService = x.ForeignCustomerService,
ForeignCustomerServiceName = x.ForeignCustomerServiceName
}).FirstAsync();
}
if (order == null)
{
return DataResult<Dictionary<TaskBaseTypeEnum, List<RecvUserInfo>>>.Success($"根据海运出口订单Id{seaExportId}未查询到海运出口订单", [], MultiLanguageConst.DataQueryNoData);
}
var result = new Dictionary<TaskBaseTypeEnum, List<RecvUserInfo>>();
foreach (var targetList in allotTargetList)
{
var userList = new List<RecvUserInfo>();
foreach (var setItem in targetList.Value)
{
// 根据分配规则+订单,生成人员列表作为结果
if (setItem.IsAllotCustomerService)
{
if (order.CustomerService != 0 && !string.IsNullOrEmpty(order.CustomerServiceName))
{
userList.Add(new RecvUserInfo(order.CustomerService, order.CustomerServiceName));
}
if (order.ForeignCustomerService != 0 && !string.IsNullOrEmpty(order.ForeignCustomerServiceName))
{
userList.Add(new RecvUserInfo(order.ForeignCustomerService, order.ForeignCustomerServiceName));
}
}
if (setItem.IsAllotOperator
&& order.OperatorId != 0 && !string.IsNullOrEmpty(order.OperatorName))
{
userList.Add(new RecvUserInfo(order.OperatorId, order.OperatorName));
}
if (setItem.IsAllotSale
&& order.SaleId != 0 && !string.IsNullOrEmpty(order.Sale))
{
userList.Add(new RecvUserInfo(order.SaleId, order.Sale));
}
if (setItem.IsAllotVouchingClerk
&& order.Doc != 0 && !string.IsNullOrEmpty(order.DocName))
{
userList.Add(new RecvUserInfo(order.Doc, order.DocName));
}
// 后期实现如果设置了角色Id列表则将角色对应的人员列表合并到结果中
}
if (userList.Count > 0)
{
result.Add(targetList.Key, userList.DistinctBy(x => x.RecvUserId).ToList());
}
}
return DataResult<Dictionary<TaskBaseTypeEnum, List<RecvUserInfo>>>.Success($"查询成功", result, MultiLanguageConst.OperationSuccess);
}
}
}

@ -1,4 +1,8 @@
using DS.Module.Core;
using DS.Module.Core.Data;
using DS.Module.SqlSugar;
using DS.Module.UserModule;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.TaskPlat.Dtos;
using DS.WMS.Core.TaskPlat.Entity;
using DS.WMS.Core.TaskPlat.Interface;
@ -13,10 +17,11 @@ namespace DS.WMS.TaskApi.Controllers;
public class TaskAllocationController : ApiController
{
private readonly ITaskAllocationService taskAllocationService;
public TaskAllocationController(ITaskAllocationService taskAllocationService)
protected readonly IServiceProvider serviceProvider;
public TaskAllocationController(ITaskAllocationService taskAllocationService, IServiceProvider serviceProvider)
{
this.taskAllocationService = taskAllocationService;
this.serviceProvider = serviceProvider;
}
/// <summary>
/// 获取任务分配列表
@ -47,4 +52,28 @@ public class TaskAllocationController : ApiController
var result = await taskAllocationService.Save(saveDto);
return result;
}
/// <summary>
/// (测试)任务台任务分配
/// </summary>
/// <returns></returns>
[HttpPost("Test")]
public async Task Test()
{
var saasDbService = serviceProvider.GetService<ISaasDbService>();
var user = serviceProvider.GetService<IUser>();
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
var order = await tenantDb.Queryable<SeaExport>().FirstAsync(x => x.Id == 1816649497120477184);
TaskFlowDataContext dataContext = new(
(TaskFlowDataNameConst.Business, order)
);
var result = taskAllocationService.GetAllotUserBySeaExportId(new List<TaskBaseTypeEnum>() {
TaskBaseTypeEnum.INVOICE_BILL_MAIL,
TaskBaseTypeEnum.NOT_LOADED,
TaskBaseTypeEnum.NOT_SHIPMENG,
}, 1816649497120477184, dataContext);
}
}
Loading…
Cancel
Save