diff --git a/Myshipping.Application/Entity/BookingVGMStatus.cs b/Myshipping.Application/Entity/BookingVGMStatus.cs new file mode 100644 index 00000000..2875e274 --- /dev/null +++ b/Myshipping.Application/Entity/BookingVGMStatus.cs @@ -0,0 +1,54 @@ +using Myshipping.Core.Entity; +using SqlSugar; +using System.ComponentModel; +namespace Myshipping.Application.Entity +{ + /// + /// VGM发送状态表 + /// + [SugarTable("booking_vgm_status")] + [Description("VGM发送状态表")] + public class BookingVGMStatus : DBEntityTenant + { + /// + /// 业务id + /// + public long BookingId { get; set; } + + /// + /// VGM平台主键 + /// + public string MFNO { get; set; } + + /// + /// 是否已发送船司 + /// + public bool IsSendCarrier { get; set; } + /// + /// 发送船司是否成功 + /// + public bool IsSendCarrierSuccess { get; set; } + /// + /// 发送船司是否直发 + /// + public bool IsSendCarrierDirect { get; set; } + /// + /// 发送船司结果消息 + /// + public string SendCarrierMessage { get; set; } + + + /// + /// 是否已发送云港通 + /// + public bool IsSendYgt { get; set; } + /// + /// 发送云港通是否成功 + /// + public bool IsSendYgtSuccess { get; set; } + /// + /// 发送云港通结果消息 + /// + public string SendYgtMessage { get; set; } + } +} \ No newline at end of file diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index 74df3cd3..0a02731c 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -1,93 +1,64 @@ -using Myshipping.Core; +using Furion; using Furion.DependencyInjection; +using Furion.DistributedIDGenerator; using Furion.DynamicApiController; +using Furion.EventBus; +using Furion.FriendlyException; +using Furion.JsonSerialization; +using Furion.RemoteRequest.Extensions; using Mapster; -using Microsoft.AspNetCore.Mvc; -using SqlSugar; -using System.Linq; -using System.Threading.Tasks; -using Myshipping.Application.Entity; using Microsoft.AspNetCore.Authorization; -using Furion; using Microsoft.AspNetCore.Http; -using Furion.DataEncryption; -using System.Collections.Generic; -using System.Security.Claims; -using Microsoft.AspNetCore.Authentication.Cookies; -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Identity; -using Furion.FriendlyException; -using Furion.Logging; -using System; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; -using System.Reflection; -using System.ComponentModel; -using Myshipping.Application.Service.BookingOrder.Dto; using Myshipping.Application.ConfigOption; -using System.IO; -using Yitter.IdGenerator; -using Myshipping.Core.Entity; -using Furion.RemoteRequest.Extensions; -using System.Net.Http; -using Myshipping.Core.Service; using Myshipping.Application.EDI; -using System.Text; -using System.Web; -using Newtonsoft.Json.Linq; -using Myshipping.Core.Helper; -using Myshipping.Application.Enum; -using Org.BouncyCastle.Asn1.X500; -using System.Drawing.Drawing2D; -using StackExchange.Profiling.Internal; -using Myshipping.Application; +using Myshipping.Application.EDI.ESL; using Myshipping.Application.EDI.PIL; -using Newtonsoft.Json; +using Myshipping.Application.EDI.SeaLead; +using Myshipping.Application.EDI.SITC; using Myshipping.Application.EDI.TSL; +using Myshipping.Application.EDI.VOLTA; using Myshipping.Application.EDI.WY; using Myshipping.Application.EDI.YML; using Myshipping.Application.EDI.YT; -using System.Runtime.InteropServices; -using System.Threading; -using Furion.JsonSerialization; -using System.Xml.Linq; +using Myshipping.Application.Entity; +using Myshipping.Application.Enum; using Myshipping.Application.Helper; -using System.Net; -using Furion.DistributedIDGenerator; -using System.Linq.Expressions; +using Myshipping.Application.Service.BookingOrder.Dto; +using Myshipping.Application.Service.BookingOrder.Dto.MSKAPI; +using Myshipping.Application.Service.BookingSlot.Dto; +using Myshipping.Application.Service.DataSync.Dto; +using Myshipping.Core; +using Myshipping.Core.Const; +using Myshipping.Core.Entity; +using Myshipping.Core.Entity.PingTai; using Myshipping.Core.Extension; -using System.Text.RegularExpressions; -using MathNet.Numerics.Distributions; -using Microsoft.IdentityModel.Tokens; -using Myshipping.Application.EDI.ESL; +using Myshipping.Core.Helper; +using Myshipping.Core.Service; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; -using NPOI.SS.Formula.Functions; -using NPOI.HPSF; -using MimeKit; -using NPOI.SS.Formula; -using NPOI.Util; +using RabbitMQ.Client; +using SqlSugar; +using StackExchange.Profiling.Internal; +using System; +using System.Collections.Generic; using System.Collections.Specialized; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Net.Http; using System.Net.Http.Headers; -using MySqlX.XDevAPI.Common; -using Ubiety.Dns.Core; -using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData; -using System.Security.Cryptography; -using Myshipping.Application.Service.DataSync.Dto; -using RabbitMQ.Client; -using System.Configuration; -using System.Collections; -using System.Security.Principal; -using Myshipping.Core.Const; -using ICSharpCode.SharpZipLib.BZip2; -using Myshipping.Application.EDI.VOLTA; +using System.Runtime.InteropServices; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using System.Web; using TinyPinyin; -using Furion.EventBus; -using Myshipping.Application.Service.BookingSlot.Dto; -using Myshipping.Application.Service.BookingOrder.Dto.MSKAPI; -using Microsoft.AspNetCore.Routing.Template; -using Myshipping.Application.EDI.SeaLead; -using Myshipping.Application.EDI.SITC; -using Myshipping.Core.Entity.PingTai; +using Yitter.IdGenerator; namespace Myshipping.Application { @@ -5240,10 +5211,418 @@ namespace Myshipping.Application /// /// 直发VGM(单票) /// - /// + /// 订单Id + /// 是否发送船司 + /// 是否发送云港通 + /// 是否检查重复发送 /// [HttpPost("/BookingOrder/VgmSend")] - public async Task VgmSend(long bookingId) + public async Task VgmSend(long bookingId, bool isSendCarr, bool isSendYGT, bool? isCheckRepeat) + { + //throw Oops.Bah(201, $"是否重新发送?"); + //throw Oops.Bah($"是否重新发送?"); + if (App.Configuration["RunType"] == CommonConst.RUN_TYPE_HECHUAN && App.Configuration["RunTest"] == "true") + { + return await VgmSendNewSchema(bookingId, isSendCarr, isSendYGT, isCheckRepeat); + } + else + { + return await VgmSendOldSchema(bookingId); + } + } + + /// + /// VGM发送(新) + /// + /// 订单Id + /// 是否发送船司 + /// 是否发送云港通 + /// 是否检查重复发送 + /// 发船司判断走船司直发或者通过大简云新API发送;发云港通通过大简云新API发送 + public async Task VgmSendNewSchema(long bookingId, bool isSendCarr, bool isSendYGT, bool? isCheckRepeat) + { + if (!isSendCarr && !isSendYGT) + { + throw Oops.Bah("VGM发送船司或云港通至少选择一项"); + } + + var order = await _rep.FirstOrDefaultAsync(x => x.Id == bookingId); + var ctns = await _repCtn.Where(x => x.BILLID == bookingId).ToListAsync(); + + if (order == null) + { + throw Oops.Bah("未获取到订单信息,可能已被删除,请关闭页面重新打开"); + } + + if (ctns.Count == 0) + { + throw Oops.Bah("箱信息为空"); + } + + // 查询vgm发送状态 + var vgmStatus = await _rep.Context.Queryable().Where(x => x.BookingId == bookingId).FirstAsync(); + if (vgmStatus == null) + { + vgmStatus = new BookingVGMStatus() + { + BookingId = bookingId + }; + } + + // 船司VGM是否通过直发的方式 + bool isSendCarrDirect = false; + + //船公司 + if (string.IsNullOrEmpty(order.CARRIERID)) + { + throw Oops.Bah(BookingErrorCode.BOOK118); + } + + //提单号不能为空 + if (string.IsNullOrEmpty(order.MBLNO)) + { + throw Oops.Bah(BookingErrorCode.BOOK127); + } + + if (string.IsNullOrEmpty(order.YARD) || string.IsNullOrEmpty(order.YARDID)) + { + throw Oops.Bah("场站未正确选择"); + } + + // 验证是否重复发送 + if (isCheckRepeat == true) + { + var repeatType = new List(2); + if (isSendCarr && vgmStatus.IsSendCarrierSuccess) + { + repeatType.Add("【船司】"); + } + if (isSendYGT && vgmStatus.IsSendYgtSuccess) + { + repeatType.Add("【云港通】"); + } + if (repeatType.Count > 0) + { + throw Oops.Bah($"已发送过{string.Join("、", repeatType)}VGM,是否重新发送?"); + } + } + + if (ctns.Where(c => c.WEIGHTYPE == "累加" && + ( + string.IsNullOrEmpty(c.CNTRNO) + || !c.WEIGHKGS.HasValue + || c.WEIGHKGS == 0 + || !c.TAREWEIGHT.HasValue + || c.TAREWEIGHT == 0 + || !c.KGS.HasValue + || c.KGS == 0) + ).Count() > 0) + { + throw Oops.Bah("称重方式为累加时,箱号、重量、箱皮重以及称重重量都不能为空"); + } + + if (ctns.Where(c => c.WEIGHTYPE == "总重" && + ( + string.IsNullOrEmpty(c.CNTRNO) + || !c.WEIGHKGS.HasValue + || c.WEIGHKGS == 0) + ).Count() > 0) + { + throw Oops.Bah("称重方式为总重时,箱号和称重重量都不能为空"); + } + + var tenantParamList = _cache.GetAllTenantParam().Result; + + if (isSendCarr) + { + var config = tenantParamList.FirstOrDefault(x => x.TenantId == UserManager.TENANT_ID && x.ParaCode == "VgmDirectSendCarrierId"); + if (config != null + && config.ItemCode?.Split(",", StringSplitOptions.RemoveEmptyEntries)?.Contains(order.CARRIERID) == true) + { + isSendCarrDirect = true; + } + + + if (isSendCarrDirect) + { + try + { + await VGMDirectSendCarrier(bookingId, order, ctns); + + vgmStatus.IsSendCarrier = true; + vgmStatus.IsSendCarrierDirect = true; + vgmStatus.IsSendCarrierSuccess = true; + vgmStatus.SendCarrierMessage = "发送船司成功"; + } + catch (Exception ex) + { + vgmStatus.IsSendCarrier = true; + vgmStatus.IsSendCarrierDirect = true; + vgmStatus.IsSendCarrierSuccess = false; + vgmStatus.SendCarrierMessage = $"发送船司失败:{ex.Message}"; + } + } + } + + if ((isSendCarr && !isSendCarrDirect) || isSendYGT) + { + try + { + var sysconfig = await _cache.GetAllSysConfig(); + var urlConfig = sysconfig.FirstOrDefault(x => x.GroupCode == "DJY_CONST" && x.Code == "DjyCarrierAndYgtVgmApi"); + + // 获取用户Key及Secret + var keySecretParam = tenantParamList.FirstOrDefault(x => x.TenantId == UserManager.TENANT_ID && x.ParaCode == "DjyCarrierAndYgtVgmApiKeySecret"); + if (keySecretParam == null || !keySecretParam.ItemCode.Contains(',')) + { + throw Oops.Bah("请在租户参数配置【船司及云港通VGM发送API】所需的Key及Secret"); + } + var keySecretArr = keySecretParam.ItemCode.Split(','); + var dicHead = new Dictionary + { + { "USER_KEY", keySecretArr[0] }, + { "USER_SECRET", keySecretArr[1] } + }; + + //ETD不能为空 + if (!order.ETD.HasValue) + { + throw Oops.Bah("ETD不能为空"); + } + + //重量不能为空 + if (!order.KGS.HasValue) + { + throw Oops.Bah("重量不能为空"); + } + + // 场站映射 + string mappingYard; + var yardMapList = _cache.GetAllMappingYard().Result?.Where(y => y.Code == order.YARDID && y.Module == "VgmPlat" && (y.CarrierCode == null || y.CarrierCode == "" || y.CarrierCode == order.CARRIERID))?.ToList(); + if (yardMapList?.Any() == true) + { + var yardset = yardMapList.FirstOrDefault(x => x.CarrierCode == order.CARRIERID) + ?? yardMapList.FirstOrDefault(x => x.CarrierCode == null || x.CarrierCode == ""); + + mappingYard = yardset.MapName; + } + else + { + mappingYard = order.YARD; + } + + #region 判断并验证发送类型 + string carrSendType = null, ygtSendType = null; + if (isSendCarr && !isSendCarrDirect) + { + if (vgmStatus.IsSendCarrierSuccess) + { + carrSendType = "update"; + } + else + { + carrSendType = "add"; + } + } + if (isSendYGT) + { + if (vgmStatus.IsSendYgtSuccess) + { + ygtSendType = "update"; + } + else + { + ygtSendType = "add"; + } + } + if (carrSendType != null && ygtSendType != null && carrSendType != ygtSendType) + { + if (carrSendType == "add" && ygtSendType == "update") + { + throw Oops.Bah("检测到已发送过船司VGM非直发,请分别进行船司VGM的非直发新增以及云港通VGM的修改操作"); + } + else + { + throw Oops.Bah("检测到已发送过云港通VGM,请分别进行船司VGM的非直发修改以及云港通VGM的新增操作"); + } + } + #endregion + + var sendObj = new VgmPlatDto + { + // 到这一步,carrSendType和ygtSendType在都不为null的情况下,应该是一致的 + SendType = (carrSendType ?? ygtSendType) switch + { + "add" => "9", + "update" => "5", + _ => throw Oops.Bah("无法判断发送类型") + }, + SendCarr = (isSendCarr && !isSendCarrDirect), + SendYGT = isSendYGT, + IsLinkSave = false, + IsApiSave = false, + MFNO = vgmStatus.MFNO, + MBLNO = order.MBLNO, + CARRIER = order.CARRIERID, + ETD = order.ETD, + WeiTuoFaSongFang = "", + ChuanMing = order.VESSEL, + HangCi = order.VOYNO, + BeiZhu = order.CZRemark, + ZhuangHuoGang = order.PORTLOAD, + ZhuangHuoGangDaiMa = order.PORTLOADID, + YARD = mappingYard, + ORDERNO = order.CUSTNO, + VGMCLOSETIME = order.CLOSEVGMDATE, + + CtnList = ctns.Select(c => new VgmPlatCtnDto() + { + CTNALL = c.CTNALL, + CNTRNO = c.CNTRNO, + SEALNO = c.SEALNO, + KGS = c.KGS, + PKGS = c.PKGS, + PIZHONG = c.TAREWEIGHT.Value, + ChengZhongFangShi = c.WEIGHTYPE, + ChengZhongShiJian = string.IsNullOrEmpty(c.WEIGHDATE) ? DateTime.Today.ToString("yyyy-MM-dd") : c.WEIGHDATE, + ChengZhongZhongLiang = c.WEIGHKGS, + SendFlag = true + }).ToList() + }; + + _logger.LogInformation($"调用VGM平台的发送接口:{urlConfig.Value},参数:{JsonConvert.SerializeObject(sendObj)}"); + + var rtn = await urlConfig.Value + .SetBody(sendObj, "application/json") + .SetHeaders(dicHead) + .PostAsStringAsync(); + + _logger.LogInformation($"调用VGM平台的发送接口:{urlConfig.Value},返回:{rtn}"); + + var jobjRtn = JObject.Parse(rtn); + var isSuccess = jobjRtn.GetBooleanValue("succeeded"); + var errors = jobjRtn.GetStringValue("errors"); + + var jobjData = jobjRtn.GetJObjectValue("data"); + var carrSendFlag = jobjData?.GetIntValue("carrierSendFlag"); + var ygtSendFlag = jobjData?.GetIntValue("ygtSendFlag"); + var sendRltMsg = jobjData?.GetStringValue("sendRltMsg"); + var vgmMFNO = jobjData?.GetValue("mfno")?.ToString(); + + if (!string.IsNullOrWhiteSpace(vgmMFNO)) + { + vgmStatus.MFNO = vgmMFNO; + } + if (isSuccess) + { + //货运动态(两种) + var statusLogList = new List(); + + if (isSendCarr && !isSendCarrDirect) + { + vgmStatus.IsSendCarrier = true; + if (carrSendFlag == 1) + { + vgmStatus.IsSendCarrierSuccess = true; + vgmStatus.SendCarrierMessage = "发送船司成功"; + + statusLogList.Add(new BookingStatusLog() + { + BookingId = bookingId, + Status = $"发送船司VGM", + OpTime = DateTime.Now, + Category = "ship", + MBLNO = order.MBLNO + }); + } + else + { + vgmStatus.IsSendCarrierSuccess = false; + vgmStatus.SendCarrierMessage = $"发送船司失败:{sendRltMsg}"; + } + } + + if (isSendYGT) + { + vgmStatus.IsSendYgt = true; + if (ygtSendFlag == 1) + { + vgmStatus.IsSendYgtSuccess = true; + vgmStatus.SendYgtMessage = "发送云港通成功"; + + statusLogList.Add(new BookingStatusLog() + { + BookingId = bookingId, + Status = $"发送云港通VGM", + OpTime = DateTime.Now, + Category = "ship", + MBLNO = order.MBLNO + }); + } + else + { + vgmStatus.IsSendYgtSuccess = false; + vgmStatus.SendYgtMessage = $"发送云港通失败:{sendRltMsg}"; + } + } + await _repStatuslog.InsertAsync(statusLogList); + } + else + { + throw Oops.Bah($"VGM平台返回错误({errors})"); + } + } + catch (Exception ex) + { + if (isSendCarr && !isSendCarrDirect) + { + if (!string.IsNullOrEmpty(vgmStatus.MFNO)) + { + vgmStatus.IsSendCarrier = true; + } + vgmStatus.IsSendCarrierSuccess = false; + vgmStatus.SendCarrierMessage = $"发送船司失败:{ex.Message}"; + } + + if (isSendYGT) + { + if (!string.IsNullOrEmpty(vgmStatus.MFNO)) + { + vgmStatus.IsSendYgt = true; + } + vgmStatus.IsSendYgtSuccess = false; + vgmStatus.SendYgtMessage = $"发送云港通失败:{ex.Message}"; + } + } + } + + if (vgmStatus.Id == 0) + { + await _rep.Context.Insertable(vgmStatus).ExecuteCommandAsync(); + } + else + { + await _rep.Context.Updateable(vgmStatus).ExecuteCommandAsync(); + } + + if ( + (!isSendCarr || (isSendCarr && vgmStatus.IsSendCarrierSuccess)) + && + (!isSendYGT || (isSendYGT && vgmStatus.IsSendYgtSuccess)) + ) + { + //设置货物状态:已发VGM,并回传东胜 + await SetGoodsStatus("YFVGM", bookingId); + await SendBookingOrder(new long[] { bookingId }); + } + + return vgmStatus; + } + + /// + /// VGM发送(通过船司直发或者大简云发送) + /// + public async Task VgmSendOldSchema(long bookingId) { object result = null; @@ -5499,173 +5878,180 @@ namespace Myshipping.Application // VGM发送方式3:直接调用vgm接口直发 else { - //判断船公司是否支持 - var allowCarrier = _cache.GetAllDictData().Result.Where(x => x.TypeCode == "vgm_carrier_list").Select(x => x.Code).ToList(); - if (!allowCarrier.Contains(order.CARRIERID)) - { - throw Oops.Bah(BookingErrorCode.BOOK117); - } + await VGMDirectSendCarrier(bookingId, order, ctns); + } + } - //船公司网站账号 - var carrWebAccMap = _cache.GetAllDictData().Result.FirstOrDefault(x => x.TypeCode == "carrier_web_account_mapping" && x.Code == order.CARRIERID); - if (carrWebAccMap == null) - { - throw Oops.Bah("不支持的船公司或账号映射未配置"); - } + //设置货物状态:已发VGM,并回传东胜 + await SetGoodsStatus("YFVGM", bookingId); + await SendBookingOrder(new long[] { bookingId }); - var webacc = _webAccountConfig.GetAccountConfig(carrWebAccMap.Value, UserManager.UserId).Result; - if (webacc == null) - { - throw Oops.Bah(BookingErrorCode.BOOK125); - } + return result; + } - ////箱型映射 - //var ctnMapping = await _cache.GetAllMappingCtn(); - //ctnMapping = ctnMapping.Where(x => x.Module == "BookingVgm").ToList(); - //if (ctnMapping.Count == 0) - //{ - // throw Oops.Bah(BookingErrorCode.BOOK122); - //} + /// + /// VGM直发船司 + /// + private async Task VGMDirectSendCarrier(long bookingId, BookingOrder order, List ctns) + { + //判断船公司是否支持 + var allowCarrier = _cache.GetAllDictData().Result.Where(x => x.TypeCode == "vgm_carrier_list").Select(x => x.Code).ToList(); + if (!allowCarrier.Contains(order.CARRIERID)) + { + throw Oops.Bah(BookingErrorCode.BOOK117); + } - //var expCode = ctns.Select(x => x.CTNCODE).Distinct().Except(ctnMapping.Select(y => y.Code)).ToList(); - //if (expCode.Count > 0) - //{ - // throw Oops.Bah(BookingErrorCode.BOOK123, string.Join(',', expCode)); - //} + //船公司网站账号 + var carrWebAccMap = _cache.GetAllDictData().Result.FirstOrDefault(x => x.TypeCode == "carrier_web_account_mapping" && x.Code == order.CARRIERID); + if (carrWebAccMap == null) + { + throw Oops.Bah("不支持的船公司或账号映射未配置"); + } - #region 箱信息校验,2022-7-1修改:【累加】的必须有重量、皮重和称重重量;【总重】的只需要称重重量不为空 - if (ctns.Where(c => c.WEIGHTYPE == "累加" && - ( - string.IsNullOrEmpty(c.CNTRNO) - || !c.WEIGHKGS.HasValue - || c.WEIGHKGS == 0 - || !c.TAREWEIGHT.HasValue - || c.TAREWEIGHT == 0 - || !c.KGS.HasValue - || c.KGS == 0) - ).Count() > 0) - { - throw Oops.Bah("称重方式为累加时,箱号、重量、箱皮重以及称重重量都不能为空"); - } + var webacc = _webAccountConfig.GetAccountConfig(carrWebAccMap.Value, UserManager.UserId).Result; + if (webacc == null) + { + throw Oops.Bah(BookingErrorCode.BOOK125); + } - if (ctns.Where(c => c.WEIGHTYPE == "总重" && - ( - string.IsNullOrEmpty(c.CNTRNO) - || !c.WEIGHKGS.HasValue - || c.WEIGHKGS == 0) - ).Count() > 0) - { - throw Oops.Bah("称重方式为总重时,箱号和称重重量都不能为空"); - } - #endregion + ////箱型映射 + //var ctnMapping = await _cache.GetAllMappingCtn(); + //ctnMapping = ctnMapping.Where(x => x.Module == "BookingVgm").ToList(); + //if (ctnMapping.Count == 0) + //{ + // throw Oops.Bah(BookingErrorCode.BOOK122); + //} + //var expCode = ctns.Select(x => x.CTNCODE).Distinct().Except(ctnMapping.Select(y => y.Code)).ToList(); + //if (expCode.Count > 0) + //{ + // throw Oops.Bah(BookingErrorCode.BOOK123, string.Join(',', expCode)); + //} - ////场站转换 - //var yardset = _cache.GetAllMappingYard().Result.FirstOrDefault(y => y.Code == order.YARDID && y.Module == "BookingVgm"); - //if (yardset == null) - //{ - // throw Oops.Bah(BookingErrorCode.BOOK120, order.YARDID); - //} - if (string.IsNullOrEmpty(order.YARD) || string.IsNullOrEmpty(order.YARDID)) - { - throw Oops.Bah("场站未正确选择"); - } - // 场站映射 - string mappingYard, mappingYardId; - var yardMapList = _cache.GetAllMappingYard().Result?.Where(y => y.Code == order.YARDID && y.Module == "BookingVgm" && (y.CarrierCode == null || y.CarrierCode == "" || y.CarrierCode == order.CARRIERID))?.ToList(); - if (yardMapList?.Any() == true) - { - var yardset = yardMapList.FirstOrDefault(x => x.CarrierCode == order.CARRIERID) - ?? yardMapList.FirstOrDefault(x => x.CarrierCode == null || x.CarrierCode == ""); + #region 箱信息校验,2022-7-1修改:【累加】的必须有重量、皮重和称重重量;【总重】的只需要称重重量不为空 + if (ctns.Where(c => c.WEIGHTYPE == "累加" && + ( + string.IsNullOrEmpty(c.CNTRNO) + || !c.WEIGHKGS.HasValue + || c.WEIGHKGS == 0 + || !c.TAREWEIGHT.HasValue + || c.TAREWEIGHT == 0 + || !c.KGS.HasValue + || c.KGS == 0) + ).Count() > 0) + { + throw Oops.Bah("称重方式为累加时,箱号、重量、箱皮重以及称重重量都不能为空"); + } - mappingYard = yardset.MapName; - mappingYardId = yardset.MapCode; - } - else - { - mappingYard = order.YARD; - mappingYardId = order.YARDID; - } - - // 船司映射 - var carrMap = _cache.GetAllMappingCarrier().Result?.Where(y => y.Code == order.CARRIERID && y.Module == "BookingVgm")?.FirstOrDefault(); - string mappingCarrierId = carrMap != null ? carrMap.MapCode : order.CARRIERID; - - var user = await _repUser.FirstOrDefaultAsync(x => x.Id == UserManager.UserId); - - int idx = 1; - //调用接口 - var dicUrl = _cache.GetAllDictData().Result.First(x => x.TypeCode == "url_set" && x.Code == "vgm_service_single"); - var sendObj = new - { - SystemCode = "djy_hechuan", - billOrderId = order.Id.ToString(), - sendOrderCode = order.MBLNO, - customerName = $"{UserManager.TENANT_NAME}+{UserManager.Name}", //公司名称+用户姓名 - customerId = order.CUSTOMERID.ToString(), - agentName = string.IsNullOrEmpty(order.FORWARDER) ? UserManager.TENANT_NAME : order.FORWARDER, - carrierCode = mappingCarrierId, - userName = webacc.Account, - userPassword = webacc.Password, - depotCode = mappingYardId, - depotName = mappingYard, - linkName = UserManager.Name, - linkMobile = user.Phone, - linkEmail = user.Email, - userId = user.DjyUserId, - signatory = user.NickName, //2023年8月28日,董怡含:把用户昵称当做vgm上传人 - returnUrl = "", - shipName = order.VESSEL, - voyNo = order.VOYNO, - etdstr = order.ETD.HasValue ? order.ETD.Value.ToString("yyyy-MM-dd") : string.Empty, - potrSend = order.PORTLOAD, - potrGoal = order.PORTDISCHARGE, - boxinfoStr = order.CNTRTOTAL.Replace("'", ""), - vgmEndTimeStr = order.CLOSEVGMDATE.HasValue ? order.CLOSEVGMDATE.Value.ToString("yyyy-MM-dd") : string.Empty, - BoxInfo = ctns.Select(c => new - { - index = idx++, - boxType = c.CTNALL.Replace("'", ""), - boxcount = c.CTNNUM.HasValue ? c.CTNNUM.Value : 0, - code = c.CNTRNO, - sealCode = c.SEALNO, - weigth = c.KGS, - weigthTare = c.TAREWEIGHT, - weigthTotal = c.WEIGHKGS, - weigthType = c.WEIGHTYPE == "累加" ? "SM2" : "SM1" - }).ToList(), - returnOkUrl = "" - }; + if (ctns.Where(c => c.WEIGHTYPE == "总重" && + ( + string.IsNullOrEmpty(c.CNTRNO) + || !c.WEIGHKGS.HasValue + || c.WEIGHKGS == 0) + ).Count() > 0) + { + throw Oops.Bah("称重方式为总重时,箱号和称重重量都不能为空"); + } + #endregion - string strPostObj = sendObj.ToJsonString(); - _logger.LogInformation($"调用VGM直发接口 {dicUrl.Value} 传递数据:{strPostObj}"); - var strResp = await dicUrl.Value.SetBody(sendObj).PostAsStringAsync(); - _logger.LogInformation($"调用VGM直发接口返回:{strResp}"); - var jobjResp = JObject.Parse(strResp); - int respCode = jobjResp.GetIntValue("code"); - if (respCode != 200) - { - throw Oops.Bah(BookingErrorCode.BOOK128, jobjResp.GetStringValue("message")); - } - //货运动态 - var bsl = new BookingStatusLog(); - bsl.BookingId = bookingId; - bsl.Status = $"直发VGM"; - bsl.OpTime = DateTime.Now; - bsl.Category = "ship"; - bsl.MBLNO = order.MBLNO; - await _repStatuslog.InsertAsync(bsl); - } + ////场站转换 + //var yardset = _cache.GetAllMappingYard().Result.FirstOrDefault(y => y.Code == order.YARDID && y.Module == "BookingVgm"); + //if (yardset == null) + //{ + // throw Oops.Bah(BookingErrorCode.BOOK120, order.YARDID); + //} + if (string.IsNullOrEmpty(order.YARD) || string.IsNullOrEmpty(order.YARDID)) + { + throw Oops.Bah("场站未正确选择"); } + // 场站映射 + string mappingYard, mappingYardId; + var yardMapList = _cache.GetAllMappingYard().Result?.Where(y => y.Code == order.YARDID && y.Module == "BookingVgm" && (y.CarrierCode == null || y.CarrierCode == "" || y.CarrierCode == order.CARRIERID))?.ToList(); + if (yardMapList?.Any() == true) + { + var yardset = yardMapList.FirstOrDefault(x => x.CarrierCode == order.CARRIERID) + ?? yardMapList.FirstOrDefault(x => x.CarrierCode == null || x.CarrierCode == ""); - //设置货物状态:已发VGM,并回传东胜 - await SetGoodsStatus("YFVGM", bookingId); - await SendBookingOrder(new long[] { bookingId }); + mappingYard = yardset.MapName; + mappingYardId = yardset.MapCode; + } + else + { + mappingYard = order.YARD; + mappingYardId = order.YARDID; + } - return result; - } + // 船司映射 + var carrMap = _cache.GetAllMappingCarrier().Result?.Where(y => y.Code == order.CARRIERID && y.Module == "BookingVgm")?.FirstOrDefault(); + string mappingCarrierId = carrMap != null ? carrMap.MapCode : order.CARRIERID; + var user = await _repUser.FirstOrDefaultAsync(x => x.Id == UserManager.UserId); + + int idx = 1; + //调用接口 + var dicUrl = _cache.GetAllDictData().Result.First(x => x.TypeCode == "url_set" && x.Code == "vgm_service_single"); + var sendObj = new + { + SystemCode = "djy_hechuan", + billOrderId = order.Id.ToString(), + sendOrderCode = order.MBLNO, + customerName = $"{UserManager.TENANT_NAME}+{UserManager.Name}", //公司名称+用户姓名 + customerId = order.CUSTOMERID.ToString(), + agentName = string.IsNullOrEmpty(order.FORWARDER) ? UserManager.TENANT_NAME : order.FORWARDER, + carrierCode = mappingCarrierId, + userName = webacc.Account, + userPassword = webacc.Password, + depotCode = mappingYardId, + depotName = mappingYard, + linkName = UserManager.Name, + linkMobile = user.Phone, + linkEmail = user.Email, + userId = user.DjyUserId, + signatory = user.NickName, //2023年8月28日,董怡含:把用户昵称当做vgm上传人 + returnUrl = "", + shipName = order.VESSEL, + voyNo = order.VOYNO, + etdstr = order.ETD.HasValue ? order.ETD.Value.ToString("yyyy-MM-dd") : string.Empty, + potrSend = order.PORTLOAD, + potrGoal = order.PORTDISCHARGE, + boxinfoStr = order.CNTRTOTAL.Replace("'", ""), + vgmEndTimeStr = order.CLOSEVGMDATE.HasValue ? order.CLOSEVGMDATE.Value.ToString("yyyy-MM-dd") : string.Empty, + BoxInfo = ctns.Select(c => new + { + index = idx++, + boxType = c.CTNALL.Replace("'", ""), + boxcount = c.CTNNUM.HasValue ? c.CTNNUM.Value : 0, + code = c.CNTRNO, + sealCode = c.SEALNO, + weigth = c.KGS, + weigthTare = c.TAREWEIGHT, + weigthTotal = c.WEIGHKGS, + weigthType = c.WEIGHTYPE == "累加" ? "SM2" : "SM1" + }).ToList(), + returnOkUrl = "" + }; + + string strPostObj = sendObj.ToJsonString(); + _logger.LogInformation($"调用VGM直发接口 {dicUrl.Value} 传递数据:{strPostObj}"); + var strResp = await dicUrl.Value.SetBody(sendObj).PostAsStringAsync(); + _logger.LogInformation($"调用VGM直发接口返回:{strResp}"); + + var jobjResp = JObject.Parse(strResp); + int respCode = jobjResp.GetIntValue("code"); + if (respCode != 200) + { + throw Oops.Bah(BookingErrorCode.BOOK128, jobjResp.GetStringValue("message")); + } + //货运动态 + var bsl = new BookingStatusLog(); + bsl.BookingId = bookingId; + bsl.Status = $"发送船司VGM(直发)"; + bsl.OpTime = DateTime.Now; + bsl.Category = "ship"; + bsl.MBLNO = order.MBLNO; + await _repStatuslog.InsertAsync(bsl); + } /// /// 批量编辑vgm @@ -7755,7 +8141,7 @@ namespace Myshipping.Application { var multiline = _repBookingMultiLineSplitRecord.AsQueryable().First(b => b.Id == model.multilineid.Value); - if(multiline == null) + if (multiline == null) throw Oops.Oh($"收、发、通拆分信息获取失败"); primaryModel.SHIPPER = multiline.SHIPPERNAME; @@ -8686,10 +9072,10 @@ namespace Myshipping.Application fileRole = fileRole, send = false, sendType = sendType, - + }; - if(!string.IsNullOrWhiteSpace(multilineid)) + if (!string.IsNullOrWhiteSpace(multilineid)) { model.multilineid = long.Parse(multilineid); } @@ -11868,7 +12254,7 @@ namespace Myshipping.Application _logger.LogInformation("批次={no}提取订单信息完成", batchNo); - if (model.sendType.Equals("B", StringComparison.OrdinalIgnoreCase) && order.CARRIERID.Equals("SITC",StringComparison.OrdinalIgnoreCase)) + if (model.sendType.Equals("B", StringComparison.OrdinalIgnoreCase) && order.CARRIERID.Equals("SITC", StringComparison.OrdinalIgnoreCase)) { VOLTAEDIBaseModel sitcModel = new VOLTAEDIBaseModel(); if (!string.IsNullOrWhiteSpace(order.SHIPPER)) @@ -11904,7 +12290,7 @@ namespace Myshipping.Application { throw Oops.Bah("只接受发送类型截单(E)"); } - + var allowCarrier = App.Configuration["VOLTASIExportCarrier"].Split(new char[] { ',' }); //if (!order.CARRIERID.Equals("VOL", StringComparison.OrdinalIgnoreCase) && !order.CARRIERID.Equals("FCS", StringComparison.OrdinalIgnoreCase) @@ -11930,7 +12316,7 @@ namespace Myshipping.Application bool isSeaLead = false; //if (order.MBLNO.StartsWith("SLS")) - if (order.CARRIERID.Equals("SLS",StringComparison.OrdinalIgnoreCase)) + if (order.CARRIERID.Equals("SLS", StringComparison.OrdinalIgnoreCase)) isSeaLead = true; //箱信息 diff --git a/Myshipping.Application/Service/BookingOrder/Dto/VgmPlatDto.cs b/Myshipping.Application/Service/BookingOrder/Dto/VgmPlatDto.cs new file mode 100644 index 00000000..88572953 --- /dev/null +++ b/Myshipping.Application/Service/BookingOrder/Dto/VgmPlatDto.cs @@ -0,0 +1,191 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; + +namespace Myshipping.Application.Service.BookingOrder.Dto +{ + public class VgmPlatDto + { + /// + /// 主键 + /// + public string MFNO { get; set; } + + /// + /// 提单号 + /// + public string MBLNO { get; set; } + + /// + /// 船司 + /// + public string CARRIER { get; set; } + + /// + /// 开船日期 + /// + public DateTime? ETD { get; set; } + + /// + /// 委托发送方 + /// + public string WeiTuoFaSongFang { get; set; } + + /// + /// 船名 + /// + public string ChuanMing { get; set; } + + /// + /// 船名ID + /// + public string VSID { get; set; } + + /// + /// 航次 + /// + public string HangCi { get; set; } + + /// + /// 备注 + /// + public string BeiZhu { get; set; } + + /// + /// 装货港 + /// + public string ZhuangHuoGang { get; set; } + + /// + /// 装货港代码 + /// + public string ZhuangHuoGangDaiMa { get; set; } + + /// + /// 场站 + /// + public string YARD { get; set; } + + /// + /// 订舱编号 + /// + public string ORDERNO { get; set; } + + /// + /// 截VMG时间 + /// + public DateTime? VGMCLOSETIME { get; set; } + + /// + /// 码头 + /// + [MaxLength(30)] + public string Wharf { get; set; } + + /// + /// 发送类型 + /// + public string SendType { get; set; } + + /// + /// 是否发送到船公司 + /// + public bool SendCarr { get; set; } + + /// + /// 是否发送到云港通 + /// + public bool SendYGT { get; set; } + + /// + /// 是否链接发送 + /// + public bool IsLinkSave { get; set; } + + /// + /// 是否API保存 + /// + public bool IsApiSave { get; set; } + /// + /// 箱信息 + /// + public List CtnList { get; set; } + } + + /// + /// 箱信息dto + /// + public class VgmPlatCtnDto + { + /// + /// 主键 + /// + public string ctn_id { get; set; } + + /// + /// 箱型,例如:20GP + /// + public string CTNALL { get; set; } + + /// + /// 箱号 + /// + public string CNTRNO { get; set; } + + /// + /// 封号 + /// + public string SEALNO { get; set; } + + /// + /// 件数 + /// + public int? PKGS { get; set; } + + /// + /// 重量 + /// + public decimal? KGS { get; set; } + + /// + /// 尺码 + /// + public decimal? CBM { get; set; } + + /// + /// 称重重量 + /// + public decimal? ChengZhongZhongLiang { get; set; } + + /// + /// 称重方式,累加、总重 + /// + public string ChengZhongFangShi { get; set; } + + /// + /// 称重时间 + /// + public string ChengZhongShiJian { get; set; } + + /// + /// 皮重 + /// + public decimal PIZHONG { get; set; } + + /// + /// 场站 + /// + public string Yard { get; set; } + + /// + /// 货物类型 + /// + public string CargoId { get; set; } + + /// + /// 发送标志 + /// + public bool SendFlag { get; set; } = false; + + } +} diff --git a/Myshipping.Web.Entry/appsettings.json b/Myshipping.Web.Entry/appsettings.json index 8ceafb13..e42ffbb6 100644 --- a/Myshipping.Web.Entry/appsettings.json +++ b/Myshipping.Web.Entry/appsettings.json @@ -45,5 +45,8 @@ CUST 客户订舱系统-客户端 DJY 客户订舱系统-大简云运营端 */ - "RunType": "HeChuan" + "RunType": "HeChuan", + + // 是否运行在测试环境 + "RunTest": "true" } \ No newline at end of file