diff --git a/Myshipping.Application/Enum/BookingErrorCode.cs b/Myshipping.Application/Enum/BookingErrorCode.cs index 2717b492..b6473960 100644 --- a/Myshipping.Application/Enum/BookingErrorCode.cs +++ b/Myshipping.Application/Enum/BookingErrorCode.cs @@ -121,6 +121,18 @@ namespace Myshipping.Application.Enum [ErrorCodeItemMetadata("vgm链接生成失败:{0}")] BOOK126, + /// + /// 主提单号不能为空 + /// + [ErrorCodeItemMetadata("主提单号不能为空")] + BOOK127, + + /// + /// vgm发送失败 + /// + [ErrorCodeItemMetadata("vgm发送失败:{0}")] + BOOK128, + /// /// 附件不存在 diff --git a/Myshipping.Application/Myshipping.Application.xml b/Myshipping.Application/Myshipping.Application.xml index 8550907f..031e6dc0 100644 --- a/Myshipping.Application/Myshipping.Application.xml +++ b/Myshipping.Application/Myshipping.Application.xml @@ -5766,6 +5766,16 @@ vgm链接生成失败 + + + 主提单号不能为空 + + + + + vgm发送失败 + + 附件不存在 @@ -6630,7 +6640,20 @@ - + + + 获取VGM、VGM SI链接 + + + + + + + 直发VGM(单票) + + + + 发送订舱、截单EDI diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index 567b8013..1920579a 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -57,7 +57,7 @@ namespace Myshipping.Application private readonly SqlSugarRepository _repPrint; private readonly ILogger _logger; private readonly ISysCacheService _cache; - private readonly SqlSugarRepository _statuslog; + private readonly SqlSugarRepository _repStatuslog; private readonly SqlSugarRepository _statuslogdetail; private readonly SqlSugarRepository _repPrintTemplate; private readonly SqlSugarRepository _repLetterYard; @@ -85,7 +85,7 @@ namespace Myshipping.Application this._repPrint = repPrint; this._dicdata = dicdata; this._cache = cache; - this._statuslog = statuslog; + this._repStatuslog = statuslog; this._statuslogdetail = statuslogdetail; this._repPrintTemplate = repPrintTemplate; this._repLetterYard = repLetterYard; @@ -555,7 +555,7 @@ namespace Myshipping.Application public async Task> GetBookingStatusLog(long Id) { - var statuslog = await _statuslog.AsQueryable().Where(x => x.BookingId == Id).ToListAsync(); + var statuslog = await _repStatuslog.AsQueryable().Where(x => x.BookingId == Id).ToListAsync(); var dto = statuslog.Adapt>(); foreach (var item in dto) { @@ -610,8 +610,8 @@ namespace Myshipping.Application foreach (var item in all) { //清空原有数据 - var old = await _statuslog.AsQueryable().Where(x => x.BookingId == item.BookingId && x.Category == "ship").ToListAsync(); - await _statuslog.DeleteAsync(x => x.BookingId == item.BookingId && x.Category == "ship"); + var old = await _repStatuslog.AsQueryable().Where(x => x.BookingId == item.BookingId && x.Category == "ship").ToListAsync(); + await _repStatuslog.DeleteAsync(x => x.BookingId == item.BookingId && x.Category == "ship"); foreach (var ot in old) { await _statuslogdetail.DeleteAsync(x => x.PId == ot.Id); @@ -624,7 +624,7 @@ namespace Myshipping.Application bookingStatusLog.Status = item.Status; bookingStatusLog.OpTime = item.OpTime; bookingStatusLog.MBLNO = item.MBLNO; - var id = await _statuslog.InsertReturnSnowflakeIdAsync(bookingStatusLog); + var id = await _repStatuslog.InsertReturnSnowflakeIdAsync(bookingStatusLog); if (item.detail != null && item.detail.Count > 0) { foreach (var dt in item.detail) @@ -947,13 +947,23 @@ namespace Myshipping.Application var txxpUrl = jobjResp.GetStringValue("data"); ordUrl.UrlTxxp = txxpUrl; await _repOrderUrl.UpdateAsync(ordUrl); + + //货运动态 + var bsl = new BookingStatusLog(); + bsl.BookingId = bookingId; + bsl.Status = $"生成提箱小票链接"; + bsl.OpTime = DateTime.Now; + bsl.Gategory = "ship"; + bsl.MBLNO = order.MBLNO; + await _repStatuslog.InsertAsync(bsl); + return txxpUrl; } #endregion #region VGM及VMG链接 /// - /// 获取VGM、VGM&SI链接 + /// 获取VGM、VGM SI链接 /// /// /// @@ -985,6 +995,7 @@ namespace Myshipping.Application throw Oops.Oh(BookingErrorCode.BOOK118); } + var ctns = await _repCtn.Where(x => x.BILLID == bookingId).ToListAsync(); //判断船公司是否支持 var allowCarrier = _cache.GetAllDictData().Result.Where(x => x.TypeCode == "vgm_carrier_list").Select(x => x.Code).ToList(); if (!allowCarrier.Contains(order.CARRIERID)) @@ -1007,7 +1018,6 @@ namespace Myshipping.Application throw Oops.Oh(BookingErrorCode.BOOK120, order.YARDID); } - var ctns = await _repCtn.Where(x => x.BILLID == bookingId).ToListAsync(); //校验箱子数据录入 if (ctns.Where(c => string.IsNullOrEmpty(c.CTNALL) || !c.CTNNUM.HasValue).Count() > 0) { @@ -1028,10 +1038,14 @@ namespace Myshipping.Application throw Oops.Oh(BookingErrorCode.BOOK123, string.Join(',', expCode)); } + //接收反馈地址 + var dicUrlVgmResp = _cache.GetAllDictData().Result.FirstOrDefault(x => x.TypeCode == "url_reponse" && x.Code == "vgm_si_post_reponse"); + var dicUrlSiResp = _cache.GetAllDictData().Result.FirstOrDefault(x => x.TypeCode == "url_reponse" && x.Code == "si_post_response"); + var user = await _repUser.FirstOrDefaultAsync(x => x.Id == UserManager.UserId); - //调用小票服务 - var dicUrlTxxp = _cache.GetAllDictData().Result.First(x => x.TypeCode == "url_set" && x.Code == "vgm_link_service"); + //调用vgm链接服务 + var dicUrl = _cache.GetAllDictData().Result.First(x => x.TypeCode == "url_set" && x.Code == "vgm_link_service"); var postObj = new { SystemCode = "djy_hechuan", @@ -1049,7 +1063,7 @@ namespace Myshipping.Application linkMobile = user.Tel, linkEmail = user.Email, userId = UserManager.DjyUserId, - returnUrl = "", + returnUrl = dicUrlVgmResp?.Value, shipName = order.VESSEL, voyNo = order.VOYNO, etdstr = order.ETD.HasValue ? order.ETD.Value.ToString("yyyy-MM-dd") : string.Empty, @@ -1058,7 +1072,7 @@ namespace Myshipping.Application boxinfoStr = order.CNTRTOTAL, vgmEndTimeStr = order.CLOSEVGMDATE.HasValue ? order.CLOSEVGMDATE.Value.ToString("yyyy-MM-dd") : string.Empty, returnOkUrl = "", - SiReturnUrl = "", + SiReturnUrl = dicUrlSiResp?.Value, DataInfoJson = new { order.SHIPPER, @@ -1083,8 +1097,8 @@ namespace Myshipping.Application }; string strPostObj = postObj.ToJsonString(); - _logger.LogInformation($"调用VGM链接接口传递数据:{strPostObj}"); - var strResp = await dicUrlTxxp.Value.SetBody(postObj).PostAsStringAsync(); + _logger.LogInformation($"调用VGM链接接口 {dicUrl.Value} 传递数据:{strPostObj}"); + var strResp = await dicUrl.Value.SetBody(postObj).PostAsStringAsync(); _logger.LogInformation($"调用VGM链接接口返回:{strResp}"); var jobjResp = JObject.Parse(strResp); @@ -1094,13 +1108,184 @@ namespace Myshipping.Application throw Oops.Oh(BookingErrorCode.BOOK126, jobjResp.GetStringValue("message")); } + //保存url var memoData = jobjResp.GetJObjectValue("memoData"); ordUrl.UrlVgm = memoData.GetStringValue("vgmUrl"); ordUrl.UrlVgmSi = memoData.GetStringValue("vgmAndSiUrl"); await _repOrderUrl.UpdateAsync(ordUrl); + + + //货运动态 + var bsl = new BookingStatusLog(); + bsl.BookingId = bookingId; + bsl.Status = $"生成VGM链接"; + bsl.OpTime = DateTime.Now; + bsl.Gategory = "ship"; + bsl.MBLNO = order.MBLNO; + await _repStatuslog.InsertAsync(bsl); + return new string[] { ordUrl.UrlVgm, ordUrl.UrlVgmSi }; } + + /// + /// 直发VGM(单票) + /// + /// + /// + [HttpPost("/BookingOrder/vgmsend")] + public async Task VgmSend(long bookingId) + { + var order = _rep.FirstOrDefault(x => x.Id == bookingId); + var ctns = _repCtn.Where(x => x.BILLID == bookingId).ToList(); + + var dicUrlVgm = _cache.GetAllDictData().Result.First(x => x.TypeCode == "url_set" && x.Code == "vgm_service_single"); + + //船公司 + if (string.IsNullOrEmpty(order.CARRIERID)) + { + throw Oops.Oh(BookingErrorCode.BOOK118); + } + + //判断船公司是否支持 + var allowCarrier = _cache.GetAllDictData().Result.Where(x => x.TypeCode == "vgm_carrier_list").Select(x => x.Code).ToList(); + if (!allowCarrier.Contains(order.CARRIERID)) + { + throw Oops.Oh(BookingErrorCode.BOOK117); + } + + //船公司网站账号 + var carrWebAccMap = _cache.GetAllDictData().Result.FirstOrDefault(x => x.TypeCode == "carrier_web_account_mapping" && x.Code == order.CARRIERID); + var webacc = _repWebAcc.FirstOrDefault(x => x.TypeCode == carrWebAccMap.Value && x.CreatedUserId == UserManager.UserId); + if (webacc == null) + { + throw Oops.Oh(BookingErrorCode.BOOK125); + } + + //提单号不能为空 + if (string.IsNullOrEmpty(order.MBLNO)) + { + throw Oops.Oh(BookingErrorCode.BOOK127); + } + + //箱型映射 + var ctnMapping = await _cache.GetAllMappingCtn(); + ctnMapping = ctnMapping.Where(x => x.Module == "BookingVgm").ToList(); + if (ctnMapping.Count == 0) + { + throw Oops.Oh(BookingErrorCode.BOOK122); + } + + var expCode = ctns.Select(x => x.CTNCODE).Distinct().Except(ctnMapping.Select(y => y.Code)).ToList(); + if (expCode.Count > 0) + { + throw Oops.Oh(BookingErrorCode.BOOK123, string.Join(',', expCode)); + } + + #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.Oh("称重方式为累加时,箱号、重量、箱皮重以及称重重量都不能为空"); + } + + if (ctns.Where(c => c.WEIGHTYPE == "总重" && + ( + string.IsNullOrEmpty(c.CNTRNO) + || !c.WEIGHKGS.HasValue + || c.WEIGHKGS == 0) + ).Count() > 0) + { + throw Oops.Oh("称重方式为总重时,箱号和称重重量都不能为空"); + } + #endregion + + + //场站转换 + var yardset = _cache.GetAllMappingYard().Result.FirstOrDefault(y => y.Code == order.YARDID && y.Module == "BookingVgm"); + if (yardset == null) + { + throw Oops.Oh(BookingErrorCode.BOOK120, order.YARDID); + } + + 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, + agentName = string.IsNullOrEmpty(order.FORWARDER) ? UserManager.TENANT_NAME : order.FORWARDER, + carrierCode = order.CARRIERID, + userName = webacc.Account, + userPassword = webacc.Password, + depotCode = yardset.MapCode, + depotName = yardset.MapName, + linkName = UserManager.Name, + linkMobile = user.Tel, + linkEmail = user.Email, + userId = user.DjyUserId, + 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, + vgmEndTimeStr = order.CLOSEVGMDATE.HasValue ? order.CLOSEVGMDATE.Value.ToString("yyyy-MM-dd") : string.Empty, + BoxInfo = ctns.Select(c => new + { + index = idx++, + boxType = c.CTNALL, + 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.Oh(BookingErrorCode.BOOK128, jobjResp.GetStringValue("message")); + } + + + //货运动态 + var bsl = new BookingStatusLog(); + bsl.BookingId = bookingId; + bsl.Status = $"直发VGM"; + bsl.OpTime = DateTime.Now; + bsl.Gategory = "ship"; + bsl.MBLNO = order.MBLNO; + await _repStatuslog.InsertAsync(bsl); + + + } + #endregion #region 订舱、截单EDI