diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/TaskTransferMsgDto.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/TaskTransferMsgDto.cs new file mode 100644 index 00000000..989f9f2e --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/TaskTransferMsgDto.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.Core.TaskPlat.Dtos +{ + /// + /// 任务转发消息回执 + /// + public class TaskTransferMsgDto + { + /// + /// 执行日期 + /// + public DateTime ExcuteDate { get; set; } + + /// + /// 明细 + /// + public List Detail { get; set; } + } + + public class TaskTransferMsgDataDto + { + /// + /// 业务ID + /// + public long BusinessId { get; set; } + + /// + /// 提单号 + /// + public string MBlNo { get; set; } + + /// + /// 状态 + /// + public string Status { get; set; } + + /// + /// 消息 + /// + public string Message { get; set; } + } +} diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/POLContainerNotPickUp/ITaskPOLContainerNotPickUpService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/POLContainerNotPickUp/ITaskPOLContainerNotPickUpService.cs index 9e3e6ca9..baa939b1 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/POLContainerNotPickUp/ITaskPOLContainerNotPickUpService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/POLContainerNotPickUp/ITaskPOLContainerNotPickUpService.cs @@ -35,20 +35,20 @@ namespace DS.WMS.Core.TaskPlat.Interface /// 起运港未提箱任务主键 /// 邮件模板主键 /// 返回回执 - Task InnerSendEmailToCustomer(long taskPKId, long businessTaskMailId); + Task> InnerSendEmailToCustomer(long taskPKId, long businessTaskMailId); /// /// 发送邮件通知给客户(任务自动机调取) /// /// 数据上下文 /// 返回回执 - Task SendEmailToCustomerTask(TaskFlowDataContext dataContext); + Task> SendEmailToCustomerTask(TaskFlowDataContext dataContext); /// /// 手工发送邮件通知给客户 /// /// 起运港未提箱任务主键 /// 返回回执 - Task ManualSendEmailToCustomer(long taskPKId); + Task> ManualSendEmailToCustomer(long taskPKId); } } diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/POLContainerNotPickUp/TaskPOLContainerNotPickUpService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/POLContainerNotPickUp/TaskPOLContainerNotPickUpService.cs index 1674a4af..0d47e270 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/POLContainerNotPickUp/TaskPOLContainerNotPickUpService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/POLContainerNotPickUp/TaskPOLContainerNotPickUpService.cs @@ -130,7 +130,7 @@ namespace DS.WMS.Core.TaskPlat.Method /// 起运港未提箱主键 /// 邮件模板主键 /// 返回回执 - public async Task InnerSendEmailToCustomer(long taskPKId, long businessTaskMailId) + public async Task> InnerSendEmailToCustomer(long taskPKId, long businessTaskMailId) { /* 1、先匹配订单。这里可能关联的是拆票订单,如果是拆票订单需要所有拆票记录都要发邮件通知) @@ -153,23 +153,40 @@ namespace DS.WMS.Core.TaskPlat.Method { logger.LogInformation($"匹配订单信息失败 mblno={entity.MBL_NO},原因:{queryRlt.Message}"); - return DataResult.Failed($"匹配订单信息失败 mblno={entity.MBL_NO},原因:{queryRlt.Message}"); + return DataResult.Failed($"匹配订单信息失败 mblno={entity.MBL_NO},原因:{queryRlt.Message}"); } + var taskInfo = entity.Adapt(); + + BusinessTaskMail? mailConfig = _taskMailService.GetAsync(businessTaskMailId).GetAwaiter().GetResult().Data; + + if (mailConfig == null) + { + await _logService.WriteLogAsync(new Op.Dtos.TaskInteraction.TaskUpdateRequest + { + BusinessId = taskPKId, + BusinessType = BusinessType.OceanShippingExport, + AutoCreateNext = true, + TaskTypeName = TaskBaseTypeEnum.POL_CTN_NOT_PICKUP.ToString(), + + }, $"未能根据任务配置值获取邮件模板设置"); + + return DataResult.Failed("未能根据任务配置值获取邮件模板设置"); + } var orderInfo = queryRlt.Data; logger.LogInformation($"获取订单详情成功 bookid={orderInfo.currOrder.Id}"); DateTime nowDate = DateTime.Now; + List orderIdList = new List { orderInfo.currOrder.Id }; + + if (orderInfo.otherOrderList.Count > 0) + orderIdList.AddRange(orderInfo.otherOrderList.Select(t => t.Id).ToList()); + //如果是拆票需要处理,处理所以分票记录 if (orderInfo.currOrder.SplitOrMergeFlag == 1) { - List orderIdList = new List { orderInfo.currOrder.Id }; - - if (orderInfo.otherOrderList.Count > 0) - orderIdList.AddRange(orderInfo.otherOrderList.Select(t => t.Id).ToList()); - foreach (var id in orderIdList) { var taskAllocList = tenantDb.Queryable().Where(a => a.TaskId == taskPKId).ToList(); @@ -236,51 +253,59 @@ namespace DS.WMS.Core.TaskPlat.Method } } + TaskTransferMsgDto resultDto = new TaskTransferMsgDto { + ExcuteDate = nowDate, + Detail = new List() + }; - BusinessTaskMail? mailConfig = _taskMailService.GetAsync(businessTaskMailId).GetAwaiter().GetResult().Data; + Dictionary> dict = new Dictionary>(); - if (mailConfig == null) + foreach (var id in orderIdList) { - await _logService.WriteLogAsync(new Op.Dtos.TaskInteraction.TaskUpdateRequest + TaskTransferMsgDataDto detail = new TaskTransferMsgDataDto { + BusinessId = id, + }; + + var model = new MailTemplateModel(taskInfo) { - BusinessId = taskPKId, + BusinessId = id, BusinessType = BusinessType.OceanShippingExport, - AutoCreateNext = true, - TaskTypeName = TaskBaseTypeEnum.POL_CTN_NOT_PICKUP.ToString(), + }; - }, $"未能根据任务配置值获取邮件模板设置"); + MailService mailService = new MailService(serviceProvider); + var result = await mailService.SendAsync(mailConfig, model); - return DataResult.Failed("未能根据任务配置值获取邮件模板设置"); - } - var taskInfo = entity.Adapt(); + if (!result.Succeeded) + { + await _logService.WriteLogAsync(new Op.Dtos.TaskInteraction.TaskUpdateRequest + { + BusinessId = taskPKId, + BusinessType = BusinessType.OceanShippingExport, + AutoCreateNext = true, + TaskTypeName = TaskBaseTypeEnum.POL_CTN_NOT_PICKUP.ToString(), - var model = new MailTemplateModel(taskInfo) - { - BusinessId = orderInfo.currOrder.Id, - BusinessType = BusinessType.OceanShippingExport, - }; + }, result.Message); - MailService mailService = new MailService(serviceProvider); - var result = await mailService.SendAsync(mailConfig, model); + //return DataResult.Failed(result.Message); + } - if (!result.Succeeded) - { - await _logService.WriteLogAsync(new Op.Dtos.TaskInteraction.TaskUpdateRequest - { - BusinessId = taskPKId, - BusinessType = BusinessType.OceanShippingExport, - AutoCreateNext = true, - TaskTypeName = TaskBaseTypeEnum.POL_CTN_NOT_PICKUP.ToString(), + detail.Status = result.Succeeded ? "SUCC" : "FAILURE"; + detail.Message = result.Message; + detail.MBlNo = entity.MBL_NO; - }, result.Message); + resultDto.Detail.Add(detail); - return DataResult.Failed(result.Message); + dict.Add(id, new Tuple(result.Succeeded, result.Message, entity.MBL_NO)); } - //发送完邮件,自动标记任务状态为完成 - await SetTaskStatus(taskPKId, TaskBaseTypeEnum.POL_CTN_NOT_PICKUP, TaskStatusEnum.Complete, DateTime.Now, null); + //如果存在失败记录,不能置完成状态 + if (!dict.Any(t => !t.Value.Item1)) + { + //发送完邮件,自动标记任务状态为完成 + await SetTaskStatus(taskPKId, TaskBaseTypeEnum.POL_CTN_NOT_PICKUP, TaskStatusEnum.Complete, DateTime.Now, null); + } - return DataResult.Successed(result.Message); + return DataResult.Success(resultDto); } #endregion @@ -290,7 +315,7 @@ namespace DS.WMS.Core.TaskPlat.Method /// /// 数据上下文 /// 返回回执 - public async Task SendEmailToCustomerTask(TaskFlowDataContext dataContext) + public async Task> SendEmailToCustomerTask(TaskFlowDataContext dataContext) { var taskPKId = dataContext.Get>(TaskFlowDataNameConst.TaskPKId) ?? throw new ArgumentException($"缺少参数:{nameof(TaskFlowDataNameConst.TaskPKId)}"); var businessTaskMailId = dataContext.Get>($"{nameof(BusinessTaskMail)}.{nameof(BusinessTaskMail.Id)}") ?? throw new ArgumentException(); @@ -305,7 +330,7 @@ namespace DS.WMS.Core.TaskPlat.Method }, $"缺少参数:{nameof(BusinessTaskMail)}.{nameof(BusinessTaskMail.Id)}"); - return DataResult.Failed($"缺少参数:{nameof(BusinessTaskMail)}.{nameof(BusinessTaskMail.Id)}"); + return DataResult.Failed($"缺少参数:{nameof(BusinessTaskMail)}.{nameof(BusinessTaskMail.Id)}"); } return await InnerSendEmailToCustomer(taskPKId, businessTaskMailId); @@ -318,7 +343,7 @@ namespace DS.WMS.Core.TaskPlat.Method /// /// 起运港未提箱任务主键 /// 返回回执 - public async Task ManualSendEmailToCustomer(long taskPKId) + public async Task> ManualSendEmailToCustomer(long taskPKId) { var paramConfig = _configService.GetConfig("POLContainerNotPickUpEmailTemplateID", long.Parse(user.TenantId), false).GetAwaiter().GetResult()?.Data?.Value; @@ -330,7 +355,7 @@ namespace DS.WMS.Core.TaskPlat.Method } else { - return DataResult.Failed($"缺少系统参数参数:起运港未提箱邮件模板ID-POLContainerNotPickUpEmailTemplateID"); + return DataResult.Failed($"缺少系统参数参数:起运港未提箱邮件模板ID-POLContainerNotPickUpEmailTemplateID"); } return await InnerSendEmailToCustomer(taskPKId, businessTaskMailId);