修改BC生成订舱,增加往来单位联系人必填

master
jianghaiqing 6 months ago
parent da9d2e60bb
commit 9b6a65e794

@ -41,5 +41,25 @@ namespace Myshipping.Application
/// 最后转发客户邮件结果
/// </summary>
public string LST_TRANSFER_NOTES { get; set; }
/// <summary>
/// 最后转发客户邮件状态 TEMP-暂存 SUCC-发送成功 FAILURE-发送失败
/// </summary>
public string LST_STATUS { get; set; }
/// <summary>
/// 最后转发客户邮件状态名称
/// </summary>
public string LST_STATUS_NAME { get; set; }
/// <summary>
/// 提单号
/// </summary>
public string MBL_NO { get; set; }
/// <summary>
/// 是否有效 1-有效 0-失效
/// </summary>
public bool IS_ENABLE { get; set; }
}
}

@ -112,6 +112,21 @@ namespace Myshipping.Application
/// </summary>
public string AdvisoryTitle { get; set; }
/// <summary>
/// 同一航次订单数量
/// </summary>
public int totalNum { get; set; }
/// <summary>
/// 同一航次订单发送消息成功数量
/// </summary>
public int totalSucc { get; set; }
/// <summary>
/// 同一航次订单发送消息失败数量
/// </summary>
public int totalFailure { get; set; }
/// <summary>
/// 相关订舱列表
/// </summary>

@ -22,16 +22,21 @@ namespace Myshipping.Application
/// 自动转发船舶相关截止时间的通知
/// </summary>
/// <param name="taskPKId">船舶相关截止时间的通知任务主键</param>
/// <param name="tenantId">租户ID</param>
/// <returns>返回回执</returns>
Task<TaskManageOrderResultDto> AutoTransferNotice(string taskPKId, long tenantId);
Task<TaskManageOrderResultDto> AutoTransferNotice(string taskPKId);
/// <summary>
/// 检索同一航次对应的订舱订单(并对应记录)
/// </summary>
/// <param name="taskPKId">船舶相关截止时间的通知任务主键</param>
/// <param name="tenantId">租户ID</param>
/// <returns>返回回执</returns>
Task<TaskManageOrderResultDto> QueryVesselVoynoBookingOrder(string taskPKId, long tenantId);
Task<TaskManageOrderResultDto> QueryVesselVoynoBookingOrder(string taskPKId);
/// <summary>
/// 批量发送邮件通知给客户
/// </summary>
/// <param name="detailPKIds">船舶相关截止时间的通知订舱明细记录主键组</param>
/// <returns>返回回执</returns>
Task<TaskManageOrderResultDto> BatchSendEmailToCustomer(string[] detailPKIds);
}
}

