jianghaiqing 5 months ago
commit 0f2a8954ce

@ -13,31 +13,31 @@ namespace DS.WMS.Core.TaskPlat.Entity
/// <summary> /// <summary>
/// 任务主键 /// 任务主键
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "任务主键", IsNullable = false ) ] [SugarColumn(ColumnDescription = "任务主键", IsNullable = false)]
public long? TaskId { get; set; } public long? TaskId { get; set; }
/// <summary> /// <summary>
/// 所属任务类型 /// 所属任务类型
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "所属任务类型", IsNullable = false, Length = 255 ) ] [SugarColumn(ColumnDescription = "所属任务类型", IsNullable = false, Length = 255)]
public string? TaskType { get; set; } public string? TaskType { get; set; }
/// <summary> /// <summary>
/// 是否匹配到主入口流程 /// 是否匹配到主入口流程
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "是否匹配到主入口流程", IsNullable = false , Length = 1 ) ] [SugarColumn(ColumnDescription = "是否匹配到主入口流程", IsNullable = false, Length = 1)]
public bool IsMatch { get; set; } public bool IsMatch { get; set; }
/// <summary> /// <summary>
/// 匹配到的主入口流程的主键 /// 匹配到的主入口流程的主键
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "匹配到的主入口流程的主键", IsNullable = true ) ] [SugarColumn(ColumnDescription = "匹配到的主入口流程的主键", IsNullable = true)]
public long? MatchMainConfigId { get; set; } public long? MatchMainConfigId { get; set; }
/// <summary> /// <summary>
/// 待执行流程清单 /// 待执行流程清单
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "待执行流程清单", IsNullable = true , Length = 4000 ) ] [SugarColumn(ColumnDescription = "待执行流程清单", IsNullable = true, Length = 4000)]
public string? ConfigList { get; set; } public string? ConfigList { get; set; }
/// <summary> /// <summary>
@ -47,15 +47,33 @@ namespace DS.WMS.Core.TaskPlat.Entity
public string? ModuleList { get; set; } public string? ModuleList { get; set; }
/// <summary> /// <summary>
/// 执行状态 1=正常结束 2=执行过程中发生异常 /// 原始数据内容
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "执行状态 1=正常结束 2=执行过程中发生异常", IsNullable = false, Length = 1)] [SugarColumn(ColumnDescription = "原始数据内容", IsNullable = true)]
public int ExecuteStatus { get; set; } public string? OriginDataContext { get; set; }
///// <summary>
///// 执行状态 1=正常结束 2=执行过程中发生异常
///// </summary>
//[SugarColumn(ColumnDescription = "执行状态 1=正常结束 2=执行过程中发生异常", IsNullable = false)]
//public int ExecuteStatus { get; set; }
/// <summary>
/// 模块是否全部执行完成
/// </summary>
[SugarColumn(ColumnDescription = "模块是否全部执行完成", IsNullable = false)]
public bool IsComplete { get; set; }
/// <summary>
/// 模块是否全部执行成功
/// </summary>
[SugarColumn(ColumnDescription = "模块是否全部执行成功", IsNullable = false)]
public bool IsSuccess { get; set; }
/// <summary> /// <summary>
/// 异常内容 /// 异常内容
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "异常内容", IsNullable = true, Length = 4000)] [SugarColumn(ColumnDescription = "异常内容", IsNullable = true, ColumnDataType = "text")]
public string? ExceptionMessage { get; set; } public string? ExceptionMessage { get; set; }
} }

@ -30,23 +30,47 @@ namespace DS.WMS.Core.TaskPlat.Entity
public long ModuleId { get; set; } public long ModuleId { get; set; }
/// <summary> /// <summary>
/// 执行状态 1=正常结束 2=执行过程中发生异常 /// 原始数据内容
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "执行状态 1=正常结束 2=执行过程中发生异常", Length = 1)] [SugarColumn(ColumnDescription = "原始数据内容", IsNullable = true)]
public int ExecuteStatus { get; set; } public string? OriginDataContext { get; set; }
///// <summary>
///// 执行状态 1=正常结束 2=执行过程中发生异常
///// </summary>
//[SugarColumn(ColumnDescription = "执行状态 1=正常结束 2=执行过程中发生异常", IsNullable = false)]
//public int ExecuteStatus { get; set; }
/// <summary>
/// 模块是否全部执行完成
/// </summary>
[SugarColumn(ColumnDescription = "模块是否全部执行完成", IsNullable = false)]
public bool IsComplete { get; set; }
/// <summary>
/// 模块是否全部执行成功
/// </summary>
[SugarColumn(ColumnDescription = "模块是否全部执行成功", IsNullable = false)]
public bool IsSuccess { get; set; }
/// <summary> /// <summary>
/// 异常内容 /// 异常内容
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "异常内容", IsNullable = true, Length = 4000)] [SugarColumn(ColumnDescription = "异常内容", IsNullable = true, ColumnDataType = "text")]
public string? ExceptionMessage { get; set; } public string? ExceptionMessage { get; set; }
/// <summary>
/// 执行返回结果
/// </summary>
[SugarColumn(ColumnDescription = "执行返回结果", IsNullable = true, Length = 2000)]
public string? ExecuteReturn { get; set; }
/// <summary> /// <summary>
/// 执行耗时 /// 执行耗时
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "执行耗时")] [SugarColumn(ColumnDescription = "执行耗时", IsNullable = false)]
public long ElapsedMillisecond { get; set; } public long ElapsedMillisecond { get; set; }
} }
} }

