From cec4b05e5fe24fcf12a6a7b48c4fc56427e0408d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B5=87=E6=96=87=E9=BE=99?= Date: Thu, 15 Aug 2024 18:26:49 +0800 Subject: [PATCH] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E6=9D=BFbug?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TaskInteraction/ActionExecutionContext.cs | 3 ++ .../TaskInteraction/TaskCreationRequest.cs | 14 +++++- .../Entity/TaskInteraction/BusinessTaskLog.cs | 8 +++- .../TaskInteraction/MailTemplateModel.cs | 5 +-- .../Booking/BookingActionExecutor.cs | 20 ++++++--- .../Booking/EDIActionExecutor.cs | 4 +- .../Booking/MailActionExecutor.cs | 12 +++-- .../TaskInteraction/ActionManagerService.cs | 4 +- .../Op/Method/TaskInteraction/MailService.cs | 45 ++++++++++++------- .../Op/Method/TaskInteraction/TaskService.cs | 16 +++++-- .../Op/Templates/订舱委托.cshtml | 2 +- ds-wms-service/DS.WMS.Core/ServiceBase.cs | 1 + 12 files changed, 91 insertions(+), 43 deletions(-) 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 index 80928c35..b83c0a5f 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Dtos/TaskInteraction/ActionExecutionContext.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Dtos/TaskInteraction/ActionExecutionContext.cs @@ -1,4 +1,5 @@ using DS.WMS.Core.Op.Entity.TaskInteraction; +using DS.WMS.Core.Op.Interface.TaskInteraction; namespace DS.WMS.Core.Op.Dtos.TaskInteraction { @@ -7,6 +8,8 @@ namespace DS.WMS.Core.Op.Dtos.TaskInteraction /// public class ActionExecutionContext { + public IActionManagerService ActionManager { get; set; } + public BusinessTask TaskInfo { get; internal set; } public IServiceProvider ServiceProvider { get; internal set; } diff --git a/ds-wms-service/DS.WMS.Core/Op/Dtos/TaskInteraction/TaskCreationRequest.cs b/ds-wms-service/DS.WMS.Core/Op/Dtos/TaskInteraction/TaskCreationRequest.cs index 407bec4f..f8da14c8 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Dtos/TaskInteraction/TaskCreationRequest.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Dtos/TaskInteraction/TaskCreationRequest.cs @@ -1,4 +1,6 @@ -namespace DS.WMS.Core.Op.Dtos.TaskInteraction +using DS.Module.Core; + +namespace DS.WMS.Core.Op.Dtos.TaskInteraction { /// /// 任务台创建参数 @@ -24,5 +26,15 @@ /// 驳回审批理由 /// public string? RejectReason { get; set; } + + /// + /// 下一任务类型 + /// + public TaskBaseTypeEnum? NextType { get; set; } + + /// + /// 下一任务配置ID + /// + public long? NextId { get; set; } } } 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 f54f8126..84da8363 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 @@ -21,7 +21,7 @@ namespace DS.WMS.Core.Op.Entity.TaskInteraction /// 动作类型 /// [SugarColumn(ColumnDescription = "动作类型", IsNullable = false)] - public ActionType? ActionType { get; set; } + public ActionType ActionType { get; set; } /// /// 业务ID @@ -89,6 +89,12 @@ namespace DS.WMS.Core.Op.Entity.TaskInteraction /// public enum ActionType { + /// + /// 未指定 + /// + [Description("未指定")] + Unspecified = 0, + /// /// 新增 /// diff --git a/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/MailTemplateModel.cs b/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/MailTemplateModel.cs index 8cee738e..25883d5f 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/MailTemplateModel.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/MailTemplateModel.cs @@ -1,5 +1,4 @@ -using System.Collections.ObjectModel; -using System.Dynamic; +using System.Dynamic; namespace DS.WMS.Core.Op.Entity { @@ -41,7 +40,7 @@ namespace DS.WMS.Core.Op.Entity /// /// 主要数据项 /// - public dynamic Primary { get; set; } = new ExpandoObject(); + public dynamic? Primary { get; protected internal set; } } public class MailSender diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionExecutor/Booking/BookingActionExecutor.cs b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionExecutor/Booking/BookingActionExecutor.cs index b2a339ba..8e76d993 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionExecutor/Booking/BookingActionExecutor.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionExecutor/Booking/BookingActionExecutor.cs @@ -1,4 +1,5 @@ using DS.Module.Core; +using DS.Module.Core.Extensions; using DS.WMS.Core.Op.Dtos.TaskInteraction; using DS.WMS.Core.Op.Interface.TaskInteraction; using Masuit.Tools.Systems; @@ -11,8 +12,6 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction.ActionExecutor.Booking /// public class BookingActionExecutor : DefaultActionExecutor { - internal const TaskBaseTypeEnum Booking_TaskType = TaskBaseTypeEnum.WAIT_BOOKING; - /// /// 任务服务 /// @@ -30,9 +29,12 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction.ActionExecutor.Booking return Task.CompletedTask; } - protected async Task CreateTask(ActionExecutionContext context) + protected async Task CreateTaskIfNotExistAsync(ActionExecutionContext context) { - var result = await TaskService.Exists(context.TaskInfo.BusinessId, context.TaskInfo.BusinessType, Booking_TaskType); + if (!context.TaskInfo.NextType.HasValue) + return DataResult.Success; + + var result = await TaskService.Exists(context.TaskInfo.BusinessId, context.TaskInfo.BusinessType, context.TaskInfo.NextType.Value); //任务已存在,跳过创建步骤 if (result.Data) return DataResult.Success; @@ -41,22 +43,26 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction.ActionExecutor.Booking { BusinessId = context.TaskInfo.BusinessId, BusinessType = context.TaskInfo.BusinessType, - TaskTypeName = Booking_TaskType.ToString() + TaskTypeName = context.TaskInfo.NextType.Value.ToString(), + NextId = context.TaskInfo.NextId }); } protected async Task SetTaskComplete(ActionExecutionContext context) { + if (!context.TaskInfo.NextType.HasValue) + return; + var result = await TaskService.SetTaskStatusAsync(new TaskUpdateRequest { BusinessId = context.TaskInfo.BusinessId, BusinessType = context.TaskInfo.BusinessType, - TaskTypeName = Booking_TaskType.ToString(), + TaskTypeName = context.TaskInfo.NextType.Value.ToString(), TaskStatus = TaskStatusEnum.Complete, AutoCreateNext = true }); if (!result.Succeeded) - await LogService.WriteLogAsync(context.TaskInfo, $"未能设置任务【{Booking_TaskType.GetDescription()}】完成,返回结果:{result.Message}"); + await LogService.WriteLogAsync(context.TaskInfo, $"未能设置任务【{context.TaskInfo.NextType.Value.GetDescription()}】完成,返回结果:{result.Message}"); } } } diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionExecutor/Booking/EDIActionExecutor.cs b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionExecutor/Booking/EDIActionExecutor.cs index 42472b6f..442a9699 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionExecutor/Booking/EDIActionExecutor.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionExecutor/Booking/EDIActionExecutor.cs @@ -15,10 +15,10 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction.ActionExecutor.Booking public async override Task ExecuteAsync(ActionExecutionContext context) { await base.ExecuteAsync(context); - var result = await CreateTask(context); + var result = await CreateTaskIfNotExistAsync(context); if (!result.Succeeded) { - await LogService.WriteLogAsync(context.TaskInfo, $"创建任务【{Booking_TaskType.GetDescription()}】失败,返回结果:{result.Message}"); + await LogService.WriteLogAsync(context.TaskInfo, $"创建任务【{context.TaskInfo.NextType?.GetDescription()}】失败,返回结果:{result.Message}"); return; } diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionExecutor/Booking/MailActionExecutor.cs b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionExecutor/Booking/MailActionExecutor.cs index 87873c48..a8bb6f62 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionExecutor/Booking/MailActionExecutor.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionExecutor/Booking/MailActionExecutor.cs @@ -24,16 +24,14 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction.ActionExecutor.Booking public async override Task ExecuteAsync(ActionExecutionContext context) { await base.ExecuteAsync(context); - var result = await CreateTask(context); + var result = await CreateTaskIfNotExistAsync(context); if (!result.Succeeded) { - await LogService.WriteLogAsync(context.TaskInfo, $"创建任务【{Booking_TaskType.GetDescription()}】失败,返回结果:{result.Message}"); + await LogService.WriteLogAsync(context.TaskInfo, $"创建任务【{context.TaskInfo.NextType?.GetDescription()}】失败,返回结果:{result.Message}"); return; } var taskMailService = context.ServiceProvider.GetRequiredService(); - var opService = context.ServiceProvider.GetRequiredService(); - BusinessTaskMail? mailConfig = null; if (context.AdditionalData.TryGetValue(nameof(BusinessTaskMail) + "." + nameof(BusinessTaskMail.Id), out var id)) { @@ -62,14 +60,14 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction.ActionExecutor.Booking return; } - var result2 = opService.GetSeaExportInfo(context.TaskInfo.BusinessId.ToString()); - if (!result2.Succeeded || result2.Data == null) + var data = await context.ActionManager.GetBusinessDataAsync(context.TaskInfo.BusinessId, context.TaskInfo.BusinessType); + if (data == null) { await LogService.WriteLogAsync(context.TaskInfo, $"未能获取Id={context.TaskInfo.BusinessId} {context.TaskInfo.BusinessType.GetDescription()}的订单数据"); return; } - var model = new MailTemplateModel(result2.Data) + var model = new MailTemplateModel(data) { BusinessId = context.TaskInfo.BusinessId, BusinessType = context.TaskInfo.BusinessType, diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionManagerService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionManagerService.cs index df56027f..a3526e98 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionManagerService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionManagerService.cs @@ -28,6 +28,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction public ActionManagerService(IServiceProvider serviceProvider) : base(serviceProvider) { logService = serviceProvider.GetRequiredService(); + TenantDb.QueryFilter.Clear(); } /// @@ -167,6 +168,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction var context = new ActionExecutionContext { + ActionManager = this, TaskInfo = dataContext.GetOrDefault(TaskFlowDataNameConst.BusinessTask), ServiceProvider = ServiceProvider }; @@ -201,9 +203,9 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction return; } - await currentExecutor.ExecuteAsync(context); var logService = context.ServiceProvider.GetRequiredService(); await logService.WriteLogAsync(context.TaskInfo, $"开始运行后台任务({currentExecutor.GetType().FullName})..."); + await currentExecutor.ExecuteAsync(context); } public async Task TriggerTestAsync(TaskBaseTypeEnum taskType, long? id) diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailService.cs index 430b212b..bc0b8860 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailService.cs @@ -1,4 +1,5 @@ using System.Collections.Concurrent; +using System.DirectoryServices; using DS.Module.Core; using DS.Module.Core.Data; using DS.Module.PrintModule; @@ -9,6 +10,7 @@ using DS.WMS.Core.Op.Entity.TaskInteraction; using DS.WMS.Core.Op.Method.TaskInteraction.ActionExecutor; using DS.WMS.Core.Op.Method.TaskInteraction.ActionExecutor.Booking; using DS.WMS.Core.Sys.Entity; +using Fasterflect; using HtmlAgilityPack; using Masuit.Tools; using Microsoft.Extensions.Configuration; @@ -36,6 +38,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction public MailService(IServiceProvider provider) : base(provider) { config = provider.GetRequiredService(); + TenantDb.QueryFilter.Clear(); } static async Task RenderTemplateAsync(string name, string templateText, object model, IRazorEngine? razorEngine = null) @@ -82,6 +85,9 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction return DataResult.Failed($"未能获取订单({templateModel.BusinessId})数据"); //设置发件人 + if (mailConfig.Sender == null) + return DataResult.Failed("未设置发件人"); + long senderId = 0; if (mailConfig.Sender.IsSale) senderId = order.SaleId; @@ -98,28 +104,34 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction SignatureHtml = x.SignatureHtml }).FirstAsync(); if (templateModel.Sender == null) - return DataResult.Failed("未设置发件人"); + return DataResult.Failed("邮件模板未设置发件人"); var senderConfig = await TenantDb.Queryable().FirstAsync(x => x.CreateBy == senderId); if (senderConfig == null) return DataResult.Failed($"发件人用户:{templateModel.Sender.DisplayName} 未设置SMTP发件信息"); - //设置抄送人 - List ccIds = []; List ccList = []; - if (mailConfig.CC.IsSale) - ccIds.Add(order.SaleId); - else if (mailConfig.CC.IsOperator) - ccIds.Add(order.OperatorId); - else if (mailConfig.CC.IsCustomerService) - ccIds.Add(order.CustomerService); - else if (mailConfig.CC.IsVouchingClerk) - ccIds.Add(order.Doc); - - if (ccIds.Count > 0) - ccList = await Db.Queryable().Where(x => ccIds.Contains(x.Id)).Select(x => x.Email).ToListAsync(); + if (mailConfig.CC != null) + { + //设置抄送人 + List ccIds = []; + if (mailConfig.CC.IsSale) + ccIds.Add(order.SaleId); + else if (mailConfig.CC.IsOperator) + ccIds.Add(order.OperatorId); + else if (mailConfig.CC.IsCustomerService) + ccIds.Add(order.CustomerService); + else if (mailConfig.CC.IsVouchingClerk) + ccIds.Add(order.Doc); + + if (ccIds.Count > 0) + ccList = await Db.Queryable().Where(x => ccIds.Contains(x.Id)).Select(x => x.Email).ToListAsync(); + } //设置收件人 + if (mailConfig.Receiver == null) + return DataResult.Failed("邮件模板未设置收件人"); + List receiverTypes = []; if (mailConfig.Receiver.IsCarrier) receiverTypes.Add("carrier"); @@ -185,15 +197,16 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction string requestUrl = config["TaskMail:FileBaseUrl"] + config["TaskMail:SQLPrint"]; foreach (var item in mailConfig.Attachments) { + object? obj = PropertyExtensions.GetPropertyValue(templateModel, nameof(MailTemplateModel.Primary), Flags.InstancePublic); var req = new OpenPrintReq { - ParamJsonStr = JsonConvert.SerializeObject(templateModel.Primary), + ParamJsonStr = JsonConvert.SerializeObject(obj), PrintType = ((int)FileFormat.PDF).ToString(), TemplateId = item.TemplateId, TenantId = tenantId }; var reqResult = await Api.PostAsync(requestUrl, req); - if (!reqResult.Succeeded) + if (!reqResult.Data.Succeeded) return DataResult.Failed($"未能获取打印API生成的文件,请求地址:{requestUrl}"); string url = config["TaskMail:FileBaseUrl"] + @"/PrintTempFile/" + reqResult.Data.Data; diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskService.cs index 6d9e2561..076b1ebf 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskService.cs @@ -77,6 +77,8 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction FlowService = provider.GetRequiredService(); ActionService = provider.GetRequiredService(); OpService = provider.GetRequiredService(); + + TenantDb.QueryFilter.Clear(); } /// @@ -86,7 +88,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction /// public async Task GetNextTypeAsync(BusinessTask current) { - var order = OpService.GetSeaExportInfo(current.BusinessId.ToString()); + var order = await ActionService.GetBusinessDataAsync(current.BusinessId, current.BusinessType); TaskFlowRuner flowRuner = new(TenantDb, ServiceProvider); var result = await flowRuner.GetWorkFlowNextConfig(TaskBaseTypeEnum.WORK_FLOW_MAIN, new TaskFlowDataContext( (TaskFlowDataNameConst.Business, order) @@ -365,9 +367,13 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction TaskStatus = TaskStatusEnum.Create, RecvUsers = string.Join(',', info.Main.RecvUserInfoList.Select(x => x.RecvUserId)), CreateBy = long.Parse(User.UserId), - CreateTime = DateTime.Now + CreateTime = DateTime.Now, + NextType = request.NextType, + NextId = request.NextId }; - task.NextType = await GetNextTypeAsync(task); + if (!task.NextType.HasValue) + task.NextType = await GetNextTypeAsync(task); + await TenantDb.Insertable(task).ExecuteCommandAsync(); //审核任务需创建工作流 @@ -506,7 +512,8 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction BusinessId = request.BusinessId, BusinessType = request.BusinessType, TaskTypeName = task.NextType.ToString(), - RecvUserIdList = task.RecvUserIdArray + RecvUserIdList = task.RecvUserIdArray, + NextId = task.NextId }; result = await CreateTaskAsync(req, false); if (!result.Succeeded) @@ -638,6 +645,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction Remark = remark }); } + /// /// 获取指定类型的业务关联任务 /// diff --git a/ds-wms-service/DS.WMS.Core/Op/Templates/订舱委托.cshtml b/ds-wms-service/DS.WMS.Core/Op/Templates/订舱委托.cshtml index c1150d90..5e812f43 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Templates/订舱委托.cshtml +++ b/ds-wms-service/DS.WMS.Core/Op/Templates/订舱委托.cshtml @@ -27,7 +27,7 @@ *** Auto Email, please reply to all (delete sender Admin)!If only reply to sender, we will not be able to find and deal with it! *** - +
Dear @Model.Contacts
diff --git a/ds-wms-service/DS.WMS.Core/ServiceBase.cs b/ds-wms-service/DS.WMS.Core/ServiceBase.cs index b38af8ac..4bc4a734 100644 --- a/ds-wms-service/DS.WMS.Core/ServiceBase.cs +++ b/ds-wms-service/DS.WMS.Core/ServiceBase.cs @@ -1,4 +1,5 @@ using DS.Module.Core; +using DS.Module.Core.Data; using DS.Module.SqlSugar; using DS.Module.UserModule; using DS.WMS.Core.Flow.Entity;