From 14e329def198c26e097d978696efeb0a7e04ca01 Mon Sep 17 00:00:00 2001 From: zhangxiaofeng <1939543722@qq.com> Date: Thu, 18 Jul 2024 15:52:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=8F=B0=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TaskPlat/Entity/TaskFlowLog.cs | 54 ++++++++++++------- .../TaskPlat/Entity/TaskFlowLogDetail.cs | 36 ++++++++++--- .../TaskPlat/Method/MyModuleTest1.cs | 10 ++-- .../TaskPlat/Method/MyModuleTest2.cs | 4 +- .../TaskPlat/Method/MyModuleTest3.cs | 2 +- .../TaskPlat/Method/TaskManageService.cs | 14 ++--- .../TaskPlat/Other/TaskFlowRuner.cs | 49 ++++++++++++----- ds-wms-service/DS.WMS.Test/SaasTest.cs | 11 ++-- 8 files changed, 122 insertions(+), 58 deletions(-) diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Entity/TaskFlowLog.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Entity/TaskFlowLog.cs index 44fd2a9c..83555867 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Entity/TaskFlowLog.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Entity/TaskFlowLog.cs @@ -13,31 +13,31 @@ namespace DS.WMS.Core.TaskPlat.Entity /// /// 任务主键 /// - [SugarColumn(ColumnDescription = "任务主键", IsNullable = false ) ] - public long? TaskId { get; set; } - + [SugarColumn(ColumnDescription = "任务主键", IsNullable = false)] + public long? TaskId { get; set; } + /// /// 所属任务类型 /// - [SugarColumn(ColumnDescription = "所属任务类型", IsNullable = false, Length = 255 ) ] - public string? TaskType { get; set; } - + [SugarColumn(ColumnDescription = "所属任务类型", IsNullable = false, Length = 255)] + public string? TaskType { get; set; } + /// /// 是否匹配到主入口流程 /// - [SugarColumn(ColumnDescription = "是否匹配到主入口流程", IsNullable = false , Length = 1 ) ] - public bool IsMatch { get; set; } - + [SugarColumn(ColumnDescription = "是否匹配到主入口流程", IsNullable = false, Length = 1)] + public bool IsMatch { get; set; } + /// /// 匹配到的主入口流程的主键 /// - [SugarColumn(ColumnDescription = "匹配到的主入口流程的主键", IsNullable = true ) ] - public long? MatchMainConfigId { get; set; } - + [SugarColumn(ColumnDescription = "匹配到的主入口流程的主键", IsNullable = true)] + public long? MatchMainConfigId { get; set; } + /// /// 待执行流程清单 /// - [SugarColumn(ColumnDescription = "待执行流程清单", IsNullable = true , Length = 4000 ) ] + [SugarColumn(ColumnDescription = "待执行流程清单", IsNullable = true, Length = 4000)] public string? ConfigList { get; set; } /// @@ -47,16 +47,34 @@ namespace DS.WMS.Core.TaskPlat.Entity public string? ModuleList { get; set; } /// - /// 执行状态 1=正常结束 2=执行过程中发生异常 + /// 原始数据内容 + /// + [SugarColumn(ColumnDescription = "原始数据内容", IsNullable = true)] + public string? OriginDataContext { get; set; } + + ///// + ///// 执行状态 1=正常结束 2=执行过程中发生异常 + ///// + //[SugarColumn(ColumnDescription = "执行状态 1=正常结束 2=执行过程中发生异常", IsNullable = false)] + //public int ExecuteStatus { get; set; } + + /// + /// 模块是否全部执行完成 + /// + [SugarColumn(ColumnDescription = "模块是否全部执行完成", IsNullable = false)] + public bool IsComplete { get; set; } + + /// + /// 模块是否全部执行成功 /// - [SugarColumn(ColumnDescription = "执行状态 1=正常结束 2=执行过程中发生异常", IsNullable = false, Length = 1)] - public int ExecuteStatus { get; set; } + [SugarColumn(ColumnDescription = "模块是否全部执行成功", IsNullable = false)] + public bool IsSuccess { get; set; } /// /// 异常内容 /// - [SugarColumn(ColumnDescription = "异常内容", IsNullable = true, Length = 4000)] + [SugarColumn(ColumnDescription = "异常内容", IsNullable = true, ColumnDataType = "text")] public string? ExceptionMessage { get; set; } } - + } \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Entity/TaskFlowLogDetail.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Entity/TaskFlowLogDetail.cs index 4dc82100..c175b01a 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Entity/TaskFlowLogDetail.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Entity/TaskFlowLogDetail.cs @@ -30,23 +30,47 @@ namespace DS.WMS.Core.TaskPlat.Entity public long ModuleId { get; set; } /// - /// 执行状态 1=正常结束 2=执行过程中发生异常 + /// 原始数据内容 /// - [SugarColumn(ColumnDescription = "执行状态 1=正常结束 2=执行过程中发生异常", Length = 1)] - public int ExecuteStatus { get; set; } + [SugarColumn(ColumnDescription = "原始数据内容", IsNullable = true)] + public string? OriginDataContext { get; set; } + ///// + ///// 执行状态 1=正常结束 2=执行过程中发生异常 + ///// + //[SugarColumn(ColumnDescription = "执行状态 1=正常结束 2=执行过程中发生异常", IsNullable = false)] + //public int ExecuteStatus { get; set; } + + + /// + /// 模块是否全部执行完成 + /// + [SugarColumn(ColumnDescription = "模块是否全部执行完成", IsNullable = false)] + public bool IsComplete { get; set; } + + /// + /// 模块是否全部执行成功 + /// + [SugarColumn(ColumnDescription = "模块是否全部执行成功", IsNullable = false)] + public bool IsSuccess { get; set; } /// /// 异常内容 /// - [SugarColumn(ColumnDescription = "异常内容", IsNullable = true, Length = 4000)] + [SugarColumn(ColumnDescription = "异常内容", IsNullable = true, ColumnDataType = "text")] public string? ExceptionMessage { get; set; } + /// + /// 执行返回结果 + /// + [SugarColumn(ColumnDescription = "执行返回结果", IsNullable = true, Length = 2000)] + public string? ExecuteReturn { get; set; } + /// /// 执行耗时 /// - [SugarColumn(ColumnDescription = "执行耗时")] - public long ElapsedMillisecond { get; set; } + [SugarColumn(ColumnDescription = "执行耗时", IsNullable = false)] + public long ElapsedMillisecond { get; set; } } } \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/MyModuleTest1.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/MyModuleTest1.cs index 57d9136a..e0b29ce8 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/MyModuleTest1.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/MyModuleTest1.cs @@ -1,5 +1,6 @@ using DS.Module.Core; using DS.Module.Core.Data; +using DS.WMS.Core.TaskPlat.Dtos; using DS.WMS.Core.TaskPlat.Interface; using System; using System.Collections.Generic; @@ -13,13 +14,16 @@ namespace DS.WMS.Core.TaskPlat.Method { public Task TestMethod11(TaskFlowDataContext dataContext) { - throw new Exception("TestMethod11内的测试异常"); - //return Task.FromResult(DataResult.Successed("ok")); + var address = dataContext.Get("Address"); + var height = dataContext.Get("Height"); + var info = dataContext.Get(nameof(TaskManageOrderMessageInfo)); + var bcInfoVessel = info?.Main?.BCInfo.Vessel; + + return Task.FromResult(DataResult.Successed($"TestMethod11返回的成功结果,address:{address},height:{height},bcInfoVessel:{bcInfoVessel}")); } public DataResult TestMethod12(TaskFlowDataContext dataContext) { throw new Exception("TestMethod12内的测试异常"); - //return DataResult.Successed("ok"); } } } diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/MyModuleTest2.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/MyModuleTest2.cs index abadc08b..7ecc8280 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/MyModuleTest2.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/MyModuleTest2.cs @@ -9,11 +9,11 @@ using System.Threading.Tasks; namespace DS.WMS.Core.TaskPlat.Method { - public class MyModuleService : IMyModuleTest2 + public class MyModuleTest2 : IMyModuleTest2 { public Task TestMethod21(TaskFlowDataContext dataContext) { - return Task.FromResult(DataResult.Successed("ok")); + throw new Exception("TestMethod21内的测试异常"); } } } diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/MyModuleTest3.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/MyModuleTest3.cs index b8dbcaad..bc37318e 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/MyModuleTest3.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/MyModuleTest3.cs @@ -8,7 +8,7 @@ namespace DS.WMS.Core.TaskPlat.Method { public Task TestMethod31(TaskFlowDataContext dataContext) { - return Task.FromResult(DataResult.Successed("ok")); + throw new Exception("TestMethod31内的测试异常"); } } } 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 81b30c40..e6fa3ef1 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs @@ -478,17 +478,13 @@ namespace DS.WMS.Core.TaskPlat.Method 2、推送钉钉消息@操作人 通知收到变更 */ + TaskFlowDataContext dataContext = new(nameof(TaskManageOrderMessageInfo), info); + TaskFlowRuner taskFlow = new TaskFlowRuner(tenantDb, serviceProvider); + await taskFlow.Run(info.Main.TaskType, info, taskInfo, dataContext); + if (info.Main.TaskType == TaskBaseTypeEnum.BC) { - //Dictionary dataContext = new() - //{ - // { nameof(TaskManageOrderMessageInfo), info }, - //}; - TaskFlowDataContext dataContext = new(nameof(TaskManageOrderMessageInfo), info); - - TaskFlowRuner taskFlow = new TaskFlowRuner(tenantDb, serviceProvider); - await taskFlow.Run(info.Main.TaskType,info, taskInfo, dataContext); } else if (info.Main.TaskType == TaskBaseTypeEnum.CANCELLATION) { @@ -503,7 +499,7 @@ namespace DS.WMS.Core.TaskPlat.Method var taskNo = await tenantDb.Queryable().Where(a => a.Id == taskInfo.Id).Select(a => a.TASK_NO).FirstAsync(); //回写任务号 - var result = new DataResult(ResultCode.Success, "新增任务成功", taskNo); + var result = new DataResult(ResultCode.Success, "新增任务成功", data: taskNo); return await Task.FromResult(result); } diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Other/TaskFlowRuner.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Other/TaskFlowRuner.cs index 89581ede..cf72b666 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Other/TaskFlowRuner.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Other/TaskFlowRuner.cs @@ -29,7 +29,15 @@ namespace DS.WMS.Core.TaskPlat this.tenantDb = tenantDb; this.serviceProvider = serviceProvider; } - public async Task Run(TaskBaseTypeEnum taskBaseType, TaskManageOrderMessageInfo messageInfo, TaskBaseInfo taskInfo, TaskFlowDataContext dataContext) + /// + /// 执行 + /// + /// 任务类型 + /// 任务原始接收信息 + /// 任务基础信息 + /// 原始入参数据 + /// (执行日志Id,模块是否全部执行完成,模块执行结果是否全部为success) + public async Task<(long flowLogId, bool isAllComplete, bool isAllSuccess)> Run(TaskBaseTypeEnum taskBaseType, TaskManageOrderMessageInfo messageInfo, TaskBaseInfo taskInfo, TaskFlowDataContext dataContext) { if (taskInfo == null) { @@ -52,8 +60,9 @@ namespace DS.WMS.Core.TaskPlat IsMatch = false, TaskId = taskInfo.Id, TaskType = taskBaseType.ToString(), - ExecuteStatus = 2, - ExceptionMessage = msg + IsComplete = false, + ExceptionMessage = msg, + IsSuccess = false, }; await tenantDb.Insertable(log).ExecuteCommandAsync(); throw new Exception(msg); @@ -150,7 +159,8 @@ namespace DS.WMS.Core.TaskPlat MatchMainConfigId = targetConfig.Id, ConfigList = JsonConvert.SerializeObject(configList), ModuleList = JsonConvert.SerializeObject(moduleList), - ExecuteStatus = 1 + IsComplete = true, + IsSuccess = true, }; foreach (var configItem in configList) @@ -212,31 +222,41 @@ namespace DS.WMS.Core.TaskPlat Stopwatch stopwatch = Stopwatch.StartNew(); - var invokeResult = method.Invoke(imp, new object[] { dataContext }); - // 这里需要取一下返回值 - //var b = invokeResult as DataResult; - //var c = invokeResult as Task; - //var d = c.Result; - if (invokeResult is DataResult result) + var resultTemp = method.Invoke(imp, new object[] { dataContext }); + if (resultTemp is DataResult result1 && result1 != null) { + flowLogDetail.ExecuteReturn = JsonConvert.SerializeObject(result1); + flowLogDetail.IsSuccess = result1.Succeeded; + if (!result1.Succeeded) + { + flowLog.IsSuccess = false; + } } - else if (invokeResult is Task result2) + else if (resultTemp is Task result2 && result2 != null && result2.IsCompleted) { + flowLogDetail.ExecuteReturn = JsonConvert.SerializeObject(result2.Result); + flowLogDetail.IsSuccess = result2.Result.Succeeded; + if (!result2.Result.Succeeded) + { + flowLog.IsSuccess = false; + } } stopwatch.Stop(); flowLogDetail.ElapsedMillisecond = stopwatch.ElapsedMilliseconds; - flowLogDetail.ExecuteStatus = 1; + flowLogDetail.IsComplete = true; await tenantDb.Insertable(flowLogDetail).ExecuteCommandAsync(); } catch (Exception ex) { - flowLog.ExecuteStatus = 2; + flowLog.IsComplete = false; + flowLog.IsSuccess = false; + flowLogDetail.IsComplete = false; + flowLogDetail.IsSuccess = false; flowLogDetail.ExceptionMessage = WriteLog("", ex); - flowLogDetail.ExecuteStatus = 2; await tenantDb.Insertable(flowLogDetail).ExecuteCommandAsync(); if (configItem.IsExceptionContinue) @@ -251,6 +271,7 @@ namespace DS.WMS.Core.TaskPlat } await tenantDb.Insertable(flowLog).ExecuteCommandAsync(); + return (flowLog.Id, flowLog.IsComplete, flowLog.IsSuccess); } diff --git a/ds-wms-service/DS.WMS.Test/SaasTest.cs b/ds-wms-service/DS.WMS.Test/SaasTest.cs index e78786a6..60d72acc 100644 --- a/ds-wms-service/DS.WMS.Test/SaasTest.cs +++ b/ds-wms-service/DS.WMS.Test/SaasTest.cs @@ -206,12 +206,13 @@ public class SaasTest { var tenantDb = saasService.GetBizDbScopeById("1750335377144680448"); StaticConfig.CodeFirst_MySqlCollate = "utf8mb4_0900_ai_ci";//较高版本支持 - var ass = Assembly.Load("DS.WMS.Core"); - var types = ass.GetTypes().Where(it => it.FullName?.Contains("DS.WMS.Core.TaskPlat.Entity") == true).ToArray(); - tenantDb.CodeFirst.InitTables(types); - //tenantDb.CodeFirst.InitTables(typeof(TaskFlowLog)); - //tenantDb.CodeFirst.InitTables(typeof(TaskFlowLogDetail)); + //var ass = Assembly.Load("DS.WMS.Core"); + //var types = ass.GetTypes().Where(it => it.FullName?.Contains("DS.WMS.Core.TaskPlat.Entity") == true).ToArray(); + //tenantDb.CodeFirst.InitTables(types); + + tenantDb.CodeFirst.InitTables(typeof(TaskFlowLog)); + tenantDb.CodeFirst.InitTables(typeof(TaskFlowLogDetail)); Assert.True(true); } } \ No newline at end of file