任务台子任务相关功能

dev
zhangxiaofeng 4 weeks ago
parent 634aa5c9cf
commit 88be0e7ad2

@ -565,7 +565,7 @@ namespace DS.WMS.Core.TaskInteraction.Method
DataResult result; DataResult result;
if (!FeeTypes.Contains(request.TaskType)) if (!FeeTypes.Contains(request.TaskType))
{ {
result = await ManagerService.SetTaskStatusWithBsno(request.BusinessId, request.TaskType, request.TaskStatus, DateTime.Now, request.TaskDesc); result = await ManagerService.SetTaskStatusWithBsno(request.BusinessId, request.TaskType, request.TaskStatus, DateTime.Now, false, request.TaskDesc);
if (!result.Succeeded) if (!result.Succeeded)
return DataResult.Failed(result.Message, result.MultiCode); return DataResult.Failed(result.Message, result.MultiCode);
@ -830,7 +830,7 @@ namespace DS.WMS.Core.TaskInteraction.Method
} }
else else
{ {
result = await ManagerService.SetTaskStatusWithBsno(request.BusinessId, request.TaskType, TaskStatusEnum.Cancel, dt); result = await ManagerService.SetTaskStatusWithBsno(request.BusinessId, request.TaskType, TaskStatusEnum.Cancel, dt, false);
if (!result.Succeeded) if (!result.Succeeded)
return result; return result;
} }
@ -966,7 +966,7 @@ namespace DS.WMS.Core.TaskInteraction.Method
if (relativeTasks.All(x => x.TaskStatus == TaskStatusEnum.Complete)) if (relativeTasks.All(x => x.TaskStatus == TaskStatusEnum.Complete))
{ {
var userIdList = tasks.Where(x => relativeFeeIds.Contains(x.BusinessId)).SelectMany(x => x.RecvUserIdArray).Distinct().ToList(); var userIdList = tasks.Where(x => relativeFeeIds.Contains(x.BusinessId)).SelectMany(x => x.RecvUserIdArray).Distinct().ToList();
result = await ManagerService.SetTaskStatusWithBsno(biz.Key.BusinessId, request.TaskType, TaskStatusEnum.Complete, DateTime.Now, userIdList: userIdList); result = await ManagerService.SetTaskStatusWithBsno(biz.Key.BusinessId, request.TaskType, TaskStatusEnum.Complete, DateTime.Now, false, userIdList: userIdList);
if (!result.Succeeded) if (!result.Succeeded)
return result; return result;
} }
@ -1282,7 +1282,7 @@ namespace DS.WMS.Core.TaskInteraction.Method
/// <param name="description">描述信息</param> /// <param name="description">描述信息</param>
public async Task SetTaskBaseDescription(long id, TaskBaseTypeEnum taskType, string description) public async Task SetTaskBaseDescription(long id, TaskBaseTypeEnum taskType, string description)
{ {
await ManagerService.SetTaskBaseInfoPropertyWithBsno(id, taskType, x => x.TASK_DESP == description); await ManagerService.SetTaskBaseInfoPropertyWithBsno(id, taskType, null, null, x => x.TASK_DESP == description);
} }
} }

@ -18,6 +18,16 @@ namespace DS.WMS.Core.TaskPlat.Dtos
/// </summary> /// </summary>
public long? BSNO { get; set; } public long? BSNO { get; set; }
/// <summary>
/// 子业务主键(用于创建子任务)
/// </summary>
public long ChildBSNO { get; set; }
/// <summary>
/// 是否创建为子任务
/// </summary>
public bool IsChild { get; set; }
/// <summary> /// <summary>
/// 报文类型 TASK-任务 /// 报文类型 TASK-任务
/// </summary> /// </summary>

@ -14,6 +14,11 @@ namespace DS.WMS.Core.TaskPlat.Dtos
/// </summary> /// </summary>
public TaskBaseTypeEnum TaskType { get; set; } public TaskBaseTypeEnum TaskType { get; set; }
/// <summary>
/// 子任务类型
/// </summary>
public TaskBaseTypeEnum ChildTaskType { get; set; }
/// <summary> /// <summary>
/// 校验任务重复时是否判断任务类型 /// 校验任务重复时是否判断任务类型
/// </summary> /// </summary>

@ -34,6 +34,18 @@ namespace DS.WMS.Core.TaskPlat.Entity
[SugarColumn(ColumnDescription = "任务类型名称", IsNullable = true, Length = 255)] [SugarColumn(ColumnDescription = "任务类型名称", IsNullable = true, Length = 255)]
public string? TASK_TYPE_NAME { get; set; } public string? TASK_TYPE_NAME { get; set; }
/// <summary>
/// 是否为子任务
/// </summary>
[SugarColumn(ColumnDescription = "是否为子任务", IsNullable = false, DefaultValue = "0")]
public bool IsChild { get; set; }
/// <summary>
/// 父任务主键
/// </summary>
[SugarColumn(ColumnDescription = "父任务主键", IsNullable = false, DefaultValue = "0")]
public long ParentTaskId { get; set; }
/// <summary> /// <summary>
/// 任务来源 /// 任务来源
/// </summary> /// </summary>
@ -88,6 +100,12 @@ namespace DS.WMS.Core.TaskPlat.Entity
[SugarColumn(ColumnDescription = "外业务主键", IsNullable = true)] [SugarColumn(ColumnDescription = "外业务主键", IsNullable = true)]
public long? OUT_BS_NO { get; set; } public long? OUT_BS_NO { get; set; }
/// <summary>
/// 子任务外业务主键
/// </summary>
[SugarColumn(ColumnDescription = "外业务主键", IsNullable = true)]
public long? CHILD_OUT_BS_NO { get; set; }
///// <summary> ///// <summary>
///// 基础业务类型 ///// 基础业务类型
///// </summary> ///// </summary>

@ -2,6 +2,7 @@
using DS.Module.Core.Data; using DS.Module.Core.Data;
using DS.WMS.Core.TaskPlat.Dtos; using DS.WMS.Core.TaskPlat.Dtos;
using DS.WMS.Core.TaskPlat.Entity; using DS.WMS.Core.TaskPlat.Entity;
using SqlSugar;
namespace DS.WMS.Core.TaskPlat.Interface namespace DS.WMS.Core.TaskPlat.Interface
{ {
@ -45,5 +46,6 @@ namespace DS.WMS.Core.TaskPlat.Interface
/// <param name="dataContext">数据上下文(规则匹配时用到的数据来源)</param> /// <param name="dataContext">数据上下文(规则匹配时用到的数据来源)</param>
/// <returns>指定任务类型对应的任务接收人列表</returns> /// <returns>指定任务类型对应的任务接收人列表</returns>
Task<DataResult<Dictionary<TaskBaseTypeEnum, List<RecvUserInfo>>>> GetAllotUserBySeaExportId(List<TaskBaseTypeEnum> taskTypeList, long seaExportId, TaskFlowDataContext? dataContext = null); Task<DataResult<Dictionary<TaskBaseTypeEnum, List<RecvUserInfo>>>> GetAllotUserBySeaExportId(List<TaskBaseTypeEnum> taskTypeList, long seaExportId, TaskFlowDataContext? dataContext = null);
Task<List<(long userId, string userName)>> GetAllotUserList(SqlSugarScopeProvider tenantDb, long taskId);
} }
} }

