|
|
|
@ -2194,10 +2194,11 @@ namespace Myshipping.Application
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 放舱发送
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bookingId"></param>
|
|
|
|
|
/// <param name="bookingId">订舱ID</param>
|
|
|
|
|
/// <param name="templateId">打印模板ID</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/BookingLetteryard/SendLetterYard")]
|
|
|
|
|
public async Task SendLetterYard(long bookingId)
|
|
|
|
|
public async Task SendLetterYard(long bookingId, long templateId)
|
|
|
|
|
{
|
|
|
|
|
var order = _rep.FirstOrDefault(x => x.Id == bookingId);
|
|
|
|
|
var user = await _repUser.FirstOrDefaultAsync(u => u.Id == order.CreatedUserId);
|
|
|
|
@ -2214,7 +2215,12 @@ namespace Myshipping.Application
|
|
|
|
|
throw Oops.Bah("ATTN MAIL未正确填写");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var mailAcc = await _repUserMail.FirstOrDefaultAsync(x => x.CreatedUserId == user.Id && x.MailAccount == letterYard.AttnMail && x.SmtpPort > 0 && x.SmtpServer != null && x.SmtpServer != "");
|
|
|
|
|
if (string.IsNullOrEmpty(letterYard.FromMail))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("FROM MAIL未正确填写");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var mailAcc = await _repUserMail.FirstOrDefaultAsync(x => x.CreatedUserId == user.Id && x.MailAccount == letterYard.FromMail && x.SmtpPort > 0 && x.SmtpServer != null && x.SmtpServer != "");
|
|
|
|
|
if (mailAcc == null)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("用户邮箱未设置或smtp未正确配置");
|
|
|
|
@ -2227,7 +2233,14 @@ namespace Myshipping.Application
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
#region 保存放舱文件,并挂载到订舱附件
|
|
|
|
|
var fileBytes = await GetReportFile(bookingId, "fangcang");
|
|
|
|
|
var printTemplate = await _repPrintTemplate.AsQueryable().Filter(null, true).FirstAsync(x => x.Id == templateId);
|
|
|
|
|
if (printTemplate == null)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK115);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bs = await GenPrintFile(bookingId, printTemplate);
|
|
|
|
|
|
|
|
|
|
var opt = App.GetOptions<BookingAttachOptions>();
|
|
|
|
|
var fileSaveName = $"放舱_{order.MBLNO}_{DateTime.Now.Ticks}.pdf"; // 文件原始名称
|
|
|
|
|
var dirAbs = string.Empty;
|
|
|
|
@ -2246,7 +2259,7 @@ namespace Myshipping.Application
|
|
|
|
|
var fileRelaPath = Path.Combine(opt.relativePath, fileSaveName).ToLower();
|
|
|
|
|
var fileAbsPath = Path.Combine(dirAbs, fileSaveName).ToLower();
|
|
|
|
|
|
|
|
|
|
File.WriteAllBytes(fileAbsPath, fileBytes);
|
|
|
|
|
File.WriteAllBytes(fileAbsPath, bs);
|
|
|
|
|
|
|
|
|
|
var newFile = new BookingFile
|
|
|
|
|
{
|
|
|
|
@ -2316,7 +2329,7 @@ namespace Myshipping.Application
|
|
|
|
|
邮箱:{user.Email}
|
|
|
|
|
<br/>";
|
|
|
|
|
|
|
|
|
|
var sendResult = await MailSendHelper.SendMail(mailAcc, mailSubject, mailContent, letterYard.AttnMail, new KeyValuePair<string, byte[]>(fileSaveName, fileBytes));
|
|
|
|
|
var sendResult = await MailSendHelper.SendMail(mailAcc, mailSubject, mailContent, letterYard.AttnMail, new KeyValuePair<string, byte[]>(fileSaveName, bs));
|
|
|
|
|
if (!sendResult.Key)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError($"放舱邮件发送失败:从{mailAcc.MailAccount}到{letterYard.AttnMail},主题 {mailSubject}");
|
|
|
|
|