From 73514485e9480a851e39674c53911a915ae8154b Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Sun, 24 Mar 2024 20:57:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=BB=E5=8A=A1=E5=8F=B0?= =?UTF-8?q?=E8=B4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/BookingSlot/BookingSlotService.cs | 284 +++++++++++++++++- .../BookingSlot/Dto/BookingGenerateDto.cs | 101 +++++++ .../BookingSlot/IBookingSlotService.cs | 7 + .../Interface/ITaskManageService.cs | 9 + .../TaskManagePlat/TaskManageBCService.cs | 266 ++++++++++------ .../TaskManagePlat/TaskManageService.cs | 41 ++- 6 files changed, 618 insertions(+), 90 deletions(-) create mode 100644 Myshipping.Application/Service/BookingSlot/Dto/BookingGenerateDto.cs diff --git a/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs b/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs index 46e1243a..a5fe2a62 100644 --- a/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs +++ b/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs @@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; +using Myshipping.Application.ConfigOption; using Myshipping.Application.Entity; using Myshipping.Application.Event; using Myshipping.Application.Service.BookingOrder.Dto; @@ -19,6 +20,7 @@ using Myshipping.Application.Service.BookingSlot.Dto; using Myshipping.Core; using Myshipping.Core.Service; using MySqlX.XDevAPI.Common; +using NPOI.XWPF.UserModel; using Org.BouncyCastle.Asn1.Tsp; using SqlSugar; using System; @@ -52,6 +54,7 @@ namespace Myshipping.Application private readonly SqlSugarRepository _repAllocationCtn; private readonly SqlSugarRepository _bookingFileRepository; private readonly SqlSugarRepository _bookingSlotCompareRepository; + private readonly SqlSugarRepository _bookingOrderContactRepository; private readonly SqlSugarRepository _repBookingLog; private readonly SqlSugarRepository _repBookingLogDetail; @@ -61,6 +64,9 @@ namespace Myshipping.Application private readonly ISysCacheService _cache; private readonly IEventPublisher _publisher; + private readonly IBookingOrderService _bookingOrderService; + private readonly IDjyCustomerService _djyCustomerService; + private readonly IBookingValueAddedService _bookingValueAddedService; const string CONST_BC_FILE_CODE = "bc"; const string CONST_BC_FILE_NAME = "Booking Confirmation"; @@ -83,10 +89,14 @@ namespace Myshipping.Application ILogger logger, ISysCacheService cache, IEventPublisher publisher, + IDjyCustomerService djyCustomerService, SqlSugarRepository repAllocation, SqlSugarRepository repAllocationCtn, SqlSugarRepository bookingFileRepository, - SqlSugarRepository bookingSlotCompareRepository) + SqlSugarRepository bookingSlotCompareRepository, + SqlSugarRepository bookingOrderContactRepository, + IBookingOrderService bookingOrderService, + IBookingValueAddedService bookingValueAddedService) { _repBase = repBase; _repCtn = repCtn; @@ -95,7 +105,7 @@ namespace Myshipping.Application _repBookingLogDetail = repBookingLogDetail; _repAllocation = repAllocation; _repAllocationCtn = repAllocationCtn; - + _djyCustomerService = djyCustomerService; _logger = logger; _cache = cache; @@ -104,6 +114,9 @@ namespace Myshipping.Application _bookingfile = bookingfile; _bookingFileRepository = bookingFileRepository; _bookingSlotCompareRepository = bookingSlotCompareRepository; + _bookingOrderService = bookingOrderService; + _bookingOrderContactRepository = bookingOrderContactRepository; + _bookingValueAddedService = bookingValueAddedService; } #region 舱位 @@ -1148,8 +1161,275 @@ namespace Myshipping.Application return result; } #endregion + + #region 生成订舱订单 + /// + /// 生成订舱订单 + /// + /// 生成订舱订单请求 + /// 返回回执 + public async Task CreateBookingOrder(BookingGenerateDto model) + { + TaskManageOrderResultDto result = new TaskManageOrderResultDto(); + + if (!model.SlotId.HasValue || model.SlotId.Value < 1) + throw Oops.Oh($"舱位ID不能为空"); + + var slotInfo = await _repBase.AsQueryable() + .FirstAsync(a => a.Id == model.SlotId.Value); + + if (slotInfo == null) + throw Oops.Oh($"舱位信息不存在或已作废"); + + // 判断是否已存在引用关系 + if (_repAllocation.IsExists(a => a.BOOKING_SLOT_ID == slotInfo.Id + && a.BOOKING_ID > 0 && a.IsDeleted == false)) + { + throw Oops.Oh($"舱位已有对应的订舱订单,不能重复执行"); + } + + var ctnList = _repCtn.AsQueryable().Where(a => a.SLOT_ID == slotInfo.Id && a.IsDeleted == false) + .ToList(); + + var fileList = await _bookingfile.AsQueryable().Filter(null, true) + .Where(u => u.BookingId == slotInfo.Id && u.Moudle == "BookingSlot").ToListAsync(); + + var bookingOrderId = await GenerateBookingOrder(slotInfo, ctnList, fileList, model); + + result.succ = true; + result.msg = "成功"; + + + return result; + } + #endregion + + #region 生成订舱 + /// + /// 生成订舱 + /// + /// 舱位详情 + /// 舱位集装箱列表 + /// 舱位附件列表 + /// 订舱请求详情 + /// 返回订舱ID + private async Task GenerateBookingOrder(BookingSlotBase bookingSlotBase, List bookingSlotCtnList, + List bookingSlotFileList, + BookingGenerateDto generateModel) + { + long id = 0; + + try + { + /* + 1、新增订舱 + 2、推送服务项目 + 3、推送附件 + */ + + var carrierInfo = _cache.GetAllCodeCarrier().GetAwaiter().GetResult() + .Where(t => t.Code.Equals(bookingSlotBase.CARRIERID, StringComparison.OrdinalIgnoreCase) + || t.EnName.Equals(bookingSlotBase.CARRIERID, StringComparison.OrdinalIgnoreCase) + || t.CnName.Equals(bookingSlotBase.CARRIERID, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); + + SaveBookingOrderInput bkModel = new SaveBookingOrderInput + { + CUSTOMERID = generateModel.CustomerId, + CUSTOMERNAME = generateModel.CustomerName, + CARRIERID = carrierInfo.Code?.Trim(), + CARRIER = carrierInfo.CnName?.Trim(), + MBLNO = bookingSlotBase.SLOT_BOOKING_NO.Trim(), + CONTRACTNO = !string.IsNullOrWhiteSpace(bookingSlotBase.CONTRACT_NO) ? bookingSlotBase.CONTRACT_NO : "", + VESSEL = bookingSlotBase.VESSEL.ToUpper().Trim(), + VOYNO = bookingSlotBase.VOYNO.ToUpper().Trim(), + VOYNOINNER = bookingSlotBase.VOYNO.ToUpper().Trim(), + ETD = bookingSlotBase.ETD, + ETA = bookingSlotBase.ETA, + SALEID = generateModel.SaleId.ToString(), + SALE = generateModel.SaleName, + OPID = generateModel.OpId.ToString(), + OP = generateModel.OpName, + DOCID = generateModel.DocId.ToString(), + DOC = generateModel.DocName, + ROUTEID = generateModel.RouteID.ToString(), + ROUTE = generateModel.Route, + CZRemark = generateModel.CZRemark, + ShenQingXiangShi = generateModel.ShenQingXiangShi, + LineManageID = generateModel.LineManageID.ToString(), + LineName = generateModel.LineManage, + CLOSEVGMDATE = bookingSlotBase.VGM_SUBMISSION_CUT_DATE, + CLOSINGDATE = bookingSlotBase.CY_CUT_DATE, + CLOSEDOCDATE = bookingSlotBase.SI_CUT_DATE, + ctnInputs = new List() + }; + + var ctnCodeList = _cache.GetAllCodeCtn().GetAwaiter().GetResult().ToList(); + + if (bookingSlotCtnList.Count > 0) + { + bookingSlotCtnList.ForEach(t => + { + var ctnCode = ctnCodeList.FirstOrDefault(a => !string.IsNullOrWhiteSpace(a.Name) && + a.Name.Equals(t.CTNALL, StringComparison.OrdinalIgnoreCase)); + + BookingCtnDto ctn = new BookingCtnDto + { + CTNCODE = ctnCode?.Code, + CTNALL = t.CTNALL, + CTNNUM = t.CTNNUM + }; + + bkModel.ctnInputs.Add(ctn); + }); + } + + var bkRlt = await _bookingOrderService.Save(bkModel); + + id = bkRlt.Id; + + string batchNo = IDGen.NextID().ToString(); + + if (id > 0) + { + //这里如果指定了委托单位的邮件联系人,则推送订舱联系人 + if (generateModel.CustomerContactList != null && generateModel.CustomerContactList.Count > 0) + { + var bookingContactList = _bookingOrderContactRepository.AsQueryable() + .Where(a => a.BookingId == id && !a.IsDeleted).ToList(); + + var djyCustomerInfo = _djyCustomerService.Detail(new GetDjyCustomerInput { Id = generateModel.CustomerId.Value }) + .GetAwaiter().GetResult(); + + generateModel.CustomerContactList.ForEach(contact => + { + DjyCustomerContactOutput djyCustomerContactMan = null; + + if (djyCustomerInfo.Contacts != null && djyCustomerInfo.Contacts.Count > 0) + { + djyCustomerContactMan = djyCustomerInfo.Contacts.FirstOrDefault(a => + a.Id == contact.CustomerContactId); + } + + if (djyCustomerContactMan != null) + { + var bookingContact = bookingContactList + .FirstOrDefault(x => x.Email.Equals(djyCustomerContactMan.Email, StringComparison.OrdinalIgnoreCase)); + + if (bookingContact == null) + { + bookingContact = new BookingOrderContact + { + Name = djyCustomerContactMan.Name, + BookingId = id, + Email = djyCustomerContactMan.Email, + Remark = djyCustomerContactMan.Remark, + CreatedTime = DateTime.Now, + CreatedUserId = UserManager.UserId, + CreatedUserName = UserManager.Name + }; + + _bookingOrderContactRepository.Insert(bookingContact); + } + else + { + bookingContact.Name = djyCustomerContactMan.Name; + bookingContact.Email = djyCustomerContactMan.Email; + bookingContact.Remark = djyCustomerContactMan.Remark; + bookingContact.UpdatedTime = DateTime.Now; + bookingContact.UpdatedUserId = UserManager.UserId; + bookingContact.UpdatedUserName = UserManager.Name; + + _bookingOrderContactRepository.AsUpdateable(bookingContact).UpdateColumns(it => new + { + it.Name, + it.Email, + it.Remark, + it.UpdatedTime, + it.UpdatedUserId, + it.UpdatedUserName + + }).ExecuteCommand(); + } + } + }); + + } + + if (generateModel.ProjectList != null && generateModel.ProjectList.Count > 0) + { + ModifyServiceProjectDto projectDto = new ModifyServiceProjectDto + { + BookingId = id, + ProjectCodes = generateModel.ProjectList.Distinct().ToArray(), + }; + //写入服务项目 + var prjRlt = await _bookingValueAddedService.SaveServiceProject(projectDto); + + _logger.LogInformation($"推送订舱的服务项目完成 id={id} rlt={JSON.Serialize(prjRlt)}"); + } + + var opt = App.GetOptions(); + var dirAbs = opt.basePath; + if (string.IsNullOrEmpty(dirAbs)) + { + dirAbs = App.WebHostEnvironment.WebRootPath; + } + + if (bookingSlotFileList.Any(a => a.TypeCode.Equals("bc", StringComparison.OrdinalIgnoreCase))) + { + var file = bookingSlotFileList.OrderByDescending(a => a.CreatedTime) + .FirstOrDefault(a => a.TypeCode.Equals("bc", StringComparison.OrdinalIgnoreCase)); + + var fileFullPath = Path.Combine(dirAbs, file.FilePath); + + if (File.Exists(fileFullPath)) + { + //如果确认文件读取成功 + var bookFilePath = FileAttachHelper.MoveFile(id.ToString(), fileFullPath, batchNo + , false, null, true).GetAwaiter().GetResult(); + + //将格式单附件写入订舱的附件 + SaveEDIFile(id, bookFilePath, new System.IO.FileInfo(bookFilePath).Name, file.TenantId.Value, + CONST_BC_FILE_CODE, CONST_BC_FILE_NAME).GetAwaiter(); + } + } + + if (bookingSlotFileList.Any(a => a.TypeCode.Equals("bc_notice", StringComparison.OrdinalIgnoreCase))) + { + var file = bookingSlotFileList.OrderByDescending(a => a.CreatedTime) + .FirstOrDefault(a => a.TypeCode.Equals("bc_notice", StringComparison.OrdinalIgnoreCase)); + + var fileFullPath = Path.Combine(dirAbs, file.FilePath); + + if (File.Exists(fileFullPath)) + { + //如果确认文件读取成功 + var bookFilePath = FileAttachHelper.MoveFile(id.ToString(), fileFullPath, batchNo + , false, "bcnoticefile", true).GetAwaiter().GetResult(); + + //将格式单附件写入订舱的附件 + SaveEDIFile(id, bookFilePath, new System.IO.FileInfo(bookFilePath).Name, file.TenantId.Value, + CONST_BC_FILE_CODE, CONST_BC_FILE_NAME).GetAwaiter(); + } + } + } + + _logger.LogInformation($"MBLNO:{bookingSlotBase.SLOT_BOOKING_NO} 生成订舱订单成功 id={id}"); + + } + catch (Exception ex) + { + _logger.LogError($"MBLNO:{bookingSlotBase.SLOT_BOOKING_NO} 生成订舱订单异常,原因:{ex.Message}"); + } + + + return id; + } + #endregion } + + public class DynameFileInfo { /// diff --git a/Myshipping.Application/Service/BookingSlot/Dto/BookingGenerateDto.cs b/Myshipping.Application/Service/BookingSlot/Dto/BookingGenerateDto.cs new file mode 100644 index 00000000..867e97c2 --- /dev/null +++ b/Myshipping.Application/Service/BookingSlot/Dto/BookingGenerateDto.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Myshipping.Application +{ + public class BookingGenerateDto + { + /// + /// 舱位ID + /// + public Nullable SlotId { get; set; } + + /// + /// 委托客户ID + /// + public Nullable CustomerId { get; set; } + + /// + /// 委托客户名称 + /// + public string CustomerName { get; set; } + + /// + /// 销售ID + /// + public Nullable SaleId { get; set; } + + /// + /// 销售名称 + /// + public string SaleName { get; set; } + + /// + /// 操作ID + /// + public Nullable OpId { get; set; } + + /// + /// 操作名称 + /// + public string OpName { get; set; } + + /// + /// 单证ID + /// + public Nullable DocId { get; set; } + + /// + /// 单证名称 + /// + public string DocName { get; set; } + + /// + /// 航线操作ID + /// + public Nullable RouteID { get; set; } + + /// + /// 航线操作 + /// + public string Route { get; set; } + + /// + /// 航线管理 + /// + public string LineManage { get; set; } + + /// + /// 航线管理ID + /// + public Nullable LineManageID { get; set; } + + /// + /// 操作备注 + /// + public string CZRemark { get; set; } + + /// + /// 申请箱使 + /// + public string ShenQingXiangShi { get; set; } + + /// + /// 服务项目列表(传serviceProjectCode) + /// + public List ProjectList { get; set; } + + /// + /// 联系人列表 + /// + public List CustomerContactList { get; set; } + + /// + /// 是否直接发送邮件给订舱联系人 + /// + public bool IsDirectSend { get; set; } = false; + } +} diff --git a/Myshipping.Application/Service/BookingSlot/IBookingSlotService.cs b/Myshipping.Application/Service/BookingSlot/IBookingSlotService.cs index 35bc0730..1f74733f 100644 --- a/Myshipping.Application/Service/BookingSlot/IBookingSlotService.cs +++ b/Myshipping.Application/Service/BookingSlot/IBookingSlotService.cs @@ -89,5 +89,12 @@ namespace Myshipping.Application /// 导入舱位文件 /// 返回回执 Task ImportSlotFromFile(IFormFile file); + + /// + /// 生成订舱订单 + /// + /// 生成订舱订单请求 + /// 返回回执 + Task CreateBookingOrder(BookingGenerateDto model); } } \ No newline at end of file diff --git a/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageService.cs b/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageService.cs index d9ace3f3..dd4fca33 100644 --- a/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageService.cs @@ -294,5 +294,14 @@ namespace Myshipping.Application /// BC任务详情JSON /// 返回回执 Task CreateDRAFTTaskJob(IFormFile file, IFormFile modifyFile, string jsonData); + + /// + /// 创建截单回执任务 + /// + /// 文件 + /// 截单回执变更内容后文件 + /// 截单回执任务详情JSON + /// 返回回执 + Task CreateSISubmittedTaskJob(IFormFile file, IFormFile modifyFile, string jsonData); } } diff --git a/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs b/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs index 35d8fb19..f42952c1 100644 --- a/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs @@ -841,118 +841,212 @@ namespace Myshipping.Application else if (model.GenerateMethod == "GEN_BOOKING") { #region 推送订舱 - //推送订舱 - var bookingOrderId = GenerateBookingOrder(bcOrder, bcCtnList, fileList, model).GetAwaiter().GetResult(); + long bookingId = 0; + long bookingSlotId = 0; - if (bookingOrderId > 0) + if (bcOrder.BOOKING_ORDER_ID.HasValue && bcOrder.BOOKING_ORDER_ID.Value > 0) { - if (model.IsDirectSend) - { - //异步推送邮件 - await GenerateSendEmail(bcOrder); - } + //bookingSlotId = bcOrder.BOOKING_SLOT_ID.Value; + throw Oops.Oh($"生成订舱订单失败,订舱订单已存在"); + } + + if (!bcOrder.BOOKING_SLOT_ID.HasValue || bcOrder.BOOKING_SLOT_ID.Value < 1) + { + //bookingSlotId = bcOrder.BOOKING_SLOT_ID.Value; + throw Oops.Oh($"生成订舱订单失败,舱位未生成不能直接生成订舱订单"); + } + + bookingSlotId = bcOrder.BOOKING_SLOT_ID.Value; + + //推送订舱订单 + var bookingOrderId = await GenerateBookingOrder(bcOrder, bcCtnList, fileList, model); + + List slots = new List(); + + //检索舱位信息 + var slotInfo = _bookingSlotService.Detail(bookingSlotId).GetAwaiter().GetResult(); - var bcEntity = _taskBCInfoRepository.AsQueryable().First(a => a.PK_ID == bcTaskInfo.PK_ID); + BookingSlotBaseWithCtnDto baseInfo = slotInfo.Adapt(); + baseInfo.Id = bookingSlotId; + baseInfo.CtnList = slotInfo.CtnList.Adapt>(); - if (bcEntity != null) + slots.Add(baseInfo); + + //对应订舱和舱位关系 + var allocRlt = await _bookingSlotService.ImportSlots(slots, bookingOrderId, false); + + _logger.LogInformation($"生成订舱和舱位关系完成,allocRlt={JSON.Serialize(allocRlt)} taskid={bcOrder.TASK_ID}"); + + if (!allocRlt.isSuccess) + { + throw Oops.Oh($"生成订舱和舱位关系失败"); + } + + var bcEntity = _taskBCInfoRepository.AsQueryable().First(a => a.PK_ID == bcOrder.PK_ID); + + if (bcEntity == null) + { + throw Oops.Oh($"未获取有效任务BC失败,更新失败"); + } + + bcEntity.BOOKING_ORDER_ID = bookingOrderId; + bcEntity.BOOKING_SLOT_ID = bookingSlotId; + bcEntity.UpdatedTime = DateTime.Now; + bcEntity.UpdatedUserId = UserManager.UserId; + bcEntity.UpdatedUserName = UserManager.Name; + + //更新任务BC + await _taskBCInfoRepository.AsUpdateable(bcEntity).UpdateColumns(it => new + { + it.BOOKING_ORDER_ID, + it.BOOKING_SLOT_ID, + it.UpdatedTime, + it.UpdatedUserId, + it.UpdatedUserName + + }).ExecuteCommandAsync(); + + var taskEntity = _taskBaseRepository.AsQueryable().First(u => u.PK_ID == bcEntity.TASK_ID); + + if (taskEntity == null) + { + throw Oops.Oh($"未获取有效任务记录,更新失败"); + } + + #region 更新任务 + //如果是公共任务,需要变成个人任务 RealUserId = 当前操作人 + if (taskEntity.IS_PUBLIC == 1) + { + taskEntity.IS_PUBLIC = 0; + taskEntity.RealUserId = UserManager.UserId; + taskEntity.RealUserName = UserManager.Name; + taskEntity.UpdatedTime = DateTime.Now; + taskEntity.UpdatedUserId = UserManager.UserId; + taskEntity.UpdatedUserName = UserManager.Name; + + await _taskBaseRepository.AsUpdateable(taskEntity).UpdateColumns(it => new { - if (bookingOrderId > 0) - bcEntity.BOOKING_ORDER_ID = bookingOrderId; + it.IS_PUBLIC, + it.UpdatedTime, + it.UpdatedUserId, + it.UpdatedUserName, + it.RealUserId, + it.RealUserName - bcEntity.UpdatedTime = DateTime.Now; - bcEntity.UpdatedUserId = UserManager.UserId; - bcEntity.UpdatedUserName = UserManager.Name; + }).ExecuteCommandAsync(); + } + else + { + taskEntity.UpdatedTime = DateTime.Now; + taskEntity.UpdatedUserId = UserManager.UserId; + taskEntity.UpdatedUserName = UserManager.Name; - _taskBCInfoRepository.AsUpdateable(bcEntity).UpdateColumns(it => new - { - it.BOOKING_ORDER_ID, - it.BOOKING_SLOT_ID, - it.UpdatedTime, - it.UpdatedUserId, - it.UpdatedUserName + await _taskBaseRepository.AsUpdateable(taskEntity).UpdateColumns(it => new + { + it.UpdatedTime, + it.UpdatedUserId, + it.UpdatedUserName - }).ExecuteCommand(); + }).ExecuteCommandAsync(); + } + #endregion + var currBCOrder = _taskBCInfoRepository.AsQueryable().First(a => a.PK_ID == bcEntity.PK_ID); - var taskEntity = _taskBaseRepository.AsQueryable().First(u => u.PK_ID == bcEntity.TASK_ID); + if (currBCOrder != null && model.IsDirectSend) + { + //异步推送邮件 + var mailRlt = await GenerateSendEmail(currBCOrder); - if (taskEntity != null && taskEntity.IS_PUBLIC == 1) - { - taskEntity.IS_PUBLIC = 0; - taskEntity.RealUserId = UserManager.UserId; - taskEntity.RealUserName = UserManager.Name; - taskEntity.UpdatedTime = DateTime.Now; - taskEntity.UpdatedUserId = UserManager.UserId; - taskEntity.UpdatedUserName = UserManager.Name; - - _taskBaseRepository.AsUpdateable(taskEntity).UpdateColumns(it => new - { - it.IS_PUBLIC, - it.UpdatedTime, - it.UpdatedUserId, - it.UpdatedUserName, - it.RealUserId, - it.RealUserName - - }).ExecuteCommand(); - } + if (!mailRlt.succ) + { + throw Oops.Oh($"邮件推送失败,原因:{mailRlt.msg},可以任务编辑页面重新发送邮件"); } } #endregion } else if (model.GenerateMethod == "GEN_SLOT") { - #region 推送舱位 - //推送舱位 - var bookingSlotId = GenerateBookingSlot(bcOrder, bcCtnList, fileList).GetAwaiter().GetResult(); + long bookingSlotId = 0; - if (bookingSlotId > 0) + if (bcOrder.BOOKING_SLOT_ID.HasValue && bcOrder.BOOKING_SLOT_ID.Value > 0) { - var bcEntity = _taskBCInfoRepository.AsQueryable().First(a => a.PK_ID == bcTaskInfo.PK_ID); + //bookingSlotId = bcOrder.BOOKING_SLOT_ID.Value; + throw Oops.Oh($"生成舱位失败,舱位已存在"); + } - if (bcEntity != null) - { - if (bookingSlotId > 0) - bcEntity.BOOKING_SLOT_ID = bookingSlotId; + //触发生成舱位 + bookingSlotId = await GenerateBookingSlot(bcOrder, bcCtnList, fileList); - bcEntity.UpdatedTime = DateTime.Now; - bcEntity.UpdatedUserId = UserManager.UserId; - bcEntity.UpdatedUserName = UserManager.Name; + _logger.LogInformation($"生成舱位完成,bookingSlotId={bookingSlotId} taskid={bcOrder.TASK_ID}"); - _taskBCInfoRepository.AsUpdateable(bcEntity).UpdateColumns(it => new - { - it.BOOKING_ORDER_ID, - it.BOOKING_SLOT_ID, - it.UpdatedTime, - it.UpdatedUserId, - it.UpdatedUserName + if (bookingSlotId < 1) + throw Oops.Oh($"生成舱位失败"); - }).ExecuteCommand(); + var bcEntity = _taskBCInfoRepository.AsQueryable().First(a => a.PK_ID == bcOrder.PK_ID); + if (bcEntity == null) + { + throw Oops.Oh($"未获取有效任务BC失败,更新失败"); + } - var taskEntity = _taskBaseRepository.AsQueryable().First(u => u.PK_ID == bcEntity.TASK_ID); + bcEntity.BOOKING_SLOT_ID = bookingSlotId; + bcEntity.UpdatedTime = DateTime.Now; + bcEntity.UpdatedUserId = UserManager.UserId; + bcEntity.UpdatedUserName = UserManager.Name; - if (taskEntity != null && taskEntity.IS_PUBLIC == 1) - { - taskEntity.IS_PUBLIC = 0; - taskEntity.RealUserId = UserManager.UserId; - taskEntity.RealUserName = UserManager.Name; - taskEntity.UpdatedTime = DateTime.Now; - taskEntity.UpdatedUserId = UserManager.UserId; - taskEntity.UpdatedUserName = UserManager.Name; - - _taskBaseRepository.AsUpdateable(taskEntity).UpdateColumns(it => new - { - it.IS_PUBLIC, - it.UpdatedTime, - it.UpdatedUserId, - it.UpdatedUserName, - it.RealUserId, - it.RealUserName - - }).ExecuteCommand(); - } - } + //更新任务BC + await _taskBCInfoRepository.AsUpdateable(bcEntity).UpdateColumns(it => new + { + it.BOOKING_SLOT_ID, + it.UpdatedTime, + it.UpdatedUserId, + it.UpdatedUserName + + }).ExecuteCommandAsync(); + + var taskEntity = _taskBaseRepository.AsQueryable().First(u => u.PK_ID == bcEntity.TASK_ID); + + if (taskEntity == null) + { + throw Oops.Oh($"未获取有效任务记录,更新失败"); + } + + #region 更新任务 + //如果是公共任务,需要变成个人任务 RealUserId = 当前操作人 + if (taskEntity.IS_PUBLIC == 1) + { + taskEntity.IS_PUBLIC = 0; + taskEntity.RealUserId = UserManager.UserId; + taskEntity.RealUserName = UserManager.Name; + taskEntity.UpdatedTime = DateTime.Now; + taskEntity.UpdatedUserId = UserManager.UserId; + taskEntity.UpdatedUserName = UserManager.Name; + + await _taskBaseRepository.AsUpdateable(taskEntity).UpdateColumns(it => new + { + it.IS_PUBLIC, + it.UpdatedTime, + it.UpdatedUserId, + it.UpdatedUserName, + it.RealUserId, + it.RealUserName + + }).ExecuteCommandAsync(); + } + else + { + taskEntity.UpdatedTime = DateTime.Now; + taskEntity.UpdatedUserId = UserManager.UserId; + taskEntity.UpdatedUserName = UserManager.Name; + + await _taskBaseRepository.AsUpdateable(taskEntity).UpdateColumns(it => new + { + it.UpdatedTime, + it.UpdatedUserId, + it.UpdatedUserName + + }).ExecuteCommandAsync(); } #endregion } diff --git a/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs b/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs index 70b97b49..57b6ea0a 100644 --- a/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs @@ -5685,8 +5685,8 @@ namespace Myshipping.Application /// 创建DRAFT任务 /// /// 文件 - /// BC变更内容后文件 - /// BC任务详情JSON + /// DRAFT变更内容后文件 + /// DRAFT任务详情JSON /// 返回回执 [AllowAnonymous, HttpPost("/TaskManage/CreateDRAFTTaskJob"), ApiUser(ApiCode = "BCTaskManage")] public async Task CreateDRAFTTaskJob(IFormFile file, IFormFile modifyFile, [FromForm] string jsonData) @@ -5717,6 +5717,43 @@ namespace Myshipping.Application } #endregion + #region 创建截单回执任务 + /// + /// 创建截单回执任务 + /// + /// 文件 + /// 截单回执变更内容后文件 + /// 截单回执任务详情JSON + /// 返回回执 + [AllowAnonymous, HttpPost("/TaskManage/CreateSISubmittedTaskJob"), ApiUser(ApiCode = "BCTaskManage")] + public async Task CreateSISubmittedTaskJob(IFormFile file, IFormFile modifyFile, [FromForm] string jsonData) + { + TaskManageOrderResultDto result = new TaskManageOrderResultDto(); + + string batchNo = IDGen.NextID().ToString(); + + _logger.LogInformation("批次={no} 接收到创建任务报文 报文={msg}", batchNo, jsonData); + + + try + { + TaskManageOrderMessageInfo info = JSON.Deserialize(jsonData); + + if (info == null) + throw Oops.Bah("jsonData请求内容错误,无法反序列化报文"); + + result = await InitTaskJob(info, batchNo, file, modifyFile); + } + catch (Exception ex) + { + result.succ = false; + result.msg = $"请求任务异常,{ex.Message}"; + } + + return result; + } + #endregion + #region 获取文件类型 /// /// 获取文件类型