@ -1,5 +1,6 @@
using DS.Module.Core; using DS.Module.Core;
using DS.Module.Core.Data; using DS.Module.Core.Data;
using DS.WMS.Core.TaskPlat.Dtos;
using DS.WMS.Core.TaskPlat.Interface; using DS.WMS.Core.TaskPlat.Interface;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -13,13 +14,16 @@ namespace DS.WMS.Core.TaskPlat.Method
{ {
public Task<DataResult> TestMethod11(TaskFlowDataContext dataContext) public Task<DataResult> TestMethod11(TaskFlowDataContext dataContext)
{ {
throw new Exception("TestMethod11内的测试异常"); var address = dataContext.Get<string>("Address");
//return Task.FromResult(DataResult.Successed("ok")); var height = dataContext.Get<string>("Height");
var info = dataContext.Get<TaskManageOrderMessageInfo>(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) public DataResult TestMethod12(TaskFlowDataContext dataContext)
{ {
throw new Exception("TestMethod12内的测试异常"); throw new Exception("TestMethod12内的测试异常");
//return DataResult.Successed("ok");
} }
} }
} }

@ -9,11 +9,11 @@ using System.Threading.Tasks;
namespace DS.WMS.Core.TaskPlat.Method namespace DS.WMS.Core.TaskPlat.Method
{ {
public class MyModuleService : IMyModuleTest2 public class MyModuleTest2 : IMyModuleTest2
{ {
public Task<DataResult> TestMethod21(TaskFlowDataContext dataContext) public Task<DataResult> TestMethod21(TaskFlowDataContext dataContext)
{ {
return Task.FromResult(DataResult.Successed("ok")); throw new Exception("TestMethod21内的测试异常");
} }
} }
} }

@ -8,7 +8,7 @@ namespace DS.WMS.Core.TaskPlat.Method
{ {
public Task<DataResult> TestMethod31(TaskFlowDataContext dataContext) public Task<DataResult> TestMethod31(TaskFlowDataContext dataContext)
{ {
return Task.FromResult(DataResult.Successed("ok")); throw new Exception("TestMethod31内的测试异常");
} }
} }
} }

