diff --git a/Myshipping.Application/Service/BookingOrder/BookingValueAddedService.cs b/Myshipping.Application/Service/BookingOrder/BookingValueAddedService.cs index 08c2926f..8728ee51 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingValueAddedService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingValueAddedService.cs @@ -7,6 +7,7 @@ using Furion.FriendlyException; using Furion.JsonSerialization; using Furion.RemoteRequest.Extensions; using Mapster; +using MathNet.Numerics; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; @@ -16,6 +17,7 @@ using Myshipping.Application.Entity; using Myshipping.Core; using Myshipping.Core.Entity; using Myshipping.Core.Service; +using MySqlX.XDevAPI.Common; using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Utilities; using SqlSugar; @@ -55,6 +57,7 @@ namespace Myshipping.Application private readonly SqlSugarRepository _djyWebsiteAccountConfigRepository; private readonly SqlSugarRepository _sysUserRepository; private readonly SqlSugarRepository _bookingLetteryardRepository; + private readonly SqlSugarRepository _taskBCInfoRepository; const string CONST_MAPPING_BC_MODULE_ROUTE = "BC_DOWN_RT"; const string CONST_MAPPING_DRAFT_MODULE_ROUTE = "DRAFT_DOWN_RT"; @@ -72,7 +75,8 @@ namespace Myshipping.Application public BookingValueAddedService(ISysCacheService cache, ILogger logger, SqlSugarRepository bookingOrderRepository, SqlSugarRepository bookingfile, SqlSugarRepository djyWebsiteAccountConfigRepository, SqlSugarRepository sysUserRepository, - SqlSugarRepository bookingLetteryardRepository, IBookingOrderService bookingOrderService) + SqlSugarRepository bookingLetteryardRepository, IBookingOrderService bookingOrderService + , SqlSugarRepository taskBCInfoRepository) { _cache = cache; _logger = logger; @@ -84,6 +88,7 @@ namespace Myshipping.Application _sysUserRepository = sysUserRepository; _bookingLetteryardRepository = bookingLetteryardRepository; _bookingOrderService = bookingOrderService; + _taskBCInfoRepository = taskBCInfoRepository; } @@ -1400,9 +1405,121 @@ namespace Myshipping.Application */ var bookingOrder = _bookingOrderRepository.AsQueryable().First(a => a.Id == model.BookingOrderId); - if(bookingOrder == null) + if (bookingOrder == null) throw Oops.Bah($"订舱信息获取失败,订舱信息不存在或已作废"); + var updateRlt = InnerBCUpdateBookingOrder(model, bookingOrder, batchNo,1).GetAwaiter().GetResult(); + + if (!updateRlt.succ) + throw Oops.Bah($"订舱信息更新失败,{updateRlt.msg}"); + + if (model.IsLetterYard) + { + _logger.LogInformation("批次={no} id={id} 单票BC更新订舱后,用户选择转为入货通知,开始执行入货通知", batchNo + , bookingOrder.Id); + + if (string.IsNullOrWhiteSpace(model.FileTempPath)) + { + _logger.LogInformation("批次={no} id={id} 未提交文件路径,请求失败", batchNo + , bookingOrder.Id); + + throw Oops.Bah($"未提交文件路径,执行放舱失败"); + } + + var letterYardDto = new UpdateBookingLetteryardInput(); + + letterYardDto = model.LetteryardDto.Adapt(); + + if (model.LetterYardId.HasValue && model.LetterYardId.Value > 0) + { + letterYardDto.Id = model.LetterYardId.Value; + + _logger.LogInformation("批次={no} id={id} 单票BC更新订舱后,存在放舱记录 LetterYardId={LetterYardId}", batchNo + , bookingOrder.Id, letterYardDto.Id); + } + else + { + var letterYardModel = _bookingLetteryardRepository.AsQueryable() + .First(x => x.BookingId == model.BookingOrderId); + + if(letterYardModel != null) + letterYardDto.Id = letterYardModel.Id; + } + + //放舱保存 + var letterYardId = await _bookingOrderService.LetteryardSave(letterYardDto); + + _logger.LogInformation("批次={no} id={id} 已完放舱记录保存 返回结果{rlt}", batchNo + , bookingOrder.Id, letterYardId); + + _logger.LogInformation("批次={no} id={id} templateid={tempid} 开始发送放舱", batchNo + , bookingOrder.Id, model.TemplateId); + + //发送放舱 + await _bookingOrderService.SendLetterYard(model.BookingOrderId, model.TemplateId); + + _logger.LogInformation("批次={no} id={id} templateid={tempid} 完成发送放舱", batchNo + , bookingOrder.Id, model.TemplateId); + + string fileTypeCode = "bc"; + string fileTypeName = "Booking Confirmation"; + + //重新将暂存文件写入正式路径 + + //读取文件配置 + var bookFilePath = await FileAttachHelper.MoveFile(bookingOrder.Id.ToString(), model.FileTempPath,batchNo); + + //将BC引入的文件写入订舱的附件 + await SaveEDIFile(bookingOrder.Id, bookFilePath, new System.IO.FileInfo(bookFilePath).Name, + fileTypeCode, fileTypeName); + + _logger.LogInformation("批次={no} id={id} 完成写入附件表 {filepath}", batchNo + , bookingOrder.Id, model.FileTempPath); + } + + result.succ = true; + result.msg = "执行成功"; + } + catch (Exception ex) + { + result.succ = false; + result.msg = ex.Message; + } + + return result; + } + #endregion + + #region 单票BC更新订舱信息 + /// + /// 单票BC更新订舱信息 + /// + /// BC详情 + /// 订舱详情 + /// 批次号 + /// 顺序号 + /// 返回回执 + private async Task InnerBCUpdateBookingOrder(SingleBCDto model, BookingOrder bookingOrder, + string batchNo,int sortNo) + { + TaskManageOrderResultDto result = new TaskManageOrderResultDto(); + + result.bno = bookingOrder.MBLNO; + + try + { + if (string.IsNullOrWhiteSpace(result.bno)) + { + if (!string.IsNullOrWhiteSpace(bookingOrder.CUSTNO)) + { + result.bno = $"订 {bookingOrder.CUSTNO}"; + } + else + { + result.bno = $"NO.{sortNo}"; + } + } + //截单日期 if (model.ClosingDate.HasValue) { @@ -1419,7 +1536,7 @@ namespace Myshipping.Application bookingOrder.CLOSEVGMDATE = model.VGMCutOffTime; } - + //截港日期 if (model.CYCutOffTime.HasValue) { @@ -1436,16 +1553,16 @@ namespace Myshipping.Application bookingOrder.ETD = model.ETD; } - + //船名 - if(!string.IsNullOrWhiteSpace(model.Vessel)) + if (!string.IsNullOrWhiteSpace(model.Vessel)) { _logger.LogInformation("批次={no} id={id} 更新船名 原:{date1} 变更为 {date2}", batchNo, bookingOrder.Id, bookingOrder.VESSEL, model.Vessel); bookingOrder.VESSEL = model.Vessel; } - + //航次 if (!string.IsNullOrWhiteSpace(model.Voyage)) { @@ -1454,7 +1571,7 @@ namespace Myshipping.Application bookingOrder.VOYNO = model.Voyage; } - + //提单号 if (!string.IsNullOrWhiteSpace(model.BLNo)) { @@ -1463,13 +1580,12 @@ namespace Myshipping.Application bookingOrder.MBLNO = model.BLNo; } - bookingOrder.UpdatedTime = DateTime.Now; bookingOrder.UpdatedUserId = UserManager.UserId; bookingOrder.UpdatedUserName = UserManager.Name; - _bookingOrderRepository.AsUpdateable(bookingOrder).UpdateColumns(it => new + await _bookingOrderRepository.AsUpdateable(bookingOrder).UpdateColumns(it => new { it.UpdatedTime, it.UpdatedUserId, @@ -1481,81 +1597,117 @@ namespace Myshipping.Application it.VESSEL, it.VOYNO, it.MBLNO - }).ExecuteCommand(); + }).ExecuteCommandAsync(); _logger.LogInformation("批次={no} id={id} BC引入更新订舱完成", batchNo, bookingOrder.Id); - if (model.IsLetterYard) - { - _logger.LogInformation("批次={no} id={id} 单票BC更新订舱后,用户选择转为入货通知,开始执行入货通知", batchNo - , bookingOrder.Id); - - if (string.IsNullOrWhiteSpace(model.FileTempPath)) - { - _logger.LogInformation("批次={no} id={id} 未提交文件路径,请求失败", batchNo - , bookingOrder.Id); + result.succ = true; + result.msg = "执行成功"; + } + catch (Exception ex) + { + result.succ = false; + result.msg = ex.Message; + } - throw Oops.Bah($"未提交文件路径,执行放舱失败"); - } + return result; + } + #endregion - var letterYardDto = new UpdateBookingLetteryardInput(); + #region 批量BC更新订舱 + /// + /// 批量BC更新订舱 + /// + /// 批量BC更新列表 + /// 返回回执 + [HttpPost("/BookingValueAdded/BatchBCUpdate")] + public async Task BatchBCUpdate([FromBody]List batchBCList) + { + TaskManageOrderResultDto result = new TaskManageOrderResultDto(); + List> taskList = new List>(); - letterYardDto = model.LetteryardDto.Adapt(); + string batchNo = IDGen.NextID().ToString(); - if (model.LetterYardId.HasValue && model.LetterYardId.Value > 0) - { - letterYardDto.Id = model.LetterYardId.Value; + try + { + var bcTaskList = batchBCList.Select(a=>a.bcPKId).Distinct().ToList(); + var bkOrderList = batchBCList.Select(a => a.bkOrderId.Value).Distinct().ToList(); - _logger.LogInformation("批次={no} id={id} 单票BC更新订舱后,存在放舱记录 LetterYardId={LetterYardId}", batchNo - , bookingOrder.Id, letterYardDto.Id); - } - else - { - var letterYardModel = _bookingLetteryardRepository.AsQueryable() - .First(x => x.BookingId == model.BookingOrderId); + var bklist = _bookingOrderRepository.AsQueryable() + .Where(a => bkOrderList.Contains(a.Id)).ToList(); - if(letterYardModel != null) - letterYardDto.Id = letterYardModel.Id; - } + var bclist = _taskBCInfoRepository.AsQueryable() + .Where(a => bcTaskList.Contains(a.PK_ID)).ToList(); - //放舱保存 - var letterYardId = await _bookingOrderService.LetteryardSave(letterYardDto); + if (bklist.Count != bkOrderList.Count) + throw Oops.Oh($"订舱信息获取失败,订舱信息不存在或已作废"); - _logger.LogInformation("批次={no} id={id} 已完放舱记录保存 返回结果{rlt}", batchNo - , bookingOrder.Id, letterYardId); + var noList = bklist.Select((a, idx) => new { no = idx + 1, id = a.Id }).ToList(); + foreach (var bk in bklist) + { + var sortNo = noList.FirstOrDefault(a => a.id == bk.Id).no; - _logger.LogInformation("批次={no} id={id} templateid={tempid} 开始发送放舱", batchNo - , bookingOrder.Id, model.TemplateId); + var currBC = batchBCList.Join(bclist, l => l.bcPKId, r => r.PK_ID, (l, r) => { + return r; + }).FirstOrDefault(); + + SingleBCDto singleBCDto = new SingleBCDto { + BLNo = currBC.MBL_NO, + Vessel = currBC.VESSEL, + Voyage = currBC.VOYNO, + ETD = currBC.ETD, + CYCutOffTime = currBC.CY_CUTOFF_TIME, + VGMCutOffTime = currBC.VGM_CUTOFF_TIME, + ClosingDate = currBC.CUT_SINGLE_TIME + }; + taskList.Add(Task.Run(() => InnerBCUpdateBookingOrder(singleBCDto,bk, batchNo, sortNo))); + } - //发送放舱 - await _bookingOrderService.SendLetterYard(model.BookingOrderId, model.TemplateId); + Task.WaitAll(taskList.ToArray()); - _logger.LogInformation("批次={no} id={id} templateid={tempid} 完成发送放舱", batchNo - , bookingOrder.Id, model.TemplateId); + result.succ = true; + result.msg = "批量执行成功"; - string fileTypeCode = "bc"; - string fileTypeName = "Booking Confirmation"; + var downResultList = taskList.Select(x => x.Result).ToList(); - //重新将暂存文件写入正式路径 + if (downResultList.Any(x => !x.succ)) + { + result.succ = false; + result.msg = "批量执行失败"; + } + else + { + result.succ = true; + result.msg = downResultList.FirstOrDefault().msg; + } - //读取文件配置 - var bookFilePath = await FileAttachHelper.MoveFile(bookingOrder.Id.ToString(), model.FileTempPath,batchNo); + result.ext = downResultList; - //将BC引入的文件写入订舱的附件 - await SaveEDIFile(bookingOrder.Id, bookFilePath, new System.IO.FileInfo(bookFilePath).Name, - fileTypeCode, fileTypeName); + var succ = downResultList.Count(x => x.succ); + var fail = downResultList.Count(x => !x.succ); - _logger.LogInformation("批次={no} id={id} 完成写入附件表 {filepath}", batchNo - , bookingOrder.Id, model.FileTempPath); + if (succ > 0) + { + result.batchTotal = succ.ToString(); + } + else + { + result.batchTotal = "- "; } - result.succ = true; - result.msg = "执行成功"; + if (fail > 0) + { + result.batchTotal += "/" + fail.ToString(); + } + else + { + result.batchTotal += " -"; + } } catch (Exception ex) { result.succ = false; - result.msg = ex.Message; + result.msg = $"批量执行失败,原因:{ex.Message}"; } return result; diff --git a/Myshipping.Application/Service/BookingOrder/Dto/BatchBCDto.cs b/Myshipping.Application/Service/BookingOrder/Dto/BatchBCDto.cs new file mode 100644 index 00000000..a1607113 --- /dev/null +++ b/Myshipping.Application/Service/BookingOrder/Dto/BatchBCDto.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Myshipping.Application +{ + /// + /// BC批量引入 + /// + public class BatchBCDto + { + /// + /// BC的主键 + /// + public string bcPKId { get; set; } + + /// + /// 订舱主键 + /// + public Nullable bkOrderId { get; set; } + } +} diff --git a/Myshipping.Application/Service/BookingOrder/IBookingValueAddedService.cs b/Myshipping.Application/Service/BookingOrder/IBookingValueAddedService.cs index 11cd4bcf..65dc2a2b 100644 --- a/Myshipping.Application/Service/BookingOrder/IBookingValueAddedService.cs +++ b/Myshipping.Application/Service/BookingOrder/IBookingValueAddedService.cs @@ -51,5 +51,11 @@ namespace Myshipping.Application /// 返回回执 Task SingleBCUpdateBookingOrder(SingleBCDto model); + /// + /// 批量BC更新订舱 + /// + /// 批量BC更新列表 + /// 返回回执 + Task BatchBCUpdate(List batchBCList); } } diff --git a/Myshipping.Application/Service/TaskManagePlat/Dtos/BC/BookingOrderBCTaskDto.cs b/Myshipping.Application/Service/TaskManagePlat/Dtos/BC/BookingOrderBCTaskDto.cs new file mode 100644 index 00000000..38d90520 --- /dev/null +++ b/Myshipping.Application/Service/TaskManagePlat/Dtos/BC/BookingOrderBCTaskDto.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Myshipping.Application +{ + public class BookingOrderBCTaskDto: BookingOrderDto + { + /// + /// 序号 + /// + public int Indx { get; set; } + + /// + /// 对应BC序号 + /// + public int BCIndx { get; set; } + } +} diff --git a/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskBCInfoDto.cs b/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskBCInfoDto.cs index 71861e0a..bf98bc31 100644 --- a/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskBCInfoDto.cs +++ b/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskBCInfoDto.cs @@ -240,9 +240,15 @@ namespace Myshipping.Application /// 集装箱列表 /// public List CtnList { get; set; } + /// /// 顺序号 /// public int Indx { get; set; } + + /// + /// 对应订舱序号 + /// + public int BKOrderIndx { get; set; } } } diff --git a/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs b/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs index 59c83998..39733ff8 100644 --- a/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs @@ -258,6 +258,10 @@ namespace Myshipping.Application }).OrderByDescending(a => a.Sort).FirstOrDefault().OBJ.Adapt(); bookingOrder.Indx = odNum; + bookingOrder.BCIndx = num; + + bcInfo.BKOrderIndx = odNum; + odNum++; tupList.Add(new Tuple( @@ -276,7 +280,8 @@ namespace Myshipping.Application num++; } - result.ext = tupList; + result.ext = tupList.Select(a=>a.Item1).ToList(); + result.ext2 = tupList.Select(a => a.Item2).ToList(); } result.succ = true;