jianghaiqing 4 months ago
commit 0f2a8954ce

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

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

@ -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<DataResult> TestMethod11(TaskFlowDataContext dataContext)
{
throw new Exception("TestMethod11内的测试异常");
//return Task.FromResult(DataResult.Successed("ok"));
var address = dataContext.Get<string>("Address");
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)
{
throw new Exception("TestMethod12内的测试异常");
//return DataResult.Successed("ok");
}
}
}

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

@ -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<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)
{
@ -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 result = new DataResult(ResultCode.Success, "新增任务成功", taskNo);
var result = new DataResult(ResultCode.Success, "新增任务成功", data: taskNo);
return await Task.FromResult(result);
}

@ -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)
/// <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)
{
@ -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<DataResult>;
//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<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();
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);
}

@ -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);
}
}
Loading…
Cancel
Save