From 5ffc74190300632b7e87817867bc7e09743bc3c0 Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Thu, 18 Jan 2024 08:50:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9BC=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Helper/FileAttachHelper.cs | 11 +- .../TaskManagePlat/TaskDraftCompareService.cs | 2 +- .../TaskManagePlat/TaskManageBCService.cs | 283 ++++++++++++++++-- 3 files changed, 267 insertions(+), 29 deletions(-) diff --git a/Myshipping.Application/Helper/FileAttachHelper.cs b/Myshipping.Application/Helper/FileAttachHelper.cs index 7a3a2a5f..d37f1a68 100644 --- a/Myshipping.Application/Helper/FileAttachHelper.cs +++ b/Myshipping.Application/Helper/FileAttachHelper.cs @@ -31,9 +31,10 @@ namespace Myshipping.Application /// 批次号 /// 是否生成本地文件 /// 附件类型 bcfiles-BC文件 + /// 是否保留原文件 /// 返回新的文件路径 public static async Task MoveFile(string fileDictKey,string sourceFilePath,string batchNo, - bool isLocalTempFile = false,string attachFileType = "bcfiles") + bool isLocalTempFile = false,string attachFileType = "bcfiles",bool isKeepSource = false) { var logger = Log.CreateLogger(nameof(FileAttachHelper)); @@ -115,10 +116,14 @@ namespace Myshipping.Application file.Close(); + try { - //删除原文件 - System.IO.File.Delete(sourceFilePath); + if (!isKeepSource) + { + //删除原文件 + System.IO.File.Delete(sourceFilePath); + } } catch(Exception delEx) { diff --git a/Myshipping.Application/Service/TaskManagePlat/TaskDraftCompareService.cs b/Myshipping.Application/Service/TaskManagePlat/TaskDraftCompareService.cs index 5bb02dfb..e0e6b051 100644 --- a/Myshipping.Application/Service/TaskManagePlat/TaskDraftCompareService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/TaskDraftCompareService.cs @@ -249,7 +249,7 @@ namespace Myshipping.Application } //如果确认文件读取成功 - var bookFilePath = await FileAttachHelper.MoveFile(bookingOrder.Id.ToString(), fileFullName, batchNo); + var bookFilePath = await FileAttachHelper.MoveFile(bookingOrder.Id.ToString(), fileFullName, batchNo, false, "draftfiles"); //将格式单附件写入订舱的附件 await SaveEDIFile(bookingOrder.Id, bookFilePath, new System.IO.FileInfo(fileFullName).Name, entity.TenantId.Value, diff --git a/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs b/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs index 2580989b..1a7cd46c 100644 --- a/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs @@ -50,8 +50,13 @@ namespace Myshipping.Application private readonly IServiceWorkFlowBaseService _serviceWorkFlowBaseService; private readonly IBookingOrderService _bookingOrderService; private readonly IBookingSlotService _bookingSlotService; - private readonly IBookingValueAddedService _bookingValueAddedService; + private readonly IBookingValueAddedService _bookingValueAddedService; + const string CONST_BC_FILE_CODE = "bc"; + const string CONST_BC_FILE_NAME = "Booking Confirmation"; + + const string CONST_BC_NOTICE_FILE_CODE = "bc_notice"; + const string CONST_BC_NOTICE_FILE_NAME = "Booking Confirmation Notice"; public TaskManageBCService(SqlSugarRepository taskBCInfoRepository, SqlSugarRepository taskBaseRepository, @@ -661,14 +666,179 @@ namespace Myshipping.Application throw Oops.Oh($"当前BC任务已生成订舱或舱位,不能重复生成"); } - if (model.GenerateMethod == "GEN_BOOKING_SLOT") { + #region 推送舱位、推送订舱 //推送舱位 - GenerateBookingSlot(bcOrder, bcCtnList, fileList).GetAwaiter().GetResult(); + var bookingSlotId = GenerateBookingSlot(bcOrder, bcCtnList, fileList).GetAwaiter().GetResult(); + + //推送订舱 + var bookingOrderId = GenerateBookingOrder(bcOrder, bcCtnList, fileList, model).GetAwaiter().GetResult(); + + if (bookingSlotId > 0 || bookingOrderId > 0) + { + var bcEntity = _taskBCInfoRepository.AsQueryable().First(a => a.PK_ID == bcTaskInfo.PK_ID); + + if (bcEntity != null) + { + if (bookingOrderId > 0) + bcEntity.BOOKING_ORDER_ID = bookingOrderId; + + if (bookingSlotId > 0) + bcEntity.BOOKING_SLOT_ID = bookingSlotId; + + bcEntity.UpdatedTime = DateTime.Now; + bcEntity.UpdatedUserId = UserManager.UserId; + bcEntity.UpdatedUserName = UserManager.Name; + _taskBCInfoRepository.AsUpdateable(bcEntity).UpdateColumns(it => new + { + it.BOOKING_ORDER_ID, + it.BOOKING_SLOT_ID, + it.UpdatedTime, + it.UpdatedUserId, + it.UpdatedUserName + + }).ExecuteCommand(); + + + var taskEntity = _taskBaseRepository.AsQueryable().First(u => u.PK_ID == bcEntity.TASK_ID); + + if(taskEntity != null && taskEntity.IS_PUBLIC == 1) + { + taskEntity.IS_PUBLIC = 0; + taskEntity.CreatedUserId = UserManager.UserId; + taskEntity.CreatedUserName = 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.CreatedUserId, + it.CreatedUserName + + }).ExecuteCommand(); + } + } + } + #endregion + } + else if (model.GenerateMethod == "GEN_BOOKING") + { + #region 推送订舱 //推送订舱 var bookingOrderId = GenerateBookingOrder(bcOrder, bcCtnList, fileList, model).GetAwaiter().GetResult(); + + if (bookingOrderId > 0) + { + var bcEntity = _taskBCInfoRepository.AsQueryable().First(a => a.PK_ID == bcTaskInfo.PK_ID); + + if (bcEntity != null) + { + if (bookingOrderId > 0) + bcEntity.BOOKING_ORDER_ID = bookingOrderId; + + bcEntity.UpdatedTime = DateTime.Now; + bcEntity.UpdatedUserId = UserManager.UserId; + bcEntity.UpdatedUserName = UserManager.Name; + + _taskBCInfoRepository.AsUpdateable(bcEntity).UpdateColumns(it => new + { + it.BOOKING_ORDER_ID, + it.BOOKING_SLOT_ID, + it.UpdatedTime, + it.UpdatedUserId, + it.UpdatedUserName + + }).ExecuteCommand(); + + + var taskEntity = _taskBaseRepository.AsQueryable().First(u => u.PK_ID == bcEntity.TASK_ID); + + if (taskEntity != null && taskEntity.IS_PUBLIC == 1) + { + taskEntity.IS_PUBLIC = 0; + taskEntity.CreatedUserId = UserManager.UserId; + taskEntity.CreatedUserName = 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.CreatedUserId, + it.CreatedUserName + + }).ExecuteCommand(); + } + } + } + #endregion + } + else if (model.GenerateMethod == "GEN_BOOKING_SLOT") + { + #region 推送舱位 + //推送舱位 + var bookingSlotId = GenerateBookingSlot(bcOrder, bcCtnList, fileList).GetAwaiter().GetResult(); + + if (bookingSlotId > 0) + { + var bcEntity = _taskBCInfoRepository.AsQueryable().First(a => a.PK_ID == bcTaskInfo.PK_ID); + + if (bcEntity != null) + { + if (bookingSlotId > 0) + bcEntity.BOOKING_SLOT_ID = bookingSlotId; + + bcEntity.UpdatedTime = DateTime.Now; + bcEntity.UpdatedUserId = UserManager.UserId; + bcEntity.UpdatedUserName = UserManager.Name; + + _taskBCInfoRepository.AsUpdateable(bcEntity).UpdateColumns(it => new + { + it.BOOKING_ORDER_ID, + it.BOOKING_SLOT_ID, + it.UpdatedTime, + it.UpdatedUserId, + it.UpdatedUserName + + }).ExecuteCommand(); + + + var taskEntity = _taskBaseRepository.AsQueryable().First(u => u.PK_ID == bcEntity.TASK_ID); + + if (taskEntity != null && taskEntity.IS_PUBLIC == 1) + { + taskEntity.IS_PUBLIC = 0; + taskEntity.CreatedUserId = UserManager.UserId; + taskEntity.CreatedUserName = 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.CreatedUserId, + it.CreatedUserName + + }).ExecuteCommand(); + } + } + } + #endregion } result.succ = true; @@ -710,6 +880,7 @@ namespace Myshipping.Application { CARRIERID = taskBCInfo.CARRIERID, CARRIER = carrierInfo.CnName?.Trim(), + SLOT_BOOKING_NO = taskBCInfo.MBL_NO, BOOKING_PARTY = taskBCInfo.BOOKING_PARTY, BOOKING_SLOT_TYPE = taskBCInfo.BOOKING_SLOT_TYPE, BOOKING_SLOT_TYPE_NAME = taskBCInfo.BOOKING_SLOT_TYPE_NAME, @@ -768,15 +939,44 @@ namespace Myshipping.Application //成功后写入附件 if (id > 0) { - taskFileList.ForEach(async file => + var opt = App.GetOptions(); + var dirAbs = opt.basePath; + if (string.IsNullOrEmpty(dirAbs)) { - //System.IO.FileStream file = new System.IO.FileStream(file, FileMode.Open, FileAccess.Read); - //附件暂存 - //var fileFullName = await FileAttachHelper.SaveFile(id, file, batchNo, "bc"); + dirAbs = App.WebHostEnvironment.WebRootPath; + } + + taskFileList.ForEach(file => + { + if (file.FILE_CATEGORY == TaskFileCategoryEnum.BC.ToString()) + { + var fileFullPath = Path.Combine(dirAbs, file.FILE_PATH); + if (File.Exists(fileFullPath)) + { + //如果确认文件读取成功 + var bookFilePath = FileAttachHelper.MoveFile(id.ToString(), fileFullPath, batchNo, false, "bcfiles", true).GetAwaiter().GetResult(); + //将格式单附件写入订舱的附件 + SaveEDIFile(id, bookFilePath, new System.IO.FileInfo(bookFilePath).Name, taskBCInfo.TenantId.Value, + CONST_BC_FILE_CODE, CONST_BC_FILE_NAME).GetAwaiter(); + } + } + else if (file.FILE_CATEGORY == TaskFileCategoryEnum.BC_NOTICE.ToString()) + { + var fileFullPath = Path.Combine(dirAbs, file.FILE_PATH); + + 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, taskBCInfo.TenantId.Value, + CONST_BC_NOTICE_FILE_CODE, CONST_BC_NOTICE_FILE_NAME).GetAwaiter(); + } + } }); - } } catch (Exception ex) @@ -871,29 +1071,62 @@ namespace Myshipping.Application id = bkRlt.Id; - //附件暂存 - //var fileFullName = await FileAttachHelper.SaveFile(id, file, batchNo, CONST_DRAFT_FILE_CODE); + string batchNo = IDGen.NextID().ToString(); - //如果确认文件读取成功 - //var bookFilePath = await FileAttachHelper.MoveFile(bookingOrder.Id.ToString(), fileFullName, batchNo); + if (id > 0) + { + 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); - //写入附件 - //await SaveEDIFile(id, bookFilePath, new System.IO.FileInfo(fileFullName).Name, entity.TenantId.Value, - // CONST_DRAFT_FILE_CODE, CONST_DRAFT_FILE_NAME); + _logger.LogInformation($"推送订舱的服务项目完成 id={id} rlt={JSON.Serialize(prjRlt)}"); + } - if (generateModel.ProjectList != null && generateModel.ProjectList.Count > 0) - { - ModifyServiceProjectDto projectDto = new ModifyServiceProjectDto + var opt = App.GetOptions(); + var dirAbs = opt.basePath; + if (string.IsNullOrEmpty(dirAbs)) + { + dirAbs = App.WebHostEnvironment.WebRootPath; + } + + taskFileList.ForEach(file => { - BookingId = id, - ProjectCodes = generateModel.ProjectList.Distinct().ToArray(), - }; - //写入服务项目 - var prjRlt = await _bookingValueAddedService.SaveServiceProject(projectDto); + if (file.FILE_CATEGORY == TaskFileCategoryEnum.BC.ToString()) + { + var fileFullPath = Path.Combine(dirAbs, file.FILE_PATH); + + if (File.Exists(fileFullPath)) + { + //如果确认文件读取成功 + var bookFilePath = FileAttachHelper.MoveFile(id.ToString(), fileFullPath, batchNo).GetAwaiter().GetResult(); + + //将格式单附件写入订舱的附件 + SaveEDIFile(id, bookFilePath, new System.IO.FileInfo(bookFilePath).Name, taskBCInfo.TenantId.Value, + CONST_BC_FILE_CODE, CONST_BC_FILE_NAME).GetAwaiter(); + } + } + else if (file.FILE_CATEGORY == TaskFileCategoryEnum.BC_NOTICE.ToString()) + { + var fileFullPath = Path.Combine(dirAbs, file.FILE_PATH); - _logger.LogInformation($"推送订舱的服务项目完成 id={id} rlt={JSON.Serialize(prjRlt)}"); + if (File.Exists(fileFullPath)) + { + //如果确认文件读取成功 + var bookFilePath = FileAttachHelper.MoveFile(id.ToString(), fileFullPath, batchNo, false, "bcnoticefile").GetAwaiter().GetResult(); + + //将格式单附件写入订舱的附件 + SaveEDIFile(id, bookFilePath, new System.IO.FileInfo(bookFilePath).Name, taskBCInfo.TenantId.Value, + CONST_BC_NOTICE_FILE_CODE, CONST_BC_NOTICE_FILE_NAME).GetAwaiter(); + } + } + }); } - _logger.LogInformation($"任务BC MBLNO:{taskBCInfo.MBL_NO} 生成订舱成功 id={id}");