@ -47,12 +47,17 @@ namespace DS.WMS.Core.TaskPlat.Interface
/// <summary> /// <summary>
/// 工作流设置任务在个人下的状态 /// 工作流设置任务在个人下的状态
/// </summary> /// </summary>
/// <param name="bsno">业务主键</param> /// <param name="bsno">业务主键</param>
/// <param name="taskBaseTypeEnum">业务类型</param> /// <param name="taskBaseTypeEnum">业务类型</param>
/// <param name="taskStatusEnum">业务状态</param> /// <param name="taskStatusEnum">业务状态</param>
/// <param name="statusTime">状态发生时间</param> /// <param name="statusTime">状态发生时间</param>
/// <param name="userInfos">要设置任务状态的人员列表</param> /// <param name="userInfos">要设置任务状态的人员列表</param>
Task<DataResult> SetTaskUserStatus(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, TaskStatusEnum taskStatusEnum, DateTime? statusTime, List<RecvUserInfo> userInfos); /// <param name="childBsno">子业务主键[可选,当不为空时表示设置子任务的个人状态]</param>
/// <param name="childTaskBaseTypeEnum">子业务类型</param>
Task<DataResult> SetTaskUserStatus(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, TaskStatusEnum taskStatusEnum, DateTime? statusTime, List<RecvUserInfo> userInfos,
long? childBsno = null, TaskBaseTypeEnum? childTaskBaseTypeEnum = null);
/// <summary> /// <summary>
/// 工作流设置任务状态 /// 工作流设置任务状态
/// </summary> /// </summary>
@ -60,22 +65,31 @@ namespace DS.WMS.Core.TaskPlat.Interface
/// <param name="taskBaseTypeEnum">业务类型</param> /// <param name="taskBaseTypeEnum">业务类型</param>
/// <param name="taskStatusEnum">业务状态</param> /// <param name="taskStatusEnum">业务状态</param>
/// <param name="statusTime">状态发生时间</param> /// <param name="statusTime">状态发生时间</param>
/// <param name="isCheckAllChildTaskComplete">完成任务前是否检查所有子任务是否完成</param>
/// <param name="taskDesc">任务描述</param> /// <param name="taskDesc">任务描述</param>
/// <param name="userIdList">用户Id列表用于筛选指定用户下的任务</param> /// <param name="userIdList">用户Id列表用于筛选指定用户下的任务[可选,当不为空时会设置此用户列表涉及到的相关任务的状态]</param>
Task<DataResult> SetTaskStatusWithBsno(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, TaskStatusEnum taskStatusEnum, DateTime? statusTime, string? taskDesc = null, List<long>? userIdList = null); /// <param name="childBsno">子业务主键[可选,当不为空时表示设置子任务的状态]</param>
/// <param name="childTaskBaseTypeEnum">子业务类型</param>
Task<DataResult> SetTaskStatusWithBsno(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, TaskStatusEnum taskStatusEnum, DateTime? statusTime,bool isCheckAllChildTaskComplete, string? taskDesc = null, List<long>? userIdList = null,
long? childBsno = null, TaskBaseTypeEnum? childTaskBaseTypeEnum = null);
/// <summary> /// <summary>
/// 工作流任务转交 /// 工作流任务转交
/// </summary> /// </summary>
/// <param name="bsno">业务主键</param> /// <param name="bsno">业务主键</param>
/// <param name="taskBaseTypeEnum">业务类型</param> /// <param name="taskBaseTypeEnum">业务类型</param>
/// <param name="userInfos">要转交的人员信息列表</param> /// <param name="userInfos">要转交的人员信息列表</param>
Task<DataResult> TransferTask(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, List<RecvUserInfo> userInfos, SqlSugarScopeProvider? tenantDb = null); /// <param name="childBsno">子业务主键[可选,当不为空时表示设置子任务的状态]</param>
/// <param name="childTaskBaseTypeEnum">子业务类型</param>
Task<DataResult> TransferTask(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, List<RecvUserInfo> userInfos, SqlSugarScopeProvider? tenantDb = null,
long? childBsno = null, TaskBaseTypeEnum? childTaskBaseTypeEnum = null);
/// <summary> /// <summary>
/// 工作流设置任务对象属性 /// 工作流设置任务对象属性
/// </summary> /// </summary>
Task<DataResult> SetTaskBaseInfoPropertyWithBsno(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, params Expression<Func<TaskBaseInfo, bool>>[] columns); Task<DataResult> SetTaskBaseInfoPropertyWithBsno(long bsno, TaskBaseTypeEnum taskBaseTypeEnum,
long? childBsno = null, TaskBaseTypeEnum? childTaskBaseTypeEnum = null,
params Expression<Func<TaskBaseInfo, bool>>[] columns);
/// <summary> /// <summary>
/// 测试用 /// 测试用
@ -86,5 +100,10 @@ namespace DS.WMS.Core.TaskPlat.Interface
/// 领取任务到当前登陆人(可批量) /// 领取任务到当前登陆人(可批量)
/// </summary> /// </summary>
Task<DataResult> PullTask(long[] ids); Task<DataResult> PullTask(long[] ids);
/// <summary>
/// 任务台台账子任务列表查询
/// </summary>
Task<DataResult<List<dynamic>>> GetChildTaskList(long taskId);
} }
} }

@ -498,5 +498,21 @@ namespace DS.WMS.Core.TaskPlat.Method
return DataResult<Dictionary<TaskBaseTypeEnum, List<RecvUserInfo>>>.Success($"查询成功", result, MultiLanguageConst.OperationSuccess); return DataResult<Dictionary<TaskBaseTypeEnum, List<RecvUserInfo>>>.Success($"查询成功", result, MultiLanguageConst.OperationSuccess);
} }
/// <summary>
/// 获取任务接收人列表
/// </summary>
/// <param name="tenantDb"></param>
/// <param name="taskId"></param>
/// <returns></returns>
public async Task<List<(long userId, string userName)>> GetAllotUserList(SqlSugarScopeProvider tenantDb, long taskId)
{
var allotUserList = await tenantDb.Queryable<TaskBaseAllocation>()
.Where(x => x.TaskId == taskId)
.Select(x => new { x.UserId, x.UserName })
.ToListAsync();
return allotUserList.Select(x => (x.UserId, x.UserName)).ToList();
}
} }
} }

