|
|
|
@ -1,16 +1,19 @@
|
|
|
|
|
using DS.Module.Core;
|
|
|
|
|
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;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Web;
|
|
|
|
|
//using static DS.WMS.Core.TaskPlat.Dtos.MatchTaskResultDto;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
|
{
|
|
|
|
@ -19,12 +22,16 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class TaskManageBaseService<T> : ITaskManageBaseService
|
|
|
|
|
{
|
|
|
|
|
// 实例化时构建
|
|
|
|
|
protected readonly IUser user;
|
|
|
|
|
protected readonly ILogger<T> logger;
|
|
|
|
|
protected readonly ISaasDbService saasDbService;
|
|
|
|
|
protected readonly IServiceProvider serviceProvider;
|
|
|
|
|
protected readonly IWebHostEnvironment environment;
|
|
|
|
|
|
|
|
|
|
// 按需构建
|
|
|
|
|
private Lazy<ITaskAllocationService> allocationService;
|
|
|
|
|
|
|
|
|
|
public TaskManageBaseService(IUser user,
|
|
|
|
|
ILogger<T> logger,
|
|
|
|
|
ISaasDbService saasDbService,
|
|
|
|
@ -36,6 +43,8 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
|
this.saasDbService = saasDbService;
|
|
|
|
|
this.serviceProvider = serviceProvider;
|
|
|
|
|
this.environment = environment;
|
|
|
|
|
|
|
|
|
|
allocationService = new Lazy<ITaskAllocationService>(serviceProvider.GetRequiredService<ITaskAllocationService>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -300,5 +309,163 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
|
return (fileFullPath, fileName);
|
|
|
|
|
//return (new FileStream(fileFullPath, FileMode.Open), fileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据订单及配置,将所有或指定的公共任务匹配到个人
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="taskIdList">任务Id列表(当传入时,则只匹配列表中指定的任务)</param>
|
|
|
|
|
/// <returns>涉及当前登陆人的匹配结果</returns>
|
|
|
|
|
public async Task<DataResult<MatchTaskResultDto>> MatchTask(List<long>? taskIdList)
|
|
|
|
|
{
|
|
|
|
|
MatchTaskResultDto result = new MatchTaskResultDto();
|
|
|
|
|
|
|
|
|
|
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
var taskList = await tenantDb.Queryable<TaskBaseInfo>()
|
|
|
|
|
.Where(x => x.IS_PUBLIC == 1
|
|
|
|
|
&& x.STATUS == TaskStatusEnum.Create.ToString()
|
|
|
|
|
&& !string.IsNullOrEmpty(x.MBL_NO))
|
|
|
|
|
.WhereIF(taskIdList != null && taskIdList.Count > 0, x => taskIdList!.Contains(x.Id))
|
|
|
|
|
.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,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var allotSetList = await allocationService.Value.GetAllList();
|
|
|
|
|
|
|
|
|
|
if (!allotSetList.Succeeded || allotSetList.Data?.Any() != true)
|
|
|
|
|
{
|
|
|
|
|
return DataResult<MatchTaskResultDto>.Success("操作成功!", result, MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 需要查询的订单的提单号的集合,用于一次性将需要查询的订单查询出来;
|
|
|
|
|
List<string> waitQuerySeaExportWithMblnoList = new();
|
|
|
|
|
// 后续如果需要查询舱位,可以再补充字段如List<string> waitQuerySlotWithMblnoList = new();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<(TaskBaseInfo task, TaskAllocationtSetDto allotSet, List<RecvUserInfo> allotUserList)> allotData = new();
|
|
|
|
|
|
|
|
|
|
foreach (var item in taskList)
|
|
|
|
|
{
|
|
|
|
|
// 查找配置规则
|
|
|
|
|
var targetAllotSet = allotSetList.Data.Where(x => x.TaskTypeCode == item.TASK_TYPE && x.CarrierCode == 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>()));
|
|
|
|
|
|
|
|
|
|
// 如果配置的下面四种接收对象,则需要查询订单
|
|
|
|
|
if (targetAllotSet.IsAllotCustomerService
|
|
|
|
|
|| targetAllotSet.IsAllotSale
|
|
|
|
|
|| targetAllotSet.IsAllotOperator
|
|
|
|
|
|| targetAllotSet.IsAllotVouchingClerk)
|
|
|
|
|
{
|
|
|
|
|
waitQuerySeaExportWithMblnoList.Add(item.MBL_NO!);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查出涉及到的订单
|
|
|
|
|
var seaExportList = await tenantDb.Queryable<SeaExport>()
|
|
|
|
|
.Where(x => waitQuerySeaExportWithMblnoList.Contains(x.MBLNO) && x.ParentId == 0)
|
|
|
|
|
.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)
|
|
|
|
|
{
|
|
|
|
|
// 如果某条任务配置的接收目标为销售、操作、单证、客服中的一项,则需要查订单
|
|
|
|
|
if (item.allotSet.IsAllotCustomerService
|
|
|
|
|
|| item.allotSet.IsAllotOperator
|
|
|
|
|
|| item.allotSet.IsAllotSale
|
|
|
|
|
|| item.allotSet.IsAllotVouchingClerk)
|
|
|
|
|
{
|
|
|
|
|
var order = seaExportList.FirstOrDefault(x => x.MBLNO == item.task.MBL_NO);
|
|
|
|
|
if (order == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* 操作Operator=订单里的:OperatorId+OperatorName
|
|
|
|
|
* 单证VouchingClerk=订单里的:Doc+DocName
|
|
|
|
|
* 销售Sale=订单里的:SaleId+Sale
|
|
|
|
|
* 客服CustomerService=订单里的:CustomerService+CustomerServiceName / ForeignCustomerService+ForeignCustomerServiceName
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (item.allotSet.IsAllotCustomerService)
|
|
|
|
|
{
|
|
|
|
|
if (order.CustomerService != 0 && !string.IsNullOrEmpty(order.CustomerServiceName))
|
|
|
|
|
{
|
|
|
|
|
item.allotUserList.Add(new RecvUserInfo(order.CustomerService, order.CustomerServiceName));
|
|
|
|
|
}
|
|
|
|
|
if (order.ForeignCustomerService != 0 && !string.IsNullOrEmpty(order.ForeignCustomerServiceName))
|
|
|
|
|
{
|
|
|
|
|
item.allotUserList.Add(new RecvUserInfo(order.ForeignCustomerService, order.ForeignCustomerServiceName));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
foreach (var item in allotData)
|
|
|
|
|
{
|
|
|
|
|
await SetTaskOwner([item.task.Id], item.allotUserList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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<MatchTaskResultDto>.Success(result, MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|