@ -13,6 +13,11 @@ using System.Text;
using System.Threading.Tasks;
using Furion.FriendlyException;
using NPOI.POIFS.Storage;
using Yitter.IdGenerator;
using Furion.DistributedIDGenerator;
using System.Text.RegularExpressions;
using Furion;
using Myshipping.Application.Helper;
namespace Myshipping.Application
{
@ -29,12 +34,16 @@ namespace Myshipping.Application
private readonly SqlSugarRepository<TaskRouteChangeAdvisoryDetailInfo> _taskRouteChangeAdvisoryDetailInfoRepository;
private readonly SqlSugarRepository<DjyUserMailAccount> _djyUserMailAccount;
private readonly SqlSugarRepository<BookingOrder> _bookingOrderRepository;
private readonly SqlSugarRepository<BookingOrderContact> _bookingOrderContactRepository;
private readonly SqlSugarRepository<SysUser> _sysUserRepository;
public RouteChangeAdvisoryService(ISysCacheService cache, ILogger<TaskCautionNoticeService> logger,
SqlSugarRepository<TaskBaseInfo> taskBaseRepository,
SqlSugarRepository<TaskRouteChangeAdvisoryInfo> taskRouteChangeAdvisoryInfoRepository,
SqlSugarRepository<TaskRouteChangeAdvisoryDetailInfo> taskRouteChangeAdvisoryDetailInfoRepository,
SqlSugarRepository<DjyUserMailAccount> djyUserMailAccount,
SqlSugarRepository<BookingOrderContact> bookingOrderContactRepository,
SqlSugarRepository<SysUser> sysUserRepository,
SqlSugarRepository<BookingOrder> bookingOrderRepository)
{
_cache = cache;
@ -45,7 +54,8 @@ namespace Myshipping.Application
_taskRouteChangeAdvisoryDetailInfoRepository = taskRouteChangeAdvisoryDetailInfoRepository;
_djyUserMailAccount = djyUserMailAccount;
_bookingOrderRepository = bookingOrderRepository;
_bookingOrderContactRepository = bookingOrderContactRepository;
_sysUserRepository = sysUserRepository;
}
#region 获取船舶相关截止时间的通知详情
@ -97,11 +107,11 @@ namespace Myshipping.Application
BuisList = new List<TaskRouteChangeAdvisoryBusiShowDto>()
};
if(detailList.Count > 0)
if (detailList.Count > 0)
{
var queryList = detailList.Where(a => a.BOOKING_ID.HasValue).Select(a => a.BOOKING_ID.Value).ToList();
if(queryList.Count > 0)
if (queryList.Count > 0)
{
//查询整船的订舱订单列表
var bookList = _bookingOrderRepository.AsQueryable().Where(a => queryList.Contains(a.Id) && a.IsDeleted == false).ToList();
@ -114,7 +124,7 @@ namespace Myshipping.Application
IsTransferUser = p.IS_TRANSFER_USER,
LstTransferNote = p.LST_TRANSFER_NOTES,
BookingId = p.BOOKING_ID.Value,
IsEnable = true
IsEnable = p.IS_ENABLE
};
var bookInfo = bookList.FirstOrDefault(x => x.Id == p.BOOKING_ID.Value);
@ -161,18 +171,65 @@ namespace Myshipping.Application
/// 自动转发船舶相关截止时间的通知
/// </summary>
/// <param name="taskPKId">船舶相关截止时间的通知任务主键</param>
/// <param name="tenantId">租户ID</param>
/// <returns>返回回执</returns>
[HttpGet("/RouteChangeAdvisory/AutoTransferNotice")]
public async Task<TaskManageOrderResultDto> AutoTransferNotice(string taskPKId, long tenantId)
public async Task<TaskManageOrderResultDto> AutoTransferNotice(string taskPKId)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
var taskBase = _taskBaseRepository.AsQueryable().First(a => a.PK_ID == taskPKId);
if (taskBase == null)
throw Oops.Oh($"任务主键{taskPKId}无法获取业务信息");
var advisoryInfo = _taskRouteChangeAdvisoryInfoRepository.AsQueryable().First(a => a.TASK_ID == taskBase.PK_ID);
if (advisoryInfo == null)
throw Oops.Oh($"船舶相关截止时间的通知主键{taskPKId}无法获取业务信息");
var detailList = _taskRouteChangeAdvisoryDetailInfoRepository.AsQueryable()
.Where(a => a.P_ID == advisoryInfo.PK_ID).ToList();
//通过船名航次取是主单的订舱记录列表
var bookList = _bookingOrderRepository.AsQueryable().Where(a => a.VESSEL == advisoryInfo.VESSEL && (a.VOYNO == advisoryInfo.VOYNO || a.VOYNOINNER == advisoryInfo.VOYNO)
&& a.IsDeleted == false && (a.ParentId == null || a.ParentId == 0)).ToList();
//用查询到的订舱列表和明细记录标做匹配,如果没有需要新增记录表
var addList = bookList.GroupJoin(detailList, l => l.Id, r => r.BOOKING_ID.Value, (l, r) =>
{
var currList = r.ToList();
if (currList.Count == 0)
{
return new { IsAdd = true, book = l };
}
return new { IsAdd = false, book = l };
}).Where(t => t.IsAdd).Select(t => t.book).ToList();
DateTime nowDate = DateTime.Now;
if (addList.Count > 0)
{
addList.ForEach(t =>
{
TaskRouteChangeAdvisoryDetailInfo detail = new TaskRouteChangeAdvisoryDetailInfo
{
PK_ID = IDGen.NextID().ToString(),
BOOKING_ID = t.Id,
MBL_NO = t.MBLNO,
CreatedTime = nowDate,
UpdatedTime = nowDate,
CreatedUserId = UserManager.UserId,
CreatedUserName = UserManager.Name,
TenantId = UserManager.TENANT_ID
};
});
}
}
catch(Exception ex)
catch (Exception ex)
{
}
@ -186,24 +243,209 @@ namespace Myshipping.Application
/// 检索同一航次对应的订舱订单(并对应记录)
/// </summary>
/// <param name="taskPKId">船舶相关截止时间的通知任务主键</param>
/// <param name="tenantId">租户ID</param>
/// <returns>返回回执</returns>
[HttpGet("/RouteChangeAdvisory/QueryVesselVoynoBookingOrder")]
public async Task<TaskManageOrderResultDto> QueryVesselVoynoBookingOrder(string taskPKId, long tenantId)
public async Task<TaskManageOrderResultDto> QueryVesselVoynoBookingOrder(string taskPKId)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
var taskBase = _taskBaseRepository.AsQueryable().First(a => a.PK_ID == taskPKId);
if (taskBase == null)
throw Oops.Oh($"任务主键{taskPKId}无法获取业务信息");
var advisoryInfo = _taskRouteChangeAdvisoryInfoRepository.AsQueryable().First(a => a.TASK_ID == taskBase.PK_ID);
if (advisoryInfo == null)
throw Oops.Oh($"船舶相关截止时间的通知主键{taskPKId}无法获取业务信息");
var detailList = _taskRouteChangeAdvisoryDetailInfoRepository.AsQueryable()
.Where(a => a.P_ID == advisoryInfo.PK_ID).ToList();
//通过船名航次取是主单的订舱记录列表
var bookList = _bookingOrderRepository.AsQueryable().Where(a => a.VESSEL == advisoryInfo.VESSEL && (a.VOYNO == advisoryInfo.VOYNO || a.VOYNOINNER == advisoryInfo.VOYNO)
&& a.IsDeleted == false && (a.ParentId == null || a.ParentId == 0)).ToList();
//用查询到的订舱列表和明细记录标做匹配,如果没有需要新增记录表
var addList = bookList.GroupJoin(detailList, l => l.Id, r => r.BOOKING_ID.Value, (l, r) =>
{
var currList = r.ToList();
if (currList.Count == 0)
{
return new { IsAdd = true, book = l };
}
return new { IsAdd = false, book = l };
}).Where(t => t.IsAdd).Select(t => t.book).ToList();
DateTime nowDate = DateTime.Now;
if (addList.Count > 0)
{
addList.ForEach(t =>
{
TaskRouteChangeAdvisoryDetailInfo detail = new TaskRouteChangeAdvisoryDetailInfo
{
PK_ID = IDGen.NextID().ToString(),
P_ID = advisoryInfo.PK_ID,
IsDeleted = false,
BOOKING_ID = t.Id,
MBL_NO = t.MBLNO,
CreatedTime = nowDate,
UpdatedTime = nowDate,
CreatedUserId = UserManager.UserId,
CreatedUserName = UserManager.Name,
TenantId = UserManager.TENANT_ID
};
_taskRouteChangeAdvisoryDetailInfoRepository.Insert(detail);
});
}
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"检索失败,原因:{ex.Message}";
_logger.LogInformation($"taskPKId={taskPKId} 检索同一航次对应的订舱订单(并对应记录) 处理异常,原因:{ex.Message}");
}
return result;
}
#endregion
#region 批量发送邮件通知给客户
/// <summary>
/// 批量发送邮件通知给客户
/// </summary>
/// <param name="detailPKIds">船舶相关截止时间的通知订舱明细记录主键组</param>
/// <returns>返回回执</returns>
public async Task<TaskManageOrderResultDto> BatchSendEmailToCustomer(string[] detailPKIds)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
if (detailPKIds == null || detailPKIds.Length == 0)
throw Oops.Oh($"未选择需要发送订单明细");
var detailList = _taskRouteChangeAdvisoryDetailInfoRepository.AsQueryable()
.Where(a => detailPKIds.Contains(a.PK_ID) && a.IsDeleted == false).ToList();
if (detailPKIds.Length != detailList.Count)
{
throw Oops.Oh($"未选择订单明细检索失败");
}
var bookIdList = detailList.Where(t => t.IS_ENABLE == true)
.Select(t => t.BOOKING_ID.Value).ToList();
if (bookIdList.Count == 0)
{
throw Oops.Oh($"相关订单没有课");
}
//需要根据订单的往来单位统一推送一封邮件,里面有提单号列表
var bookList = _bookingOrderRepository.AsQueryable().Where(a => bookIdList.Contains(a.Id)
&& a.IsDeleted == false && (a.ParentId == null || a.ParentId == 0)).ToList();
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"批量发送失败,原因:{ex.Message}";
_logger.LogInformation($"detailPKIds={string.Join(",", detailPKIds)} 批量发送邮件通知给客户 处理异常,原因:{ex.Message}");
}
return result;
}
#endregion
//private void SendUser
private void GenerateSendEmail(TaskRouteChangeAdvisoryInfo model,long bookingId,string mblNo)
{
/*
//TO 邮件接收人
string toEmail = string.Empty;
//订舱OP的邮箱
string opEmail = string.Empty;
//读取订舱数据
var bookingOrderEntity = _bookingOrderRepository.AsQueryable().Filter(null, true)
.First(a => a.Id == bookingId);
var bookingContactList = _bookingOrderContactRepository.AsQueryable().Filter(null, true)
.Where(a => a.BookingId == bookingId).ToList();
if (bookingContactList == null || bookingContactList.Count == 0)
{
_logger.LogInformation($"当前订舱未指定的联系人toEmail={toEmail}");
new EmailNoticeHelper().SendEmailNotice($"MBLNO={mblNo} 转发【船舶相关截止时间的通知】通知邮件失败", $"MBLNO={mblNo} 转发【船舶相关截止时间的通知】通知邮件失败,原因:当前订舱未指定的联系人", App.Configuration["EmailNoticeDefaultUser"].GetUserEmailList());
throw Oops.Oh($"{mblNo} 当前订舱未指定的联系人,发送通知失败");
}
toEmail = string.Join(";", bookingContactList.Select(x => x.Email.Trim()).Distinct().ToArray());
//获取操作OP的邮箱
if (!string.IsNullOrWhiteSpace(bookingOrderEntity.OPID))
{
var opId = long.Parse(bookingOrderEntity.OPID);
var opUser = _sysUserRepository.AsQueryable().Filter(null, true).First(a => a.Id == opId);
if (opUser != null && !string.IsNullOrWhiteSpace(opUser.Email))
{
opEmail = opUser.Email.Trim();
_logger.LogInformation($"获取操作OP的邮箱opEmail={opEmail} id={opId} name={opUser.Name}");
}
}
//提取当前公共邮箱的配置
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 != "");
if (publicMailAccount == null)
{
throw Oops.Oh($"提取公共邮箱配置失败请在用户邮箱账号管理增加配置显示名为PublicSend或者配置个人邮箱");
}
_logger.LogInformation($"提取当前公共邮箱的配置完成id={publicMailAccount.Id}");
string emailTitle = $"Advisory{model.EMAIL_SUBJECT} : {taskBCInfo.MBL_NO}";
string filePath = string.Empty;
SysUser opUserInfo = null;
if (!string.IsNullOrWhiteSpace(bookingOrderEntity.OPID) && Regex.IsMatch(bookingOrderEntity.OPID, "[0-9]+"))
opUserInfo = _sysUserRepository.AsQueryable().Filter(null, true).First(u => u.Id == long.Parse(bookingOrderEntity.OPID));
if (taskBCInfo.BUSI_TYPE == "BookingAmendment")
{
emailTitle = $"【变更】Booking Amendment : {taskBCInfo.MBL_NO}";
}
//读取邮件模板并填充数据
string emailHtml = string.Empty;
if (taskBCInfo.BUSI_TYPE == "BookingAmendment")
{
emailHtml = GenerateSendEmailHtmlAmendment(taskBCInfo, opUserInfo, UserManager.TENANT_NAME).GetAwaiter().GetResult();
}
else
{
emailHtml = GenerateSendEmailHtml(taskBCInfo, opUserInfo, UserManager.TENANT_NAME).GetAwaiter().GetResult();
}*/
}
}
}