@ -3101,7 +3101,7 @@ namespace DS.WMS.Core.TaskPlat.Method
return DataResult.Failed("未获取到BC任务对象TaskBaseInfo"); return DataResult.Failed("未获取到BC任务对象TaskBaseInfo");
} }
await SetTaskStatus(taskBaseInfo, TaskStatusEnum.Complete, DateTime.Now); await SetTaskStatus(taskBaseInfo, TaskStatusEnum.Complete, DateTime.Now, false);
if (taskBaseInfo.OUT_BS_NO is null or 0) if (taskBaseInfo.OUT_BS_NO is null or 0)
{ {

@ -47,6 +47,10 @@ namespace DS.WMS.Core.TaskPlat.Method
protected Lazy<ISeaExportCommonService> seaExportCommonService; protected Lazy<ISeaExportCommonService> seaExportCommonService;
protected Lazy<IDjyServiceStatusService> djyServiceStatusService; protected Lazy<IDjyServiceStatusService> djyServiceStatusService;
protected static readonly string createStatusStr = TaskStatusEnum.Create.ToString();
protected static readonly string pendingStatusStr = TaskStatusEnum.Pending.ToString();
protected static readonly string completeStatusStr = TaskStatusEnum.Complete.ToString();
public TaskManageBaseService(IUser user, public TaskManageBaseService(IUser user,
ILogger<T> logger, ILogger<T> logger,
ISaasDbService saasDbService, ISaasDbService saasDbService,
@ -583,18 +587,19 @@ namespace DS.WMS.Core.TaskPlat.Method
.Where(t => t.Id == taskBaseId) .Where(t => t.Id == taskBaseId)
.FirstAsync(); .FirstAsync();
return await SetTaskStatus(taskInfo, taskStatusEnum, statusTime, bsno); return await SetTaskStatus(taskInfo, taskStatusEnum, statusTime, false, bsno);
} }
/// <summary> /// <summary>
/// 通过任务主表对象设置任务状态( /// 通过任务主表对象设置任务状态(通用
/// </summary> /// </summary>
/// <param name="taskInfo">任务主表对象</param> /// <param name="taskInfo">任务主表对象</param>
/// <param name="taskStatusEnum">业务状态</param> /// <param name="taskStatusEnum">业务状态</param>
/// <param name="statusTime">状态发生时间</param> /// <param name="statusTime">状态发生时间</param>
/// <param name="isCheckAllChildTaskComplete">完成任务前是否检查所有子任务是否完成</param>
/// <param name="bsno">业务主键</param> /// <param name="bsno">业务主键</param>
/// <param name="taskDesc">任务描述</param> /// <param name="taskDesc">任务描述</param>
public async Task<DataResult> SetTaskStatus(TaskBaseInfo taskInfo, TaskStatusEnum taskStatusEnum, DateTime? statusTime, long? bsno = null, string? taskDesc = null) public async Task<DataResult> SetTaskStatus(TaskBaseInfo taskInfo, TaskStatusEnum taskStatusEnum, DateTime? statusTime, bool isCheckAllChildTaskComplete, long? bsno = null, string? taskDesc = null)
{ {
if (taskInfo is null) if (taskInfo is null)
{ {
@ -603,9 +608,22 @@ namespace DS.WMS.Core.TaskPlat.Method
SqlSugarScopeProvider tenantDb = saasDbService.GetBizDbScopeById(user.TenantId); SqlSugarScopeProvider tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
if (!taskInfo.IsChild && isCheckAllChildTaskComplete && taskStatusEnum == TaskStatusEnum.Complete)
{
if (await tenantDb.Queryable<TaskBaseInfo>()
.Where(x => x.IsChild == true && x.ParentTaskId == taskInfo.Id && (x.STATUS == createStatusStr || x.STATUS == pendingStatusStr))
.AnyAsync())
{
return DataResult.Failed("任务设置完成前,需要所有子任务非待处理中或挂起中");
}
}
// 修改任务的状态 // 修改任务的状态
taskInfo.STATUS = taskStatusEnum.ToString(); string taskStatusStr = taskStatusEnum.ToString();
taskInfo.STATUS_NAME = taskStatusEnum.EnumDescription(); string taskStatusNameStr = taskStatusEnum.EnumDescription();
taskInfo.STATUS = taskStatusStr;
taskInfo.STATUS_NAME = taskStatusNameStr;
taskInfo.RealUserId = long.Parse(user.UserId); taskInfo.RealUserId = long.Parse(user.UserId);
taskInfo.RealUserName = user.UserName; taskInfo.RealUserName = user.UserName;
@ -621,8 +639,10 @@ namespace DS.WMS.Core.TaskPlat.Method
} }
// 任务状态为“完成”且来源为工作流时要做的工作: // 任务状态为“完成” && 来源为工作流 && 非子任务 时要做的工作:
if (taskStatusEnum == TaskStatusEnum.Complete && taskInfo.TASK_SOURCE == TaskSourceEnum.WORK_FLOW.ToString()) if (taskStatusEnum == TaskStatusEnum.Complete
&& taskInfo.TASK_SOURCE == TaskSourceEnum.WORK_FLOW.ToString()
&& !taskInfo.IsChild)
{ {
long? orderId = bsno; long? orderId = bsno;
if (orderId == null || orderId == 0) if (orderId == null || orderId == 0)
@ -669,8 +689,20 @@ namespace DS.WMS.Core.TaskPlat.Method
try try
{ {
var taskBaseAllocationList = await tenantDb.Queryable<TaskBaseAllocation>().Where(x => x.TaskId == taskInfo.Id && x.Status != taskStatusStr).ToListAsync();
List<long> waitUpdateChildTaskIdList = [];
if (!taskInfo.IsChild)
{
waitUpdateChildTaskIdList = await tenantDb.Queryable<TaskBaseInfo>()
.Where(x => x.IsChild == true && x.ParentTaskId == taskInfo.Id && x.STATUS != taskStatusStr)
.Select(x => x.Id)
.ToListAsync();
}
await tenantDb.Ado.BeginTranAsync(); await tenantDb.Ado.BeginTranAsync();
// 更新主任务的状态
await tenantDb.Updateable(taskInfo).UpdateColumns(x => new await tenantDb.Updateable(taskInfo).UpdateColumns(x => new
{ {
x.UpdateBy, x.UpdateBy,
@ -687,15 +719,13 @@ namespace DS.WMS.Core.TaskPlat.Method
x.TASK_DESP x.TASK_DESP
}).ExecuteCommandAsync(); }).ExecuteCommandAsync();
//var taskBaseAllocationList = await tenantDb.Queryable<TaskBaseAllocation>().Where(x => x.TaskId == taskInfo.Id).ToListAsync(); // 更新主任务的任务接收人下的状态
// 取出所有状态与目标状态不一致的关系数据,进行更新
var taskBaseAllocationList = await tenantDb.Queryable<TaskBaseAllocation>().Where(x => x.TaskId == taskInfo.Id && x.Status != taskStatusEnum.ToString()).ToListAsync();
if (taskBaseAllocationList.Count != 0) if (taskBaseAllocationList.Count != 0)
{ {
taskBaseAllocationList.ForEach(x => taskBaseAllocationList.ForEach(x =>
{ {
x.Status = taskStatusEnum.ToString(); x.Status = taskStatusStr;
x.StatusName = taskStatusEnum.EnumDescription(); x.StatusName = taskStatusNameStr;
x.StatusTime = statusTime; x.StatusTime = statusTime;
}); });
@ -709,6 +739,41 @@ namespace DS.WMS.Core.TaskPlat.Method
x.StatusTime x.StatusTime
}).ExecuteCommandAsync(); }).ExecuteCommandAsync();
} }
if (!taskInfo.IsChild && waitUpdateChildTaskIdList.Count > 0)
{
// 更新子任务的状态
await tenantDb.Updateable<TaskBaseInfo>()
.SetColumns(x => new TaskBaseInfo()
{
UpdateBy = long.Parse(user.UserId),
UpdateTime = DateTime.Now,
UpdateUserName = user.UserName,
IS_COMPLETE = taskInfo.IS_COMPLETE,
COMPLETE_DATE = taskInfo.COMPLETE_DATE,
STATUS = taskInfo.STATUS,
STATUS_NAME = taskInfo.STATUS_NAME,
RealUserId = taskInfo.RealUserId,
RealUserName = taskInfo.RealUserName,
})
.Where(x => waitUpdateChildTaskIdList.Contains(x.Id) && x.STATUS != taskStatusStr)
.ExecuteCommandAsync();
// 更新子任务的任务接收人下的状态
await tenantDb.Updateable<TaskBaseAllocation>()
.SetColumns(x => new TaskBaseAllocation()
{
UpdateBy = long.Parse(user.UserId),
UpdateTime = DateTime.Now,
UpdateUserName = user.UserName,
Status = taskInfo.STATUS,
StatusName = taskInfo.STATUS_NAME,
StatusTime = statusTime,
})
.Where(x => waitUpdateChildTaskIdList.Contains(x.TaskId) && x.Status != taskStatusStr)
.ExecuteCommandAsync();
}
await tenantDb.Ado.CommitTranAsync(); await tenantDb.Ado.CommitTranAsync();
} }
catch (Exception) catch (Exception)

@ -87,30 +87,57 @@ namespace DS.WMS.Core.TaskPlat.Method
/// <summary> /// <summary>
/// 工作流设置任务在个人下的状态 /// 工作流设置任务在个人下的状态
/// </summary> /// </summary>
/// <param name="bsno">业务主键</param> /// <param name="bsno">业务主键</param>
/// <param name="taskBaseTypeEnum">业务类型</param> /// <param name="taskBaseTypeEnum">业务类型</param>
/// <param name="taskStatusEnum">业务状态</param> /// <param name="taskStatusEnum">业务状态</param>
/// <param name="statusTime">状态发生时间</param> /// <param name="statusTime">状态发生时间</param>
/// <param name="userInfos">要设置任务状态的人员列表</param> /// <param name="userInfos">要设置任务状态的人员列表</param>
public async Task<DataResult> SetTaskUserStatus(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, TaskStatusEnum taskStatusEnum, DateTime? statusTime, List<RecvUserInfo> userInfos) /// <param name="childBsno">子业务主键[可选,当不为空时表示设置子任务的个人状态]</param>
/// <param name="childTaskBaseTypeEnum">子业务类型</param>
public async Task<DataResult> SetTaskUserStatus(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, TaskStatusEnum taskStatusEnum, DateTime? statusTime, List<RecvUserInfo> userInfos,
long? childBsno = null, TaskBaseTypeEnum? childTaskBaseTypeEnum = null)
{ {
logger.LogInformation("接收到任务个人状态修改报文 bsno={bsno} 状态设置={status} 人员列表={userList} childBsno={childBsno} childTaskBaseTypeEnum={childTaskBaseTypeEnum}", bsno, taskStatusEnum.ToString(), JsonConvert.SerializeObject(userInfos), childBsno, childTaskBaseTypeEnum);
SqlSugarScopeProvider tenantDb = saasDbService.GetBizDbScopeById(user.TenantId); SqlSugarScopeProvider tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
TaskBaseInfo taskInfo = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId)) var taskTypeStr = taskBaseTypeEnum.ToString();
var taskId = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId))
.OrderByDescending(a => a.Id) .OrderByDescending(a => a.Id)
.FirstAsync(t => t.OUT_BS_NO == bsno && t.TASK_TYPE == taskBaseTypeEnum.ToString()); .Where(t => t.OUT_BS_NO == bsno && t.TASK_TYPE == taskTypeStr)
.Select(t => new { t.Id })
.FirstAsync();
if (taskInfo == null) if (taskId == null)
{ {
logger.LogInformation($"根据bsno:【{bsno}】,TaskBaseTypeEnum【{taskBaseTypeEnum}】未查询到任务"); logger.LogInformation($"根据bsno:【{bsno}】,TaskBaseTypeEnum【{taskTypeStr}】未查询到任务");
return DataResult.Failed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataQueryNoData))); return DataResult.Failed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataQueryNoData)));
} }
logger.LogInformation("接收到任务个人状态修改报文 任务主键={id} 状态设置={status} 人员列表={userList}", taskInfo.Id, taskStatusEnum.ToString(), JsonConvert.SerializeObject(userInfos)); long waitSetTaskId = taskId.Id;
if (childBsno != null)
{
var childTypeStr = childTaskBaseTypeEnum.ToString();
var childTaskId = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId))
.OrderByDescending(a => a.Id)
.Where(t => t.CHILD_OUT_BS_NO == childBsno && t.TASK_TYPE == childTypeStr && t.ParentTaskId == taskId.Id)
.Select(t => new { t.Id })
.FirstAsync();
if (childTaskId == null)
{
logger.LogInformation($"根据childBsno:【{childBsno}】,childTaskBaseTypeEnum【{childTypeStr}】未查询到任务");
return DataResult.Failed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataQueryNoData)));
}
waitSetTaskId = childTaskId.Id;
}
var userIdList = userInfos.Select(x => x.RecvUserId).ToList(); var userIdList = userInfos.Select(x => x.RecvUserId).ToList();
var taskBaseAllocationList = await tenantDb.Queryable<TaskBaseAllocation>() var taskBaseAllocationList = await tenantDb.Queryable<TaskBaseAllocation>()
.Where(x => x.TaskId == taskInfo.Id && userIdList.Contains(x.UserId)) .Where(x => x.TaskId == waitSetTaskId && userIdList.Contains(x.UserId))
.ToListAsync(); .ToListAsync();
if (taskBaseAllocationList.Any()) if (taskBaseAllocationList.Any())
{ {
@ -142,53 +169,103 @@ namespace DS.WMS.Core.TaskPlat.Method
/// <param name="taskBaseTypeEnum">业务类型</param> /// <param name="taskBaseTypeEnum">业务类型</param>
/// <param name="taskStatusEnum">业务状态</param> /// <param name="taskStatusEnum">业务状态</param>
/// <param name="statusTime">状态发生时间</param> /// <param name="statusTime">状态发生时间</param>
/// <param name="isCheckAllChildTaskComplete">完成任务前是否检查所有子任务是否完成</param>
/// <param name="taskDesc">任务描述</param> /// <param name="taskDesc">任务描述</param>
/// <param name="userIdList">用户Id列表用于筛选指定用户下的任务</param> /// <param name="userIdList">用户Id列表用于筛选指定用户下的任务[可选,当不为空时会设置此用户列表涉及到的相关任务的状态]</param>
public async Task<DataResult> SetTaskStatusWithBsno(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, TaskStatusEnum taskStatusEnum, DateTime? statusTime, string? taskDesc = null, List<long>? userIdList = null) /// <param name="childBsno">子业务主键[可选,当不为空时表示设置子任务的状态]</param>
/// <param name="childTaskBaseTypeEnum">子业务类型</param>
public async Task<DataResult> SetTaskStatusWithBsno(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, TaskStatusEnum taskStatusEnum, DateTime? statusTime, bool isCheckAllChildTaskComplete, string? taskDesc = null, List<long>? userIdList = null,
long? childBsno = null, TaskBaseTypeEnum? childTaskBaseTypeEnum = null)
{ {
SqlSugarScopeProvider tenantDb = saasDbService.GetBizDbScopeById(user.TenantId); SqlSugarScopeProvider tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
if (userIdList == null || userIdList.Count() == 0) var taskTypeStr = taskBaseTypeEnum.ToString();
{
TaskBaseInfo taskInfo = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId)) // 表示修改子任务的状态
.OrderByDescending(a => a.Id) if (childBsno != null)
.FirstAsync(t => t.OUT_BS_NO == bsno && t.TASK_TYPE == taskBaseTypeEnum.ToString());
if (taskInfo == null)
{
logger.LogInformation($"根据bsno:【{bsno}】,TaskBaseTypeEnum【{taskBaseTypeEnum}】未查询到任务");
return DataResult.Failed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataQueryNoData)));
}
return await SetTaskStatus(taskInfo, taskStatusEnum, statusTime, bsno, taskDesc);
}
else
{ {
var taskIdList = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId)) var taskId = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId))
.OrderByDescending(a => a.Id) .Where(t => t.OUT_BS_NO == bsno && t.TASK_TYPE == taskTypeStr)
.Where(t => t.OUT_BS_NO == bsno && t.TASK_TYPE == taskBaseTypeEnum.ToString()) .OrderByDescending(a => a.Id)
.Select(x => x.Id) .Select(t => new { t.Id })
.ToListAsync(); .FirstAsync();
if (taskIdList.Count() == 0) if (taskId == null)
{ {
var log = $"设置子任务状态时未查询到父任务父任务BSNO{bsno}父任务TaskBaseTypeEnum{taskBaseTypeEnum}";
logger.LogInformation(log);
return DataResult.Failed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataQueryNoData))); return DataResult.Failed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataQueryNoData)));
} }
var waitSetStatusTaskIdList = await tenantDb.Queryable<TaskBaseAllocation>().Where(x => taskIdList.Contains(x.TaskId) && userIdList.Contains(x.UserId)).Select(x => x.TaskId).Distinct().ToListAsync(); var childTaskTypeStr = childTaskBaseTypeEnum.ToString();
var taskInfoList = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId)).Where(x => waitSetStatusTaskIdList.Contains(x.Id)).ToListAsync();
var resultList = new List<bool>(); var childTask = await tenantDb.Queryable<TaskBaseInfo>()
foreach (var item in taskInfoList) .Where(x => x.IsChild == true
&& x.TASK_TYPE == childTaskTypeStr
&& x.CHILD_OUT_BS_NO == childBsno)
.FirstAsync();
if (childTask == null)
{ {
var itemResult = await SetTaskStatus(item, taskStatusEnum, statusTime, bsno, taskDesc); var log = $"设置子任务状态时未查询到子任务父任务BSNO{bsno}父任务TaskBaseTypeEnum{taskBaseTypeEnum}子任务childBsno{childBsno}子任务childTaskBaseTypeEnum{childTaskBaseTypeEnum}";
resultList.Add(itemResult.Succeeded); logger.LogInformation(log);
return DataResult.Failed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataQueryNoData)));
} }
if (resultList.Any(x => !x))
return await SetTaskStatus(childTask, taskStatusEnum, statusTime, isCheckAllChildTaskComplete, bsno, taskDesc);
}
// 表示修改主任务的状态
else
{
// 表示修改主任务的状态
if (userIdList == null || userIdList.Count() == 0)
{ {
return DataResult.Failed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataQueryNoData))); TaskBaseInfo taskInfo = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId))
.OrderByDescending(t => t.Id)
.FirstAsync(t => t.OUT_BS_NO == bsno && t.TASK_TYPE == taskTypeStr);
if (taskInfo == null)
{
logger.LogInformation($"根据bsno:【{bsno}】,TaskBaseTypeEnum【{taskBaseTypeEnum}】未查询到任务");
return DataResult.Failed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataQueryNoData)));
}
return await SetTaskStatus(taskInfo, taskStatusEnum, statusTime, isCheckAllChildTaskComplete, bsno, taskDesc);
} }
// 表示修改主任务的状态,但是通过用户列表做进一步筛选
else else
{ {
return DataResult.Successed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataUpdateSuccess))); var taskIdList = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId))
.OrderByDescending(t => t.Id)
.Where(t => t.OUT_BS_NO == bsno && t.TASK_TYPE == taskTypeStr)
.Select(x => x.Id)
.ToListAsync();
if (taskIdList.Count() == 0)
{
return DataResult.Failed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataQueryNoData)));
}
var waitSetStatusTaskIdList = await tenantDb.Queryable<TaskBaseAllocation>()
.Where(x => taskIdList.Contains(x.TaskId) && userIdList.Contains(x.UserId))
.Select(x => x.TaskId)
.Distinct()
.ToListAsync();
var taskInfoList = await tenantDb.Queryable<TaskBaseInfo>()
.ClearFilter(typeof(IOrgId))
.Where(x => waitSetStatusTaskIdList.Contains(x.Id))
.ToListAsync();
var resultList = new List<bool>();
foreach (var item in taskInfoList)
{
var itemResult = await SetTaskStatus(item, taskStatusEnum, statusTime, isCheckAllChildTaskComplete, bsno, taskDesc);
resultList.Add(itemResult.Succeeded);
}
if (resultList.Any(x => !x))
{
return DataResult.Failed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataQueryNoData)));
}
else
{
return DataResult.Successed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataUpdateSuccess)));
}
} }
} }
} }
@ -199,29 +276,60 @@ namespace DS.WMS.Core.TaskPlat.Method
/// <param name="bsno">业务主键</param> /// <param name="bsno">业务主键</param>
/// <param name="taskBaseTypeEnum">业务类型</param> /// <param name="taskBaseTypeEnum">业务类型</param>
/// <param name="userInfos">要转交的人员信息列表</param> /// <param name="userInfos">要转交的人员信息列表</param>
public async Task<DataResult> TransferTask(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, List<RecvUserInfo> userInfos, SqlSugarScopeProvider? tenantDb = null) /// <param name="childBsno">子业务主键[可选,当不为空时表示设置子任务的状态]</param>
/// <param name="childTaskBaseTypeEnum">子业务类型</param>
public async Task<DataResult> TransferTask(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, List<RecvUserInfo> userInfos, SqlSugarScopeProvider? tenantDb = null,
long? childBsno = null, TaskBaseTypeEnum? childTaskBaseTypeEnum = null)
{ {
tenantDb ??= saasDbService.GetBizDbScopeById(user.TenantId); tenantDb ??= saasDbService.GetBizDbScopeById(user.TenantId);
logger.LogInformation("接收到任务转交报文 bsno={bsno} taskBaseTypeEnum={taskBaseTypeEnum} 转交人员列表={userinfo} childBsno={childBsno} childTaskBaseTypeEnum={childTaskBaseTypeEnum}",
bsno,
taskBaseTypeEnum,
JsonConvert.SerializeObject(userInfos),
childBsno,
childTaskBaseTypeEnum);
try try
{ {
var taskTypeStr = taskBaseTypeEnum.ToString();
var childTaskTypeStr = childTaskBaseTypeEnum.ToString();
var task = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId)) var task = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId))
.Where(t => t.OUT_BS_NO == bsno && t.TASK_TYPE == taskBaseTypeEnum.ToString()) .Where(t => t.OUT_BS_NO == bsno && t.TASK_TYPE == taskTypeStr)
.OrderByDescending(a => a.Id) .OrderByDescending(a => a.Id)
.Select(t => new { t.Id, t.IS_PUBLIC }) .Select(t => new { t.Id, t.IS_PUBLIC })
.FirstAsync(); .FirstAsync();
if (task == null) if (task == null)
{ {
logger.LogInformation($"根据bsno:【{bsno}】,TaskBaseTypeEnum【{taskBaseTypeEnum}】未查询到任务"); logger.LogInformation($"根据bsno:【{bsno}】,TaskBaseTypeEnum【{taskBaseTypeEnum}】未查询到任务");
return DataResult.Failed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataQueryNoData))); return DataResult.Failed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataQueryNoData)));
} }
string? completedBusinessStatusCode = "";
logger.LogInformation("接收到任务转交报文 任务主键={id} 转交人员列表={userinfo}", task.Id, JsonConvert.SerializeObject(userInfos)); if (childBsno != null)
{
var completedBusinessStatusCode = await tenantDb.Queryable<TaskFlowModule>() var childTask = await tenantDb.Queryable<TaskBaseInfo>()
.Where(x => x.ModuleType == 2 && x.TaskType == taskBaseTypeEnum.ToString()) .Where(x => x.IsChild == true
&& x.TASK_TYPE == childTaskTypeStr
&& x.CHILD_OUT_BS_NO == childBsno)
.Select(t => new { t.Id, t.IS_PUBLIC })
.FirstAsync();
if (childTask == null)
{
logger.LogInformation($"根据childBsno:【{childBsno}】,childTaskTypeStr【{childTaskTypeStr}】未查询到子任务");
return DataResult.Failed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataQueryNoData)));
}
task = childTask;
}
else
{
completedBusinessStatusCode = await tenantDb.Queryable<TaskFlowModule>()
.Where(x => x.ModuleType == 2 && x.TaskType == taskTypeStr)
.Select(x => x.CompletedBusinessStatusCode) .Select(x => x.CompletedBusinessStatusCode)
.FirstAsync(); .FirstAsync();
}
await tenantDb.Ado.BeginTranAsync(); await tenantDb.Ado.BeginTranAsync();
@ -277,13 +385,19 @@ namespace DS.WMS.Core.TaskPlat.Method
/// <summary> /// <summary>
/// 工作流设置任务对象属性 /// 工作流设置任务对象属性
/// </summary> /// </summary>
public async Task<DataResult> SetTaskBaseInfoPropertyWithBsno(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, params Expression<Func<TaskBaseInfo, bool>>[] columns) public async Task<DataResult> SetTaskBaseInfoPropertyWithBsno(long bsno, TaskBaseTypeEnum taskBaseTypeEnum,
long? childBsno = null, TaskBaseTypeEnum? childTaskBaseTypeEnum = null,
params Expression<Func<TaskBaseInfo, bool>>[] columns)
{ {
SqlSugarScopeProvider tenantDb = saasDbService.GetBizDbScopeById(user.TenantId); SqlSugarScopeProvider tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
var taskTypeStr = taskBaseTypeEnum.ToString();
var childTaskTypeStr = childTaskBaseTypeEnum.ToString();
long? taskInfoId = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId)) long? taskInfoId = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId))
.OrderByDescending(a => a.Id) .OrderByDescending(a => a.Id)
.Where(t => t.OUT_BS_NO == bsno && t.TASK_TYPE == taskBaseTypeEnum.ToString()) .Where(t => t.OUT_BS_NO == bsno && t.TASK_TYPE == taskTypeStr)
.Select(t => t.Id) .Select(t => t.Id)
.FirstAsync(); .FirstAsync();
if (taskInfoId == null || taskInfoId == 0) if (taskInfoId == null || taskInfoId == 0)
@ -295,6 +409,24 @@ namespace DS.WMS.Core.TaskPlat.Method
{ {
logger.LogInformation($"根据bsno:【{bsno}】,查询出taskInfoId=【{taskInfoId}】"); logger.LogInformation($"根据bsno:【{bsno}】,查询出taskInfoId=【{taskInfoId}】");
} }
if (childBsno != null)
{
long? childTaskId = await tenantDb.Queryable<TaskBaseInfo>()
.Where(x => x.IsChild == true
&& x.TASK_TYPE == childTaskTypeStr
&& x.CHILD_OUT_BS_NO == childBsno)
.Select(t => t.Id)
.FirstAsync();
if (childTaskId == null || childTaskId == 0)
{
logger.LogInformation($"根据childBsno:【{childBsno}】,childTaskTypeStr【{childTaskTypeStr}】未查询到子任务");
return DataResult.Failed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataQueryNoData)));
}
taskInfoId = childTaskId;
}
var updateable = tenantDb.Updateable<TaskBaseInfo>(); var updateable = tenantDb.Updateable<TaskBaseInfo>();
foreach (var item in columns) foreach (var item in columns)
{ {
@ -311,6 +443,10 @@ namespace DS.WMS.Core.TaskPlat.Method
} }
#endregion #endregion
private static object ImportLockObj = new object(); private static object ImportLockObj = new object();
/// <summary> /// <summary>
/// 创建任务公共方法 /// 创建任务公共方法
@ -327,6 +463,11 @@ namespace DS.WMS.Core.TaskPlat.Method
//Monitor.Enter(ImportLockObj); //Monitor.Enter(ImportLockObj);
logger.LogInformation("批次={no} 接收到创建任务报文 报文={msg}", batchNo, JsonConvert.SerializeObject(info)); logger.LogInformation("批次={no} 接收到创建任务报文 报文={msg}", batchNo, JsonConvert.SerializeObject(info));
if (info.Head.IsChild && info.Head.ChildBSNO == 0)
{
throw new Exception("创建子任务需要指定子任务的业务主键[info.Head.ChildBSNO]");
}
SqlSugarScopeProvider tenantDb = saasDbService.GetBizDbScopeById(user.TenantId); SqlSugarScopeProvider tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
// 人员信息测试用 // 人员信息测试用
@ -340,70 +481,106 @@ namespace DS.WMS.Core.TaskPlat.Method
TaskBaseInfo taskInfo = null; TaskBaseInfo taskInfo = null;
var taskTypeStr = info.Main.TaskType.ToString(); var taskTypeStr = info.Main.TaskType.ToString();
var childTaskTypeStr = info.Main.ChildTaskType.ToString();
var createStatusStr = TaskStatusEnum.Create.ToString(); var createStatusStr = TaskStatusEnum.Create.ToString();
var pendingStatusStr = TaskStatusEnum.Pending.ToString(); var pendingStatusStr = TaskStatusEnum.Pending.ToString();
// 特殊处理:费用审核、修改、删除(明细)相关的审核,同一单子可以有多条费用审核及特殊费用审核任务,所属人 long parentTaskId = 0;
if ((info.Main.TaskType if (info.Head.IsChild)
is TaskBaseTypeEnum.FEE_AUDIT {
or TaskBaseTypeEnum.FEE_REJECTED // 根据BSNO查现有任务的主键
or TaskBaseTypeEnum.FEE_MODIFY_AUDIT var parentTask = await tenantDb.Queryable<TaskBaseInfo>()
or TaskBaseTypeEnum.FEE_MODIFY_REJECTED .Where(x => x.OUT_BS_NO == info.Head.BSNO && x.TASK_TYPE == taskTypeStr && x.IsChild == false)
or TaskBaseTypeEnum.FEE_DELETE_AUDIT .OrderByDescending(x => x.Id)
or TaskBaseTypeEnum.FEE_DELETE_REJECTED) .Select(x => new { x.Id })
&& info.Main.RecvUserInfoList?.Count > 0) .FirstAsync();
{ if (parentTask == null)
// 先查此订单在任务台账是否有指定类型的待处理的任务,如果有,查这些任务的归属人里是否已经包含了任务接收人
var existsTaskList = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId))
.Where(t => t.TASK_SOURCE == TaskSourceEnum.WORK_FLOW.ToString()
&& t.OUT_BS_NO == info.Head.BSNO
&& t.TASK_TYPE == taskTypeStr
&& (t.STATUS == createStatusStr || t.STATUS == pendingStatusStr))
.Select(x => new { x.Id, x.TASK_NO })
.ToListAsync();
if (existsTaskList.Count > 0)
{ {
var existsTaskIdList = existsTaskList.Select(x => x.Id); throw new Exception($"创建子任务时根据未查询到父任务父任务BSNO{info.Head.BSNO}父任务TaskBaseTypeEnum{taskTypeStr}");
var recvUser = info.Main.RecvUserInfoList.First(); }
var existsRecvUser = await tenantDb.Queryable<TaskBaseAllocation>().Where(x => existsTaskIdList.Contains(x.TaskId) && x.UserId == recvUser.RecvUserId).AnyAsync(); parentTaskId = parentTask.Id;
if (existsRecvUser)
{ // 判断子任务是否重复
string log = $"订单Id{info.Head.BSNO}业务类型:{taskTypeStr}已有接收人:{recvUser.RecvUserId}/{recvUser.RecvUserName},跳过创建"; var existsChildTask = await tenantDb.Queryable<TaskBaseInfo>()
// 回写任务号 .Where(x => x.IsChild == true
return await Task.FromResult(new DataResult(ResultCode.Success, log, data: existsTaskList.Select(x => x.TASK_NO))); //&& x.ParentTaskId == parentTask.Id
} && x.TASK_TYPE == childTaskTypeStr
&& x.CHILD_OUT_BS_NO == info.Head.ChildBSNO
&& (x.STATUS == createStatusStr || x.STATUS == pendingStatusStr))
.Select(x => new { x.Id, x.TASK_NO })
.FirstAsync();
if (existsChildTask != null)
{
var allotUserList = await allocationService.Value.GetAllotUserList(tenantDb, existsChildTask.Id);
var allotUserName = allotUserList.Select(x => x.userName);
var log = $"同一业务下已存在同任务类型的指定状态(待处理或挂起中)的子任务,不能重复创建(任务流水号:{existsChildTask.TASK_NO},接收人:{string.Join("", allotUserName)}";
throw new Exception(log);
} }
} }
else else
{ {
// 如果业务主键不为空,则通过业务主键进行重复判断 // 特殊处理:费用审核、修改、删除(明细)相关的审核,同一单子可以有多条费用审核及特殊费用审核任务,所属人
if (info.Head.BSNO is not (null or 0)) if ((info.Main.TaskType
is TaskBaseTypeEnum.FEE_AUDIT
or TaskBaseTypeEnum.FEE_REJECTED
or TaskBaseTypeEnum.FEE_MODIFY_AUDIT
or TaskBaseTypeEnum.FEE_MODIFY_REJECTED
or TaskBaseTypeEnum.FEE_DELETE_AUDIT
or TaskBaseTypeEnum.FEE_DELETE_REJECTED)
&& info.Main.RecvUserInfoList?.Count > 0)
{ {
taskInfo = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId)) // 先查此订单在任务台账是否有指定类型的待处理的任务,如果有,查这些任务的归属人里是否已经包含了任务接收人
.Where(t => t.OUT_BS_NO == info.Head.BSNO) var existsTaskList = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId))
.WhereIF(info.Main.IsCheckExistsByTaskType, t => t.TASK_TYPE == taskTypeStr) .Where(t => t.TASK_SOURCE == TaskSourceEnum.WORK_FLOW.ToString()
.OrderByDescending(a => a.Id) && t.OUT_BS_NO == info.Head.BSNO
.Select(x => new TaskBaseInfo() && t.TASK_TYPE == taskTypeStr
{ && (t.STATUS == createStatusStr || t.STATUS == pendingStatusStr))
Id = x.Id, .Select(x => new { x.Id, x.TASK_NO })
STATUS = x.STATUS .ToListAsync();
})
.FirstAsync(); if (existsTaskList.Count > 0)
{
var existsTaskIdList = existsTaskList.Select(x => x.Id);
var recvUser = info.Main.RecvUserInfoList.First();
var existsRecvUser = await tenantDb.Queryable<TaskBaseAllocation>().Where(x => existsTaskIdList.Contains(x.TaskId) && x.UserId == recvUser.RecvUserId).AnyAsync();
if (existsRecvUser)
{
string log = $"订单Id{info.Head.BSNO}业务类型:{taskTypeStr}已有接收人:{recvUser.RecvUserId}/{recvUser.RecvUserName},跳过创建";
// 回写任务号
return await Task.FromResult(new DataResult(ResultCode.Success, log, data: existsTaskList.Select(x => x.TASK_NO)));
}
}
} }
// 否则通过Head.GID进行判断
else else
{ {
taskInfo = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId)) // 如果业务主键不为空,则通过业务主键进行重复判断
.Where(t => t.OUT_BUSI_NO == $"{info.Head.SenderId}_{info.Head.GID}") if (info.Head.BSNO is not (null or 0))
.WhereIF(info.Main.IsCheckExistsByTaskType, t => t.TASK_TYPE == taskTypeStr) {
.OrderByDescending(a => a.Id) taskInfo = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId))
.Select(x => new TaskBaseInfo() .Where(t => t.OUT_BS_NO == info.Head.BSNO)
{ .WhereIF(info.Main.IsCheckExistsByTaskType, t => t.TASK_TYPE == taskTypeStr)
Id = x.Id, .OrderByDescending(a => a.Id)
STATUS = x.STATUS .Select(x => new TaskBaseInfo()
}) {
.FirstAsync(); Id = x.Id,
STATUS = x.STATUS
})
.FirstAsync();
}
// 否则通过Head.GID进行判断
else
{
taskInfo = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId))
.Where(t => t.OUT_BUSI_NO == $"{info.Head.SenderId}_{info.Head.GID}")
.WhereIF(info.Main.IsCheckExistsByTaskType, t => t.TASK_TYPE == taskTypeStr)
.OrderByDescending(a => a.Id)
.Select(x => new TaskBaseInfo()
{
Id = x.Id,
STATUS = x.STATUS
})
.FirstAsync();
}
} }
} }
@ -412,8 +589,11 @@ namespace DS.WMS.Core.TaskPlat.Method
&& taskInfo.STATUS != TaskStatusEnum.Cancel.ToString() && taskInfo.STATUS != TaskStatusEnum.Cancel.ToString()
&& taskInfo.STATUS != TaskStatusEnum.Complete.ToString()) && taskInfo.STATUS != TaskStatusEnum.Complete.ToString())
{ {
logger.LogInformation("批次={no} 状态已存在,不能重复创建任务 status={status}", batchNo, taskInfo.STATUS); var allotUserList = await allocationService.Value.GetAllotUserList(tenantDb, taskInfo.Id);
throw new Exception($"状态已存在,不能重复创建任务"); var allotUserName = allotUserList.Select(x => x.userName);
var log = $"同一业务下已存在同任务类型的指定状态(待处理或挂起中)的任务,不能重复创建(任务流水号:{taskInfo.TASK_NO},接收人:{string.Join("", allotUserName)}";
throw new Exception(log);
} }
logger.LogInformation("批次={no} 接收到创建任务报文 结束查询任务 {msg}", batchNo, taskInfo == null ? "不存在" : "存在"); logger.LogInformation("批次={no} 接收到创建任务报文 结束查询任务 {msg}", batchNo, taskInfo == null ? "不存在" : "存在");
@ -493,9 +673,12 @@ namespace DS.WMS.Core.TaskPlat.Method
CreateTime = DateTime.Now, CreateTime = DateTime.Now,
}; };
if (info.Main.ExtData != null) if (info.Head.IsChild)
{ {
taskInfo.ExtData = info.Main.ExtData.ToJson(); taskInfo.IsChild = true;
taskInfo.ParentTaskId = parentTaskId;
taskInfo.CHILD_OUT_BS_NO = info.Head.ChildBSNO;
taskInfo.TASK_TYPE = childTaskTypeStr;
} }
if (Enum.TryParse(typeof(TaskBaseTypeEnum), taskInfo.TASK_TYPE, out object? taskTypeTemp)) if (Enum.TryParse(typeof(TaskBaseTypeEnum), taskInfo.TASK_TYPE, out object? taskTypeTemp))
@ -503,6 +686,11 @@ namespace DS.WMS.Core.TaskPlat.Method
taskInfo.TASK_TYPE_NAME = ((TaskBaseTypeEnum)taskTypeTemp).EnumDescription(); taskInfo.TASK_TYPE_NAME = ((TaskBaseTypeEnum)taskTypeTemp).EnumDescription();
} }
if (info.Main.ExtData != null)
{
taskInfo.ExtData = info.Main.ExtData.ToJson();
}
// 如果船公司主键不为空则直接保存船公司主键、Code、Name等信息如果Name为空查询一下再赋值 // 如果船公司主键不为空则直接保存船公司主键、Code、Name等信息如果Name为空查询一下再赋值
if (taskInfo.CARRIER_ID != null) if (taskInfo.CARRIER_ID != null)
{ {
@ -601,7 +789,7 @@ namespace DS.WMS.Core.TaskPlat.Method
catch (Exception ex) catch (Exception ex)
{ {
logger.LogError(ex, "任务创建时设置订单业务状态的过程中发生异常orderId={0}taskType={1}", (long)info.Head.BSNO, taskInfo.TASK_TYPE); logger.LogError(ex, "任务创建时设置订单业务状态的过程中发生异常orderId={0}taskType={1}", (long)info.Head.BSNO, taskInfo.TASK_TYPE);
throw; //throw;
} }
try try
@ -617,7 +805,7 @@ namespace DS.WMS.Core.TaskPlat.Method
catch (Exception ex) catch (Exception ex)
{ {
logger.LogError(ex, "任务创建时设置订单的货物状态时发生异常orderId={0}taskType={1}", (long)info.Head.BSNO, taskInfo.TASK_TYPE); logger.LogError(ex, "任务创建时设置订单的货物状态时发生异常orderId={0}taskType={1}", (long)info.Head.BSNO, taskInfo.TASK_TYPE);
throw; //throw;
} }
} }
@ -644,7 +832,7 @@ namespace DS.WMS.Core.TaskPlat.Method
Status = TaskStatusEnum.Create.ToString(), Status = TaskStatusEnum.Create.ToString(),
StatusName = TaskStatusEnum.Create.EnumDescription(), StatusName = TaskStatusEnum.Create.EnumDescription(),
StatusTime = DateTime.Now, StatusTime = DateTime.Now,
BusinessId = taskInfo.OUT_BS_NO, BusinessId = info.Head.IsChild ? taskInfo.CHILD_OUT_BS_NO : taskInfo.OUT_BS_NO,
GoodStatusCode = completedBusinessStatusCode, GoodStatusCode = completedBusinessStatusCode,
OrgId = userWithOrgMap.FirstOrDefault(m => m.Id == x.RecvUserId)?.DefaultOrgId ?? 0 OrgId = userWithOrgMap.FirstOrDefault(m => m.Id == x.RecvUserId)?.DefaultOrgId ?? 0
}; };
@ -1900,6 +2088,7 @@ namespace DS.WMS.Core.TaskPlat.Method
} }
/// <summary> /// <summary>
/// 任务台台账列表查询 /// 任务台台账列表查询
/// </summary> /// </summary>
@ -2676,7 +2865,7 @@ namespace DS.WMS.Core.TaskPlat.Method
item.RecvUserList = recvUserList; item.RecvUserList = recvUserList;
} }
// 2.部分字段值覆盖提单号、ETD、船公司(如果订单的号码不为空则采用订单的号码) // 2.部分字段值覆盖提单号、ETD、船公司、委托编号(如果订单的号码不为空则采用订单的号码)
if (!string.IsNullOrEmpty(item.orderMBLNO)) if (!string.IsNullOrEmpty(item.orderMBLNO))
{ {
item.MBL_NO = item.orderMBLNO; item.MBL_NO = item.orderMBLNO;
@ -2691,6 +2880,10 @@ namespace DS.WMS.Core.TaskPlat.Method
item.CARRIER_ID = item.orderCarrierId; item.CARRIER_ID = item.orderCarrierId;
item.CARRIER_NAME = null; item.CARRIER_NAME = null;
} }
if (!string.IsNullOrEmpty(item.customerNo))
{
item.customeR_NO = item.customerNo;
}
// 3.ExtData字段从Data转为对象 // 3.ExtData字段从Data转为对象
if (!string.IsNullOrEmpty(item.ExtData)) if (!string.IsNullOrEmpty(item.ExtData))
@ -3327,6 +3520,133 @@ namespace DS.WMS.Core.TaskPlat.Method
} }
/// <summary>
/// 任务台台账子任务列表查询
/// </summary>
public async Task<DataResult<List<dynamic>>> GetChildTaskList(long taskId)
{
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
tenantDb.QueryFilter.Clear();
var userId = long.Parse(user.UserId);
var queryable = tenantDb.Queryable<TaskBaseInfo>()
.LeftJoin<TaskBaseAllocation>((t, a) => t.Id == a.TaskId && a.Deleted == false)
.LeftJoin<SeaExport>((t, a, s) => t.OUT_BS_NO == s.Id)
.Where(t => t.IsChild == true && t.ParentTaskId == taskId);
ISugarQueryable<dynamic> queryableTemp = queryable.Select<dynamic>((t, a, s) => new
{
PK_ID = t.Id.SelectAll(),
orderMBLNO = s.MBLNO,
orderETD = s.ETD,
orderCarrier = s.Carrier,
orderCarrierId = s.CarrierId,
s.CustomerNo,
s.CustomerNum,
s.BookingNo,
s.HBLNO,
s.CustomerName,
s.Sale,
s.CustomerServiceName,
s.OperatorName,
s.LoadPortCode,
s.LoadPort,
s.DischargePortCode,
s.DischargePort,
s.CntrTotal,
}).Distinct();
List<dynamic> data = await queryableTemp.ToListAsync();
var result = DataResult<List<dynamic>>.Success(data);
if (result.Data?.Count > 0)
{
// 查询任务接收人列表
var taskIdList = result.Data.Select(x => (long)x.Id).ToList();
var allRecvUserList = await tenantDb.Queryable<TaskBaseAllocation>()
.Where(x => taskIdList.Contains(x.TaskId))
.Select(x => new RecvUserInfo()
{
TaskId = x.TaskId,
RecvUserId = x.UserId,
RecvUserName = x.UserName,
RecvUserStatus = x.Status,
RecvUserStatusName = x.StatusName,
RecvUserStatusTime = x.StatusTime
}).ToListAsync();
// 一些特殊处理
foreach (var item in result.Data)
{
// 1.任务接收人赋值
if (allRecvUserList.Count > 0)
{
var recvUserList = allRecvUserList.Where(x => x.TaskId == item.Id).ToList();
var currentUserStatus = recvUserList.FirstOrDefault(x => x.RecvUserId == userId);
if (currentUserStatus != null)
{
var n = recvUserList.IndexOf(currentUserStatus);
if (n != 0)
{
recvUserList.RemoveAt(n);
recvUserList.Insert(0, currentUserStatus);
}
item.TASK_USER_STATUS = currentUserStatus.RecvUserStatus;
item.TASK_USER_STATUS_NAME = currentUserStatus.RecvUserStatusName;
item.TASK_USER_STATUS_TIME = currentUserStatus.RecvUserStatusTime;
}
item.RecvUserList = recvUserList;
}
// 2.部分字段值覆盖提单号、ETD、船公司、委托编号如果订单的号码不为空则采用订单的号码
if (!string.IsNullOrEmpty(item.orderMBLNO))
{
item.MBL_NO = item.orderMBLNO;
}
if (item.orderETD != null)
{
item.ETD = item.orderETD;
}
if (!string.IsNullOrEmpty(item.orderCarrier))
{
item.CARRIER_CODE = item.orderCarrier;
item.CARRIER_ID = item.orderCarrierId;
item.CARRIER_NAME = null;
}
if (!string.IsNullOrEmpty(item.CustomerNo))
{
item.CUSTOMER_NO = item.CustomerNo;
}
// 3.ExtData字段从Data转为对象
if (!string.IsNullOrEmpty(item.ExtData))
{
try
{
item.ExtData = JObject.Parse(item.ExtData);
}
catch
{
item.ExtData = new { ParseError = true, ParseMessage = "ExtData为非标准Json导致解析异常" };
}
}
}
}
return result;
}
/// <summary> /// <summary>
/// 完成任务(可批量) /// 完成任务(可批量)
/// </summary> /// </summary>

