diff --git a/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs b/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs index 478560dc..ba17ca72 100644 --- a/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs +++ b/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs @@ -206,7 +206,10 @@ public static class MultiLanguageConst /// [Description("权限模块不存在")] public const string PermissionNotExist = "Permission_NotExist"; - + + [Description("此模块未授权")] + public const string ModuleUnauthorized = "Module_Unauthorized"; + [Description("数据权限已存在")] public const string DataRuleExist = "Data_Rule_Exist"; diff --git a/ds-wms-service/DS.Module.Core/Data/DataResult.cs b/ds-wms-service/DS.Module.Core/Data/DataResult.cs index f1a57846..260b4c30 100644 --- a/ds-wms-service/DS.Module.Core/Data/DataResult.cs +++ b/ds-wms-service/DS.Module.Core/Data/DataResult.cs @@ -88,6 +88,17 @@ public class DataResult : DataResult return new DataResult(ResultCode.Success, message, multiCode); } + public static DataResult SuccessedWithDesc(string fieldName) + { + var fieldInfo = typeof(MultiLanguageConst).GetField(fieldName) ?? throw new ArgumentException($"不存在的常量:{fieldName}", fieldName); + + var attribute = fieldInfo.GetCustomAttribute(); + var desc = attribute?.Description ?? string.Empty; + var value = fieldInfo.GetValue(null) as string ?? string.Empty; + + return Successed(desc, value); + } + /// /// 其他操作 /// @@ -125,7 +136,7 @@ public class DataResult : DataResult /// public static DataResult FailedWithPlaceholder(ISqlSugarClient db, IHttpContextAccessor accessor, string multiCode, string placeholde1 = "", string placeholde2 = "", string placeholde3 = "", string placeholde4 = "", string placeholde5 = "") { - + var desc = string.Empty; var language = accessor.HttpContext.Request.Headers["LanguageType"].FirstOrDefault(); if (language.IsNullOrEmpty()) @@ -144,16 +155,16 @@ public class DataResult : DataResult { if (language == "CN") { - var fieldInfo = typeof(MultiLanguageConst).GetField(nameof(multiCode)); + var fieldInfo = typeof(MultiLanguageConst).GetField(nameof(multiCode)); var attribute = fieldInfo.GetCustomAttribute(); - desc = attribute?.Description ?? string.Empty; + desc = attribute?.Description ?? string.Empty; } else { throw new Exception($"未设置多语言:" + language + "下的消息提示代码:" + multiCode); } } - + return new DataResult(ResultCode.Error, string.Format(desc, placeholde1, placeholde2, placeholde3, placeholde4, placeholde5), multiCode); } @@ -170,7 +181,7 @@ public class DataResult : DataResult var desc = attribute?.Description ?? string.Empty; var value = fieldInfo.GetValue(null) as string ?? string.Empty; - return Failed(desc, fieldName); + return Failed(desc, value); } } @@ -269,7 +280,7 @@ public class DataResult : IDataResult /// /// 附加数据 /// - public Dictionary? AdditionalData { get; set; } + public Dictionary? AdditionalData { get; set; } /// /// 返回成功的结果 diff --git a/ds-wms-service/DS.WMS.Core/Flow/Method/ClientFlowInstanceService.cs b/ds-wms-service/DS.WMS.Core/Flow/Method/ClientFlowInstanceService.cs index 860b4aa2..8828daf9 100644 --- a/ds-wms-service/DS.WMS.Core/Flow/Method/ClientFlowInstanceService.cs +++ b/ds-wms-service/DS.WMS.Core/Flow/Method/ClientFlowInstanceService.cs @@ -23,7 +23,7 @@ public class ClientFlowInstanceService : FlowInstanceService, IClientFlowInstanc saasService = serviceProvider.GetRequiredService(); } - protected override FlowInstance BuildInstance(CreateFlowInstanceReq req) + protected override FlowInstance? BuildInstance(CreateFlowInstanceReq req) { if (string.IsNullOrEmpty(req.TemplateId.ToString())) return null; diff --git a/ds-wms-service/DS.WMS.Core/Flow/Method/FlowInstanceService.cs b/ds-wms-service/DS.WMS.Core/Flow/Method/FlowInstanceService.cs index 42448271..d2adc268 100644 --- a/ds-wms-service/DS.WMS.Core/Flow/Method/FlowInstanceService.cs +++ b/ds-wms-service/DS.WMS.Core/Flow/Method/FlowInstanceService.cs @@ -1,4 +1,3 @@ -using System.Text; using DS.Module.Core; using DS.Module.Core.Extensions; using DS.Module.UserModule; @@ -78,7 +77,7 @@ public class FlowInstanceService : IFlowInstanceService } } - protected virtual FlowInstance BuildInstance(CreateFlowInstanceReq req) + protected virtual FlowInstance? BuildInstance(CreateFlowInstanceReq req) { if (string.IsNullOrEmpty(req.TemplateId.ToString())) return null; diff --git a/ds-wms-service/DS.WMS.Core/Op/Dtos/TaskInteraction/TaskUpdateRequest.cs b/ds-wms-service/DS.WMS.Core/Op/Dtos/TaskInteraction/TaskUpdateRequest.cs index 1504f2a8..d3d1b634 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Dtos/TaskInteraction/TaskUpdateRequest.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Dtos/TaskInteraction/TaskUpdateRequest.cs @@ -27,5 +27,10 @@ namespace DS.WMS.Core.Op.Dtos.TaskInteraction /// 任务状态 /// public TaskStatusEnum TaskStatus { get; set; } + + /// + /// 当任务完成时,是否根据任务类型自动创建下一任务;默认为true + /// + public bool AutoCreateNext { get; set; } = true; } } diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/SeaExportTaskService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/SeaExportTaskService.cs index eb05b84a..2d516dbc 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/SeaExportTaskService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/SeaExportTaskService.cs @@ -147,7 +147,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction protected override async Task OnTaskStatusChanged(TaskUpdateRequest request) { //放舱结束,根据业务所选服务,生成子任务 - if (request.TaskType == TaskBaseTypeEnum.WAIT_SPACE_RELEASE) + if (request.TaskType == TaskBaseTypeEnum.WAIT_SPACE_RELEASE && request.TaskStatus == TaskStatusEnum.Complete) { var list = await GetSubRequestAsync(request.BusinessId, request.BusinessType); await CreateSubTaskAsync(list); diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskService.cs index 8c635486..7247ba7f 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskService.cs @@ -1,5 +1,6 @@ using DS.Module.Core; using DS.Module.Core.Extensions; +using DS.Module.Core.Helpers; using DS.WMS.Core.Fee.Method; using DS.WMS.Core.Flow.Dtos; using DS.WMS.Core.Op.Dtos.TaskInteraction; @@ -20,6 +21,8 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction /// public abstract class TaskService : FeeServiceBase, ITaskService { + const long PERMISSION_ID = 1815294400855674880; + /// /// 任务管理服务 /// @@ -34,6 +37,26 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction ManagerService = provider.GetRequiredService(); } + /// + /// 确保任务交互模块已授权 + /// + /// + protected virtual async Task EnsureModuleAuthorized() + { + //if (!await Db.Queryable().AnyAsync(x => x.PermissionId == PERMISSION_ID)) + // return false; + + long tid = long.Parse(User.TenantId); + var authStr = await Db.Queryable().Where(x => x.PermissionId == PERMISSION_ID && x.TenantId == tid && + SqlFunc.Subqueryable().Where(spt => spt.PermissionId == x.PermissionId).Any()) + .Select(x => x.AuthNum).FirstAsync(); + if (authStr.IsNullOrEmpty()) + return false; + + var appSecret = await Db.Queryable().Where(x => x.Id == tid).Select(x => x.AppSecret).FirstAsync(); + return int.TryParse(EncrypteHelper.DecryptData(authStr, appSecret), out int authNum) && authNum > 0; + } + /// /// 创建关联任务 /// @@ -42,6 +65,9 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction /// public async Task CreateTaskAsync(TaskCreationRequest request, bool useTransaction = true) { + if (!await EnsureModuleAuthorized()) + return DataResult.SuccessedWithDesc(nameof(MultiLanguageConst.ModuleUnauthorized)); + var task = await GetTaskAsync(request.BusinessId, request.BusinessType, request.TaskType); if (task != null) return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Task_Exists)); @@ -137,7 +163,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction /// /// /// - protected virtual Task OnTaskCreated(BusinessTask task) + protected virtual Task OnTaskCreated(BusinessTask task) { return Task.FromResult(DataResult.Success); } @@ -149,6 +175,9 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction /// public async Task SetTaskStatusAsync(TaskUpdateRequest request) { + if (!await EnsureModuleAuthorized()) + return DataResult.SuccessedWithDesc(nameof(MultiLanguageConst.ModuleUnauthorized)); + await TenantDb.Ado.BeginTranAsync(); try { @@ -161,7 +190,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction if (task == null) return DataResult.FailedWithDesc(nameof(MultiLanguageConst.EmptyData)); - if (task.TaskStatus!= request.TaskStatus) + if (task.TaskStatus != request.TaskStatus) await OnTaskStatusChanged(request); task.TaskStatus = request.TaskStatus; @@ -170,7 +199,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction if (task.TaskStatus == TaskStatusEnum.Complete) { //若存在下一任务,则继续创建 - if (task.NextType.HasValue) + if (task.NextType.HasValue && request.AutoCreateNext) { var req = new TaskCreationRequest { @@ -198,7 +227,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction /// /// /// - protected virtual Task OnTaskStatusChanged(TaskUpdateRequest request) + protected virtual Task OnTaskStatusChanged(TaskUpdateRequest request) { return Task.CompletedTask; } @@ -214,7 +243,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction ArgumentNullException.ThrowIfNull(callback, nameof(callback)); //更新任务状态为完成 - await SetTaskStatusAsync(new TaskUpdateRequest + await SetTaskStatusAsync(new TaskUpdateRequest { BusinessId = callback.BusinessId, BusinessType = callback.BusinessType.GetValueOrDefault(), @@ -223,6 +252,13 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction }); } + /// + /// 获取指定类型的业务关联任务 + /// + /// 业务ID + /// 业务类型 + /// 任务类型 + /// protected internal async Task GetTaskAsync(long id, BusinessType businessType, TaskBaseTypeEnum taskType) { return await TenantDb.Queryable().FirstAsync(x =>