|
|
@ -39,35 +39,38 @@ using DS.WMS.Core.Op.EDI;
|
|
|
|
using DS.WMS.Core.Sys.Dtos;
|
|
|
|
using DS.WMS.Core.Sys.Dtos;
|
|
|
|
using DS.WMS.Core.Code.Dtos;
|
|
|
|
using DS.WMS.Core.Code.Dtos;
|
|
|
|
using DS.Module.Core.Data;
|
|
|
|
using DS.Module.Core.Data;
|
|
|
|
|
|
|
|
using DS.WMS.Core.Op.Entity.TaskInteraction;
|
|
|
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
using DS.WMS.Core.Op.Interface.TaskInteraction;
|
|
|
|
|
|
|
|
using DS.WMS.Core.Op.Method.TaskInteraction;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 截止时间变更
|
|
|
|
/// 截止时间变更
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public class TaskManageCutDateChangeService: ITaskManageCutDateChangeService
|
|
|
|
public class TaskManageCutDateChangeService: TaskManageBaseService<TaskManageCutDateChangeService>,ITaskManageCutDateChangeService
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
|
|
|
|
private readonly ISqlSugarClient db;
|
|
|
|
|
|
|
|
private readonly IUser user;
|
|
|
|
|
|
|
|
private readonly ISaasDbService saasService;
|
|
|
|
|
|
|
|
private readonly ISeaExportService _seaExportService;
|
|
|
|
private readonly ISeaExportService _seaExportService;
|
|
|
|
private readonly IConfigService _configService;
|
|
|
|
private readonly IConfigService _configService;
|
|
|
|
private readonly IUserService _userService;
|
|
|
|
private readonly IUserService _userService;
|
|
|
|
|
|
|
|
private readonly ITaskLogService _logService;
|
|
|
|
private static readonly NLog.Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
private readonly ITaskMailService _taskMailService;
|
|
|
|
|
|
|
|
private readonly ITaskAllocationService _taskAllocationService;
|
|
|
|
const string EMAIL_API_URL = "email_api_url";
|
|
|
|
|
|
|
|
|
|
|
|
public TaskManageCutDateChangeService(IUser user, ILogger<TaskManageCutDateChangeService> logger,
|
|
|
|
public TaskManageCutDateChangeService(IServiceProvider serviceProvider)
|
|
|
|
ISaasDbService saasDbService,
|
|
|
|
|
|
|
|
IServiceProvider serviceProvider,
|
|
|
|
|
|
|
|
IWebHostEnvironment environment) : base(user, logger, saasDbService, serviceProvider, environment)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
user = serviceProvider.GetRequiredService<IUser>();
|
|
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
|
|
_seaExportService = serviceProvider.GetRequiredService<ISeaExportService>();
|
|
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
|
|
_configService = serviceProvider.GetRequiredService<IConfigService>();
|
|
|
|
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
|
|
|
|
_userService = serviceProvider.GetRequiredService<IUserService>();
|
|
|
|
_seaExportService = _serviceProvider.GetRequiredService<ISeaExportService>();
|
|
|
|
_taskMailService = serviceProvider.GetRequiredService<ITaskMailService>();
|
|
|
|
_configService = _serviceProvider.GetRequiredService<IConfigService>();
|
|
|
|
_taskAllocationService = serviceProvider.GetRequiredService<ITaskAllocationService>();
|
|
|
|
_userService = _serviceProvider.GetRequiredService<IUserService>();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region 通过任务主键获取截止时间变更详情
|
|
|
|
#region 通过任务主键获取截止时间变更详情
|
|
|
@ -80,7 +83,7 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
{
|
|
|
|
{
|
|
|
|
List<TaskCutDateChangeShowDto> list = new List<TaskCutDateChangeShowDto>();
|
|
|
|
List<TaskCutDateChangeShowDto> list = new List<TaskCutDateChangeShowDto>();
|
|
|
|
|
|
|
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
|
|
|
|
//任务不考虑OrgId,这里去掉
|
|
|
|
//任务不考虑OrgId,这里去掉
|
|
|
|
tenantDb.QueryFilter.Clear<IOrgId>();
|
|
|
|
tenantDb.QueryFilter.Clear<IOrgId>();
|
|
|
|
|
|
|
|
|
|
|
@ -89,7 +92,7 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
.Where((a, b) => a.Id == taskPKId)
|
|
|
|
.Where((a, b) => a.Id == taskPKId)
|
|
|
|
.Select((a, b) => new { Base = a, Cut = b })
|
|
|
|
.Select((a, b) => new { Base = a, Cut = b })
|
|
|
|
.ToListAsync();
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
//任务主键{taskPkId}无法获取业务信息
|
|
|
|
//任务主键{taskPkId}无法获取业务信息
|
|
|
|
if (queryList.Count == 0)
|
|
|
|
if (queryList.Count == 0)
|
|
|
|
throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskBaseInfoFromTaskIdNull)), taskPKId));
|
|
|
|
throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskBaseInfoFromTaskIdNull)), taskPKId));
|
|
|
@ -99,7 +102,7 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
var detailList = await tenantDb.Queryable<TaskCutDateChangeDetailInfo>()
|
|
|
|
var detailList = await tenantDb.Queryable<TaskCutDateChangeDetailInfo>()
|
|
|
|
.Where(a => parentIdList.Contains(a.P_ID)).ToListAsync();
|
|
|
|
.Where(a => parentIdList.Contains(a.P_ID)).ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
if (detailList.Count > 0)
|
|
|
|
if (queryList.Count > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
list = detailList.OrderBy(p => p.MBL_NO).Select(p =>
|
|
|
|
list = detailList.OrderBy(p => p.MBL_NO).Select(p =>
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -127,7 +130,7 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
SeaExportOrderExtension orderInfo = null;
|
|
|
|
SeaExportOrderExtension orderInfo = null;
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
|
|
|
|
//任务不考虑OrgId,这里去掉
|
|
|
|
//任务不考虑OrgId,这里去掉
|
|
|
|
tenantDb.QueryFilter.Clear<IOrgId>();
|
|
|
|
tenantDb.QueryFilter.Clear<IOrgId>();
|
|
|
|
|
|
|
|
|
|
|
@ -198,7 +201,7 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"taskPKId={taskPKId} 检索截止时间变更订舱记录 处理异常,原因:{ex.Message}");
|
|
|
|
logger.LogError($"taskPKId={taskPKId} 检索截止时间变更订舱记录 处理异常,原因:{ex.Message}");
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult<SeaExportOrderExtension>.FailedData(orderInfo,$"检索失败,原因:{ex.Message}", MultiLanguageConst.Operation_Failed);
|
|
|
|
return DataResult<SeaExportOrderExtension>.FailedData(orderInfo,$"检索失败,原因:{ex.Message}", MultiLanguageConst.Operation_Failed);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -235,14 +238,14 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
var slotRlt = UpdateBookingSlotCutDate(taskPKId, orderInfo);
|
|
|
|
var slotRlt = UpdateBookingSlotCutDate(taskPKId, orderInfo);
|
|
|
|
|
|
|
|
|
|
|
|
//如果没有配置批量,则按单票发送邮件
|
|
|
|
//如果没有配置批量,则按单票发送邮件
|
|
|
|
var rlt = await SendEmailToCustomer(taskPKId);
|
|
|
|
//var rlt = await SendEmailToCustomer(taskPKId);
|
|
|
|
|
|
|
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"taskPKId={taskPKId} 推送邮件完成,结果:{JsonConvert.SerializeObject(rlt)}");
|
|
|
|
//logger.LogInformation($"taskPKId={taskPKId} 推送邮件完成,结果:{JsonConvert.SerializeObject(rlt)}");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(Exception ex)
|
|
|
|
catch(Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"taskPKId={taskPKId} 自动更新订单的截单日期并转发失败异常,原因:{ex.Message}");
|
|
|
|
//Logger.Log(NLog.LogLevel.Info, $"taskPKId={taskPKId} 自动更新订单的截单日期并转发失败异常,原因:{ex.Message}");
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult.Failed( $"自动更新订单的截单日期并转发失败,原因:{ex.Message}", MultiLanguageConst.Operation_Failed);
|
|
|
|
return DataResult.Failed( $"自动更新订单的截单日期并转发失败,原因:{ex.Message}", MultiLanguageConst.Operation_Failed);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -260,7 +263,7 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
private async Task<DataResult> UpdateBookingOrderCutDate(long taskPKId, SeaExportOrderExtension orderInfo)
|
|
|
|
private async Task<DataResult> UpdateBookingOrderCutDate(long taskPKId, SeaExportOrderExtension orderInfo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
|
|
|
|
//任务不考虑OrgId,这里去掉
|
|
|
|
//任务不考虑OrgId,这里去掉
|
|
|
|
tenantDb.QueryFilter.Clear<IOrgId>();
|
|
|
|
tenantDb.QueryFilter.Clear<IOrgId>();
|
|
|
|
|
|
|
|
|
|
|
@ -287,7 +290,7 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
if (orderInfo.otherOrderList.Count > 0)
|
|
|
|
if (orderInfo.otherOrderList.Count > 0)
|
|
|
|
ids.AddRange(orderInfo.otherOrderList.Select(a => a.Id).ToList());
|
|
|
|
ids.AddRange(orderInfo.otherOrderList.Select(a => a.Id).ToList());
|
|
|
|
|
|
|
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"截止时间变更主键{taskPKId} MBLNO={cutDetail.MBL_NO} 检索海运出口订单匹配到拆票信息 ids={string.Join(",", ids.ToArray())}");
|
|
|
|
//Logger.Log(NLog.LogLevel.Info, $"截止时间变更主键{taskPKId} MBLNO={cutDetail.MBL_NO} 检索海运出口订单匹配到拆票信息 ids={string.Join(",", ids.ToArray())}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var id in ids)
|
|
|
|
foreach (var id in ids)
|
|
|
@ -325,13 +328,13 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
it.CloseDocDate
|
|
|
|
it.CloseDocDate
|
|
|
|
}).ExecuteCommand();
|
|
|
|
}).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"截止时间变更主键{taskPKId} id={id} mblno={bookingInfo.MBLNO} 更新订舱完毕 详情 {doBuilder.ToString()}");
|
|
|
|
//Logger.Log(NLog.LogLevel.Info, $"截止时间变更主键{taskPKId} id={id} mblno={bookingInfo.MBLNO} 更新订舱完毕 详情 {doBuilder.ToString()}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(Exception ex)
|
|
|
|
catch(Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"taskPKId={taskPKId} 自动更新订单的截单日期更新订舱异常,原因:{ex.Message}");
|
|
|
|
//Logger.Log(NLog.LogLevel.Info, $"taskPKId={taskPKId} 自动更新订单的截单日期更新订舱异常,原因:{ex.Message}");
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult.Failed($"自动更新订单的截单日期更新订舱,原因:{ex.Message}", MultiLanguageConst.Operation_Failed);
|
|
|
|
return DataResult.Failed($"自动更新订单的截单日期更新订舱,原因:{ex.Message}", MultiLanguageConst.Operation_Failed);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -349,7 +352,7 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
private async Task<DataResult> UpdateBookingSlotCutDate(long taskPKId, SeaExportOrderExtension orderInfo)
|
|
|
|
private async Task<DataResult> UpdateBookingSlotCutDate(long taskPKId, SeaExportOrderExtension orderInfo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
|
|
|
|
//任务不考虑OrgId,这里去掉
|
|
|
|
//任务不考虑OrgId,这里去掉
|
|
|
|
tenantDb.QueryFilter.Clear<IOrgId>();
|
|
|
|
tenantDb.QueryFilter.Clear<IOrgId>();
|
|
|
|
|
|
|
|
|
|
|
@ -410,13 +413,13 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
it.ManifestCutDate
|
|
|
|
it.ManifestCutDate
|
|
|
|
}).ExecuteCommand();
|
|
|
|
}).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"截止时间变更主键{taskPKId} id={cutBase.Id} mblno={slotOrder.SlotBookingNo} 更新舱位完毕 详情 {doBuilder.ToString()}");
|
|
|
|
//Logger.Log(NLog.LogLevel.Info, $"截止时间变更主键{taskPKId} id={cutBase.Id} mblno={slotOrder.SlotBookingNo} 更新舱位完毕 详情 {doBuilder.ToString()}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"taskPKId={taskPKId} 自动更新订单的截单日期更新舱位异常,原因:{ex.Message}");
|
|
|
|
//Logger.Log(NLog.LogLevel.Info, $"taskPKId={taskPKId} 自动更新订单的截单日期更新舱位异常,原因:{ex.Message}");
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult.Failed($"自动更新订单的截单日期更新舱位,原因:{ex.Message}", MultiLanguageConst.Operation_Failed);
|
|
|
|
return DataResult.Failed($"自动更新订单的截单日期更新舱位,原因:{ex.Message}", MultiLanguageConst.Operation_Failed);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -426,475 +429,286 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 发送邮件通知给客户
|
|
|
|
#region 发送邮件通知给客户
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 发送邮件通知给客户
|
|
|
|
/// 发送邮件通知给客户
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="taskPKId">截止时间变更主键</param>
|
|
|
|
/// <param name="taskPKId">起运港未提箱主键</param>
|
|
|
|
|
|
|
|
/// <param name="businessTaskMailId">邮件模板主键</param>
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
public async Task<DataResult> SendEmailToCustomer(long taskPKId)
|
|
|
|
public async Task<DataResult<TaskTransferMsgDto>> InnerSendEmailToCustomer(long taskPKId, long businessTaskMailId)
|
|
|
|
{
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 生成并转发通知邮件
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 生成并转发通知邮件
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
|
|
|
/// <param name="bookingOrderList"></param>
|
|
|
|
|
|
|
|
/// <param name="bookingContactList"></param>
|
|
|
|
|
|
|
|
/// <param name="taskBaskInfo"></param>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
[NonAction]
|
|
|
|
|
|
|
|
private async Task<TaskManageOrderResultDto> GenerateSendEmail(TaskCutDateChangeInfo model, List<TaskCutDateChangeDetailInfo> rowList, List<SeaExportRes> bookingOrderList, List<BusinessOrderContactRes> bookingContactList)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
/*
|
|
|
|
|
|
|
|
1、先匹配订单。这里可能关联的是拆票订单,如果是拆票订单需要所有拆票记录都要发邮件通知)
|
|
|
|
try
|
|
|
|
2、有订单,调取任务规则补全相关人(如果当票已经有了人员表记录 task_base_allocation则不再处理人员)
|
|
|
|
{
|
|
|
|
3、调取发送模板。
|
|
|
|
//TO 邮件接收人
|
|
|
|
4、填充模板数据。
|
|
|
|
string toEmail = string.Empty;
|
|
|
|
5、发送邮件。
|
|
|
|
//订舱OP的邮箱
|
|
|
|
6、成功后置任务为完成状态。
|
|
|
|
string opEmail = string.Empty;
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
//去重客户联系人的邮箱
|
|
|
|
|
|
|
|
toEmail = string.Join(";", bookingContactList.Select(x => x.Email.Trim()).Distinct().ToArray());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<string> opEmailList = new List<string>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UserViewModel opUserInfo = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bookingOrderList.ForEach(bk =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//获取操作OP的邮箱
|
|
|
|
|
|
|
|
if (bk.OperatorId > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var opUser = _userService.GetUserInfo(bk.OperatorId.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (opUser.Succeeded && opUser.Data != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (opUserInfo == null)
|
|
|
|
|
|
|
|
opUserInfo = opUser.Data;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(opUserInfo.Email))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
opEmailList.Add(opUserInfo.Email.Trim());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"id={bk.Id} mblno={bk.MBLNO} 获取操作OP的邮箱,opEmail={opEmail} opid={bk.OperatorId} name={opUserInfo.UserName}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"id={bk.Id} mblno={bk.MBLNO} 获取操作OP的邮箱失败,opEmail={opUserInfo.Email} opid={bk.OperatorId} name={opUserInfo.UserName}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"id={bk.Id} mblno={bk.MBLNO} 检索操作OP信息失败,opid={bk.OperatorId} name={opUserInfo.UserName}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取客服的邮箱
|
|
|
|
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
|
|
|
|
if (bk.CustomerService > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var opUser = _userService.GetUserInfo(bk.CustomerService.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (opUser.Succeeded && opUser.Data != null)
|
|
|
|
var entity = tenantDb.Queryable<TaskCutDateChangeInfo>().Filter(null, true).First(a => a.TASK_ID == taskPKId);
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(opUser.Data.Email))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
opEmailList.Add(opUser.Data.Email.Trim());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"id={bk.Id} mblno={bk.MBLNO} 获取客服的邮箱,opEmail={opEmail} opid={bk.CustomerService} name={opUser.Data.UserName}");
|
|
|
|
var baseInfo = tenantDb.Queryable<TaskBaseInfo>().Filter(null, true).First(a => a.Id == taskPKId);
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"id={bk.Id} mblno={bk.MBLNO} 获取客服的邮箱失败,opEmail={opUser.Data.Email} opid={bk.CustomerService} name={opUser.Data.UserName}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"id={bk.Id} mblno={bk.MBLNO} 检索客服信息失败,opid={bk.CustomerService} name={opUser.Data.UserName}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
if (opEmailList.Count > 0)
|
|
|
|
|
|
|
|
opEmail = string.Join(";", opEmailList.Distinct().ToArray());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string emailTitle = $"{model.MBL_NO} Cut-off Details {model.VESSEL}/{model.VOYNO}/";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (model.PORTLOAD_AREA.Equals("NORTH_PORT", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
emailTitle = $"{model.MBL_NO} 截止时间变更 {model.VESSEL}/{model.VOYNO}/";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////提取当前公共邮箱的配置
|
|
|
|
var queryRlt = await _seaExportService.SearchOrderInfo(entity.MBL_NO);
|
|
|
|
//DjyUserMailAccount publicMailAccount = _djyUserMailAccount.AsQueryable().Filter(null, true).First(x => x.TenantId == UserManager.TENANT_ID && x.ShowName == "PublicSend"
|
|
|
|
|
|
|
|
// && x.SmtpPort > 0 && x.SmtpServer != null && x.SmtpServer != "");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Logger.Log(NLog.LogLevel.Info, $"提取当前公共邮箱的配置完成,id={publicMailAccount.Id}");
|
|
|
|
if (!queryRlt.Succeeded)
|
|
|
|
|
|
|
|
|
|
|
|
//if (publicMailAccount == null)
|
|
|
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
// throw Oops.Oh($"提取公共邮箱配置失败,请在用户邮箱账号管理增加配置显示名为PublicSend或者配置个人邮箱");
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////获取邮件模板
|
|
|
|
|
|
|
|
//var printTemplate = _repPrintTemplate.AsQueryable().Filter(null, true).First(x => x.CateCode.Contains("for_information_cutoff_detail") && x.TenantId == UserManager.TENANT_ID);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if (printTemplate == null)
|
|
|
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
// throw Oops.Bah(BookingErrorCode.BOOK115);
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CodeUserEmailRes publicMailAccount = new CodeUserEmailRes();
|
|
|
|
|
|
|
|
//读取邮件模板并填充数据
|
|
|
|
|
|
|
|
string emailHtml = "";//await GenerateSendEmailHtml(model, rowList, bookingOrderList, "", opUserInfo, user.TenantName).GetAwaiter().GetResult();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EmailApiUserDefinedDto emailApiUserDefinedDto = new EmailApiUserDefinedDto
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
SendTo = toEmail,
|
|
|
|
|
|
|
|
//CCTo = opEmail,
|
|
|
|
|
|
|
|
Title = emailTitle,
|
|
|
|
|
|
|
|
Body = emailHtml,
|
|
|
|
|
|
|
|
Account = publicMailAccount.MailAccount?.Trim(),
|
|
|
|
|
|
|
|
Password = publicMailAccount.Password?.Trim(),
|
|
|
|
|
|
|
|
Server = publicMailAccount.SmtpServer?.Trim(),
|
|
|
|
|
|
|
|
Port = publicMailAccount.SmtpPort.HasValue ? publicMailAccount.SmtpPort.Value : 465,
|
|
|
|
|
|
|
|
UseSSL = publicMailAccount.SmtpSSL.HasValue ? publicMailAccount.SmtpSSL.Value : true,
|
|
|
|
|
|
|
|
Attaches = new List<AttachesInfo>()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//如果配置了租户参数(AUTO_TRANS_EMAIL_OP_CCTO-自动转发是否默认抄送操作=ENABLE)发送邮件时自动抄送操作
|
|
|
|
|
|
|
|
//DjyTenantParamValueOutput paramConfig = _djyTenantParamService.GetParaCodeWithValue(new[] { "AUTO_TRANS_EMAIL_OP_CCTO" }).GetAwaiter().GetResult().FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if (paramConfig != null && paramConfig.ParaValue.Equals("ENABLE", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
// emailApiUserDefinedDto.CCTo = opEmail;
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"生成请求邮件参数,结果:{JsonConvert.SerializeObject(emailApiUserDefinedDto)}");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//推送邮件
|
|
|
|
|
|
|
|
var emailRlt = await PushEmail(emailApiUserDefinedDto);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"推送邮件完成,结果:{JsonConvert.SerializeObject(emailRlt)}");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (emailRlt.Succeeded)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
result.succ = true;
|
|
|
|
|
|
|
|
result.msg = "成功";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
result.succ = false;
|
|
|
|
|
|
|
|
result.msg = emailRlt.Message;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//new EmailNoticeHelper().SendEmailNotice($"taskid={model.TASK_ID} 截止时间变更 转发通知邮件失败", $"taskid={model.TASK_ID} 转发通知邮件失败,原因:{emailRlt.msg}", App.Configuration["EmailNoticeDefaultUser"].GetUserEmailList());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
result.succ = false;
|
|
|
|
logger.LogInformation($"匹配订单信息失败 mblno={entity.MBL_NO},原因:{queryRlt.Message}");
|
|
|
|
result.msg = $"失败,原因:{ex.Message}";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//new EmailNoticeHelper().SendEmailNotice($"taskid={model.TASK_ID} 截止时间变更 转发通知邮件失败", $"taskid={model.TASK_ID} 转发通知邮件失败,原因:{ex.Message}", App.Configuration["EmailNoticeDefaultUser"].GetUserEmailList());
|
|
|
|
return DataResult<TaskTransferMsgDto>.Failed($"匹配订单信息失败 mblno={entity.MBL_NO},原因:{queryRlt.Message}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
var taskInfo = entity.Adapt<TaskCutDateChangeShowDto>();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 通过邮件模板生成HTML
|
|
|
|
BusinessTaskMail? mailConfig = _taskMailService.GetAsync(businessTaskMailId).GetAwaiter().GetResult().Data;
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 通过邮件模板生成HTML
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="model">截止时间变更详情</param>
|
|
|
|
|
|
|
|
/// <param name="seaExportRes">海运出口详情</param>
|
|
|
|
|
|
|
|
/// <param name="filePath">文件路径</param>
|
|
|
|
|
|
|
|
/// <param name="opUserInfo">相关操作OP</param>
|
|
|
|
|
|
|
|
/// <param name="tenantName">租户全称</param>
|
|
|
|
|
|
|
|
/// <returns>返回HTML字符串(邮件正文)</returns>
|
|
|
|
|
|
|
|
[NonAction]
|
|
|
|
|
|
|
|
private async Task<string> GenerateSendEmailHtml(TaskCutDateChangeInfo model, List<TaskCutDateChangeDetailInfo> rowList, SeaExportRes seaExportRes,
|
|
|
|
|
|
|
|
string filePath, SysUser opUserInfo, string tenantName,string fileAbsPath)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string result = string.Empty;
|
|
|
|
|
|
|
|
string baseHtml = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
if (mailConfig == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//var opt = App.GetOptions<PrintTemplateOptions>();
|
|
|
|
await _logService.WriteLogAsync(new Op.Dtos.TaskInteraction.TaskUpdateRequest
|
|
|
|
//var dirAbs = opt.basePath;
|
|
|
|
{
|
|
|
|
//if (string.IsNullOrEmpty(dirAbs))
|
|
|
|
BusinessId = taskPKId,
|
|
|
|
//{
|
|
|
|
BusinessType = BusinessType.OceanShippingExport,
|
|
|
|
// dirAbs = App.WebHostEnvironment.WebRootPath;
|
|
|
|
AutoCreateNext = true,
|
|
|
|
//}
|
|
|
|
TaskTypeName = TaskBaseTypeEnum.CUT_MODIFY.ToString(),
|
|
|
|
|
|
|
|
|
|
|
|
//var fileAbsPath = Path.Combine(dirAbs, filePath);
|
|
|
|
}, $"未能根据任务配置值获取邮件模板设置");
|
|
|
|
//_logger.LogInformation($"查找模板文件:{fileAbsPath}");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if (!File.Exists(fileAbsPath))
|
|
|
|
return DataResult<TaskTransferMsgDto>.Failed("未能根据任务配置值获取邮件模板设置");
|
|
|
|
//{
|
|
|
|
}
|
|
|
|
// throw Oops.Bah(BookingErrorCode.BOOK115);
|
|
|
|
var orderInfo = queryRlt.Data;
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
baseHtml = File.ReadAllText(fileAbsPath);
|
|
|
|
logger.LogInformation($"获取订单详情成功 bookid={orderInfo.currOrder.Id}");
|
|
|
|
|
|
|
|
|
|
|
|
if (opUserInfo != null && !string.IsNullOrWhiteSpace(opUserInfo.UserName))
|
|
|
|
DateTime nowDate = DateTime.Now;
|
|
|
|
{
|
|
|
|
|
|
|
|
baseHtml = baseHtml.Replace("#opname#", opUserInfo.UserName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
baseHtml = baseHtml.Replace("#opname#", "操作");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (opUserInfo != null && !string.IsNullOrWhiteSpace(opUserInfo.Email))
|
|
|
|
List<long> orderIdList = new List<long> { orderInfo.currOrder.Id };
|
|
|
|
{
|
|
|
|
|
|
|
|
baseHtml = baseHtml.Replace("#opemail#", opUserInfo.Email);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
baseHtml = baseHtml.Replace("#opemail#", "");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (opUserInfo != null && !string.IsNullOrWhiteSpace(opUserInfo.Phone))
|
|
|
|
if (orderInfo.otherOrderList != null && orderInfo.otherOrderList.Count > 0)
|
|
|
|
{
|
|
|
|
orderIdList.AddRange(orderInfo.otherOrderList.Select(t => t.Id).ToList());
|
|
|
|
baseHtml = baseHtml.Replace("#optel#", opUserInfo.Phone);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (opUserInfo != null && !string.IsNullOrWhiteSpace(opUserInfo.Tel))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
baseHtml = baseHtml.Replace("#optel#", opUserInfo.Tel);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
baseHtml = baseHtml.Replace("#optel#", "");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(model.MBL_NO))
|
|
|
|
//如果是拆票需要处理,处理所以分票记录
|
|
|
|
{
|
|
|
|
if (orderInfo.currOrder.SplitOrMergeFlag == 1)
|
|
|
|
baseHtml = baseHtml.Replace("#BillNo#", model.MBL_NO);
|
|
|
|
{
|
|
|
|
}
|
|
|
|
bool isHasAlloc = false;
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
baseHtml = baseHtml.Replace("#BillNo#", "");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(model.VESSEL))
|
|
|
|
foreach (var id in orderIdList)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string s = $"{model.VESSEL}/{model.VOYNO}";
|
|
|
|
var taskAllocList = tenantDb.Queryable<TaskBaseAllocation>().Where(a => a.TaskId == taskPKId).ToList();
|
|
|
|
baseHtml = baseHtml.Replace("#VesselVoyno#", s);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
baseHtml = baseHtml.Replace("#VesselVoyno#", "");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var detailInfo = rowList.FirstOrDefault();
|
|
|
|
var searchAllotUserRlt = _taskAllocationService.GetAllotUserBySeaExportId(TaskBaseTypeEnum.CUT_MODIFY, id, new TaskFlowDataContext()).GetAwaiter().GetResult();
|
|
|
|
|
|
|
|
|
|
|
|
if (detailInfo.SI_CUTOFF.HasValue)
|
|
|
|
if (searchAllotUserRlt.Succeeded && searchAllotUserRlt.Data?.Count > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
baseHtml = baseHtml.Replace("#SICutDate#", detailInfo.SI_CUTOFF.Value.ToString("yyyy-MM-dd HH:mm"));
|
|
|
|
isHasAlloc = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
baseHtml = baseHtml.Replace("#SICutDate#", "");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (detailInfo.VGM_CUT.HasValue)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
baseHtml = baseHtml.Replace("#VGMCutDate#", detailInfo.VGM_CUT.Value.ToString("yyyy-MM-dd HH:mm"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
baseHtml = baseHtml.Replace("#VGMCutDate#", "");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (detailInfo.CY_CUTOFF.HasValue)
|
|
|
|
var addUserList = searchAllotUserRlt.Data.GroupJoin(taskAllocList, l => l.RecvUserId, r => r.UserId, (l, r) =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
baseHtml = baseHtml.Replace("#CYCutDate#", detailInfo.CY_CUTOFF.Value.ToString("yyyy-MM-dd HH:mm"));
|
|
|
|
if (r.ToList().Count == 0)
|
|
|
|
}
|
|
|
|
return new { add = true, obl = l };
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
baseHtml = baseHtml.Replace("#CYCutDate#", "");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (detailInfo.VOUCHER_CUT_DATE.HasValue)
|
|
|
|
return new { add = false, obl = l };
|
|
|
|
{
|
|
|
|
}).Where(a => a.add).Select(a => a.obl).ToList();
|
|
|
|
baseHtml = baseHtml.Replace("#VoucherCutDate#", detailInfo.VOUCHER_CUT_DATE.Value.ToString("yyyy-MM-dd HH:mm"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
baseHtml = baseHtml.Replace("#VoucherCutDate#", "");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (detailInfo.CY_OPEN.HasValue)
|
|
|
|
if (addUserList.Count > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
baseHtml = baseHtml.Replace("#CYOpenDate#", detailInfo.CY_OPEN.Value.ToString("yyyy-MM-dd"));
|
|
|
|
//写入
|
|
|
|
}
|
|
|
|
addUserList.ForEach(b =>
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var alloc = new TaskBaseAllocation
|
|
|
|
baseHtml = baseHtml.Replace("#CYOpenDate#", "");
|
|
|
|
{
|
|
|
|
|
|
|
|
Status = baseInfo.STATUS,
|
|
|
|
|
|
|
|
StatusName = baseInfo.STATUS_NAME,
|
|
|
|
|
|
|
|
TaskId = taskPKId,
|
|
|
|
|
|
|
|
StatusTime = nowDate,
|
|
|
|
|
|
|
|
UserId = b.RecvUserId,
|
|
|
|
|
|
|
|
UserName = b.RecvUserName
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tenantDb.Insertable<TaskBaseAllocation>(alloc).ExecuteCommand();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(detailInfo.REASON))
|
|
|
|
if (isHasAlloc && baseInfo.IS_PUBLIC == 1)
|
|
|
|
{
|
|
|
|
|
|
|
|
baseHtml = baseHtml.Replace("#Reason#", model.REASON);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
baseHtml = baseHtml.Replace("#Reason#", "");
|
|
|
|
await tenantDb.Updateable<TaskBaseInfo>(baseInfo).UpdateColumns(x => new
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
x.IS_PUBLIC
|
|
|
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var taskAllocList = tenantDb.Queryable<TaskBaseAllocation>().Where(a => a.TaskId == taskPKId).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(tenantName))
|
|
|
|
if (taskAllocList.Count == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
baseHtml = baseHtml.Replace("#TenantCompanyName#", tenantName);
|
|
|
|
var searchAllotUserRlt = _taskAllocationService.GetAllotUserBySeaExportId(TaskBaseTypeEnum.CUT_MODIFY, orderInfo.currOrder.Id, new TaskFlowDataContext()).GetAwaiter().GetResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
baseHtml = baseHtml.Replace("#TenantCompanyName#", "");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HtmlDocument html = new HtmlDocument();
|
|
|
|
if (searchAllotUserRlt.Succeeded && searchAllotUserRlt.Data?.Count > 0)
|
|
|
|
html.LoadHtml(baseHtml);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var tableNode = html.DocumentNode.SelectSingleNode(".//table[@id='show-table']");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (model.PORTLOAD_AREA.Equals("SOUTH_PORT", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (tableNode != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
StringBuilder tableBuilder = new StringBuilder();
|
|
|
|
//写入
|
|
|
|
|
|
|
|
searchAllotUserRlt.Data.ForEach(b =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var alloc = new TaskBaseAllocation
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Status = baseInfo.STATUS,
|
|
|
|
|
|
|
|
StatusName = baseInfo.STATUS_NAME,
|
|
|
|
|
|
|
|
TaskId = taskPKId,
|
|
|
|
|
|
|
|
StatusTime = nowDate,
|
|
|
|
|
|
|
|
UserId = b.RecvUserId,
|
|
|
|
|
|
|
|
UserName = b.RecvUserName
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tenantDb.Insertable<TaskBaseAllocation>(alloc).ExecuteCommand();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < rowList.Count; i++)
|
|
|
|
if (baseInfo.IS_PUBLIC == 1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
tableBuilder.Append($"<tr><td>{rowList[i].MBL_NO}</td><td>{rowList[i].CONTA_NO}</td><td>{rowList[i].LOAD_PORT}</td><td>{(rowList[i].ETB.HasValue ? rowList[i].ETB.Value.ToString("yyyy-MM-dd HH:mm") : "")}</td><td>{(rowList[i].ETD.HasValue ? rowList[i].ETD.Value.ToString("yyyy-MM-dd HH:mm") : "")}</td></tr>");
|
|
|
|
baseInfo.IS_PUBLIC = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//生成From Vessel的table列表
|
|
|
|
await tenantDb.Updateable<TaskBaseInfo>(baseInfo).UpdateColumns(x => new
|
|
|
|
tableNode.ChildNodes.Add(HtmlNode.CreateNode(tableBuilder.ToString()));
|
|
|
|
{
|
|
|
|
|
|
|
|
x.IS_PUBLIC
|
|
|
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
}
|
|
|
|
{
|
|
|
|
|
|
|
|
var southPNodes = html.DocumentNode.SelectNodes(".//p[@class='south_port']");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var node in southPNodes)
|
|
|
|
TaskTransferMsgDto resultDto = new TaskTransferMsgDto
|
|
|
|
{
|
|
|
|
{
|
|
|
|
node.Remove();
|
|
|
|
ExcuteDate = nowDate,
|
|
|
|
}
|
|
|
|
Detail = new List<TaskTransferMsgDataDto>()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
tableNode.RemoveAllChildren();
|
|
|
|
Dictionary<long, Tuple<bool, string, string>> dict = new Dictionary<long, Tuple<bool, string, string>>();
|
|
|
|
|
|
|
|
|
|
|
|
var colArg = new string[] { "Shipment Number", "Vessel - voyage", "样单截止时间 SI Cut Off", "开港时间 CY Open", "截港时间 CY cut off", "舱单-入港清单截止时间", "MDGF提交截止时间 - 危险品货物", "船代VGM截止时间", "海关放行截止时间(Customs Clearance Deadline)" };
|
|
|
|
foreach (var id in orderIdList)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
TaskTransferMsgDataDto detail = new TaskTransferMsgDataDto
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
BusinessId = id,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
tableNode.ChildNodes.Add(HtmlNode.CreateNode($"<tr><th style=\"text-align: left;\">{(string.Join("</th><th style=\"text-align: left;\">", colArg))}</th></tr>"));
|
|
|
|
var model = new MailTemplateModel<TaskCutDateChangeShowDto>(taskInfo)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
BusinessId = id,
|
|
|
|
|
|
|
|
BusinessType = BusinessType.OceanShippingExport,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder tableBuilder = new StringBuilder();
|
|
|
|
MailService mailService = new MailService(serviceProvider);
|
|
|
|
|
|
|
|
var result = await mailService.SendAsync(mailConfig, model);
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < rowList.Count; i++)
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await _logService.WriteLogAsync(new Op.Dtos.TaskInteraction.TaskUpdateRequest
|
|
|
|
{
|
|
|
|
{
|
|
|
|
tableBuilder.Append($"<tr><td>{rowList[i].MBL_NO}</td>");
|
|
|
|
BusinessId = taskPKId,
|
|
|
|
tableBuilder.Append($"<td>{($"{rowList[i].VESSEL}/{rowList[i].VOYNO}")}</td>");
|
|
|
|
BusinessType = BusinessType.OceanShippingExport,
|
|
|
|
tableBuilder.Append($"<td>{(rowList[i].SI_CUTOFF.HasValue ? rowList[i].SI_CUTOFF.Value.ToString("yyyy-MM-dd HH:mm") : rowList[i].SI_CUTOFF_TXT)}</td>");
|
|
|
|
AutoCreateNext = true,
|
|
|
|
tableBuilder.Append($"<td>{(rowList[i].CY_OPEN.HasValue ? rowList[i].CY_OPEN.Value.ToString("yyyy-MM-dd HH:mm") : rowList[i].CY_OPEN_TXT)}</td>");
|
|
|
|
TaskTypeName = TaskBaseTypeEnum.CUT_MODIFY.ToString(),
|
|
|
|
tableBuilder.Append($"<td>{(rowList[i].CY_CUTOFF.HasValue ? rowList[i].CY_CUTOFF.Value.ToString("yyyy-MM-dd HH:mm") : rowList[i].CY_CUTOFF_TXT)}</td>");
|
|
|
|
|
|
|
|
tableBuilder.Append($"<td>{(rowList[i].MANIFEST_CUT.HasValue ? rowList[i].MANIFEST_CUT.Value.ToString("yyyy-MM-dd HH:mm") : rowList[i].MANIFEST_CUT_TXT)}</td>");
|
|
|
|
|
|
|
|
tableBuilder.Append($"<td>{(rowList[i].MDGF_CUT.HasValue ? rowList[i].MDGF_CUT.Value.ToString("yyyy-MM-dd HH:mm") : rowList[i].MDGF_CUT_TXT)}</td>");
|
|
|
|
|
|
|
|
tableBuilder.Append($"<td>{(rowList[i].VGM_CUT.HasValue ? rowList[i].VGM_CUT.Value.ToString("yyyy-MM-dd HH:mm") : rowList[i].VGM_CUT_TXT)}</td>");
|
|
|
|
|
|
|
|
tableBuilder.Append($"<td>{(rowList[i].CLOSING_DATE.HasValue ? rowList[i].CLOSING_DATE.Value.ToString("yyyy-MM-dd HH:mm") : rowList[i].CLOSING_DATE_TXT)}</td>");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tableBuilder.Append("</tr>");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//生成From Vessel的table列表
|
|
|
|
}, result.Message);
|
|
|
|
tableNode.ChildNodes.Add(HtmlNode.CreateNode(tableBuilder.ToString()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//return DataResult.Failed(result.Message);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
result = html.DocumentNode.OuterHtml;
|
|
|
|
detail.Status = result.Succeeded ? "SUCC" : "FAILURE";
|
|
|
|
|
|
|
|
detail.Message = result.Message;
|
|
|
|
|
|
|
|
detail.MBlNo = entity.MBL_NO;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resultDto.Detail.Add(detail);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dict.Add(id, new Tuple<bool, string, string>(result.Succeeded, result.Message, entity.MBL_NO));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
|
|
|
|
|
|
//如果存在失败记录,不能置完成状态
|
|
|
|
|
|
|
|
if (!dict.Any(t => !t.Value.Item1))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
entity.IS_TRANSFER_USER = true;
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"生成截止时间变更转发邮件正文失败,原因:{ex.Message}");
|
|
|
|
entity.LST_TRANSFER_USER_DATE = DateTime.Now;
|
|
|
|
|
|
|
|
entity.LST_STATUS = "SUCC";
|
|
|
|
|
|
|
|
entity.LST_STATUS_NAME = "发送成功";
|
|
|
|
|
|
|
|
|
|
|
|
//提单号 {0} 生成截止时间变更转发邮件正文失败,原因:{1}
|
|
|
|
await tenantDb.Updateable<TaskCutDateChangeInfo>(entity).UpdateColumns(x => new
|
|
|
|
throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskBaseCutDateTransmitGenerateEmailFail)), model.MBL_NO, ex.Message));
|
|
|
|
{
|
|
|
|
|
|
|
|
x.IS_TRANSFER_USER,
|
|
|
|
|
|
|
|
x.LST_TRANSFER_USER_DATE,
|
|
|
|
|
|
|
|
x.LST_STATUS,
|
|
|
|
|
|
|
|
x.LST_STATUS_NAME
|
|
|
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//发送完邮件,自动标记任务状态为完成
|
|
|
|
|
|
|
|
await SetTaskStatus(taskPKId, TaskBaseTypeEnum.CUT_MODIFY, TaskStatusEnum.Complete, DateTime.Now, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
return DataResult<TaskTransferMsgDto>.Success(resultDto);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 推送邮件
|
|
|
|
#region 发送邮件通知给客户(任务自动机调取)
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 推送邮件
|
|
|
|
/// 发送邮件通知给客户(任务自动机调取)
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="emailApiUserDefinedDto">自定义邮件详情</param>
|
|
|
|
/// <param name="dataContext">数据上下文</param>
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
private async Task<DataResult<string>> PushEmail(EmailApiUserDefinedDto emailApiUserDefinedDto)
|
|
|
|
public async Task<DataResult<TaskTransferMsgDto>> SendEmailToCustomerTask(TaskFlowDataContext dataContext)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
List<EmailApiUserDefinedDto> emailList = new List<EmailApiUserDefinedDto>();
|
|
|
|
var taskPKId = dataContext.Get<long>(TaskFlowDataNameConst.TaskPKId);
|
|
|
|
|
|
|
|
if (taskPKId == 0)
|
|
|
|
var emailUrl = _configService.GetConfig(EMAIL_API_URL, long.Parse(user.TenantId), false).GetAwaiter().GetResult()?.Data?.Value;
|
|
|
|
throw new ArgumentException($"缺少参数:{nameof(TaskFlowDataNameConst.TaskPKId)}");
|
|
|
|
|
|
|
|
|
|
|
|
if (emailUrl == null)
|
|
|
|
var businessTaskMailId = dataContext.Get<long>($"{nameof(BusinessTaskMail)}.{nameof(BusinessTaskMail.Id)}");
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.CurrTenantEmailApiUrlNull)));
|
|
|
|
if (businessTaskMailId == 0)
|
|
|
|
|
|
|
|
throw new ArgumentException($"缺少参数:{nameof(BusinessTaskMail)}.{nameof(BusinessTaskMail.Id)}");
|
|
|
|
|
|
|
|
|
|
|
|
emailList.Add(emailApiUserDefinedDto);
|
|
|
|
if (businessTaskMailId == 0)
|
|
|
|
|
|
|
|
|
|
|
|
DateTime bDate = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string res = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var jsonBody = JsonConvert.SerializeObject(emailList, Formatting.Indented, new JsonSerializerSettings
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
NullValueHandling = NullValueHandling.Ignore
|
|
|
|
await _logService.WriteLogAsync(new Op.Dtos.TaskInteraction.TaskUpdateRequest
|
|
|
|
});
|
|
|
|
{
|
|
|
|
|
|
|
|
BusinessId = taskPKId,
|
|
|
|
|
|
|
|
BusinessType = BusinessType.OceanShippingExport,
|
|
|
|
|
|
|
|
AutoCreateNext = true,
|
|
|
|
|
|
|
|
TaskTypeName = TaskBaseTypeEnum.CUT_MODIFY.ToString(),
|
|
|
|
|
|
|
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"发送邮件请求:{jsonBody}");
|
|
|
|
}, $"缺少参数:{nameof(BusinessTaskMail)}.{nameof(BusinessTaskMail.Id)}");
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
return DataResult<TaskTransferMsgDto>.Failed($"缺少参数:{nameof(BusinessTaskMail)}.{nameof(BusinessTaskMail.Id)}");
|
|
|
|
{
|
|
|
|
|
|
|
|
res = RequestHelper.Post(jsonBody, emailUrl);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"发送邮件异常:{ex.Message}");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Failed(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TransmitEmailFail)), ex.Message));
|
|
|
|
return await InnerSendEmailToCustomer(taskPKId, businessTaskMailId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
DateTime eDate = DateTime.Now;
|
|
|
|
#region 手工发送邮件通知给客户
|
|
|
|
TimeSpan ts = eDate.Subtract(bDate);
|
|
|
|
/// <summary>
|
|
|
|
var timeDiff = ts.TotalMilliseconds;
|
|
|
|
/// 手工发送邮件通知给客户
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="taskPKId">起运港未提箱任务主键</param>
|
|
|
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
|
|
|
public async Task<DataResult<TaskTransferMsgDto>> ManualSendEmailToCustomer(long taskPKId)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var paramConfig = _configService.GetConfig("CutDateChangeEmailTemplateID", long.Parse(user.TenantId), false).GetAwaiter().GetResult()?.Data?.Value;
|
|
|
|
|
|
|
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"发送邮件返回:{res}");
|
|
|
|
long businessTaskMailId = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(res))
|
|
|
|
if (!string.IsNullOrWhiteSpace(paramConfig))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var respObj = JsonConvert.DeserializeAnonymousType(res, new
|
|
|
|
businessTaskMailId = long.Parse(paramConfig);
|
|
|
|
{
|
|
|
|
}
|
|
|
|
Success = false,
|
|
|
|
else
|
|
|
|
Message = string.Empty,
|
|
|
|
{
|
|
|
|
Code = -9999,
|
|
|
|
return DataResult<TaskTransferMsgDto>.Failed($"缺少系统参数参数:截止时间变更邮件模板ID-\tCutDateChangeEmailTemplateID");
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(respObj.Success)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return DataResult<string>.Success(respObj.Message);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Failed(respObj.Message);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Failed(res);
|
|
|
|
return await InnerSendEmailToCustomer(taskPKId, businessTaskMailId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|
|
|
|