From 7f00cc51147bad13ac11c5d6e605f9736afc156a Mon Sep 17 00:00:00 2001 From: zhangxiaofeng <1939543722@qq.com> Date: Fri, 26 Jul 2024 09:53:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=8F=B0=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Constants/MultiLanguageConst.cs | 5 + .../Enums/TaskPlat/TaskCompleteDealEnum.cs | 16 ++ .../Enums/TaskPlat/TaskOperTypeEnum.cs | 26 ++ .../TaskPlat/Entity/TaskBaseInfo.cs | 12 +- .../TaskPlat/Interface/ITaskManageService.cs | 8 + .../TaskPlat/Method/TaskManageService.cs | 234 +++++++++++++++++- .../Controllers/TaskManageController.cs | 11 +- 7 files changed, 296 insertions(+), 16 deletions(-) create mode 100644 ds-wms-service/DS.Module.Core/Enums/TaskPlat/TaskCompleteDealEnum.cs create mode 100644 ds-wms-service/DS.Module.Core/Enums/TaskPlat/TaskOperTypeEnum.cs diff --git a/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs b/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs index f65f7b1e..39d835a4 100644 --- a/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs +++ b/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs @@ -1408,4 +1408,9 @@ public static class MultiLanguageConst [Description("此类型的任务已存在")] public const string Task_Exists = "Task_Exists"; #endregion + + #region 任务台相关 + [Description("当前状态是{0}不能执行完成")] + public const string TaskCannotCompleteWhenStatusMismatch = "TaskCannotCompleteWhenStatusMismatch"; + #endregion } \ No newline at end of file diff --git a/ds-wms-service/DS.Module.Core/Enums/TaskPlat/TaskCompleteDealEnum.cs b/ds-wms-service/DS.Module.Core/Enums/TaskPlat/TaskCompleteDealEnum.cs new file mode 100644 index 00000000..43ac5ae3 --- /dev/null +++ b/ds-wms-service/DS.Module.Core/Enums/TaskPlat/TaskCompleteDealEnum.cs @@ -0,0 +1,16 @@ +using System.ComponentModel; + +namespace DS.Module.Core +{ + /// + /// 任务完成类型枚举 + /// + public enum TaskCompleteDealEnum + { + /// + /// 手工完成 + /// + [Description("手工完成")] + MANUAL, + } +} diff --git a/ds-wms-service/DS.Module.Core/Enums/TaskPlat/TaskOperTypeEnum.cs b/ds-wms-service/DS.Module.Core/Enums/TaskPlat/TaskOperTypeEnum.cs new file mode 100644 index 00000000..6c8632b2 --- /dev/null +++ b/ds-wms-service/DS.Module.Core/Enums/TaskPlat/TaskOperTypeEnum.cs @@ -0,0 +1,26 @@ +using System.ComponentModel; + +namespace DS.Module.Core +{ + /// + /// 任务操作类型枚举 + /// + public enum TaskOperTypeEnum + { + /// + /// 完成任务 + /// + [Description("完成任务")] + COMPLETE_TASK, + /// + /// 取消任务 + /// + [Description("取消任务")] + CANCEL_TASK, + /// + /// 挂起任务 + /// + [Description("挂起任务")] + PENDING_TASK, + } +} diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Entity/TaskBaseInfo.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Entity/TaskBaseInfo.cs index df95e1eb..d8d044ff 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Entity/TaskBaseInfo.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Entity/TaskBaseInfo.cs @@ -98,20 +98,20 @@ namespace DS.WMS.Core.TaskPlat.Entity /// /// 是否异常 1-异常 0-未异常 /// - [SugarColumn(ColumnDescription = "是否异常 1-异常 0-未异常", IsNullable = true)] - public int? IS_EXCEPT { get; set; } + [SugarColumn(ColumnDescription = "是否异常 1-异常 0-未异常", IsNullable = false)] + public int IS_EXCEPT { get; set; } /// /// 是否公共 0-非公共 1-公共(当无法确认任务所属人的情况被默认为公共) /// - [SugarColumn(ColumnDescription = "是否公共 0-非公共 1-公共(当无法确认任务所属人的情况被默认为公共)", IsNullable = true)] - public int? IS_PUBLIC { get; set; } + [SugarColumn(ColumnDescription = "是否公共 0-非公共 1-公共(当无法确认任务所属人的情况被默认为公共)", IsNullable = false)] + public int IS_PUBLIC { get; set; } /// /// 是否完成 1-已完成 0-未完成 /// - [SugarColumn(ColumnDescription = "是否完成 1-已完成 0-未完成", IsNullable = true)] - public int? IS_COMPLETE { get; set; } + [SugarColumn(ColumnDescription = "是否完成 1-已完成 0-未完成", IsNullable = false)] + public int IS_COMPLETE { get; set; } /// /// 任务启动时间 diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/ITaskManageService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/ITaskManageService.cs index 2b72c5d7..b59b102b 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/ITaskManageService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/ITaskManageService.cs @@ -1,4 +1,5 @@ using DS.Module.Core; +using DS.Module.DjyServiceStatus; using DS.WMS.Core.TaskPlat.Dtos; using Microsoft.AspNetCore.Http; @@ -6,6 +7,13 @@ namespace DS.WMS.Core.TaskPlat.Interface { public interface ITaskManageService { + /// + /// 取消任务(可批量) + /// + /// 任务主键数组 + /// 返回结果 + Task> CancelTask(long[] ids); + /// /// 获取登陆人相关的任务统计信息 /// diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs index 51cbef5b..203086f3 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs @@ -14,6 +14,7 @@ using Newtonsoft.Json; using SqlSugar; using System.Runtime.InteropServices; using DS.Module.Core.Extensions; +using DS.Module.DjyServiceStatus; namespace DS.WMS.Core.TaskPlat.Method { @@ -680,11 +681,18 @@ namespace DS.WMS.Core.TaskPlat.Method whereList = tenantDb.Utilities.JsonToConditionalModels(querySearch.QueryCondition); } + // 格式化参数 TaskBaseTypeEnum? taskType = null; if (Enum.TryParse(typeof(TaskBaseTypeEnum), querySearch.OtherQueryCondition?.TaskType, out object? temp)) { taskType = (TaskBaseTypeEnum)temp; }; + TaskStatLevelEnum? taskStatLevel = null; + if (Enum.TryParse(typeof(TaskStatLevelEnum), querySearch.OtherQueryCondition?.TaskCategory, out object? tempStat)) + { + taskStatLevel = (TaskStatLevelEnum)tempStat; + }; + var userId = long.Parse(user.UserId); DataResult> result; @@ -696,6 +704,9 @@ namespace DS.WMS.Core.TaskPlat.Method .LeftJoin((t, a, bc) => t.Id == bc.TASK_ID) .Where(whereList) .Where((t, a) => a.UserId == userId || t.CreateBy == userId) + .WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1) + .WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1) + .WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0) .Select((t, a, bc) => new { Id = t.Id.SelectAll(), @@ -783,6 +794,9 @@ namespace DS.WMS.Core.TaskPlat.Method .LeftJoin((t, a, bc) => t.Id == bc.TASK_ID) .Where(whereList) .Where((t, a) => a.UserId == userId || t.CreateBy == userId) + .WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1) + .WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1) + .WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0) .Select((t, a, bc) => new { PK_ID = t.Id.SelectAll(), @@ -836,6 +850,9 @@ namespace DS.WMS.Core.TaskPlat.Method .LeftJoin((t, a, bc) => t.Id == bc.TASK_PKID) .Where(whereList) .Where((t, a) => a.UserId == userId || t.CreateBy == userId) + .WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1) + .WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1) + .WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0) .Select((t, a, bc) => new { PK_ID = t.Id.SelectAll(), @@ -859,6 +876,9 @@ namespace DS.WMS.Core.TaskPlat.Method .LeftJoin((t, a, bc) => t.Id == bc.TASK_ID) .Where(whereList) .Where((t, a) => a.UserId == userId || t.CreateBy == userId) + .WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1) + .WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1) + .WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0) .Select((t, a, bc) => new { PK_ID = t.Id.SelectAll(), @@ -923,6 +943,9 @@ namespace DS.WMS.Core.TaskPlat.Method .LeftJoin((t, a, bc) => t.Id == bc.TASK_ID) .Where(whereList) .Where((t, a) => a.UserId == userId || t.CreateBy == userId) + .WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1) + .WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1) + .WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0) .Select((t, a, bc) => new { PK_ID = t.Id.SelectAll(), @@ -942,6 +965,9 @@ namespace DS.WMS.Core.TaskPlat.Method .LeftJoin((t, a, bc) => t.Id == bc.TASK_ID) .Where(whereList) .Where((t, a) => a.UserId == userId || t.CreateBy == userId) + .WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1) + .WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1) + .WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0) .Select((t, a, bc) => new { PK_ID = t.Id.SelectAll(), @@ -967,6 +993,9 @@ namespace DS.WMS.Core.TaskPlat.Method .LeftJoin((t, a, bc) => t.Id == bc.TASK_ID) .Where(whereList) .Where((t, a) => a.UserId == userId || t.CreateBy == userId) + .WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1) + .WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1) + .WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0) .Select((t, a, bc) => new { PK_ID = t.Id.SelectAll(), @@ -989,6 +1018,9 @@ namespace DS.WMS.Core.TaskPlat.Method .LeftJoin((t, a, bc) => t.Id == bc.TASK_ID) .Where(whereList) .Where((t, a) => a.UserId == userId || t.CreateBy == userId) + .WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1) + .WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1) + .WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0) .Select((t, a, bc) => new { PK_ID = t.Id.SelectAll(), @@ -1007,6 +1039,9 @@ namespace DS.WMS.Core.TaskPlat.Method .LeftJoin((t, a, bc) => t.Id == bc.TASK_ID) .Where(whereList) .Where((t, a) => a.UserId == userId || t.CreateBy == userId) + .WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1) + .WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1) + .WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0) .Select((t, a, bc) => new { PK_ID = t.Id.SelectAll(), @@ -1034,9 +1069,12 @@ namespace DS.WMS.Core.TaskPlat.Method case TaskBaseTypeEnum.ROUTE_CUT_CHANGE: { result = await tenantDb.Queryable().LeftJoin((t, a) => t.Id == a.TaskId) - .LeftJoin((t, a, bc) => t.Id == bc.TASK_ID) - .Where(whereList) + .LeftJoin((t, a, bc) => t.Id == bc.TASK_ID) + .Where(whereList) .Where((t, a) => a.UserId == userId || t.CreateBy == userId) + .WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1) + .WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1) + .WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0) .Select((t, a, bc) => new { PK_ID = t.Id.SelectAll(), @@ -1067,6 +1105,9 @@ namespace DS.WMS.Core.TaskPlat.Method result = await tenantDb.Queryable().LeftJoin((t, a) => t.Id == a.TaskId) .Where(whereList) .Where((t, a) => a.UserId == userId || t.CreateBy == userId) + .WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1) + .WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1) + .WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0) .Select(t => t) .ToQueryPageAsync(querySearch.PageCondition); return result; @@ -1315,9 +1356,6 @@ namespace DS.WMS.Core.TaskPlat.Method return DataResult.Success(resultInfo); } - - - #region 私有方法 /// @@ -1433,6 +1471,192 @@ namespace DS.WMS.Core.TaskPlat.Method return fileType; } + + #endregion + + /// + /// 取消任务(可批量) + /// + /// 任务主键数组 + /// 返回结果 + public async Task> CancelTask(long[] ids) + { + TaskManageOrderResultDto result = new TaskManageOrderResultDto(); + + var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId); + var userId = long.Parse(user.UserId); + string batchNo = Guid.NewGuid().ToString(); + + var taskList = await tenantDb.Queryable() + .Where(x => ids.Contains(x.Id)).ToListAsync(); + + + List taskRunList = new List(); + _logger.LogInformation("批次={no} ids={ids} 取消任务开始", batchNo, string.Join(",", ids)); + + var noList = ids.Select((a, idx) => new { no = idx + 1, id = a }).ToList(); + + foreach (var bk in taskList) + { + var sortNo = noList.FirstOrDefault(a => a.id == bk.Id).no; + taskRunList.Add(await InnerManualTask(batchNo, bk, TaskOperTypeEnum.CANCEL_TASK, sortNo)); + } + + result.succ = true; + result.msg = "执行成功"; + + var downResultList = taskRunList.Select(x => x).ToList(); + + if (downResultList.Any(x => !x.succ)) + { + result.succ = false; + result.msg = "执行失败"; + } + else + { + result.succ = true; + result.msg = downResultList.FirstOrDefault().msg; + } + + result.ext = downResultList; + + var succ = downResultList.Count(x => x.succ); + var fail = downResultList.Count(x => !x.succ); + + if (succ > 0) + { + result.batchTotal = succ.ToString(); + } + else + { + result.batchTotal = "- "; + } + + if (fail > 0) + { + result.batchTotal += "/" + fail.ToString(); + } + else + { + result.batchTotal += " -"; + } + return DataResult.Success(result); + } + + #region 单票执行任务 + /// + /// 单票执行任务 + /// + /// 批次号 + /// 任务详情 + /// 操作类型 + /// 顺序号 + /// 返回回执 + private async Task InnerManualTask(string batchNo, TaskBaseInfo model, + TaskOperTypeEnum taskOperTypeEnum, int sortNo) + { + TaskManageOrderResultDto result = new TaskManageOrderResultDto(); + + result.bno = model.TASK_NO; + + try + { + var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId); + var userId = long.Parse(user.UserId); + + if (taskOperTypeEnum == TaskOperTypeEnum.COMPLETE_TASK) + { + if (model.TASK_TYPE == TaskBaseTypeEnum.TRUCK_DISPATCH.ToString()) + { + if (model.STATUS == TaskStatusEnum.Cancel.ToString()) + { + throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskCannotCompleteWhenStatusMismatch)), TaskStatusEnum.Cancel.EnumDescription())); + } + } + + if (model.TASK_TYPE == TaskBaseTypeEnum.CANCELLATION.ToString()) + { + //收到订舱已被取消邮件后生成的任务,如果点击完成,(订舱状态变为【退舱】,注意这里还需要确认) + } + + model.COMPLETE_DATE = DateTime.Now; + model.COMPLETE_DEAL = TaskCompleteDealEnum.MANUAL.ToString(); + model.COMPLETE_DEAL = TaskCompleteDealEnum.MANUAL.EnumDescription(); + model.IS_COMPLETE = 1; + model.STATUS = TaskStatusEnum.Complete.ToString(); + model.STATUS_NAME = TaskStatusEnum.Complete.EnumDescription(); + + await tenantDb.Updateable(model).UpdateColumns(it => new + { + it.COMPLETE_DATE, + it.COMPLETE_DEAL, + it.COMPLETE_DEAL_NAME, + it.IS_COMPLETE, + it.STATUS, + it.STATUS_NAME, + it.UpdateBy, + it.UpdateTime, + it.UpdateUserName + }).ExecuteCommandAsync(); + } + else if (taskOperTypeEnum == TaskOperTypeEnum.CANCEL_TASK) + { + if (model.TASK_TYPE == TaskBaseTypeEnum.CHANGE_SHIP.ToString()) + { + model.STATUS = TaskStatusEnum.Cancel.ToString(); + model.STATUS_NAME = TaskStatusEnum.Cancel.EnumDescription(); + + await tenantDb.Updateable(model).UpdateColumns(it => new + { + it.COMPLETE_DATE, + it.COMPLETE_DEAL, + it.COMPLETE_DEAL_NAME, + it.IS_COMPLETE, + it.STATUS, + it.STATUS_NAME, + it.UpdateBy, + it.UpdateTime, + it.UpdateUserName + }).ExecuteCommandAsync(); + } + else if (model.TASK_TYPE == TaskBaseTypeEnum.ABORT_CHANGE_SHIP.ToString()) + { + /* + 1.如果原换船通知已经接受,需要把原船名航次恢复并通知客户取消换船。 + 2.如果原换船通知未作处理,点击接受或者结束任务时提示:本票货存在未处理换船通知,请先结束原换船任务然后结束本任务。 + 3.如果原换船任务为结束任务,在取消换船任务点接受时,提示未做换船,请点击结束任务。 + */ + + // 查询同票主单的是否有未处理的换船通知 + // _taskBaseInfoRepository.AsQueryable().Where(t=>t.MBL_NO.Equals(taskBaseInfo.MBL_NO) && ) + } + else + { + model.STATUS = TaskStatusEnum.Cancel.ToString(); + model.STATUS_NAME = TaskStatusEnum.Cancel.EnumDescription(); + + await tenantDb.Updateable(model).UpdateColumns(it => new + { + it.STATUS, + it.STATUS_NAME, + it.UpdateBy, + it.UpdateTime, + it.UpdateUserName + }).ExecuteCommandAsync(); + } + } + + result.succ = true; + result.msg = "执行成功"; + } + catch (Exception ex) + { + result.succ = false; + result.msg = ex.Message; + } + + return result; + } #endregion } } diff --git a/ds-wms-service/DS.WMS.TaskApi/Controllers/TaskManageController.cs b/ds-wms-service/DS.WMS.TaskApi/Controllers/TaskManageController.cs index 0c6a6e2f..27d473a2 100644 --- a/ds-wms-service/DS.WMS.TaskApi/Controllers/TaskManageController.cs +++ b/ds-wms-service/DS.WMS.TaskApi/Controllers/TaskManageController.cs @@ -1,5 +1,6 @@ using DS.Module.Core; using DS.Module.Core.Attributes; +using DS.Module.DjyServiceStatus; using DS.WMS.Core.TaskPlat.Dtos; using DS.WMS.Core.TaskPlat.Interface; using Microsoft.AspNetCore.Authorization; @@ -95,14 +96,12 @@ public class TaskManageController : ApiController /// 任务主键数组 /// 返回结果 [HttpPost("CancelTask")] - public async Task> CancelTask([FromBody] string[] Ids) + public async Task> CancelTask([FromBody] long[] Ids) { - return default; - //var result = await taskManageService.GetCurrentTotalStat(isReCalc); - //return result; + var result = await taskManageService.CancelTask(Ids); + return result; } - /// /// 获取任务台相关的枚举类型的值 /// @@ -136,6 +135,8 @@ public class TaskManageController : ApiController return DataResult.Success(result); } + + // /TaskManage/CreateBCTaskJob // /TaskManage/CreateDRAFTTaskJob // /TaskManage/CreateAdvisoryTaskJob