@ -3687,6 +3687,15 @@ namespace Myshipping.Application
//校验前端提交的联系人是否是委托绑定的联系人
if (model.GenerateMethod == "GEN_BOOKING_SLOT" || model.GenerateMethod == "GEN_BOOKING" || model.GenerateMethod == "UPD_BOOKING")
{
DjyTenantParamValueOutput paramConfig = null;
var paramList = _djyTenantParamService.GetParaCodeWithValue(new[] { CONST_CREATE_BOOKING_NEED_CONTACT }).GetAwaiter().GetResult();
if (paramList != null && paramList.Count > 0)
{
paramConfig = paramList.FirstOrDefault(a => a.ParaCode.Equals(CONST_CREATE_BOOKING_NEED_CONTACT, StringComparison.OrdinalIgnoreCase));
}
if (model.CustomerContactList != null && model.CustomerContactList.Count > 0)
{
//取委托客户下面所有的联系人列表
@ -3720,6 +3729,13 @@ namespace Myshipping.Application
}
});
}
else
{
if (paramConfig != null && paramConfig.ParaValue.Equals("ENABLE", StringComparison.OrdinalIgnoreCase))
{
throw Oops.Oh($"生成订舱时往来单位联系必填,请修改");
}
}
}
}
#endregion

Loading…
Cancel
Save