From c9ed187f4a948af9153a42861e279d82715e901f Mon Sep 17 00:00:00 2001 From: zhangxiaofeng <1939543722@qq.com> Date: Thu, 8 Aug 2024 10:45:20 +0800 Subject: [PATCH 1/5] =?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 | 6 -- .../DS.WMS.Core/Info/Dtos/ClientContactRes.cs | 2 +- .../DS.WMS.Core/Info/Dtos/ClientInfoRes.cs | 2 +- .../Op/Dtos/BookingSlot/ParserBCInfoDto.cs | 30 +++++++ .../TaskPlat/Interface/IMyModuleTest1.cs | 4 +- .../TaskPlat/Method/MyModuleTest1.cs | 13 ++-- .../TaskPlat/Method/MyModuleTest2.cs | 3 +- .../TaskPlat/Method/TaskManageBCService.cs | 78 ++++++++++++++++++- .../TaskPlat/Method/TaskManageService.cs | 21 +++-- .../TaskPlat/Other/TaskFlowRuner.cs | 42 ++++++++-- 10 files changed, 166 insertions(+), 35 deletions(-) diff --git a/ds-wms-service/DS.Module.Core/Constants/TaskFlowDataNameConst.cs b/ds-wms-service/DS.Module.Core/Constants/TaskFlowDataNameConst.cs index 84492f15..3854056c 100644 --- a/ds-wms-service/DS.Module.Core/Constants/TaskFlowDataNameConst.cs +++ b/ds-wms-service/DS.Module.Core/Constants/TaskFlowDataNameConst.cs @@ -34,11 +34,5 @@ /// BC修改文件 /// public const string AmendmentFile = "AmendmentFile"; - - - /// - /// 任务主表主键 - /// - public const string TaskPkId = "taskPkId"; } } diff --git a/ds-wms-service/DS.WMS.Core/Info/Dtos/ClientContactRes.cs b/ds-wms-service/DS.WMS.Core/Info/Dtos/ClientContactRes.cs index 5ceab362..862b32d1 100644 --- a/ds-wms-service/DS.WMS.Core/Info/Dtos/ClientContactRes.cs +++ b/ds-wms-service/DS.WMS.Core/Info/Dtos/ClientContactRes.cs @@ -38,7 +38,7 @@ public class ClientContactRes /// /// 职务 /// - public string[]? Jobs => Job.IsNullOrEmpty() ? [] : Job.Split([','], StringSplitOptions.RemoveEmptyEntries); + public string[]? Jobs => Job.IsNullOrEmpty() ? [] : Job.Split(',', StringSplitOptions.RemoveEmptyEntries); /// /// Desc:通讯地址 diff --git a/ds-wms-service/DS.WMS.Core/Info/Dtos/ClientInfoRes.cs b/ds-wms-service/DS.WMS.Core/Info/Dtos/ClientInfoRes.cs index 240b0d97..67408f8a 100644 --- a/ds-wms-service/DS.WMS.Core/Info/Dtos/ClientInfoRes.cs +++ b/ds-wms-service/DS.WMS.Core/Info/Dtos/ClientInfoRes.cs @@ -344,7 +344,7 @@ public class ClientInfoRes /// 所属分部 /// public long[] SaleOrgIdList => SaleOrgId.IsNullOrEmpty() ? [] : - SaleOrgId.Split([','], StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray(); + SaleOrgId.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray(); /// /// 所属分部名称 diff --git a/ds-wms-service/DS.WMS.Core/Op/Dtos/BookingSlot/ParserBCInfoDto.cs b/ds-wms-service/DS.WMS.Core/Op/Dtos/BookingSlot/ParserBCInfoDto.cs index ceb8a1ca..c7bf636e 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Dtos/BookingSlot/ParserBCInfoDto.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Dtos/BookingSlot/ParserBCInfoDto.cs @@ -381,6 +381,36 @@ namespace DS.WMS.Core.Op.Dtos /// 计费日期 /// public Nullable PriceCalculationDate { get; set; } + + /// + /// 设置温度 + /// + public string TemperatureSet { get; set; } + + /// + /// 最低温度 + /// + public string TemperatureMin { get; set; } + + /// + /// 最高温度 + /// + public string TemperatureMax { get; set; } + + /// + /// Desc:湿度 + /// + public string Humidity { get; set; } + + /// + /// 卸货港 + /// + public string DischargePort { get; set; } + + /// + /// 目的地 + /// + public string Destination { get; set; } } public class ParserBCCTNInfoDto 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 67a98407..cdc6bd5d 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/IMyModuleTest1.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/IMyModuleTest1.cs @@ -6,8 +6,8 @@ namespace DS.WMS.Core.TaskPlat.Interface public interface IMyModuleTest1 { Task TestMethod11(TaskFlowDataContext dataContext); - Task TestMethod11(); - DataResult TestMethod12(TaskFlowDataContext dataContext); + //Task TestMethod11(); + Task 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 5977c589..976ecbd9 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/MyModuleTest1.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/MyModuleTest1.cs @@ -21,13 +21,14 @@ namespace DS.WMS.Core.TaskPlat.Method return Task.FromResult(DataResult.Successed($"TestMethod11返回的成功结果,address:{address},height:{height},bcInfoVessel:{bcInfoVessel}")); } - public Task TestMethod11() + //public Task TestMethod11() + //{ + // return Task.FromResult(DataResult.Successed($"TestMethod11返回的成功结果")); + //} + public Task TestMethod12(TaskFlowDataContext dataContext) { - return Task.FromResult(DataResult.Successed($"TestMethod11返回的成功结果")); - } - public DataResult TestMethod12(TaskFlowDataContext dataContext) - { - throw new Exception("TestMethod12内的测试异常"); + //throw new Exception("TestMethod12内的测试异常"); + return Task.FromResult(DataResult.Successed($"TestMethod12返回的成功结果")); } } } 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 7ecc8280..96ca89c4 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/MyModuleTest2.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/MyModuleTest2.cs @@ -13,7 +13,8 @@ namespace DS.WMS.Core.TaskPlat.Method { public Task TestMethod21(TaskFlowDataContext dataContext) { - throw new Exception("TestMethod21内的测试异常"); + //throw new Exception("TestMethod21内的测试异常"); + return Task.FromResult(DataResult.Successed($"TestMethod21返回的成功结果")); } } } diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBCService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBCService.cs index defe3602..ca1e729f 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBCService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBCService.cs @@ -1,6 +1,7 @@ using Amazon.Runtime.Internal.Util; using DS.Module.Core; using DS.Module.Core.Constants; +using DS.Module.Core.Data; using DS.Module.DjyServiceStatus; using DS.Module.SqlSugar; using DS.Module.UserModule; @@ -257,7 +258,7 @@ namespace DS.WMS.Core.TaskPlat.Method throw new Exception($"未获取有效任务记录,更新失败"); } - + //var currBCOrder = await tenantDb.Queryable().Where(a => a.Id == bcEntity.Id).FirstAsync(); //if (currBCOrder != null && model.IsDirectSend) @@ -1110,6 +1111,81 @@ namespace DS.WMS.Core.TaskPlat.Method } #endregion + /// + /// 对比BC与海运出口订单(任务台使用) + /// + public async Task> ExcuteCompareTask(TaskFlowDataContext dataContext) + { + try + { + var taskBcId = dataContext.Get(TaskFlowDataNameConst.TaskBCId); + if (taskBcId == null) + { + throw new ArgumentException($"缺少参数:{nameof(TaskFlowDataNameConst.TaskBCId)}"); + } + + var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId); + var taskBcInfo = await tenantDb.Queryable().Where(x => x.Id == taskBcId).FirstAsync(); + if (taskBcInfo == null) + { + string msg = $"执行ExcuteCompareTask时,根据未获取到BC信息"; + logger.LogInformation(msg); + return DataResult.Failed("对比失败:" + msg); + } + var taskBcCtnList = await tenantDb.Queryable().Where(x => x.P_ID == taskBcInfo.Id).ToListAsync(); + + // 运费协议号(约号)是唯一的,服务合同号可能不是唯一的 + + // BC信息 + ParserBCInfoDto bcSrcDto = new ParserBCInfoDto() + { + ContractNo = taskBcInfo.CONTRACTNO, + Vessel = taskBcInfo.VESSEL, + VoyNo = taskBcInfo.VOYNO, + //TemperatureMin = taskBcInfo + + + }; + + //bcTargetDto.CtnList = dto.DataObj.CtnList.GroupBy(x => x.CtnAll) + // .Select(x => + // { + // return new ParserBCCTNInfoDto + // { + // CtnALL = x.Key, + // CtnNum = x.ToList().Sum(a => a.CtnNum) + // }; + // }).ToList(); + + var seaExport = await tenantDb.Queryable().Where(x => x.MBLNO == taskBcInfo.MBL_NO).FirstAsync(); + + // 订单信息 + ParserBCInfoDto bcTargetDto = new ParserBCInfoDto() + { + ContractNo = seaExport.ContractNo, + Vessel = seaExport.Vessel, + VoyNo = seaExport.Voyno, + TemperatureMin = seaExport.TemperatureMin, + TemperatureMax = seaExport.TemperatureMax, + TemperatureSet = seaExport.TemperatureSet, + Humidity = seaExport.Humidity, + DischargePort = seaExport.DischargePort, + Destination = seaExport.Destination, + + //CtnList = new List(), + }; + + + } + catch (Exception) + { + + throw; + } + + return default; + + } #region 生成并推送邮件 /// 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 69514e37..cc415dbb 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs @@ -71,7 +71,7 @@ namespace DS.WMS.Core.TaskPlat.Method SqlSugarScopeProvider tenantDb = saasDbService.GetBizDbScopeById(user.TenantId); TaskBaseInfo taskInfo = await tenantDb.Queryable() - .OrderByDescending(a => a.CreateTime) + .OrderByDescending(a => a.Id) .FirstAsync(t => t.OUT_BS_NO == bsno && t.TASK_TYPE == taskBaseTypeEnum.ToString()); if (taskInfo == null) @@ -121,7 +121,7 @@ namespace DS.WMS.Core.TaskPlat.Method SqlSugarScopeProvider tenantDb = saasDbService.GetBizDbScopeById(user.TenantId); TaskBaseInfo taskInfo = await tenantDb.Queryable() - .OrderByDescending(a => a.CreateTime) + .OrderByDescending(a => a.Id) .FirstAsync(t => t.OUT_BS_NO == bsno && t.TASK_TYPE == taskBaseTypeEnum.ToString()); if (taskInfo == null) @@ -184,7 +184,7 @@ namespace DS.WMS.Core.TaskPlat.Method { var taskId = await tenantDb.Queryable() .Where(t => t.OUT_BS_NO == bsno && t.TASK_TYPE == taskBaseTypeEnum.ToString()) - .OrderByDescending(a => a.CreateTime) + .OrderByDescending(a => a.Id) .Select(t => t.Id) .FirstAsync(); @@ -254,7 +254,7 @@ namespace DS.WMS.Core.TaskPlat.Method taskInfo = await tenantDb.Queryable() .Where(t => t.OUT_BS_NO == info.Head.BSNO) .WhereIF(info.Main.IsCheckExistsByTaskType, t => t.TASK_TYPE == info.Main.TaskType.ToString()) - .OrderByDescending(a => a.CreateTime) + .OrderByDescending(a => a.Id) .FirstAsync(); } // 否则通过Head.GID进行判断 @@ -263,7 +263,7 @@ namespace DS.WMS.Core.TaskPlat.Method taskInfo = await tenantDb.Queryable() .Where(t => t.OUT_BUSI_NO == $"{info.Head.SenderId}_{info.Head.GID}") .WhereIF(info.Main.IsCheckExistsByTaskType, t => t.TASK_TYPE == info.Main.TaskType.ToString()) - .OrderByDescending(a => a.CreateTime) + .OrderByDescending(a => a.Id) .FirstAsync(); } @@ -2151,13 +2151,12 @@ namespace DS.WMS.Core.TaskPlat.Method //var b = user.GetOrgId(); //var b232 = user.OrgId; - // 任务匹配 - if (LastMatchTaskTime < DateTime.Now.AddSeconds(-5)) // 效果:距上一次全局任务匹配执行如果超过5秒,才进行匹配 - { - await MatchTask(); - LastMatchTaskTime = DateTime.Now; - } + //if (LastMatchTaskTime < DateTime.Now.AddSeconds(-5)) // 效果:距上一次全局任务匹配执行如果超过5秒,才进行匹配 + //{ + //LastMatchTaskTime = DateTime.Now; + //} + await MatchTask(); //序列化查询条件 List? whereList = null; 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 bcb55a32..c04d82c5 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Other/TaskFlowRuner.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Other/TaskFlowRuner.cs @@ -31,6 +31,8 @@ namespace DS.WMS.Core.TaskPlat this.serviceProvider = serviceProvider; this.logger = serviceProvider.GetRequiredService>(); } + + /// /// 执行 /// @@ -199,17 +201,29 @@ namespace DS.WMS.Core.TaskPlat }; // 执行流程 - foreach (var configItem in configList) + long? nextExecuteConfigId = targetConfig.Id; + for (int i = 0; i < configList.Count; i++) { + if (nextExecuteConfigId == null || nextExecuteConfigId == 0) + { + break; + } + var executeConfig = configList.FirstOrDefault(x => x.Id == nextExecuteConfigId); + if (executeConfig == null) + { + break; + } + nextExecuteConfigId = executeConfig.NextExecuteConfigId; + TaskFlowLogDetail flowLogDetail = new() { - ConfigId = configItem.Id, + ConfigId = executeConfig.Id, PId = flowLog.Id, IsSuccess = true, }; try { - var paramItemList = paramList.Where(x => x.ConfigId == configItem.Id).ToList(); + var paramItemList = paramList.Where(x => x.ConfigId == executeConfig.Id).ToList(); foreach (var paramItem in paramItemList) { dataContext.Set(paramItem.FieldName!, paramItem.FieldValue!); @@ -224,10 +238,10 @@ namespace DS.WMS.Core.TaskPlat //} } - var module = moduleList.FirstOrDefault(x => x.Id == configItem.ExecuteModuleId); + var module = moduleList.FirstOrDefault(x => x.Id == executeConfig.ExecuteModuleId); if (module == null) { - throw new Exception($"未找到指定流程配置,ExecuteModuleId:{configItem.ExecuteModuleId}"); + throw new Exception($"未找到指定流程配置,ExecuteModuleId:{executeConfig.ExecuteModuleId}"); } flowLogDetail.ModuleId = module.Id; @@ -319,7 +333,7 @@ namespace DS.WMS.Core.TaskPlat flowLogDetail.ExceptionMessage = WriteLog("模块执行过程中发生异常", ex); await tenantDb.Insertable(flowLogDetail).ExecuteCommandAsync(); - if (configItem.IsExceptionContinue) + if (executeConfig.IsExceptionContinue) { continue; } @@ -334,6 +348,22 @@ namespace DS.WMS.Core.TaskPlat return (flowLog.Id, flowLog.IsComplete, flowLog.IsSuccess); } + /// + /// 执行(通过业务Id) + /// + /// 任务类型 + /// 业务Id + /// 起始入参数据上下文 + /// (执行日志Id,模块是否全部执行完成,模块执行结果是否全部为success) + public async Task<(long? flowLogId, bool isAllComplete, bool isAllSuccess)> RunWithBsno(TaskBaseTypeEnum taskBaseType, long bsno, TaskFlowDataContext dataContext) + { + long taskId = await tenantDb.Queryable() + .Where(t => t.OUT_BS_NO == bsno && t.TASK_TYPE == taskBaseType.ToString()) + .OrderByDescending(a => a.Id) + .Select(t => t.Id) + .FirstAsync(); + return await Run(taskBaseType, taskId, dataContext); + } /// /// 深度获取对象属性值 From 2deab5fac39c202547be9a39731011af5aebe69b Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Thu, 8 Aug 2024 11:06:44 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9BC=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E8=BD=AC=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../Method/BookingSlot/BookingSlotService.cs | 19 ++- .../DS.WMS.Core/Op/Method/SeaExportService.cs | 2 +- .../Dtos/TaskManageOrderMessageMainInfo.cs | 5 +- .../Interface/ITaskManageBCService.cs | 9 ++ .../TaskPlat/Method/TaskManageBCService.cs | 118 +++++++++++++++--- .../TaskPlat/Method/TaskManageService.cs | 12 +- 7 files changed, 139 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index 5fb84088..00e8624a 100644 --- a/.gitignore +++ b/.gitignore @@ -67,3 +67,4 @@ LinkAttach /ds-wms-service/DS.WMS.AdminApi/Logs/internal-nlog.txt /ds-wms-service/DS.WMS.ContainerManagementApi/Logs/internal-nlog.txt /ds-wms-service/DS.WMS.OpApi/TempFiles/S24080044 +/ds-wms-service/DS.WMS.TaskApi/TaskEmailTemplate diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/BookingSlot/BookingSlotService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/BookingSlot/BookingSlotService.cs index 4e5887d0..d01f9909 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/BookingSlot/BookingSlotService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/BookingSlot/BookingSlotService.cs @@ -901,7 +901,8 @@ namespace DS.WMS.Core.Op.Method PriceCalculationDate = taskBCInfoDto.PriceCalculationDate, CtnList = new List() }, - OpType = messageInfo.Head.RequestAction?.ToLower() + OpType = messageInfo.Head.RequestAction?.ToLower(), + BatchNo = messageInfo.Main.TaskBatchNo }; if (int.TryParse(taskBCInfoDto.WeekAt, out int week)) @@ -917,7 +918,7 @@ namespace DS.WMS.Core.Op.Method { var ctnCode = ctnCodeList.FirstOrDefault(a => !string.IsNullOrWhiteSpace(a.CtnName) && a.CtnName.Equals(t.CtnALL, StringComparison.OrdinalIgnoreCase)); - t.CtnCode = ctnCode != null ? ctnCode.EdiCode : "(箱型未收录)"; + t.CtnCode = ctnCode != null ? ctnCode.EdiCode : ""; } BookingSlotCtnSaveInput ctn = new BookingSlotCtnSaveInput @@ -1222,10 +1223,10 @@ namespace DS.WMS.Core.Op.Method } else if (dto.OpType == "update") { - model = await tenantDb.Queryable().FirstAsync(x => x.SlotBookingNo == dto.DataObj.SlotBookingNo); + model = tenantDb.Queryable().First(x => x.SlotBookingNo == dto.DataObj.SlotBookingNo); if (model == null) { - //throw Oops.Bah($"未找到订舱编号为 {dto.DataObj.SlotBookingNo} 的数据"); + throw new Exception($"未找到订舱编号为 {dto.DataObj.SlotBookingNo} 的数据"); } id = model.Id; @@ -1299,6 +1300,8 @@ namespace DS.WMS.Core.Op.Method dto.DataObj.Adapt(model); + model.Id = id; + // 1.判断新的舱位信息的7个库存统计维度是否发生变化 // 2.如果有变化,则需要更新旧的库存信息 bool isNeedUpdateOldStock = false; @@ -1311,7 +1314,11 @@ namespace DS.WMS.Core.Op.Method { isNeedUpdateOldStock = true; } - await tenantDb.Updateable(model).ExecuteCommandAsync(); + await tenantDb.Updateable(model).IgnoreColumns(x=>new { + x.CreateBy, + x.CreateTime, + x.CreateUserName + }).ExecuteCommandAsync(); if (isNeedUpdateOldStock) { @@ -1420,7 +1427,7 @@ namespace DS.WMS.Core.Op.Method { // 更新标志 var slotNO = dto.DataObj.SlotBookingNo; - model = await tenantDb.Queryable().FirstAsync(x => x.SlotBookingNo == slotNO); + model = tenantDb.Queryable().First(x => x.SlotBookingNo == slotNO); if (model == null) { throw new Exception($"未找到订舱编号为 {slotNO} 的数据"); diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/SeaExportService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/SeaExportService.cs index 766c430f..4b2fafc4 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/SeaExportService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/SeaExportService.cs @@ -1030,7 +1030,7 @@ public partial class SeaExportService : ISeaExportService 3、是合票的,找到主票和其他分票,并返回当前订单的完整详情。 */ var orderList = await tenantDb.Queryable() - .Where(a => (a.MBLNO == mblNo || a.OrderNo == mblNo) && a.Deleted == false).ToListAsync(); + .Where(a => (a.MBLNO == mblNo || a.OrderNo == mblNo) && a.Deleted == false && a.ParentId == 0).ToListAsync(); var currOrder = orderList.FirstOrDefault(a => a.MBLNO == mblNo); diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/TaskManageOrderMessageMainInfo.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/TaskManageOrderMessageMainInfo.cs index c69620b1..54686db7 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/TaskManageOrderMessageMainInfo.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/TaskManageOrderMessageMainInfo.cs @@ -306,6 +306,9 @@ namespace DS.WMS.Core.TaskPlat.Dtos ///// 单票账单的解析 ///// //public perbill perbillInfo { get; set; } - + /// + /// 任务批次号 + /// + public string TaskBatchNo { get; set; } } } diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/ITaskManageBCService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/ITaskManageBCService.cs index c7815754..331638b6 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/ITaskManageBCService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/ITaskManageBCService.cs @@ -1,4 +1,5 @@ using DS.Module.Core; +using DS.Module.Core.Data; using DS.Module.DjyServiceStatus; using DS.WMS.Core.Op.Dtos; using DS.WMS.Core.TaskPlat.Dtos; @@ -34,5 +35,13 @@ namespace DS.WMS.Core.TaskPlat.Interface /// BC任务主键 /// 返回回执 Task SyncBookingSlotChange(long taskPKId); + + + /// + /// 同步舱位变更(任务自动) + /// + /// 上下文 + /// 返回回执 + Task SyncBookingSlotChangeTask(TaskFlowDataContext dataContext); } } diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBCService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBCService.cs index a9e85c9d..368ecc75 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBCService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBCService.cs @@ -1,6 +1,8 @@ using Amazon.Runtime.Internal.Util; using DS.Module.Core; using DS.Module.Core.Constants; +using DS.Module.Core.Data; +using DS.Module.Core.Helpers; using DS.Module.DjyServiceStatus; using DS.Module.SqlSugar; using DS.Module.UserModule; @@ -37,6 +39,7 @@ using NPOI.XWPF.UserModel; using SqlSugar; using System; using System.Security.Cryptography; +using System.Text.Json.Nodes; using System.Text.RegularExpressions; namespace DS.WMS.Core.TaskPlat.Method @@ -55,6 +58,7 @@ namespace DS.WMS.Core.TaskPlat.Method private readonly IUserService _userService; private readonly IUserEmailService _userEmailService; private readonly IWebHostEnvironment _environment; + private readonly ISqlSugarClient db; // 按需构建 private Lazy bookingSlotService; @@ -93,6 +97,8 @@ namespace DS.WMS.Core.TaskPlat.Method _userEmailService = userEmailService; _environment = environment; + db = serviceProvider.GetRequiredService(); + bookingSlotService = new Lazy(serviceProvider.GetRequiredService); seaExportService = new Lazy(serviceProvider.GetRequiredService); djyServiceStatusService = new Lazy(serviceProvider.GetRequiredService); @@ -1120,7 +1126,9 @@ namespace DS.WMS.Core.TaskPlat.Method /// 检索订舱相关 /// 是否默认使用用户个人邮箱发送 /// 返回回执 - private async Task GenerateSendEmail(TaskBCInfo taskBCInfo, TaskBaseInfo bcTaskInfo, SeaExportOrderExtension orderInfo, bool usePersonalEmailSend = false) + private async Task GenerateSendEmail(TaskBCInfo taskBCInfo, TaskBaseInfo bcTaskInfo, SeaExportOrderExtension orderInfo, SeaExport currSeaExportOrder, + bool saveBookingId = false, + bool usePersonalEmailSend = false) { bool result = false; string msg = string.Empty; @@ -1153,10 +1161,26 @@ namespace DS.WMS.Core.TaskPlat.Method var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId); - var bookingOrderEntity = orderInfo.currOrder; + var bookingOrderEntity = currSeaExportOrder; Logger.Log(NLog.LogLevel.Info, $"获取订舱详情完成,bookid={bookingOrderEntity.Id}"); + if (saveBookingId && taskBCInfo.BOOKING_ORDER_ID != currSeaExportOrder.Id) + { + taskBCInfo.BOOKING_ORDER_ID = currSeaExportOrder.Id; + taskBCInfo.UpdateTime = DateTime.Now; + taskBCInfo.UpdateBy = long.Parse(user.UserId); + taskBCInfo.UpdateUserName = user.UserName; + + await tenantDb.Updateable(taskBCInfo).UpdateColumns(x => new + { + x.BOOKING_ORDER_ID, + x.UpdateTime, + x.UpdateBy, + x.UpdateUserName + }).ExecuteCommandAsync(); + } + if (bookingOrderEntity.CustomerId == 0) { throw new Exception($"订舱的委托客户不能为空"); @@ -1180,7 +1204,7 @@ namespace DS.WMS.Core.TaskPlat.Method string opEmail = string.Empty; var bookingContactList = tenantDb.Queryable() - .Where(a => a.BusinessId == taskBCInfo.BOOKING_ORDER_ID).ToList(); + .Where(a => a.BusinessId == currSeaExportOrder.Id).ToList(); if (bookingContactList == null || bookingContactList.Count == 0) { @@ -1265,8 +1289,15 @@ namespace DS.WMS.Core.TaskPlat.Method } else { - fileInfo = tenantDb.Queryable().Where(a => a.TASK_PKID == taskBCInfo.TASK_ID && a.FILE_CATEGORY.Contains("BC_MODIFY_NOTICE")) - .OrderByDescending(a => a.CreateTime).First(); + if (orderInfo.splitOrMergeFlag == 1) + { + //这里需要按照箱量重新修改变更附件 + } + else + { + fileInfo = tenantDb.Queryable().Where(a => a.TASK_PKID == taskBCInfo.TASK_ID && a.FILE_CATEGORY.Contains("BC_MODIFY_NOTICE")) + .OrderByDescending(a => a.CreateTime).First(); + } } } @@ -1541,7 +1572,7 @@ namespace DS.WMS.Core.TaskPlat.Method if (string.IsNullOrEmpty(basePath)) { - dirAbs = Path.Combine(_environment.WebRootPath, relativePath); + dirAbs = Path.Combine(_environment.WebRootPath ?? "", relativePath); } else { @@ -1815,11 +1846,11 @@ namespace DS.WMS.Core.TaskPlat.Method private async Task PushEmail(EmailApiUserDefinedDto emailApiUserDefinedDto, string filePath) { List emailList = new List(); - + bool result = false; string msg = string.Empty; - var emailUrl = ""; + var emailUrl = db.Queryable().Filter(null, true).Where(x => x.Code == "email_api_url" && x.TenantId == 1288018625843826688).First().Value; if (emailUrl == null) throw new Exception("字典未配置 url_set->email_api_url 请联系管理员"); @@ -1854,10 +1885,13 @@ namespace DS.WMS.Core.TaskPlat.Method DateTime bDate = DateTime.Now; - HttpResponseMessage res = null; + string res = string.Empty; try { + var jsonBody = JsonConvert.SerializeObject(emailList); + + res = RequestHelper.Post(jsonBody, emailUrl); //res = await emailUrl.SetBody(emailList, "application/json").PostAsync(); } catch (Exception ex) @@ -1871,13 +1905,13 @@ namespace DS.WMS.Core.TaskPlat.Method Logger.Log(NLog.LogLevel.Info, $"邮件上传完成 上传文件大小:{heByte.Length} 用时:{timeDiff}ms.,"); - Logger.Log(NLog.LogLevel.Info, $"发送邮件返回:{JsonConvert.SerializeObject(res)}"); + Logger.Log(NLog.LogLevel.Info, $"发送邮件返回:{res}"); - if (res != null && res.StatusCode == System.Net.HttpStatusCode.OK) + if (!string.IsNullOrWhiteSpace(res)) { - var userResult = await res.Content.ReadAsStringAsync(); + //var userResult = await res.Content.ReadAsStringAsync(); - var respObj = JsonConvert.DeserializeAnonymousType(userResult, new + var respObj = JsonConvert.DeserializeAnonymousType(res, new { Success = false, Message = string.Empty, @@ -1952,23 +1986,73 @@ namespace DS.WMS.Core.TaskPlat.Method if (orderInfo != null && orderInfo.currOrder != null) { //更新订舱相关内容 - if (paramConfig.Equals("ENABLE", StringComparison.OrdinalIgnoreCase)) { - await GenerateSendEmail(taskBcInfo, taskBaseInfo, orderInfo); + //如果是拆票需要按照分票明细单个发送邮件 + if (orderInfo.splitOrMergeFlag == 1) + { + var splitOrderIds = new List(); + + splitOrderIds.Add(orderInfo.currOrder.Id); + splitOrderIds.Append(orderInfo.otherOrderList.Select(b => b.Id).ToList()); + + var bookList = tenantDb.Queryable().Where(b => splitOrderIds.Contains(b.Id)).ToList(); + + foreach (var seaExportId in splitOrderIds) + { + var currSeaExport = bookList.FirstOrDefault(b => b.Id == seaExportId); + + bool saveBookingId = currSeaExport.Id == orderInfo.currOrder.Id; + + await GenerateSendEmail(taskBcInfo, taskBaseInfo, orderInfo, currSeaExport, saveBookingId); + } + } + else + { + var currSeaExport = tenantDb.Queryable().First(b => b.Id == orderInfo.currOrder.Id); + //普通和合票都按单票处理 + await GenerateSendEmail(taskBcInfo, taskBaseInfo, orderInfo, currSeaExport, true); + } + + } + else + { + //这里没有取到订舱信息,终止,并发出邮件通知 + Logger.Log(NLog.LogLevel.Info, $"taskPKId={taskPKId} mblno={taskBcInfo.MBL_NO} 当前租户未配置自动转发邮件"); } } else { - //终止执行 + //这里没有取到订舱信息,终止,并发出邮件通知 + Logger.Log(NLog.LogLevel.Info, $"taskPKId={taskPKId} mblno={taskBcInfo.MBL_NO} 没有找到订单"); } } catch (Exception ex) { + Logger.Log(NLog.LogLevel.Info, $"执行SyncBookingSlotChange时,异常{ex.Message}"); + + return DataResult.Failed($"执行SyncBookingSlotChange时,异常{ex.Message}"); } - return DataResult.Successed(""); + return DataResult.Successed(MultiLanguageConst.DataCreateSuccess); } #endregion + + + /// + /// 同步舱位变更(任务自动) + /// + /// 上下文 + /// 返回回执 + public async Task SyncBookingSlotChangeTask(TaskFlowDataContext dataContext) + { + var taskBaseId = dataContext.Get(TaskFlowDataNameConst.TaskBaseId); + if (taskBaseId == null) + { + Logger.Log(NLog.LogLevel.Info, $"执行ApiReceiveTask时,未获取到{TaskFlowDataNameConst.TaskBaseId}"); + } + + return await SyncBookingSlotChange(taskBaseId.Value); + } } } 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 69514e37..9c2dcd51 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs @@ -411,6 +411,11 @@ namespace DS.WMS.Core.TaskPlat.Method taskInfo.NeedArriveTime = info.Main.TruckInfo.NeedArriveTime; } + if(string.IsNullOrWhiteSpace(info.Main.TaskBatchNo)) + { + info.Main.TaskBatchNo = SnowFlakeSingle.Instance.NextId().ToString(); + } + await tenantDb.Insertable(taskInfo).ExecuteCommandAsync(); if (!string.IsNullOrWhiteSpace(info.Main.FilePath)) @@ -873,6 +878,8 @@ namespace DS.WMS.Core.TaskPlat.Method bcInfo.CreateBy = taskInfo.CreateBy; bcInfo.CreateTime = taskInfo.CreateTime; + bcInfo.BATCH_NO = info.Main.TaskBatchNo; + if (info.Main.BCInfo.BookingSlotId.HasValue && info.Main.BCInfo.BookingSlotId.Value > 0) bcInfo.BOOKING_SLOT_ID = info.Main.BCInfo.BookingSlotId.Value; @@ -891,7 +898,7 @@ namespace DS.WMS.Core.TaskPlat.Method { var ctnCode = ctnCodeList.FirstOrDefault(a => !string.IsNullOrWhiteSpace(a.CtnName) && a.CtnName.Equals(bcCtnInfo.CTNALL, StringComparison.OrdinalIgnoreCase)); - bcCtnInfo.CTNCODE = ctnCode != null ? ctnCode.EdiCode : "(箱型未收录)"; + bcCtnInfo.CTNCODE = ctnCode != null ? ctnCode.EdiCode : ""; } bcInfo.CreateBy = taskInfo.CreateBy; @@ -916,7 +923,8 @@ namespace DS.WMS.Core.TaskPlat.Method (TaskFlowDataNameConst.TaskManageOrderMessageInfo, info), (TaskFlowDataNameConst.TaskBCId, bcInfo.Id), (TaskFlowDataNameConst.BCFile, file), - (TaskFlowDataNameConst.AmendmentFile, modifyFile) + (TaskFlowDataNameConst.AmendmentFile, modifyFile), + (TaskFlowDataNameConst.TaskBaseId, taskInfo.Id) ); TaskFlowRuner taskFlow = new TaskFlowRuner(tenantDb, serviceProvider); From 43e7d8c6ef1a5837be746d32653a19e010285325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B5=87=E6=96=87=E9=BE=99?= Date: Thu, 8 Aug 2024 11:07:10 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E7=AD=BE=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Constants/MultiLanguageConst.cs | 5 + .../Constants/TaskFlowDataNameConst.cs | 8 ++ .../DS.Module.Core/Data/BaseOrgModel.cs | 2 +- .../TaskInteraction/ActionExecutionContext.cs | 15 +++ ...ttachment.cs => BusinessTaskAttachment.cs} | 4 +- .../Entity/TaskInteraction/BusinessTaskLog.cs | 8 +- .../TaskInteraction/BusinessTaskMail.cs | 28 +++-- .../TaskInteraction/BusinessTaskMailServer.cs | 42 +++++++ .../TaskInteraction/IActionExecutor.cs | 17 +++ .../TaskInteraction/IActionManager.cs | 25 +++++ .../TaskInteraction/ITaskMailService.cs | 33 +++++- .../Method/TaskInteraction/ActionExecutor.cs | 45 ++++++++ .../Method/TaskInteraction/ActionManager.cs | 69 ++++++++++++ .../TaskInteraction/MailActionExecutor.cs | 13 +++ .../TaskInteraction/SeaExportTaskService.cs | 2 +- .../Method/TaskInteraction/TaskMailService.cs | 106 +++++++++++++----- ds-wms-service/DS.WMS.Core/ServiceBase.cs | 5 + .../Controllers/SeaExportTaskController.cs | 1 - .../Controllers/TaskMailController.cs | 63 +++++++++++ 19 files changed, 446 insertions(+), 45 deletions(-) create mode 100644 ds-wms-service/DS.WMS.Core/Op/Dtos/TaskInteraction/ActionExecutionContext.cs rename ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/{BusinessTaskMailAttachment.cs => BusinessTaskAttachment.cs} (79%) create mode 100644 ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/BusinessTaskMailServer.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/IActionExecutor.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/IActionManager.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionExecutor.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionManager.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailActionExecutor.cs create mode 100644 ds-wms-service/DS.WMS.OpApi/Controllers/TaskMailController.cs diff --git a/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs b/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs index bd2942e7..0fe81db3 100644 --- a/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs +++ b/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs @@ -1491,6 +1491,11 @@ public static class MultiLanguageConst public const string TaskAuditStatusError = "Task_Audit_Status_Error"; [Description("无法从配置中获取任务接收人,请联系管理员检查系统配置")] public const string TaskReceiverNotFound = "Task_Receiver_Not_Found"; + + [Description("任务邮件必须设置收件人")] + public const string TaskMailReceiverNotNull = "Task_Mail_Receiver_Not_Null"; + [Description("任务邮件必须设置发件人")] + public const string TaskMailSenderNotNull = "Task_Mail_Sender_Not_Null"; #endregion #region 任务台相关 diff --git a/ds-wms-service/DS.Module.Core/Constants/TaskFlowDataNameConst.cs b/ds-wms-service/DS.Module.Core/Constants/TaskFlowDataNameConst.cs index 3854056c..a928d9ce 100644 --- a/ds-wms-service/DS.Module.Core/Constants/TaskFlowDataNameConst.cs +++ b/ds-wms-service/DS.Module.Core/Constants/TaskFlowDataNameConst.cs @@ -34,5 +34,13 @@ /// BC修改文件 /// public const string AmendmentFile = "AmendmentFile"; + + + /// + /// 任务主表主键 + /// + public const string TaskPkId = "taskPkId"; + + public const string BusinessTask = "BusinessTask"; } } diff --git a/ds-wms-service/DS.Module.Core/Data/BaseOrgModel.cs b/ds-wms-service/DS.Module.Core/Data/BaseOrgModel.cs index 6565b690..b43646c8 100644 --- a/ds-wms-service/DS.Module.Core/Data/BaseOrgModel.cs +++ b/ds-wms-service/DS.Module.Core/Data/BaseOrgModel.cs @@ -30,6 +30,6 @@ public abstract class BaseOrgModelV2 : BaseModelV2, IOrgId /// /// 机构Id /// - [SugarColumn(ColumnDescription = "机构Id")] + [SugarColumn(ColumnDescription = "机构Id", IsOnlyIgnoreUpdate = true)] public long OrgId { get; set; } } \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/Op/Dtos/TaskInteraction/ActionExecutionContext.cs b/ds-wms-service/DS.WMS.Core/Op/Dtos/TaskInteraction/ActionExecutionContext.cs new file mode 100644 index 00000000..98f6a748 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/Dtos/TaskInteraction/ActionExecutionContext.cs @@ -0,0 +1,15 @@ +using DS.Module.Core.Data; +using DS.WMS.Core.Op.Entity.TaskInteraction; + +namespace DS.WMS.Core.Op.Dtos.TaskInteraction +{ + /// + /// 动作执行上下文 + /// + public class ActionExecutionContext + { + public BusinessTask Task { get; set; } + + + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/BusinessTaskMailAttachment.cs b/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/BusinessTaskAttachment.cs similarity index 79% rename from ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/BusinessTaskMailAttachment.cs rename to ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/BusinessTaskAttachment.cs index ea640308..15ba4385 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/BusinessTaskMailAttachment.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/BusinessTaskAttachment.cs @@ -5,8 +5,8 @@ namespace DS.WMS.Core.Op.Entity.TaskInteraction /// /// 任务邮件附件配置 /// - [SugarTable("business_task_mail_attachment", "任务邮件附件配置")] - public class BusinessTaskMailAttachment + [SugarTable("business_task_attachment", "任务邮件附件配置")] + public class BusinessTaskAttachment { /// /// 任务邮件配置ID diff --git a/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/BusinessTaskLog.cs b/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/BusinessTaskLog.cs index b5b60c41..94943572 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/BusinessTaskLog.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/BusinessTaskLog.cs @@ -105,6 +105,12 @@ namespace DS.WMS.Core.Op.Entity.TaskInteraction /// 审核 /// [Description("审核")] - Audit = 101 + Audit = 101, + + /// + /// 邮件服务 + /// + [Description("邮件服务")] + Mail = 201 } } diff --git a/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/BusinessTaskMail.cs b/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/BusinessTaskMail.cs index fc315b3c..8e4f869d 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/BusinessTaskMail.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/BusinessTaskMail.cs @@ -8,7 +8,7 @@ namespace DS.WMS.Core.Op.Entity.TaskInteraction /// 任务邮件发送配置 /// [SugarTable("business_task_mail", "任务邮件发送配置")] - public class BusinessTaskMail : BaseModelV2 + public class BusinessTaskMail : BaseOrgModelV2 { /// /// 任务类型 @@ -16,11 +16,11 @@ namespace DS.WMS.Core.Op.Entity.TaskInteraction [SugarColumn(ColumnDescription = "任务类型", IsNullable = false)] public TaskBaseTypeEnum TaskType { get; set; } - /// - /// 任务状态 - /// - [SugarColumn(ColumnDescription = "任务状态", IsNullable = false)] - public TaskStatusEnum TaskStatus { get; set; } + ///// + ///// 任务状态 + ///// + //[SugarColumn(ColumnDescription = "任务状态", IsNullable = false)] + //public TaskStatusEnum TaskStatus { get; set; } = TaskStatusEnum.Complete; /// /// 主题 @@ -41,10 +41,16 @@ namespace DS.WMS.Core.Op.Entity.TaskInteraction public string? CustomerName { get; set; } /// - /// 机构ID + /// 服务器设置ID + /// + [SugarColumn(ColumnDescription = "任务类型", IsNullable = false)] + public long ServerId { get; set; } + + /// + /// 服务器设置 /// - [SugarColumn(ColumnDescription = "机构ID", IsNullable = false)] - public long OrgId { get; set; } + [Navigate(NavigateType.OneToOne, nameof(ServerId))] + public BusinessTaskMailServer? Server { get; set; } /// /// 接收人设置 @@ -61,7 +67,7 @@ namespace DS.WMS.Core.Op.Entity.TaskInteraction /// /// 附件设置 /// - [Navigate(NavigateType.OneToMany, nameof(BusinessTaskMailAttachment.TaskMailId))] - public List? Attachments { get; set; } + [Navigate(NavigateType.OneToMany, nameof(BusinessTaskAttachment.TaskMailId))] + public List? Attachments { get; set; } } } diff --git a/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/BusinessTaskMailServer.cs b/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/BusinessTaskMailServer.cs new file mode 100644 index 00000000..28e5f08d --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/BusinessTaskMailServer.cs @@ -0,0 +1,42 @@ +using DS.Module.Core.Data; +using SqlSugar; + +namespace DS.WMS.Core.Op.Entity.TaskInteraction +{ + /// + /// 任务邮件服务器配置 + /// + [SugarTable("business_task_mail_server", "任务邮件服务器配置")] + public class BusinessTaskMailServer : BaseOrgModelV2 + { + /// + /// 服务器地址 + /// + [SugarColumn(ColumnDescription = "服务器地址", Length = 200, IsNullable = false)] + public string Server { get; set; } = string.Empty; + + /// + /// 端口号 + /// + [SugarColumn(ColumnDescription = "端口号")] + public int Port { get; set; } + + /// + /// 使用SSL连接 + /// + [SugarColumn(ColumnDescription = "使用SSL连接", DefaultValue = "1")] + public bool UseSSL { get; set; } = true; + + /// + /// 登录账号 + /// + [SugarColumn(ColumnDescription = "登录账号", Length = 200, IsNullable = true)] + public string? LoginName { get; set; } + + /// + /// 登录密码 + /// + [SugarColumn(ColumnDescription = "登录密码", Length = 200, IsNullable = true)] + public string? Password { get; set; } + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/IActionExecutor.cs b/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/IActionExecutor.cs new file mode 100644 index 00000000..c0f9a988 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/IActionExecutor.cs @@ -0,0 +1,17 @@ +using DS.WMS.Core.Op.Dtos.TaskInteraction; + +namespace DS.WMS.Core.Op.Interface.TaskInteraction +{ + /// + /// 动作执行器 + /// + public interface IActionExecutor + { + /// + /// 执行特定动作 + /// + /// + /// + Task ExecuteAsync(ActionExecutionContext context); + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/IActionManager.cs b/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/IActionManager.cs new file mode 100644 index 00000000..d204de7e --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/IActionManager.cs @@ -0,0 +1,25 @@ +using DS.Module.Core.Data; +using DS.WMS.Core.Op.Entity.TaskInteraction; + +namespace DS.WMS.Core.Op.Interface.TaskInteraction +{ + /// + /// 动作执行管理 + /// + public interface IActionManager + { + /// + /// 执行特定动作 + /// + /// 数据上下文 + /// + Task ExecuteAsync(TaskFlowDataContext dataContext); + + /// + /// 触发任务执行动作 + /// + /// 任务信息 + /// + Task TriggerAction(BusinessTask businessTask); + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/ITaskMailService.cs b/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/ITaskMailService.cs index f596b9cc..4e05522f 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/ITaskMailService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/ITaskMailService.cs @@ -1,9 +1,40 @@ -namespace DS.WMS.Core.Op.Interface.TaskInteraction +using DS.Module.Core; +using DS.Module.Core.Data; +using DS.WMS.Core.Op.Entity.TaskInteraction; + +namespace DS.WMS.Core.Op.Interface.TaskInteraction { /// /// 邮件配置服务定义 /// public interface ITaskMailService { + /// + /// 获取分页列表 + /// + /// + /// + Task>> GetListAsync(PageRequest request); + + /// + /// 详情 + /// + /// + /// + Task> GetAsync(long id); + + /// + /// 编辑 + /// + /// + /// + Task EditAsync(BusinessTaskMail taskMail); + + /// + /// 删除 + /// + /// + /// + Task DeleteAsync(IdModel model); } } diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionExecutor.cs b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionExecutor.cs new file mode 100644 index 00000000..81a503ef --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionExecutor.cs @@ -0,0 +1,45 @@ +using DS.Module.Core; +using DS.WMS.Core.Op.Entity.TaskInteraction; +using DS.WMS.Core.Op.Interface.TaskInteraction; +using Microsoft.Extensions.DependencyInjection; + +namespace DS.WMS.Core.Op.Method.TaskInteraction +{ + public class ActionExecutor : ServiceBase + { + //任务日志服务 + //readonly ITaskLogService LogService; + + /// + /// 初始化 + /// + /// + public ActionExecutor(IServiceProvider provider) : base(provider) + { + //LogService = provider.GetRequiredService(); + } + + ///// + ///// 执行特定任务类型的邮件服务 + ///// + ///// 任务 + ///// + ///// 为null + //public async Task ExecuteAsync(BusinessTask task) + //{ + // ArgumentNullException.ThrowIfNull(task, nameof(task)); + + // var list = await TenantDb.Queryable().Where(x => x.TaskType == task.TaskType && x.TaskStatus == task.TaskStatus) + // .Select(x => new + // { + // TemplateIds = x.Attachments.Select(x => x.TemplateId), + // x.Receiver, + // x.Sender, + // x.Title, + // x.Content + // }).ToListAsync(); + + + //} + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionManager.cs b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionManager.cs new file mode 100644 index 00000000..2858c429 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionManager.cs @@ -0,0 +1,69 @@ +using DS.Module.Core; +using DS.Module.Core.Data; +using DS.WMS.Core.Op.Entity.TaskInteraction; +using DS.WMS.Core.Op.Interface.TaskInteraction; +using DS.WMS.Core.TaskPlat; + +namespace DS.WMS.Core.Op.Method.TaskInteraction +{ + /// + /// 动作执行管理 + /// + public class ActionManager : ServiceBase, IActionManager + { + Dictionary ExecutorMappings; + + /// + /// 初始化 + /// + public ActionManager(IServiceProvider serviceProvider) : base(serviceProvider) + { + ExecutorMappings = new Dictionary(); + ExecutorMappings[TaskActionType.Mail] = new MailActionExecutor(); + } + + /// + /// 触发任务执行动作 + /// + /// 任务信息 + /// + public async Task TriggerAction(BusinessTask businessTask) + { + ArgumentNullException.ThrowIfNull(businessTask, nameof(businessTask)); + + //目前只限制任务完成才触发 + if (businessTask.TaskStatus != TaskStatusEnum.Complete) + return; + + // 执行自动化操作 + TaskFlowDataContext dataContext = new( + (TaskFlowDataNameConst.BusinessTask, businessTask) + ); + + TaskFlowRuner taskFlow = new(TenantDb, ServiceProvider); + await taskFlow.Run(businessTask.TaskType, businessTask.BusinessId, dataContext); + } + + public async Task ExecuteAsync(TaskFlowDataContext dataContext) + { + ArgumentNullException.ThrowIfNull(dataContext, nameof(dataContext)); + + } + } + + /// + /// 任务执行类型 + /// + public enum TaskActionType + { + /// + /// 后台任务 + /// + BackgroundWorker, + + /// + /// 邮件 + /// + Mail, + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailActionExecutor.cs b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailActionExecutor.cs new file mode 100644 index 00000000..4018a0e9 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailActionExecutor.cs @@ -0,0 +1,13 @@ +using DS.WMS.Core.Op.Dtos.TaskInteraction; +using DS.WMS.Core.Op.Interface.TaskInteraction; + +namespace DS.WMS.Core.Op.Method.TaskInteraction +{ + public class MailActionExecutor : IActionExecutor + { + public Task ExecuteAsync(ActionExecutionContext context) + { + throw new NotImplementedException(); + } + } +} 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 c5b1a325..afe1c01d 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 @@ -199,7 +199,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction if (((JObject)result.data)["ext"] is not JArray extArray || extArray.Count == 0) return []; - return extArray.Select(x => x["projectName"]?.Value() ?? string.Empty).ToArray(); + return extArray.Where(x => x["isYield"].Value()).Select(x => x["projectName"]?.Value() ?? string.Empty).ToArray(); } //public override async Task MarkerChangedAsync(MarkerChangedCallback callback) diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskMailService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskMailService.cs index 9150a6f8..76bbae11 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskMailService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskMailService.cs @@ -1,4 +1,5 @@ using DS.Module.Core; +using DS.Module.Core.Data; using DS.Module.Core.Extensions; using DS.WMS.Core.Op.Entity.TaskInteraction; using DS.WMS.Core.Op.Interface.TaskInteraction; @@ -30,36 +31,87 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction .Where(whereList).ToQueryPageAsync(request.PageCondition); } - ///// - ///// 编辑 - ///// - ///// - ///// - //public async Task EditAsync(BusinessTaskMail taskMail) - //{ - // try - // { + /// + /// 详情 + /// + /// + /// + public async Task> GetAsync(long id) + { + var entity = await TenantDb.Queryable().Includes(x => x.Receiver).Includes(x => x.Sender) + .Where(x => x.Id == id).FirstAsync(); + + return DataResult.Success(entity); + } + + /// + /// 编辑 + /// + /// + /// + public async Task EditAsync(BusinessTaskMail taskMail) + { + await TenantDb.Ado.BeginTranAsync(); + try + { + if (taskMail.Id == 0) + { + taskMail.Receiver ??= new(); + taskMail.Sender ??= new(); - // } - // catch (Exception ex) - // { - // await TenantDb.Ado.RollbackTranAsync(); - // await ex.LogAsync(Db); - // return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed)); - // } + taskMail = await TenantDb.InsertNav(taskMail).Include(x => x.Receiver).Include(x => x.Sender).ExecuteReturnEntityAsync(); + } + else + { + await TenantDb.UpdateNav(taskMail).Include(x => x.Receiver).Include(x => x.Sender).ExecuteCommandAsync(); + } - // if (taskMail.Id == 0) - // { - // taskMail.Receiver ??= new(); - // taskMail.Sender ??= new(); + if (taskMail.Attachments?.Count > 0) + { + var list = taskMail.Attachments.FindAll(x => x.TaskMailId == 0); + foreach (var item in list) + item.TaskMailId = taskMail.Id; + + await TenantDb.Deleteable().Where(x => x.TaskMailId == taskMail.Id).ExecuteCommandAsync(); + await TenantDb.Insertable(taskMail.Attachments).ExecuteCommandAsync(); + } + + await TenantDb.Ado.CommitTranAsync(); + return DataResult.Success; + } + catch (Exception ex) + { + await TenantDb.Ado.RollbackTranAsync(); + await ex.LogAsync(Db); + return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed)); + } + + } + + /// + /// 删除 + /// + /// + /// + public async Task DeleteAsync(IdModel model) + { + await TenantDb.Ado.BeginTranAsync(); + try + { + await TenantDb.DeleteNav(x => model.Ids.Contains(x.Id)) + .Include(x => x.Receiver).Include(x => x.Sender).Include(x => x.Attachments).ExecuteCommandAsync(); + + await TenantDb.Ado.CommitTranAsync(); + return DataResult.Success; + } + catch (Exception ex) + { + await TenantDb.Ado.RollbackTranAsync(); + await ex.LogAsync(Db); + return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed)); + } + } - // await TenantDb.InsertNav(taskMail).Include(x => x.Receiver).Include(x => x.Sender).ExecuteCommandAsync(); - - // } - // else - // { - // } - //} } } diff --git a/ds-wms-service/DS.WMS.Core/ServiceBase.cs b/ds-wms-service/DS.WMS.Core/ServiceBase.cs index a394423f..b38af8ac 100644 --- a/ds-wms-service/DS.WMS.Core/ServiceBase.cs +++ b/ds-wms-service/DS.WMS.Core/ServiceBase.cs @@ -12,6 +12,10 @@ namespace DS.WMS.Core /// public abstract class ServiceBase { + /// + /// 获取服务容器 + /// + protected IServiceProvider ServiceProvider { get; private set; } /// /// 获取用户相关信息 /// @@ -46,6 +50,7 @@ namespace DS.WMS.Core /// 服务提供程序 protected ServiceBase(IServiceProvider serviceProvider) { + ServiceProvider = serviceProvider; User = serviceProvider.GetRequiredService(); Db = serviceProvider.GetRequiredService(); SaasService = serviceProvider.GetRequiredService(); diff --git a/ds-wms-service/DS.WMS.OpApi/Controllers/SeaExportTaskController.cs b/ds-wms-service/DS.WMS.OpApi/Controllers/SeaExportTaskController.cs index 7c14fcfc..2f3fdfc9 100644 --- a/ds-wms-service/DS.WMS.OpApi/Controllers/SeaExportTaskController.cs +++ b/ds-wms-service/DS.WMS.OpApi/Controllers/SeaExportTaskController.cs @@ -1,6 +1,5 @@ using System.Net; using DS.Module.Core; -using DS.WMS.Core.Fee.Dtos; using DS.WMS.Core.Flow.Dtos; using DS.WMS.Core.Op.Dtos.TaskInteraction; using DS.WMS.Core.Op.Entity; diff --git a/ds-wms-service/DS.WMS.OpApi/Controllers/TaskMailController.cs b/ds-wms-service/DS.WMS.OpApi/Controllers/TaskMailController.cs new file mode 100644 index 00000000..a0a21775 --- /dev/null +++ b/ds-wms-service/DS.WMS.OpApi/Controllers/TaskMailController.cs @@ -0,0 +1,63 @@ +using DS.Module.Core; +using DS.WMS.Core.Op.Entity.TaskInteraction; +using DS.WMS.Core.Op.Interface.TaskInteraction; +using Microsoft.AspNetCore.Mvc; + +namespace DS.WMS.OpApi.Controllers +{ + /// + /// 任务邮件API + /// + public class TaskMailController : ApiController + { + readonly ITaskMailService service; + + /// + /// 构造函数 + /// + /// + public TaskMailController(ITaskMailService service) + { + this.service = service; + } + + /// + /// 获取分页列表 + /// + /// + /// + [HttpPost, Route("GetList")] + public async Task>> GetListAsync(PageRequest request) + { + return await service.GetListAsync(request); + } + + /// + /// 详情 + /// + /// ID + /// + [HttpGet, Route("Edit")] + public async Task>GetAsync(long id) + { + return await service.GetAsync(id); + } + + /// + /// 编辑 + /// + /// 邮件配置 + /// + [HttpPost, Route("Edit")] + public async Task EditAsync(BusinessTaskMail taskMail) + { + if (taskMail.Receiver == null) + return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskMailReceiverNotNull)); + + if (taskMail.Sender == null) + return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskMailSenderNotNull)); + + return await service.EditAsync(taskMail); + } + } +} From 10ac78498168a533df8c656f1631e1b2573df8dc Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Thu, 8 Aug 2024 11:26:01 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9BC=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E8=BD=AC=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 00e8624a..bf436333 100644 --- a/.gitignore +++ b/.gitignore @@ -68,3 +68,4 @@ LinkAttach /ds-wms-service/DS.WMS.ContainerManagementApi/Logs/internal-nlog.txt /ds-wms-service/DS.WMS.OpApi/TempFiles/S24080044 /ds-wms-service/DS.WMS.TaskApi/TaskEmailTemplate +/ds-wms-service/DS.WMS.Core/TaskPlat.zip From 5f1edc7fdfc5182debb7f8e63c22dad7d2d3f17a Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Thu, 8 Aug 2024 11:26:03 +0800 Subject: [PATCH 5/5] 1 --- .../DS.WMS.Core/TaskPlat/Method/TaskManageBCService.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBCService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBCService.cs index 985d6aed..18f17821 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBCService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBCService.cs @@ -1,6 +1,7 @@ using Amazon.Runtime.Internal.Util; using DS.Module.Core; using DS.Module.Core.Constants; +using DS.Module.Core.Data; using DS.Module.DjyServiceStatus; using DS.Module.SqlSugar; using DS.Module.UserModule; @@ -39,6 +40,7 @@ using System; using System.Security.Cryptography; using System.Text.Json.Nodes; using System.Text.RegularExpressions; +using DS.Module.Core.Helpers; namespace DS.WMS.Core.TaskPlat.Method {