@ -478,17 +478,13 @@ namespace DS.WMS.Core.TaskPlat.Method
2@ 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) if (info.Main.TaskType == TaskBaseTypeEnum.BC)
{ {
//Dictionary<string, object> 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) else if (info.Main.TaskType == TaskBaseTypeEnum.CANCELLATION)
{ {
@ -503,7 +499,7 @@ namespace DS.WMS.Core.TaskPlat.Method
var taskNo = await tenantDb.Queryable<TaskBaseInfo>().Where(a => a.Id == taskInfo.Id).Select(a => a.TASK_NO).FirstAsync(); var taskNo = await tenantDb.Queryable<TaskBaseInfo>().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); return await Task.FromResult(result);
} }

@ -29,7 +29,15 @@ namespace DS.WMS.Core.TaskPlat
this.tenantDb = tenantDb; this.tenantDb = tenantDb;
this.serviceProvider = serviceProvider; this.serviceProvider = serviceProvider;
} }
public async Task Run(TaskBaseTypeEnum taskBaseType, TaskManageOrderMessageInfo messageInfo, TaskBaseInfo taskInfo, TaskFlowDataContext dataContext) /// <summary>
/// 执行
/// </summary>
/// <param name="taskBaseType">任务类型</param>
/// <param name="messageInfo">任务原始接收信息</param>
/// <param name="taskInfo">任务基础信息</param>
/// <param name="dataContext">原始入参数据</param>
/// <returns>(执行日志Id,模块是否全部执行完成,模块执行结果是否全部为success)</returns>
public async Task<(long flowLogId, bool isAllComplete, bool isAllSuccess)> Run(TaskBaseTypeEnum taskBaseType, TaskManageOrderMessageInfo messageInfo, TaskBaseInfo taskInfo, TaskFlowDataContext dataContext)
{ {
if (taskInfo == null) if (taskInfo == null)
{ {
@ -52,8 +60,9 @@ namespace DS.WMS.Core.TaskPlat
IsMatch = false, IsMatch = false,
TaskId = taskInfo.Id, TaskId = taskInfo.Id,
TaskType = taskBaseType.ToString(), TaskType = taskBaseType.ToString(),
ExecuteStatus = 2, IsComplete = false,
ExceptionMessage = msg ExceptionMessage = msg,
IsSuccess = false,
}; };
await tenantDb.Insertable(log).ExecuteCommandAsync(); await tenantDb.Insertable(log).ExecuteCommandAsync();
throw new Exception(msg); throw new Exception(msg);
@ -150,7 +159,8 @@ namespace DS.WMS.Core.TaskPlat
MatchMainConfigId = targetConfig.Id, MatchMainConfigId = targetConfig.Id,
ConfigList = JsonConvert.SerializeObject(configList), ConfigList = JsonConvert.SerializeObject(configList),
ModuleList = JsonConvert.SerializeObject(moduleList), ModuleList = JsonConvert.SerializeObject(moduleList),
ExecuteStatus = 1 IsComplete = true,
IsSuccess = true,
}; };
foreach (var configItem in configList) foreach (var configItem in configList)
@ -212,31 +222,41 @@ namespace DS.WMS.Core.TaskPlat
Stopwatch stopwatch = Stopwatch.StartNew(); Stopwatch stopwatch = Stopwatch.StartNew();
var invokeResult = method.Invoke(imp, new object[] { dataContext }); var resultTemp = method.Invoke(imp, new object[] { dataContext });
// 这里需要取一下返回值 if (resultTemp is DataResult result1 && result1 != null)
//var b = invokeResult as DataResult;
//var c = invokeResult as Task<DataResult>;
//var d = c.Result;
if (invokeResult is DataResult result)
{ {
flowLogDetail.ExecuteReturn = JsonConvert.SerializeObject(result1);
flowLogDetail.IsSuccess = result1.Succeeded;
if (!result1.Succeeded)
{
flowLog.IsSuccess = false;
}
} }
else if (invokeResult is Task<DataResult> result2) else if (resultTemp is Task<DataResult> 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(); stopwatch.Stop();
flowLogDetail.ElapsedMillisecond = stopwatch.ElapsedMilliseconds; flowLogDetail.ElapsedMillisecond = stopwatch.ElapsedMilliseconds;
flowLogDetail.ExecuteStatus = 1; flowLogDetail.IsComplete = true;
await tenantDb.Insertable(flowLogDetail).ExecuteCommandAsync(); await tenantDb.Insertable(flowLogDetail).ExecuteCommandAsync();
} }
catch (Exception ex) catch (Exception ex)
{ {
flowLog.ExecuteStatus = 2; flowLog.IsComplete = false;
flowLog.IsSuccess = false;
flowLogDetail.IsComplete = false;
flowLogDetail.IsSuccess = false;
flowLogDetail.ExceptionMessage = WriteLog("", ex); flowLogDetail.ExceptionMessage = WriteLog("", ex);
flowLogDetail.ExecuteStatus = 2;
await tenantDb.Insertable(flowLogDetail).ExecuteCommandAsync(); await tenantDb.Insertable(flowLogDetail).ExecuteCommandAsync();
if (configItem.IsExceptionContinue) if (configItem.IsExceptionContinue)
@ -251,6 +271,7 @@ namespace DS.WMS.Core.TaskPlat
} }
await tenantDb.Insertable(flowLog).ExecuteCommandAsync(); await tenantDb.Insertable(flowLog).ExecuteCommandAsync();
return (flowLog.Id, flowLog.IsComplete, flowLog.IsSuccess);
} }

@ -206,12 +206,13 @@ public class SaasTest
{ {
var tenantDb = saasService.GetBizDbScopeById("1750335377144680448"); var tenantDb = saasService.GetBizDbScopeById("1750335377144680448");
StaticConfig.CodeFirst_MySqlCollate = "utf8mb4_0900_ai_ci";//较高版本支持 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)); //var ass = Assembly.Load("DS.WMS.Core");
//tenantDb.CodeFirst.InitTables(typeof(TaskFlowLogDetail)); //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); Assert.True(true);
} }
} }
Loading…
Cancel
Save