运营端放舱文件生成

master
wanghaomei 1 year ago
parent d4a9a2ae55
commit f535d03440

@ -823,6 +823,26 @@ namespace Myshipping.Application
throw Oops.Bah("当前版本号不一致,请刷新后在保存单据");
}
}
//2023年10月13日衣国豪箱号/封号不允许重复
//注意封号只有两种允许重复000000和W框架箱没有封号这两个封号是框架箱的通用封号
if (input.ctnInputs != null && input.ctnInputs.Count > 0)
{
var repeatCntrNO = input.ctnInputs.Where(x => !string.IsNullOrEmpty(x.CNTRNO))
.GroupBy(x => x.CNTRNO).Select(x => new { x.Key, c = x.Count() }).Where(x => x.c > 1).ToList();
if (repeatCntrNO.Count > 0)
{
throw Oops.Bah($"箱号重复:{string.Join("", repeatCntrNO.Select(x => x.Key))}");
}
var repeatSealNO = input.ctnInputs.Where(x => !string.IsNullOrEmpty(x.SEALNO) && x.SEALNO != "000000" && x.SEALNO != "W")
.GroupBy(x => x.SEALNO).Select(x => new { x.Key, c = x.Count() }).Where(x => x.c > 1).ToList();
if (repeatSealNO.Count > 0)
{
throw Oops.Bah($"封号重复:{string.Join("", repeatSealNO.Select(x => x.Key))}");
}
}
var entity = input.Adapt<BookingOrder>();
//存在船名航次引入船期数据
if (!string.IsNullOrEmpty(input.VESSEL) && !string.IsNullOrEmpty(input.VOYNO))
@ -1231,8 +1251,13 @@ namespace Myshipping.Application
}
}
//推送订舱数据到客户订舱系统
CustomerBookingSyncHelper.SendCustomerBookingSync(Id);
var runType = App.GetConfig<string>("RunType");
if (runType == "DJY") //运营端发送通知给客户端
{
//推送订舱数据到客户订舱系统
CustomerBookingSyncHelper.SendCustomerBookingSync(Id);
}
return ordOut;
}
@ -1820,7 +1845,7 @@ namespace Myshipping.Application
/// <summary>
/// 获取附件
/// </summary>
/// <param name="Id"></param>
/// <param name="Id">订舱ID</param>
/// <returns></returns>
[HttpGet("/BookingOrder/GetFile")]
public async Task<List<BookingFile>> GetFile(long Id)
@ -1829,6 +1854,46 @@ namespace Myshipping.Application
return list;
}
/// <summary>
/// 转发订舱附件
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
[HttpPost("/BookingOrder/TransmitFile")]
public async Task TransmitFile(BookingTransmitFileDto dto)
{
var fileObj = await _bookingfile.AsQueryable().Filter(null, true).FirstAsync(u => u.Id == dto.Id);
if (fileObj == null)
{
throw Oops.Bah("文件未找到");
}
var mailAcc = await _repUserMail.FirstOrDefaultAsync(x => x.CreatedUserId == UserManager.UserId && x.SmtpPort > 0 && x.SmtpServer != null && x.SmtpServer != "");
if (mailAcc == null)
{
throw Oops.Bah("用户邮箱未设置或smtp未正确配置");
}
var opt = App.GetOptions<BookingAttachOptions>();
var dirAbs = opt.basePath;
if (string.IsNullOrEmpty(dirAbs))
{
dirAbs = App.WebHostEnvironment.WebRootPath;
}
var fileFullPath = Path.Combine(dirAbs, fileObj.FilePath);
if (!File.Exists(fileFullPath))
{
throw Oops.Oh("文件未找到");
}
var rtn = await MailSendHelper.SendMail(mailAcc, dto.Subject, dto.Body, dto.SendTo, new KeyValuePair<string, byte[]>(fileObj.FileName, File.ReadAllBytes(fileFullPath)));
if (!rtn.Key)
{
throw Oops.Bah(rtn.Value);
}
}
/// <summary>
/// 获取货运动态
@ -2625,6 +2690,98 @@ namespace Myshipping.Application
}
/// <summary>
/// 生成放舱附件并挂载
/// </summary>
/// <param name="bookingId">订舱ID</param>
/// <param name="templateId">打印模板ID</param>
/// <returns></returns>
[HttpPost("/BookingLetteryard/GenLetterYard")]
public async Task GenLetterYard(long bookingId, long templateId)
{
var order = _rep.FirstOrDefault(x => x.Id == bookingId);
var user = await _repUser.FirstOrDefaultAsync(u => u.Id == order.CreatedUserId);
var tenant = await _repTenant.FirstOrDefaultAsync(t => t.Id == order.TenantId);
var letterYard = await _repLetterYard.FirstOrDefaultAsync(x => x.BookingId == bookingId);
if (letterYard == null)
{
throw Oops.Bah("放舱信息未找到,请先保存数据");
}
var orderUrl = await _repOrderUrl.FirstOrDefaultAsync(u => u.BookingId == bookingId);
//if (orderUrl == null)
//{
// throw Oops.Bah("未生成链接信息,请重新保存数据");
//}
#region 保存放舱文件,并挂载到订舱附件
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 fileSourceName = $"{order.MBLNO} 入货通知.pdf"; // 文件原始名称
var fileSaveName = $"{order.MBLNO}_{DateTime.Now.Ticks}.pdf"; // 文件保存名称
var dirAbs = string.Empty;
if (string.IsNullOrEmpty(opt.basePath))
{
dirAbs = Path.Combine(App.WebHostEnvironment.WebRootPath, opt.relativePath);
}
else
{
dirAbs = Path.Combine(opt.basePath, opt.relativePath);
}
if (!Directory.Exists(dirAbs))
Directory.CreateDirectory(dirAbs);
var fileRelaPath = Path.Combine(opt.relativePath, fileSaveName).ToLower();
var fileAbsPath = Path.Combine(dirAbs, fileSaveName).ToLower();
File.WriteAllBytes(fileAbsPath, bs);
var newFile = new BookingFile
{
FileName = fileSourceName,
FilePath = fileRelaPath,
TypeCode = "ruhuotongzhi",
TypeName = ".pdf",
BookingId = bookingId,
};
await _bookingfile.InsertAsync(newFile);
#endregion
//货运动态
var bsl = new BookingStatusLog();
bsl.BookingId = bookingId;
bsl.Status = $"生成放舱文件";
bsl.OpTime = DateTime.Now;
bsl.Category = "ship";
bsl.MBLNO = order.MBLNO;
await _repStatuslog.InsertAsync(bsl);
//订舱状态
await SaveBookingStatus(bookingId, "sta_letter_yard", "放舱");
//设置货物状态-放舱
await SetGoodsStatus("YFC", bookingId);
//await SendBookingOrder(new long[] { bookingId });
var runType = App.GetConfig<string>("RunType");
if (runType == "DJY") //运营端发送通知给客户端
{
//推送订舱数据到客户订舱系统
CustomerBookingSyncHelper.SendCustomerBookingSync(bookingId);
}
}
/// <summary>
/// 生成打印报表文件
/// </summary>

@ -12,4 +12,27 @@ namespace Myshipping.Application.Service.BookingOrder.Dto
public string TypeCode { get; set; }
public string TypeName { get; set; }
}
public class BookingTransmitFileDto
{
/// <summary>
/// 附件ID
/// </summary>
public long Id { get; set; }
/// <summary>
/// 收件人
/// </summary>
public string SendTo { get; set; }
/// <summary>
/// 邮件主题
/// </summary>
public string Subject { get; set; }
/// <summary>
/// 邮件正文内容注意正文使用html格式
/// </summary>
public string Body { get; set; }
}
}

@ -119,4 +119,6 @@
</Content>
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties appsettings_1json__JsonSchema="" /></VisualStudio></ProjectExtensions>
</Project>

Loading…
Cancel
Save