diff --git a/ds-wms-service/DS.WMS.Core/TaskInteraction/Entity/BusinessTask.cs b/ds-wms-service/DS.WMS.Core/TaskInteraction/Entity/BusinessTask.cs index 3a35017a..18c95c7a 100644 --- a/ds-wms-service/DS.WMS.Core/TaskInteraction/Entity/BusinessTask.cs +++ b/ds-wms-service/DS.WMS.Core/TaskInteraction/Entity/BusinessTask.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; using SqlSugar; @@ -9,14 +10,8 @@ namespace DS.WMS.Core.TaskInteraction.Entity /// 业务任务交互表 /// [SugarTable("business_task", "业务任务交互表")] - public class BusinessTask + public class BusinessTask : BaseModelV2 { - /// - /// ID - /// - [SugarColumn(IsPrimaryKey = true)] - public long Id { get; set; } - /// /// 上级任务ID /// @@ -78,36 +73,6 @@ namespace DS.WMS.Core.TaskInteraction.Entity public long[] RecvUserIdArray => RecvUsers.IsNullOrEmpty() ? [] : RecvUsers.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray(); - /// - /// 创建人 - /// - [SugarColumn(ColumnDescription = "创建人", IsNullable = false)] - public long CreateBy { get; set; } - - /// - /// 创建时间 - /// - [SugarColumn(ColumnDescription = "创建时间", IsNullable = false)] - public DateTime CreateTime { get; set; } - - /// - /// 更新人 - /// - [SugarColumn(ColumnDescription = "更新人", IsNullable = true)] - public long? UpdateBy { get; set; } - - /// - /// 更新时间 - /// - [SugarColumn(ColumnDescription = "更新时间", IsNullable = true)] - public DateTime? UpdateTime { get; set; } - - /// - /// 审批驳回理由 - /// - [SugarColumn(ColumnDescription = "审批驳回理由", Length = 200, IsNullable = true)] - public string? RejectReason { get; set; } - /// /// 任务步骤 /// diff --git a/ds-wms-service/DS.WMS.Core/TaskInteraction/Interface/IMailTemplateService.cs b/ds-wms-service/DS.WMS.Core/TaskInteraction/Interface/IMailTemplateService.cs index 33213fab..7ce0895a 100644 --- a/ds-wms-service/DS.WMS.Core/TaskInteraction/Interface/IMailTemplateService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskInteraction/Interface/IMailTemplateService.cs @@ -86,6 +86,15 @@ namespace DS.WMS.Core.TaskInteraction.Interface /// Task SendAsync(MailDraft draft); + /// + /// 根据任务类型的默认配置创建草稿 + /// + /// 任务信息 + /// 模板数据 + /// 是否保存草稿 + /// + Task> CreateDraftAsync(BusinessTask task, MailTemplateModel? templateModel = null, bool saveDraft = false); + /// /// 根据模板配置创建草稿 /// diff --git a/ds-wms-service/DS.WMS.Core/TaskInteraction/Interface/ITaskLogService.cs b/ds-wms-service/DS.WMS.Core/TaskInteraction/Interface/ITaskLogService.cs index 663b8415..8fbe45b8 100644 --- a/ds-wms-service/DS.WMS.Core/TaskInteraction/Interface/ITaskLogService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskInteraction/Interface/ITaskLogService.cs @@ -34,6 +34,14 @@ namespace DS.WMS.Core.TaskInteraction.Interface /// Task WriteLogAsync(BusinessTask task, string? remark = null); + /// + /// 写入任务日志 + /// + /// 备注 + /// 任务 + /// + Task WriteLogAsync(string? remark = null, params BusinessTask[] tasks); + /// /// 写入任务日志 /// diff --git a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/FeeTaskService.cs b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/FeeTaskService.cs index 19f5580c..88d42385 100644 --- a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/FeeTaskService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/FeeTaskService.cs @@ -228,13 +228,13 @@ namespace DS.WMS.Core.TaskInteraction.Method task.UpdateBy = long.Parse(User.UserId); task.UpdateTime = DateTime.Now; - task.RejectReason = request.RejectReason; + task.Note = request.RejectReason; //更新当前任务状态 task.TaskStatus = request.TaskStatus; await TenantDb.Updateable(task).UpdateColumns(x => new { x.TaskStatus, - x.RejectReason, + x.Note, x.UpdateBy, x.UpdateTime }).ExecuteCommandAsync(); diff --git a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/MailTemplateService.cs b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/MailTemplateService.cs index 0237be65..6fd9e064 100644 --- a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/MailTemplateService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/MailTemplateService.cs @@ -15,11 +15,13 @@ using DS.WMS.Core.TaskInteraction.Interface; using Fasterflect; using HtmlAgilityPack; using Masuit.Tools; +using Masuit.Tools.Systems; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using RazorEngineCore; +using SqlSugar; namespace DS.WMS.Core.TaskInteraction.Method { @@ -578,11 +580,30 @@ namespace DS.WMS.Core.TaskInteraction.Method return await SendAsync(result.Data!); } + /// + /// 根据任务类型的默认配置创建草稿 + /// + /// 任务信息 + /// 模板数据 + /// 是否保存草稿 + /// + public async Task> CreateDraftAsync(BusinessTask task, MailTemplateModel? templateModel = null, bool saveDraft = false) + { + var mailConfig = await TenantDb.Queryable() + .Includes(x => x.Sender).Includes(x => x.Receivers).Includes(x => x.CC).Includes(x => x.Attachments) + .Where(x => SqlFunc.Subqueryable().Where(y => x.Id == y.MailId && y.TaskType == task.TaskType && y.IsDefault).Any()) + .FirstAsync(); + if (mailConfig == null) + return DataResult.Failed($"无法获取【{task.TaskType.GetDescription()}】的默认邮件模板配置"); + + return await CreateDraftAsync(task, mailConfig, templateModel, saveDraft); + } + /// /// 根据模板配置创建草稿 /// - /// 邮件配置 /// 任务信息 + /// 邮件配置 /// 模板数据 /// 是否保存草稿 /// diff --git a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/PreAlertTaskService.cs b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/PreAlertTaskService.cs index 943b5c4c..07ed55dc 100644 --- a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/PreAlertTaskService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/PreAlertTaskService.cs @@ -1,11 +1,11 @@ using DS.Module.Core; -using DS.WMS.Core.Flow.Entity; using DS.WMS.Core.Op.Entity; using DS.WMS.Core.TaskInteraction.Dtos; using DS.WMS.Core.TaskInteraction.Entity; using DS.WMS.Core.TaskInteraction.Interface; using DS.WMS.Core.TaskPlat.Dtos; using Masuit.Tools.Systems; +using Microsoft.Extensions.DependencyInjection; namespace DS.WMS.Core.TaskInteraction.Method { @@ -14,7 +14,8 @@ namespace DS.WMS.Core.TaskInteraction.Method /// public class PreAlertTaskService : TaskService, IPreAlertTaskService { - const TaskBaseTypeEnum TASK_TYPE = TaskBaseTypeEnum.PRE_ALERT; + IMailTemplateService mailTemplateService; + ITaskLogService logService; /// /// 初始化 @@ -22,6 +23,8 @@ namespace DS.WMS.Core.TaskInteraction.Method /// public PreAlertTaskService(IServiceProvider provider) : base(provider) { + mailTemplateService = provider.GetRequiredService(); + logService = provider.GetRequiredService(); } /// @@ -72,7 +75,9 @@ namespace DS.WMS.Core.TaskInteraction.Method s.Id, s.CustomerNo, s.CustomerId, - s.BLConfirmationId, + s.BLConfirmationId, //提单确认方 + s.AgentId, //国外代理 + s.IssueType, s.IssuingWay, s.MBLNO, s.ETD, @@ -123,7 +128,7 @@ namespace DS.WMS.Core.TaskInteraction.Method foreach (var task in taskList) { var order = orders.Find(s => s.Id == task.BusinessId); - var request2 = new TaskCreationRequest + var request2 = new TaskCreationRequest //委托单位PA { BusinessId = task.BusinessId, BusinessType = task.BusinessType, @@ -151,7 +156,7 @@ namespace DS.WMS.Core.TaskInteraction.Method if ((order.SourceName != "CIF-自揽货" && order.SourceDetailName != "WSL Member") || (order.SourceName != "CIF-自揽货" && order.SourceDetailName != "国外同行")) { - var request3 = new TaskCreationRequest + var request3 = new TaskCreationRequest //国外代理PA { BusinessId = task.BusinessId, BusinessType = task.BusinessType, @@ -180,7 +185,7 @@ namespace DS.WMS.Core.TaskInteraction.Method if (order.IssuingWay == "zd" && order.CustomerId != order.BLConfirmationId) { - var request4 = new TaskCreationRequest + var request4 = new TaskCreationRequest //提单确认方PA { BusinessId = task.BusinessId, BusinessType = task.BusinessType, @@ -209,6 +214,58 @@ namespace DS.WMS.Core.TaskInteraction.Method } await TenantDb.Fastest().BulkCopyAsync(subTaskList);//保存子任务 + var allTasks = taskList.Union(subTaskList).ToArray(); + await logService.WriteLogAsync(string.Empty, allTasks); + + var unionIds = orders.Select(x => x.Id).Union(bills.Select(x => x.Id)); //合并订单ID与分单ID + var opFiles = await TenantDb.Queryable().Where(x => unionIds.Contains(x.LinkId)) + .Select(x => new + { + x.LinkId, + x.TypeCode, + x.FileName, + x.FilePath + }).ToListAsync(); + List mailDrafts = []; + foreach (var task in subTaskList) + { + var draftResult = await mailTemplateService.CreateDraftAsync(task); + if (!draftResult.Succeeded) + { + await LogService.WriteLogAsync(task, "未能创建默认草稿,错误消息:" + draftResult.Message); + continue; + } + + draftResult.Data.TaskId = task.Id; + var order = orders.Find(x => x.Id == task.BusinessId); + string typeCode = string.Empty; + switch (order.IssueType) + { + case "正本": + typeCode = "OringinalBill_Mbl"; //正本提单扫描件 + break; + + case "SWB": + typeCode = "swb"; + break; + + case "EBL": + typeCode = "OringinalBill_Mbl"; + break; + } + var opFile = opFiles.Find(x => x.LinkId == order.Id && x.TypeCode == typeCode); + opFile ??= opFiles.Find(x => x.LinkId == order.Id && x.TypeCode == "format_sheet"); + + if (opFile == null) //获取不到订单附件则记录错误日志 + { + + } + + mailDrafts.Add(draftResult.Data); + } + + if (mailDrafts.Count > 0) + await TenantDb.InsertNav(mailDrafts).Include(x => x.Attaches).ExecuteCommandAsync(); if (useTransaction) await TenantDb.Ado.CommitTranAsync(); @@ -220,9 +277,6 @@ namespace DS.WMS.Core.TaskInteraction.Method if (useTransaction) await TenantDb.Ado.RollbackTranAsync(); - if (result.Data is FlowInstance instance) - await Db.Deleteable(instance).ExecuteCommandAsync(); - await ex.LogAsync(Db); return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed)); } diff --git a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/TaskLogService.cs b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/TaskLogService.cs index 10f59de6..a6284176 100644 --- a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/TaskLogService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/TaskLogService.cs @@ -72,28 +72,51 @@ namespace DS.WMS.Core.TaskInteraction.Method /// public async Task WriteLogAsync(BusinessTask task, string? remark = null) { - string userNames = string.Empty; - if (task.RecvUserIdArray?.Length > 0) + await WriteLogAsync(remark, task); + } + + /// + /// 写入任务日志 + /// + /// 备注 + /// 任务 + /// + public async Task WriteLogAsync(string? remark = null, params BusinessTask[] tasks) + { + var ids = tasks.SelectMany(x => x.RecvUserIdArray).Distinct(); + var list = await Db.Queryable().Where(x => ids.Contains(x.Id)).Select(x => new { - var list = await Db.Queryable().Where(x => task.RecvUserIdArray.Contains(x.Id)).Select( - x => x.UserName).ToListAsync(); - userNames = string.Join(",", list); - } + x.Id, + x.UserName + }).ToListAsync(); - BusinessTaskLog taskLog = new BusinessTaskLog + BusinessTaskLog[] logs = new BusinessTaskLog[tasks.Length]; + var dtNow = DateTime.Now; + for (int i = 0; i < tasks.Length; i++) { - ActionType = ActionType.Create, - BusinessId = task.BusinessId, - BusinessType = task.BusinessType, - CreateBy = long.Parse(User.UserId), - CreateTime = DateTime.Now, - RecvUsers = userNames, - TaskStatus = task.TaskStatus, - TaskType = task.TaskType, - Remark = remark - }; + var task = tasks[i]; + BusinessTaskLog taskLog = new() + { + ActionType = ActionType.Create, + BusinessId = task.BusinessId, + BusinessType = task.BusinessType, + CreateBy = UserId, + CreateTime = dtNow, + TaskStatus = task.TaskStatus, + TaskType = task.TaskType, + Remark = remark + }; - await WriteLogAsync(taskLog); + if (task.RecvUserIdArray?.Length > 0) + { + var userNames = list.Where(x => task.RecvUserIdArray.Contains(x.Id)).Select(x => x.UserName); + taskLog.RecvUsers = string.Join(",", userNames); + } + + logs[i] = taskLog; + } + + await WriteLogAsync(logs); } /// diff --git a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/TaskService.cs b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/TaskService.cs index 60c14e48..7f1f02ab 100644 --- a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/TaskService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/TaskService.cs @@ -345,9 +345,6 @@ namespace DS.WMS.Core.TaskInteraction.Method if (useTransaction) await TenantDb.Ado.RollbackTranAsync(); - if (result.Data is FlowInstance instance) - await Db.Deleteable(instance).ExecuteCommandAsync(); - await ex.LogAsync(Db); return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed)); } @@ -460,13 +457,13 @@ namespace DS.WMS.Core.TaskInteraction.Method task.UpdateBy = long.Parse(User.UserId); task.UpdateTime = DateTime.Now; - task.RejectReason = request.RejectReason; + task.Note = request.RejectReason; //更新当前任务状态 task.TaskStatus = request.TaskStatus; await TenantDb.Updateable(task).UpdateColumns(x => new { x.TaskStatus, - x.RejectReason, + x.Note, x.UpdateBy, x.UpdateTime }).ExecuteCommandAsync();