From ddbff347a3c12a3258d179293c9f319ad85e03a4 Mon Sep 17 00:00:00 2001
From: zhangxiaofeng <1939543722@qq.com>
Date: Fri, 19 Jul 2024 15:31:48 +0800
Subject: [PATCH 1/3] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=8F=B0=E7=9B=B8?=
=?UTF-8?q?=E5=85=B3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Constants/TaskFlowDataNameConst.cs | 18 ++++
.../Data/TaskFlowDataContext.cs | 18 +++-
.../ISpaceBookingMSKAPIService.cs | 7 ++
.../SpaceBooking/SpaceBookingMSKAPIService.cs | 92 ++++++++++++++-----
.../TaskPlat/Interface/IMyModuleTest1.cs | 1 +
.../TaskPlat/Method/MyModuleTest1.cs | 4 +
.../TaskPlat/Method/TaskManageService.cs | 9 +-
.../TaskPlat/Other/TaskFlowRuner.cs | 56 ++++++-----
8 files changed, 158 insertions(+), 47 deletions(-)
create mode 100644 ds-wms-service/DS.Module.Core/Constants/TaskFlowDataNameConst.cs
diff --git a/ds-wms-service/DS.Module.Core/Constants/TaskFlowDataNameConst.cs b/ds-wms-service/DS.Module.Core/Constants/TaskFlowDataNameConst.cs
new file mode 100644
index 00000000..e56befd3
--- /dev/null
+++ b/ds-wms-service/DS.Module.Core/Constants/TaskFlowDataNameConst.cs
@@ -0,0 +1,18 @@
+namespace DS.Module.Core
+{
+ ///
+ /// 维护一些常用的,用于任务台数据上下文读写参数的参数名
+ ///
+ public static class TaskFlowDataNameConst
+ {
+ ///
+ /// 任务任务请求报文
+ ///
+ public const string TaskManageOrderMessageInfo = nameof(TaskManageOrderMessageInfo);
+
+ ///
+ /// 租户Id
+ ///
+ public const string TenantId = "TenantId";
+ }
+}
diff --git a/ds-wms-service/DS.Module.Core/Data/TaskFlowDataContext.cs b/ds-wms-service/DS.Module.Core/Data/TaskFlowDataContext.cs
index 4b58c19c..19092acf 100644
--- a/ds-wms-service/DS.Module.Core/Data/TaskFlowDataContext.cs
+++ b/ds-wms-service/DS.Module.Core/Data/TaskFlowDataContext.cs
@@ -14,6 +14,18 @@
{
dataContext.Add(key, value);
}
+
+ ///
+ ///
+ ///
+ public TaskFlowDataContext(params (string key, object value)[] keyValues)
+ {
+ foreach (var item in keyValues)
+ {
+ dataContext.Add(item.key, item.value);
+ }
+ }
+
///
///
///
@@ -35,7 +47,11 @@
{
if (dataContext.ContainsKey(key))
{
- return (T)dataContext[key];
+ var value = dataContext[key];
+ if (value is T t)
+ {
+ return t;
+ }
}
return default;
}
diff --git a/ds-wms-service/DS.WMS.Core/Op/Interface/SpaceBooking/ISpaceBookingMSKAPIService.cs b/ds-wms-service/DS.WMS.Core/Op/Interface/SpaceBooking/ISpaceBookingMSKAPIService.cs
index 7e12e935..f40ef2d7 100644
--- a/ds-wms-service/DS.WMS.Core/Op/Interface/SpaceBooking/ISpaceBookingMSKAPIService.cs
+++ b/ds-wms-service/DS.WMS.Core/Op/Interface/SpaceBooking/ISpaceBookingMSKAPIService.cs
@@ -1,4 +1,5 @@
using DS.Module.Core;
+using DS.Module.Core.Data;
using DS.WMS.Core.Op.Dtos;
using System;
using System.Collections.Generic;
@@ -106,6 +107,12 @@ namespace DS.WMS.Core.Op.Interface
/// 返回回执
Task> SyncBCInfo(string mblno, long tenantId, string opTypeName = "BookingConfirmation");
+ ///
+ /// 同步BC状态(BC,Cancellation)作为任务台执行模块
+ ///
+ /// 数据上下文
+ Task> SyncBCInfoTask(TaskFlowDataContext dataContext);
+
///
/// 获取初始化页面默认值
///
diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/SpaceBooking/SpaceBookingMSKAPIService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/SpaceBooking/SpaceBookingMSKAPIService.cs
index 91a24057..060ba48b 100644
--- a/ds-wms-service/DS.WMS.Core/Op/Method/SpaceBooking/SpaceBookingMSKAPIService.cs
+++ b/ds-wms-service/DS.WMS.Core/Op/Method/SpaceBooking/SpaceBookingMSKAPIService.cs
@@ -32,10 +32,13 @@ using DS.WMS.Core.Op.Interface;
using DS.WMS.Core.Map.Method;
using Microsoft.Owin.Security.Provider;
using LanguageExt;
+using DS.Module.Core.Data;
+using DS.WMS.Core.TaskPlat.Dtos;
+using NLog.Fluent;
namespace DS.WMS.Core.Op.Method
{
- public class SpaceBookingMSKAPIService: ISpaceBookingMSKAPIService
+ public class SpaceBookingMSKAPIService : ISpaceBookingMSKAPIService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
@@ -433,7 +436,8 @@ namespace DS.WMS.Core.Op.Method
}
- showDto.Legs = legs.OrderBy(t => t.ETD).Select((t, idx) => {
+ showDto.Legs = legs.OrderBy(t => t.ETD).Select((t, idx) =>
+ {
t.SortNo = idx + 1;
return t;
}).ToList();
@@ -462,7 +466,7 @@ namespace DS.WMS.Core.Op.Method
//newModel.priceID = null;
var json = Newtonsoft.Json.JsonConvert.SerializeObject(newModel);
- model.PId = SnowFlakeSingle.Instance.NextId();
+ model.PId = SnowFlakeSingle.Instance.NextId();
//string md5 = json.ToMd5();
@@ -537,7 +541,7 @@ namespace DS.WMS.Core.Op.Method
//船公司代码不能为空
//if (string.IsNullOrWhiteSpace(model.carrierId))
- //throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.SpaceBookingAPIVesselCarrierCodeNull)));
+ //throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.SpaceBookingAPIVesselCarrierCodeNull)));
string sendUrl = string.Empty;
@@ -604,7 +608,7 @@ namespace DS.WMS.Core.Op.Method
//var ctnCodeMappingList = _cache.GetAllMappingCtn().GetAwaiter().GetResult().ToList();
//if (ctnCodeMappingList.Count > 0)
- //ctnCodeMappingList = ctnCodeMappingList.Where(x => x.CarrierCode == "MSK" && x.Module == "BOOK_MSK_API").ToList();
+ //ctnCodeMappingList = ctnCodeMappingList.Where(x => x.CarrierCode == "MSK" && x.Module == "BOOK_MSK_API").ToList();
MSKAPIBookingDto bookingDto = new MSKAPIBookingDto
{
@@ -824,7 +828,7 @@ namespace DS.WMS.Core.Op.Method
//var ctnMapping = ctnCodeMappingList.FirstOrDefault(t => t.Code.Equals(ctn.ctnCode));
//if (ctnMapping == null)
- //throw Oops.Oh($"未配置相应的箱型对应{ctn.ctnName},请联系管理员");
+ //throw Oops.Oh($"未配置相应的箱型对应{ctn.ctnName},请联系管理员");
MSKAPIBookingEquipmentAndHaulage haulage = new MSKAPIBookingEquipmentAndHaulage
{
@@ -1282,7 +1286,7 @@ namespace DS.WMS.Core.Op.Method
if (model.carrierCode.Equals("MSK", StringComparison.OrdinalIgnoreCase))
{
- queryUrl = configService.GetConfig(CONST_MSK_API_LOCATION_URL,long.Parse(user.TenantId),false).GetAwaiter().GetResult()?.Data?.Value;
+ queryUrl = configService.GetConfig(CONST_MSK_API_LOCATION_URL, long.Parse(user.TenantId), false).GetAwaiter().GetResult()?.Data?.Value;
}
else
{
@@ -1293,12 +1297,12 @@ namespace DS.WMS.Core.Op.Method
//未配置 MSK API 查询港口请求接口地址(马士基API合约查询港口URL),请联系管理员
if (string.IsNullOrWhiteSpace(queryUrl))
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.SpaceBookingAPISearchLocNoConfig)));
-
+
var webAccountConfig = codeThirdPartyService.GetCodeThirdPartyInfoWithCompany("MSKApi").GetAwaiter().GetResult()?.Data;
//未配置第三方账户个人或公司账户(MSKApi)
if (webAccountConfig == null)
- throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.SpaceBookingAPIThirdPartyNull)));
+ throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.SpaceBookingAPIThirdPartyNull)));
MSKAPISearchLocationDto queryInfo = new MSKAPISearchLocationDto
{
@@ -1324,9 +1328,9 @@ namespace DS.WMS.Core.Op.Method
}
catch (Exception ex)
{
- Logger.Log(NLog.LogLevel.Info,$"请求MSK API检索始发地、目的港口异常,原因:{ex.Message}");
+ Logger.Log(NLog.LogLevel.Info, $"请求MSK API检索始发地、目的港口异常,原因:{ex.Message}");
- throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.SpaceBookingAPISearchLocException)),ex.Message));
+ throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.SpaceBookingAPISearchLocException)), ex.Message));
}
}
@@ -1363,7 +1367,7 @@ namespace DS.WMS.Core.Op.Method
var entity = await tenantDb.Queryable().FirstAsync(a => a.Id == id);
//if (entity == null)
- //throw Oops.Oh($"获取马士基API订舱详情失败,不存在或已作废");
+ //throw Oops.Oh($"获取马士基API订舱详情失败,不存在或已作废");
model = entity.Adapt();
@@ -1461,7 +1465,7 @@ namespace DS.WMS.Core.Op.Method
}
//if (selectedShipSchedule == null)
- //throw Oops.Oh("船期数据校验失败,请重新查询船期信息");
+ //throw Oops.Oh("船期数据校验失败,请重新查询船期信息");
model.placeOfReceiptCountryName = selectedShipSchedule.originCountryName;
model.placeOfReceiptRegionName = selectedShipSchedule.originRegionName;
@@ -1484,12 +1488,12 @@ namespace DS.WMS.Core.Op.Method
.First(a => a.Id == model.id);
//if (oldInfo == null)
- //throw Oops.Oh("订舱数据不存在或已作废");
+ //throw Oops.Oh("订舱数据不存在或已作废");
if (oldInfo.Status == "SUCC")
{
//if (isSendApi)
- //throw Oops.Oh("订舱数据已发送成功,不能重复发送");
+ //throw Oops.Oh("订舱数据已发送成功,不能重复发送");
//throw Oops.Oh("订舱数据已发送成功,不能修改");
}
@@ -1544,7 +1548,8 @@ namespace DS.WMS.Core.Op.Method
ctnEntity.UpdateBy = long.Parse(user.UserId);
//ctnEntity.UpdatedUserName = UserManager.Name;
- tenantDb.Updateable(ctnEntity).IgnoreColumns(x => new {
+ tenantDb.Updateable(ctnEntity).IgnoreColumns(x => new
+ {
x.CreateBy,
//x.CreatedUserName,
x.CreateTime,
@@ -1579,13 +1584,15 @@ namespace DS.WMS.Core.Op.Method
if (ctnEntityList.Count > 0)
{
- ctnEntityList.ForEach(async ctn => {
+ ctnEntityList.ForEach(async ctn =>
+ {
ctn.Deleted = true;
ctn.DeleteTime = nowDate;
ctn.DeleteBy = long.Parse(user.UserId);
//ctn.UpdatedUserName = UserManager.Name;
- await tenantDb.Updateable(ctn).UpdateColumns(x => new {
+ await tenantDb.Updateable(ctn).UpdateColumns(x => new
+ {
x.Deleted,
x.DeleteTime,
x.DeleteBy,
@@ -1690,7 +1697,8 @@ namespace DS.WMS.Core.Op.Method
shipScheduleRecord.DeleteBy = long.Parse(user.UserId);
//shipScheduleRecord.UpdatedUserName = UserManager.Name;
- await tenantDb.Updateable(shipScheduleRecord).UpdateColumns(x => new {
+ await tenantDb.Updateable(shipScheduleRecord).UpdateColumns(x => new
+ {
x.Deleted,
x.DeleteTime,
x.DeleteBy,
@@ -1743,7 +1751,8 @@ namespace DS.WMS.Core.Op.Method
info.DeleteBy = long.Parse(user.UserId);
//info.UpdatedUserName = UserManager.Name;
- await tenantDb.Updateable(info).UpdateColumns(x => new {
+ await tenantDb.Updateable(info).UpdateColumns(x => new
+ {
x.Deleted,
x.DeleteTime,
x.DeleteBy
@@ -1766,7 +1775,7 @@ namespace DS.WMS.Core.Op.Method
.Where(a => ids.Contains(a.Id)).ToListAsync();
//if (list.Count != ids.Length)
- //throw Oops.Oh("订舱数据获取失败,请确认选中的记录是否存在");
+ //throw Oops.Oh("订舱数据获取失败,请确认选中的记录是否存在");
List msgList = new List();
int totalNum = list.Count;
@@ -1976,7 +1985,8 @@ namespace DS.WMS.Core.Op.Method
model.UpdateBy = long.Parse(user.UserId);
//model.UpdatedUserName = UserManager.Name;
- await tenantDb.Updateable(model).UpdateColumns(x => new {
+ await tenantDb.Updateable(model).UpdateColumns(x => new
+ {
x.IsRecvBC,
x.LstRecvBCDate,
x.UpdateTime,
@@ -1992,7 +2002,8 @@ namespace DS.WMS.Core.Op.Method
model.UpdateBy = long.Parse(user.UserId);
//model.UpdatedUserName = UserManager.Name;
- await tenantDb.Updateable(model).UpdateColumns(x => new {
+ await tenantDb.Updateable(model).UpdateColumns(x => new
+ {
x.IsRecvBKCancel,
x.LstRecvBKCancelDate,
x.UpdateTime,
@@ -2011,6 +2022,41 @@ namespace DS.WMS.Core.Op.Method
return DataResult.Success(result);
}
+
+ ///
+ /// 同步BC状态(BC,Cancellation)作为任务台执行模块
+ ///
+ /// 数据上下文
+ public async Task> SyncBCInfoTask(TaskFlowDataContext dataContext)
+ {
+ var messageInfo = dataContext.Get(TaskFlowDataNameConst.TaskManageOrderMessageInfo);
+ if (messageInfo == null)
+ {
+ throw new ArgumentNullException($"缺少参数:{TaskFlowDataNameConst.TaskManageOrderMessageInfo}");
+ }
+ if (string.IsNullOrEmpty(messageInfo.Main?.BCInfo?.MBLNo))
+ {
+ throw new ArgumentNullException($"提单号为空");
+ }
+
+ var tenantId = dataContext.Get(TaskFlowDataNameConst.TenantId);
+ if (tenantId == 0)
+ {
+ throw new ArgumentNullException($"缺少参数:TenantId");
+ }
+
+ string type = messageInfo.Main.TaskType switch
+ {
+ TaskBaseTypeEnum.BC => "BookingConfirmation",
+ TaskBaseTypeEnum.CANCELLATION => "Cancellation",
+ _ => throw new NotImplementedException()
+ };
+
+ var result = await this.SyncBCInfo(messageInfo.Main.BCInfo.MBLNo, tenantId, type);
+ Logger.Log(NLog.LogLevel.Info, $"入库完BC,自动推送状态到API订舱列表 mblno={messageInfo.Main.BCInfo.MBLNo} synRlt={JsonConvert.SerializeObject(result)}");
+
+ return result;
+ }
#endregion
#region 批量复制前调取校验预警
diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/IMyModuleTest1.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/IMyModuleTest1.cs
index 484c2ff2..67a98407 100644
--- a/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/IMyModuleTest1.cs
+++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/IMyModuleTest1.cs
@@ -6,6 +6,7 @@ namespace DS.WMS.Core.TaskPlat.Interface
public interface IMyModuleTest1
{
Task TestMethod11(TaskFlowDataContext dataContext);
+ Task TestMethod11();
DataResult TestMethod12(TaskFlowDataContext dataContext);
//public string G()
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 e0b29ce8..5977c589 100644
--- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/MyModuleTest1.cs
+++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/MyModuleTest1.cs
@@ -21,6 +21,10 @@ namespace DS.WMS.Core.TaskPlat.Method
return Task.FromResult(DataResult.Successed($"TestMethod11返回的成功结果,address:{address},height:{height},bcInfoVessel:{bcInfoVessel}"));
}
+ public Task TestMethod11()
+ {
+ return Task.FromResult(DataResult.Successed($"TestMethod11返回的成功结果"));
+ }
public DataResult TestMethod12(TaskFlowDataContext dataContext)
{
throw new Exception("TestMethod12内的测试异常");
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 e6fa3ef1..38cdcf96 100644
--- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs
+++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs
@@ -478,9 +478,14 @@ namespace DS.WMS.Core.TaskPlat.Method
2、推送钉钉消息@操作人 通知收到变更
*/
- TaskFlowDataContext dataContext = new(nameof(TaskManageOrderMessageInfo), info);
+ // 执行自动化操作
+ TaskFlowDataContext dataContext = new(
+ (TaskFlowDataNameConst.TaskManageOrderMessageInfo, info),
+ (TaskFlowDataNameConst.TenantId, long.Parse(user.TenantId))
+ );
+
TaskFlowRuner taskFlow = new TaskFlowRuner(tenantDb, serviceProvider);
- await taskFlow.Run(info.Main.TaskType, info, taskInfo, dataContext);
+ await taskFlow.Run(info.Main.TaskType, taskInfo.Id, dataContext);
if (info.Main.TaskType == TaskBaseTypeEnum.BC)
{
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 cf72b666..fd8c8cfc 100644
--- a/ds-wms-service/DS.WMS.Core/TaskPlat/Other/TaskFlowRuner.cs
+++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Other/TaskFlowRuner.cs
@@ -1,6 +1,5 @@
using DS.Module.Core;
using DS.Module.Core.Data;
-using DS.WMS.Core.TaskPlat.Dtos;
using DS.WMS.Core.TaskPlat.Entity;
using Newtonsoft.Json;
using SqlSugar;
@@ -33,16 +32,11 @@ namespace DS.WMS.Core.TaskPlat
/// 执行
///
/// 任务类型
- /// 任务原始接收信息
- /// 任务基础信息
- /// 原始入参数据
+ /// 任务Id
+ /// 起始入参数据上下文
/// (执行日志Id,模块是否全部执行完成,模块执行结果是否全部为success)
- public async Task<(long flowLogId, bool isAllComplete, bool isAllSuccess)> Run(TaskBaseTypeEnum taskBaseType, TaskManageOrderMessageInfo messageInfo, TaskBaseInfo taskInfo, TaskFlowDataContext dataContext)
+ public async Task<(long flowLogId, bool isAllComplete, bool isAllSuccess)> Run(TaskBaseTypeEnum taskBaseType, long taskId, TaskFlowDataContext dataContext)
{
- if (taskInfo == null)
- {
- throw new ArgumentNullException(nameof(taskInfo));
- }
if (dataContext == null)
{
throw new ArgumentNullException(nameof(dataContext));
@@ -58,7 +52,7 @@ namespace DS.WMS.Core.TaskPlat
TaskFlowLog log = new()
{
IsMatch = false,
- TaskId = taskInfo.Id,
+ TaskId = taskId,
TaskType = taskBaseType.ToString(),
IsComplete = false,
ExceptionMessage = msg,
@@ -73,43 +67,60 @@ namespace DS.WMS.Core.TaskPlat
.Where(x => allConfigIdList.Contains(x.ConfigId))
.ToListAsync();
+ // 判断每项流程达成的条件数量
Dictionary configMatchCount = allConfigList.ToDictionary(x => x.Id, x => 0);
-
- //dynamic taskInfoDynamic = taskInfo;
foreach (var configItem in allConfigList)
{
var conditionListGroup = allConditionList.Where(x => x.ConfigId == configItem.Id);
foreach (var conditionItem in conditionListGroup)
{
- var (_, val, _) = GetPropertyValue(messageInfo, conditionItem.FieldName);
+ string? valStr;
+ if (conditionItem.FieldName.Contains('.'))
+ {
+ var firstKey = conditionItem.FieldName.Split('.').First();
+
+ if (!dataContext.ContainsKey(firstKey)) continue;
+
+ var obj = dataContext.Get