邮件模板bug修复

usertest
嵇文龙 3 months ago
parent 9749aa9e70
commit cec4b05e5f

@ -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
/// </summary>
public class ActionExecutionContext
{
public IActionManagerService ActionManager { get; set; }
public BusinessTask TaskInfo { get; internal set; }
public IServiceProvider ServiceProvider { get; internal set; }

@ -1,4 +1,6 @@
namespace DS.WMS.Core.Op.Dtos.TaskInteraction
using DS.Module.Core;
namespace DS.WMS.Core.Op.Dtos.TaskInteraction
{
/// <summary>
/// 任务台创建参数
@ -24,5 +26,15 @@
/// 驳回审批理由
/// </summary>
public string? RejectReason { get; set; }
/// <summary>
/// 下一任务类型
/// </summary>
public TaskBaseTypeEnum? NextType { get; set; }
/// <summary>
/// 下一任务配置ID
/// </summary>
public long? NextId { get; set; }
}
}

@ -21,7 +21,7 @@ namespace DS.WMS.Core.Op.Entity.TaskInteraction
/// 动作类型
/// </summary>
[SugarColumn(ColumnDescription = "动作类型", IsNullable = false)]
public ActionType? ActionType { get; set; }
public ActionType ActionType { get; set; }
/// <summary>
/// 业务ID
@ -89,6 +89,12 @@ namespace DS.WMS.Core.Op.Entity.TaskInteraction
/// </summary>
public enum ActionType
{
/// <summary>
/// 未指定
/// </summary>
[Description("未指定")]
Unspecified = 0,
/// <summary>
/// 新增
/// </summary>

@ -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
/// <summary>
/// 主要数据项
/// </summary>
public dynamic Primary { get; set; } = new ExpandoObject();
public dynamic? Primary { get; protected internal set; }
}
public class MailSender

@ -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
/// </summary>
public class BookingActionExecutor : DefaultActionExecutor
{
internal const TaskBaseTypeEnum Booking_TaskType = TaskBaseTypeEnum.WAIT_BOOKING;
/// <summary>
/// 任务服务
/// </summary>
@ -30,9 +29,12 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction.ActionExecutor.Booking
return Task.CompletedTask;
}
protected async Task<DataResult> CreateTask(ActionExecutionContext context)
protected async Task<DataResult> 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}");
}
}
}

@ -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;
}

@ -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<ITaskMailService>();
var opService = context.ServiceProvider.GetRequiredService<ISeaExportService>();
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<SeaExportRes>(result2.Data)
var model = new MailTemplateModel<SeaExportRes>(data)
{
BusinessId = context.TaskInfo.BusinessId,
BusinessType = context.TaskInfo.BusinessType,

@ -28,6 +28,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
public ActionManagerService(IServiceProvider serviceProvider) : base(serviceProvider)
{
logService = serviceProvider.GetRequiredService<ITaskLogService>();
TenantDb.QueryFilter.Clear<IOrgId>();
}
/// <summary>
@ -167,6 +168,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
var context = new ActionExecutionContext
{
ActionManager = this,
TaskInfo = dataContext.GetOrDefault<BusinessTask>(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<ITaskLogService>();
await logService.WriteLogAsync(context.TaskInfo, $"开始运行后台任务({currentExecutor.GetType().FullName}...");
await currentExecutor.ExecuteAsync(context);
}
public async Task<DataResult> TriggerTestAsync(TaskBaseTypeEnum taskType, long? id)

@ -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<IConfiguration>();
TenantDb.QueryFilter.Clear<IOrgId>();
}
static async Task<string> 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,15 +104,17 @@ 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<CodeUserEmail>().FirstAsync(x => x.CreateBy == senderId);
if (senderConfig == null)
return DataResult.Failed($"发件人用户:{templateModel.Sender.DisplayName} 未设置SMTP发件信息");
List<string> ccList = [];
if (mailConfig.CC != null)
{
//设置抄送人
List<long> ccIds = [];
List<string> ccList = [];
if (mailConfig.CC.IsSale)
ccIds.Add(order.SaleId);
else if (mailConfig.CC.IsOperator)
@ -118,8 +126,12 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
if (ccIds.Count > 0)
ccList = await Db.Queryable<SysUser>().Where(x => ccIds.Contains(x.Id)).Select(x => x.Email).ToListAsync();
}
//设置收件人
if (mailConfig.Receiver == null)
return DataResult.Failed("邮件模板未设置收件人");
List<string> 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<PrintResult>(requestUrl, req);
if (!reqResult.Succeeded)
if (!reqResult.Data.Succeeded)
return DataResult.Failed($"未能获取打印API生成的文件请求地址{requestUrl}");
string url = config["TaskMail:FileBaseUrl"] + @"/PrintTempFile/" + reqResult.Data.Data;

@ -77,6 +77,8 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
FlowService = provider.GetRequiredService<IClientFlowInstanceService>();
ActionService = provider.GetRequiredService<IActionManagerService>();
OpService = provider.GetRequiredService<ISeaExportService>();
TenantDb.QueryFilter.Clear<IOrgId>();
}
/// <summary>
@ -86,7 +88,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
/// <returns></returns>
public async Task<TaskBaseTypeEnum?> 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
};
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
});
}
/// <summary>
/// 获取指定类型的业务关联任务
/// </summary>

@ -27,7 +27,7 @@
</style>
<span>*** 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! ***</span>
<br />
Dear @Model.Contacts
<div class="title">

@ -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;

Loading…
Cancel
Save