@ -65,9 +65,9 @@ public class TaskManageController : ApiController
/// </summary> /// </summary>
[HttpPost("SetTaskUserStatus")] [HttpPost("SetTaskUserStatus")]
[ApiUser(ApiCode = "BCTaskManage"), AllowAnonymous] [ApiUser(ApiCode = "BCTaskManage"), AllowAnonymous]
public async Task<DataResult> SetTaskUserStatus(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, TaskStatusEnum taskStatusEnum, DateTime? statusTime, [FromBody] List<RecvUserInfo> userInfos) public async Task<DataResult> SetTaskUserStatus(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, TaskStatusEnum taskStatusEnum, DateTime? statusTime, [FromBody] List<RecvUserInfo> userInfos, long? childBsno = null, TaskBaseTypeEnum? childTaskBaseTypeEnum = null)
{ {
var result = await taskManageService.SetTaskUserStatus(bsno, taskBaseTypeEnum, taskStatusEnum, statusTime, userInfos); var result = await taskManageService.SetTaskUserStatus(bsno, taskBaseTypeEnum, taskStatusEnum, statusTime, userInfos, childBsno, childTaskBaseTypeEnum);
return result; return result;
} }
/// <summary> /// <summary>
@ -75,9 +75,9 @@ public class TaskManageController : ApiController
/// </summary> /// </summary>
[HttpPost("SetTaskStatus")] [HttpPost("SetTaskStatus")]
[ApiUser(ApiCode = "BCTaskManage"), AllowAnonymous] [ApiUser(ApiCode = "BCTaskManage"), AllowAnonymous]
public async Task<DataResult> SetTaskStatus(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, TaskStatusEnum taskStatusEnum, DateTime? statusTime) public async Task<DataResult> SetTaskStatus(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, TaskStatusEnum taskStatusEnum, DateTime? statusTime, long? childBsno = null, TaskBaseTypeEnum? childTaskBaseTypeEnum = null)
{ {
var result = await taskManageService.SetTaskStatusWithBsno(bsno, taskBaseTypeEnum, taskStatusEnum, statusTime); var result = await taskManageService.SetTaskStatusWithBsno(bsno, taskBaseTypeEnum, taskStatusEnum, statusTime, true, null, null, childBsno, childTaskBaseTypeEnum);
return result; return result;
} }
/// <summary> /// <summary>
@ -85,9 +85,9 @@ public class TaskManageController : ApiController
/// </summary> /// </summary>
[HttpPost("TransferTask")] [HttpPost("TransferTask")]
[ApiUser(ApiCode = "BCTaskManage"), AllowAnonymous] [ApiUser(ApiCode = "BCTaskManage"), AllowAnonymous]
public async Task<DataResult> TransferTask(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, List<RecvUserInfo> userInfos) public async Task<DataResult> TransferTask(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, List<RecvUserInfo> userInfos, long? childBsno = null, TaskBaseTypeEnum? childTaskBaseTypeEnum = null)
{ {
var result = await taskManageService.TransferTask(bsno, taskBaseTypeEnum, userInfos); var result = await taskManageService.TransferTask(bsno, taskBaseTypeEnum, userInfos, null, childBsno, childTaskBaseTypeEnum);
return result; return result;
} }
@ -113,6 +113,17 @@ public class TaskManageController : ApiController
return result; return result;
} }
/// <summary>
/// 任务台台账子任务列表查询
/// </summary>
[HttpGet("GetChildTaskList")]
public async Task<DataResult<List<dynamic>>> GetChildTaskList(long taskId)
{
var result = await taskManageService.GetChildTaskList(taskId);
return result;
}
/// <summary> /// <summary>
/// 完成任务(可批量) /// 完成任务(可批量)
/// </summary> /// </summary>

