From f535d0344094bd907e33cca37a965c19888f2dfd Mon Sep 17 00:00:00 2001 From: wanghaomei Date: Mon, 16 Oct 2023 10:06:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=90=E8=90=A5=E7=AB=AF=E6=94=BE=E8=88=B1?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BookingOrder/BookingOrderService.cs | 163 +++++++++++++++++- .../BookingOrder/Dto/BookingFileDto.cs | 23 +++ .../Myshipping.Web.Entry.csproj | 2 + 3 files changed, 185 insertions(+), 3 deletions(-) diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index e46fa5d..b6c4269 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -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(); //存在船名航次引入船期数据 if (!string.IsNullOrEmpty(input.VESSEL) && !string.IsNullOrEmpty(input.VOYNO)) @@ -1231,8 +1251,13 @@ namespace Myshipping.Application } } - //推送订舱数据到客户订舱系统 - CustomerBookingSyncHelper.SendCustomerBookingSync(Id); + var runType = App.GetConfig("RunType"); + if (runType == "DJY") //运营端发送通知给客户端 + { + //推送订舱数据到客户订舱系统 + CustomerBookingSyncHelper.SendCustomerBookingSync(Id); + } + return ordOut; } @@ -1820,7 +1845,7 @@ namespace Myshipping.Application /// /// 获取附件 /// - /// + /// 订舱ID /// [HttpGet("/BookingOrder/GetFile")] public async Task> GetFile(long Id) @@ -1829,6 +1854,46 @@ namespace Myshipping.Application return list; } + /// + /// 转发订舱附件 + /// + /// + /// + [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(); + 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(fileObj.FileName, File.ReadAllBytes(fileFullPath))); + if (!rtn.Key) + { + throw Oops.Bah(rtn.Value); + } + } + /// /// 获取货运动态 @@ -2625,6 +2690,98 @@ namespace Myshipping.Application } + /// + /// 生成放舱附件并挂载 + /// + /// 订舱ID + /// 打印模板ID + /// + [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(); + 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("RunType"); + if (runType == "DJY") //运营端发送通知给客户端 + { + //推送订舱数据到客户订舱系统 + CustomerBookingSyncHelper.SendCustomerBookingSync(bookingId); + } + } + + /// /// 生成打印报表文件 /// diff --git a/Myshipping.Application/Service/BookingOrder/Dto/BookingFileDto.cs b/Myshipping.Application/Service/BookingOrder/Dto/BookingFileDto.cs index 39495a1..3112ff2 100644 --- a/Myshipping.Application/Service/BookingOrder/Dto/BookingFileDto.cs +++ b/Myshipping.Application/Service/BookingOrder/Dto/BookingFileDto.cs @@ -12,4 +12,27 @@ namespace Myshipping.Application.Service.BookingOrder.Dto public string TypeCode { get; set; } public string TypeName { get; set; } } + + public class BookingTransmitFileDto + { + /// + /// 附件ID + /// + public long Id { get; set; } + + /// + /// 收件人 + /// + public string SendTo { get; set; } + + /// + /// 邮件主题 + /// + public string Subject { get; set; } + + /// + /// 邮件正文内容(注意:正文使用html格式!!!) + /// + public string Body { get; set; } + } } diff --git a/Myshipping.Web.Entry/Myshipping.Web.Entry.csproj b/Myshipping.Web.Entry/Myshipping.Web.Entry.csproj index c1eb6a4..61432e6 100644 --- a/Myshipping.Web.Entry/Myshipping.Web.Entry.csproj +++ b/Myshipping.Web.Entry/Myshipping.Web.Entry.csproj @@ -119,4 +119,6 @@ + +