From 5efcd92d5678e47b57f9ac2a7be568b88f9a96e5 Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Thu, 25 Jan 2024 16:20:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EBC=E8=88=B1=E4=BD=8D=E6=AF=94?= =?UTF-8?q?=E5=AF=B9=E7=BB=93=E6=9E=9C=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entity/BookingSlot/BookingSlotCompare.cs | 53 +++++++ .../Enum/TaskBusiTypeEnum.cs | 6 + .../Myshipping.Application.csproj | 1 - .../Service/BookingSlot/BookingSlotService.cs | 136 +++++++++++++++++- .../BookingSlot/Dto/BookingSlotMapper.cs | 77 ++++++++++ 5 files changed, 271 insertions(+), 2 deletions(-) create mode 100644 Myshipping.Application/Entity/BookingSlot/BookingSlotCompare.cs create mode 100644 Myshipping.Application/Service/BookingSlot/Dto/BookingSlotMapper.cs diff --git a/Myshipping.Application/Entity/BookingSlot/BookingSlotCompare.cs b/Myshipping.Application/Entity/BookingSlot/BookingSlotCompare.cs new file mode 100644 index 00000000..2a79d425 --- /dev/null +++ b/Myshipping.Application/Entity/BookingSlot/BookingSlotCompare.cs @@ -0,0 +1,53 @@ +using Myshipping.Core.Entity; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Myshipping.Application +{ + /// + /// 舱位变更比对记录表 + /// + [SugarTable("booking_slot_compare", TableDescription = "舱位变更比对记录表")] + public class BookingSlotCompare : DBEntityTenant + { + /// + /// 舱位主键 + /// + [SugarColumn(ColumnName = "SLOT_ID")] + [Description("舱位主键")] + public long SLOT_ID { get; set; } + + /// + /// 打印时间 + /// + [SugarColumn(ColumnName = "PRINT_DATE")] + [Description("打印时间")] + public Nullable PRINT_DATE { get; set; } + + /// + /// 比对类型 BC_MODIFY-BC变更比对 + /// + [SugarColumn(ColumnName = "COMPARE_TYPE")] + [Description("比对类型")] + public string COMPARE_TYPE { get; set; } + + /// + /// 比对结果JSON + /// + [SugarColumn(ColumnName = "COMPARE_RLT")] + [Description("比对结果JSON")] + public string COMPARE_RLT { get; set; } + + /// + /// 比对差异项数 + /// + [SugarColumn(ColumnName = "COMPARE_DIFF_NUM")] + [Description("比对差异项数")] + public Nullable COMPARE_DIFF_NUM { get; set; } + } +} diff --git a/Myshipping.Application/Enum/TaskBusiTypeEnum.cs b/Myshipping.Application/Enum/TaskBusiTypeEnum.cs index 461b82e1..81affe9c 100644 --- a/Myshipping.Application/Enum/TaskBusiTypeEnum.cs +++ b/Myshipping.Application/Enum/TaskBusiTypeEnum.cs @@ -154,5 +154,11 @@ namespace Myshipping.Application /// [Description("派车")] TRUCK_DISPATCH, + + /// + /// Booking Amendment + /// + [Description("BC变更")] + BC_MODIFY } } diff --git a/Myshipping.Application/Myshipping.Application.csproj b/Myshipping.Application/Myshipping.Application.csproj index 8b9c5aa3..a91b1b23 100644 --- a/Myshipping.Application/Myshipping.Application.csproj +++ b/Myshipping.Application/Myshipping.Application.csproj @@ -47,7 +47,6 @@ - diff --git a/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs b/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs index 4b1fcf9f..391c2e49 100644 --- a/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs +++ b/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs @@ -1,10 +1,12 @@ -using Furion.DependencyInjection; +using Furion; +using Furion.DependencyInjection; using Furion.DistributedIDGenerator; using Furion.DynamicApiController; using Furion.EventBus; using Furion.Extensions; using Furion.FriendlyException; using Furion.JsonSerialization; +using Furion.RemoteRequest.Extensions; using Mapster; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; @@ -16,17 +18,24 @@ using Myshipping.Application.Service.BookingOrder.Dto; using Myshipping.Application.Service.BookingSlot.Dto; using Myshipping.Core; using Myshipping.Core.Service; +using MySqlX.XDevAPI.Common; using Org.BouncyCastle.Asn1.Tsp; using SqlSugar; using System; using System.Collections.Generic; +using System.Collections.Specialized; using System.ComponentModel; using System.Drawing.Imaging; using System.IO; using System.Linq; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Text; using System.Threading; using System.Threading.Tasks; +using System.Web; using Yitter.IdGenerator; +using static Aliyun.OSS.Model.CreateSelectObjectMetaInputFormatModel; namespace Myshipping.Application { @@ -361,6 +370,41 @@ namespace Myshipping.Application throw Oops.Bah($"未找到订舱编号为 {dto.DataObj.SLOT_BOOKING_NO} 的数据"); } + id = model.Id; + + //生成待比对详情 + TaskBCInfoDto bcSrcDto = model.Adapt(); + TaskBCInfoDto bcTargetDto = dto.DataObj.Adapt(); + + //提取箱信息 + var ctnList = _repCtn.AsQueryable() + .Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID + && x.SLOT_ID == model.Id).ToList(); + + if(ctnList != null) + { + bcSrcDto.CtnList = ctnList.GroupBy(x => x.CTNALL) + .Select(x => + { + return new TaskBCCTNInfoDto { CtnALL = x.Key, CTNNUM = x.ToList() + .Sum(a => a.CTNNUM) }; + }).ToList(); + } + + if (dto.DataObj.CtnList != null && dto.DataObj.CtnList.Count > 0) + { + bcTargetDto.CtnList = dto.DataObj.CtnList.GroupBy(x => x.CTNALL) + .Select(x => + { + return new TaskBCCTNInfoDto + { + CtnALL = x.Key, + CTNNUM = x.ToList() + .Sum(a => a.CTNNUM) + }; + }).ToList(); + } + var oldObj = model.Adapt(); dto.DataObj.Adapt(model); @@ -409,6 +453,9 @@ namespace Myshipping.Application CONST_BC_MODIFY_NOTICE_FILE_CODE, CONST_BC_MODIFY_NOTICE_FILE_NAME).GetAwaiter(); } } + + //一般更新数据指的是Booking Amendment,需要与舱位进行数据比对 + await PushCompareBCInfo(bcSrcDto, bcTargetDto,id); } else if (dto.OpType == "del") { @@ -918,6 +965,93 @@ namespace Myshipping.Application await _bookingFileRepository.InsertAsync(bookFile); } #endregion + + + private async Task PushCompareBCInfo(TaskBCInfoDto bcSrcDto, TaskBCInfoDto bcTargetDto,long slotId) + { + string batchNo = IDGen.NextID().ToString(); + + DateTime bDate = DateTime.Now; + + var compareResult = await ExcuteCompare(bcSrcDto, bcTargetDto); + + DateTime eDate = DateTime.Now; + TimeSpan ts = eDate.Subtract(bDate); + var timeDiff = ts.TotalMilliseconds; + + _logger.LogInformation("批次={no} 请求完成,耗时:{timeDiff}ms. 结果{msg}", batchNo, timeDiff, compareResult.succ ? "成功" : "失败"); + + if (compareResult == null) + throw Oops.Oh($"舱位主键{slotId}请求BC比对失败,返回为空"); + + + + + } + + #region 请求BC比对 + /// + /// 请求BC比对 + /// + /// BC详情 + /// BC变更后详情 + /// 返回回执 + [NonAction] + private async Task ExcuteCompare(TaskBCInfoDto bcSrcDto, TaskBCInfoDto bcTargetDto) + { + TaskManageExcuteResultDto model = null; + /* + 1、读取配置文件中的规则引擎URL + 2、填充请求的类,并生成JSON报文 + 3、POST请求接口,并记录回执。 + 4、返回信息。 + */ + + var url = App.Configuration["BCCompareUrl"]; + + using (var httpClient = new HttpClient()) + { + try + { + using (var reduceAttach = new MultipartFormDataContent()) + { + var dataContent = new ByteArrayContent(Encoding.UTF8.GetBytes(JSON.Serialize(bcSrcDto))); + + dataContent.Headers.ContentDisposition = new ContentDispositionHeaderValue($"form-data") + { + Name = "srcJson" + }; + + reduceAttach.Add(dataContent); + + var dataContent2 = new ByteArrayContent(Encoding.UTF8.GetBytes(JSON.Serialize(bcTargetDto))); + + dataContent2.Headers.ContentDisposition = new ContentDispositionHeaderValue($"form-data") + { + Name = "destJson" + }; + + reduceAttach.Add(dataContent2); + + //请求 + var response = httpClient.PostAsync(url, reduceAttach).Result; + + var result = response.Content.ReadAsStringAsync().Result; + + model = JSON.Deserialize(result); + } + } + catch (Exception ex) + { + _logger.LogInformation("推送BC比对异常,原因:{error}", ex.Message); + + throw Oops.Oh($"推送BC比对异常,原因:{ex.Message}"); + } + } + + return model; + } + #endregion } public class DynameFileInfo diff --git a/Myshipping.Application/Service/BookingSlot/Dto/BookingSlotMapper.cs b/Myshipping.Application/Service/BookingSlot/Dto/BookingSlotMapper.cs new file mode 100644 index 00000000..4e1c45d3 --- /dev/null +++ b/Myshipping.Application/Service/BookingSlot/Dto/BookingSlotMapper.cs @@ -0,0 +1,77 @@ +using Mapster; +using Myshipping.Application.Entity; +using Myshipping.Application.Service.BookingSlot.Dto; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Myshipping.Application +{ + public class BookingSlotMapper : IRegister + { + public void Register(TypeAdapterConfig config) + { + config.ForType() + .Map(dest => dest.CarrierId, src => src.CARRIERID) + .Map(dest => dest.Carrier, src => src.CARRIER) + .Map(dest => dest.MBLNo, src => src.SLOT_BOOKING_NO) + .Map(dest => dest.BookingSlotType, src => src.BOOKING_SLOT_TYPE) + .Map(dest => dest.BookingSlotTypeName, src => src.BOOKING_SLOT_TYPE_NAME) + .Map(dest => dest.Vessel, src => src.VESSEL) + .Map(dest => dest.VoyNo, src => src.VOYNO) + .Map(dest => dest.VGMSubmissionCutDate, src => src.VGM_SUBMISSION_CUT_DATE) + .Map(dest => dest.WeekAt, src => src.WEEK_AT) + .Map(dest => dest.CarriageType, src => src.CARRIAGE_TYPE) + .Map(dest => dest.CarriageTypeName, src => src.CARRIAGE_TYPE_NAME) + .Map(dest => dest.ContractNo, src => src.CONTRACT_NO) + .Map(dest => dest.CtnStat, src => src.CTN_STAT) + .Map(dest => dest.CYCutoffTime, src => src.CY_CUT_DATE) + .Map(dest => dest.DetensionFreeDays, src => src.DETENSION_FREE_DAYS) + .Map(dest => dest.ETD, src => src.ETD) + .Map(dest => dest.ETA, src => src.ETA) + .Map(dest => dest.LaneCode, src => src.LANECODE) + .Map(dest => dest.LaneName, src => src.LANENAME) + .Map(dest => dest.ManifestCutDate, src => src.MANIFEST_CUT_DATE) + .Map(dest => dest.MDGFCutDate, src => src.MDGF_CUT_DATE) + .Map(dest => dest.PlaceDelivery, src => src.PLACEDELIVERY) + .Map(dest => dest.PlaceReceipt, src => src.PLACERECEIPT) + .Map(dest => dest.PortDischarge, src => src.PORTDISCHARGE) + .Map(dest => dest.Portload, src => src.PORTLOAD) + .Map(dest => dest.TransferPort1, src => src.TRANSFER_PORT_1) + .Map(dest => dest.TransferPort2, src => src.TRANSFER_PORT_2); + + config.ForType() + .Map(dest => dest.CarrierId, src => src.CARRIERID) + .Map(dest => dest.Carrier, src => src.CARRIER) + .Map(dest => dest.MBLNo, src => src.SLOT_BOOKING_NO) + .Map(dest => dest.BookingSlotType, src => src.BOOKING_SLOT_TYPE) + .Map(dest => dest.BookingSlotTypeName, src => src.BOOKING_SLOT_TYPE_NAME) + .Map(dest => dest.Vessel, src => src.VESSEL) + .Map(dest => dest.VoyNo, src => src.VOYNO) + .Map(dest => dest.VGMSubmissionCutDate, src => src.VGM_SUBMISSION_CUT_DATE) + .Map(dest => dest.WeekAt, src => src.WEEK_AT) + .Map(dest => dest.CarriageType, src => src.CARRIAGE_TYPE) + .Map(dest => dest.CarriageTypeName, src => src.CARRIAGE_TYPE_NAME) + .Map(dest => dest.ContractNo, src => src.CONTRACT_NO) + .Map(dest => dest.CtnStat, src => src.CTN_STAT) + .Map(dest => dest.CYCutoffTime, src => src.CY_CUT_DATE) + .Map(dest => dest.DetensionFreeDays, src => src.DETENSION_FREE_DAYS) + .Map(dest => dest.ETD, src => src.ETD) + .Map(dest => dest.ETA, src => src.ETA) + .Map(dest => dest.LaneCode, src => src.LANECODE) + .Map(dest => dest.LaneName, src => src.LANENAME) + .Map(dest => dest.ManifestCutDate, src => src.MANIFEST_CUT_DATE) + .Map(dest => dest.MDGFCutDate, src => src.MDGF_CUT_DATE) + .Map(dest => dest.PlaceDelivery, src => src.PLACEDELIVERY) + .Map(dest => dest.PlaceReceipt, src => src.PLACERECEIPT) + .Map(dest => dest.PortDischarge, src => src.PORTDISCHARGE) + .Map(dest => dest.Portload, src => src.PORTLOAD) + .Map(dest => dest.TransferPort1, src => src.TRANSFER_PORT_1) + .Map(dest => dest.TransferPort2, src => src.TRANSFER_PORT_2); + + + } + } +}