@ -242,14 +242,14 @@ public class SaasTest
[Fact] [Fact]
public void InitTableTestZXF() public void InitTableTestZXF()
{ {
var tenantDb = saasService.GetBizDbScopeById("1750335377144680448"); var tenantDb = saasService.GetBizDbScopeById("1819549542425694208");
StaticConfig.CodeFirst_MySqlCollate = "utf8mb4_0900_ai_ci";//较高版本支持 StaticConfig.CodeFirst_MySqlCollate = "utf8mb4_0900_ai_ci";//较高版本支持
//var ass = Assembly.Load("DS.WMS.Core"); //var ass = Assembly.Load("DS.WMS.Core");
//var types = ass.GetTypes().Where(it => it.FullName?.Contains("DS.WMS.Core.TaskPlat.Entity") == true).ToArray(); //var types = ass.GetTypes().Where(it => it.FullName?.Contains("DS.WMS.Core.TaskPlat.Entity") == true).ToArray();
//tenantDb.CodeFirst.InitTables(types); //tenantDb.CodeFirst.InitTables(types);
tenantDb.CodeFirst.InitTables(typeof(TaskBCInfo)); tenantDb.CodeFirst.InitTables(typeof(TaskBaseInfo));
//tenantDb.CodeFirst.InitTables(typeof(TaskFlowLogDetail)); //tenantDb.CodeFirst.InitTables(typeof(TaskFlowLogDetail));
Assert.True(true); Assert.True(true);
} }

Loading…
Cancel
Save