From b52d7fc85aa0d06d9f0563f9dc1dfebb7d59d6d1 Mon Sep 17 00:00:00 2001 From: wet <1034391973@qq.com> Date: Tue, 18 Apr 2023 15:00:44 +0800 Subject: [PATCH 1/2] 1 --- .../Enum/BookingErrorCode.cs | 6 +- .../BookingOrder/BookingOrderService.cs | 9 +- .../BookingOrderSeaeEdiService.cs | 209 +++++++----------- .../DjyWebsiteAccountConfigService.cs | 7 +- 4 files changed, 97 insertions(+), 134 deletions(-) diff --git a/Myshipping.Application/Enum/BookingErrorCode.cs b/Myshipping.Application/Enum/BookingErrorCode.cs index 20c561ce..f308728e 100644 --- a/Myshipping.Application/Enum/BookingErrorCode.cs +++ b/Myshipping.Application/Enum/BookingErrorCode.cs @@ -133,7 +133,11 @@ namespace Myshipping.Application.Enum [ErrorCodeItemMetadata("vgm发送失败:{0}")] BOOK128, - + /// + /// 舱单发送失败 + /// + [ErrorCodeItemMetadata("舱单发送失败:{0}")] + BOOK129, /// /// 附件不存在 diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index 082cb606..df802e0e 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -5460,9 +5460,7 @@ namespace Myshipping.Application } else { - item.CARRIER = _cache.GetAllCodeCarrier().Result.Where(x => x.Code == item.CARRIERID).Select(x => x.CnName).FirstOrDefault(); - } } if (!string.IsNullOrEmpty(item.ISSUETYPE)) @@ -5471,10 +5469,6 @@ namespace Myshipping.Application item.ISSUETYPE = ISSUETYPE; } - - - - var ctn = await _repCtn.AsQueryable().Filter(null, true).Where(x => x.BILLID == item.Id && x.IsDeleted == false).ToListAsync(); item.ctnInputs = ctn.Adapt>(); foreach (var it in item.ctnInputs) @@ -5523,7 +5517,8 @@ namespace Myshipping.Application const string MqActionExchangeName = "djy.output.dingcang.ds6"; const string MqActionQueueName = "djy.output.dingcang.ds6"; ConnectionFactory factory = new ConnectionFactory(); - factory.Uri = new Uri(App.Configuration["BookingOrderMQUri"]); + factory.Uri = new Uri(_cache.GetAllDictData().Result.Where(x => x.Code == "BookingOrderMQUri").Select(x => x.Value).FirstOrDefault()); + using (IConnection conn = factory.CreateConnection()) { IModel mqModel = conn.CreateModel(); diff --git a/Myshipping.Application/Service/BookingOrderSeaeEdi/BookingOrderSeaeEdiService.cs b/Myshipping.Application/Service/BookingOrderSeaeEdi/BookingOrderSeaeEdiService.cs index b28ef0d0..0a4e169e 100644 --- a/Myshipping.Application/Service/BookingOrderSeaeEdi/BookingOrderSeaeEdiService.cs +++ b/Myshipping.Application/Service/BookingOrderSeaeEdi/BookingOrderSeaeEdiService.cs @@ -31,6 +31,11 @@ using System.Net.Http; using Myshipping.Core.Service; using System.Reflection.Emit; using Myshipping.Application.Service.BookingOrderSeaeEdi.Dto; +using Myshipping.Application.Enum; +using Myshipping.Application.Service.BookingOrder.Dto; +using Newtonsoft.Json.Linq; +using System.Text; +using System.Web; namespace Myshipping.Application { @@ -43,13 +48,19 @@ namespace Myshipping.Application private readonly ILogger _logger; private readonly SqlSugarRepository _seaeedi; private readonly SqlSugarRepository _seaeedictn; - - public BookingOrderSeaeEdiService(ILogger logger, SqlSugarRepository seaeedi, SqlSugarRepository seaeedictn) + private readonly ISysCacheService _cache; + private readonly SqlSugarRepository _repStatuslog; + private readonly IDjyWebsiteAccountConfigService _webAccountConfig; + public BookingOrderSeaeEdiService(ILogger logger, SqlSugarRepository seaeedi, + SqlSugarRepository seaeedictn, ISysCacheService cache, SqlSugarRepository repStatuslog, + IDjyWebsiteAccountConfigService webAccountConfig) { this._logger = logger; this._seaeedi = seaeedi; this._seaeedictn = seaeedictn; - + this._cache = cache; + this._repStatuslog = repStatuslog; + this._webAccountConfig = webAccountConfig; } /// @@ -172,128 +183,76 @@ namespace Myshipping.Application #region 舱单 - ///// - ///// 舱单 - ///// - ///// - ///// - //[HttpPost("/BookingOrderSeaeEdi/CustEDI")] - //public async Task CustEDI(long bookingId) - //{ - // var order = _seaeedi.FirstOrDefault(x => x.BookingId == bookingId); - - - // var ctns = _seaeedictn.Where(x => x.BILLID == bookingId).ToList(); - - // //船公司 - // if (string.IsNullOrEmpty(order.CARRIERID)) - // { - // throw Oops.Bah(BookingErrorCode.BOOK118); - // } - - // //提单号不能为空 - // if (string.IsNullOrEmpty(order.MBLNO)) - // { - // throw Oops.Bah(BookingErrorCode.BOOK127); - // } - // if (string.IsNullOrEmpty(order.YARDID)) - // { - // throw Oops.Bah("场站未正确选择"); - // } - // List custEDIDtos = new List(); - // MDATA mDATA = new MDATA(); - - // mDATA.MBLNO = order.MBLNO; - // mDATA.HBLNO = order.HBLNO; - // mDATA.ETD = order.ETD == null ? "" : Convert.ToDateTime(order.ETD).ToString("yyyy-MM-dd"); - // mDATA.FORWARDER = order.SHIPAGENCY; - // mDATA.VESSEL = order.VESSEL; - // mDATA.VOYNO = order.VOYNO; - // mDATA.CARRIER = order.CARRIERID; - // mDATA.SHIPPERNAME = order.SHIPPER; - // mDATA.SHIPPERADDR1 = order.SHIPPERADDR1; - // mDATA.SHIPPERCOUNTRY = order.SHIPPERCOUNTRY; - // mDATA.SHIPPERTEL = order.SHIPPERTEL; - // mDATA.CONSIGNEENAME = order.CONSIGNEE; - // mDATA.CONSIGNEEADDR1 = order.CONSIGNEEADDR1; - // mDATA.CONSIGNEECOUNTRY = order.CONSIGNEERCOUNTRY; - // mDATA.CONSIGNEETEL = order.CONSIGNEETEL; - // mDATA.NOTIFYPARTYNAME = order.NOTIFYPARTY; - // mDATA.NOTIFYPARTYADDR1 = order.NOTIFYPARTYADDR1; - // mDATA.NOTIFYPARTYCOUNTRY = order.NOTIFYPARTYCOUNTRY; - // mDATA.NOTIFYPARTYTEL = order.NOTIFYPARTYTEL; - - - - - - - // //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 == "request_emf"); - // // 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 = order.CARRIERID, - // // userName = webacc.Account, - // // userPassword = webacc.Password, - // // depotCode = order.YARDID, - // // depotName = order.YARD, - // // linkName = UserManager.Name, - // // linkMobile = user.Phone, - // // 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.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); - - //} + /// + /// 舱单 + /// + /// + /// + [HttpPost("/BookingOrderSeaeEdi/CustEDI")] + public async Task CustEDI(long bookingId) + { + var order = await _seaeedi.AsQueryable().Filter(null, true).Where(x => x.BookingId == bookingId).FirstAsync(); + var ctns = await _seaeedictn.AsQueryable().Filter(null, true).Where(x => x.PId == order.Id).ToListAsync(); + //船公司 + if (string.IsNullOrEmpty(order.CARRIERID)) + { + throw Oops.Bah(BookingErrorCode.BOOK118); + } + //提单号不能为空 + if (string.IsNullOrEmpty(order.MBLNO)) + { + throw Oops.Bah(BookingErrorCode.BOOK127); + } + if (string.IsNullOrEmpty(order.YARDID)) + { + throw Oops.Bah("场站未正确选择"); + } + var dicUrl = _cache.GetAllDictData().Result.First(x => x.TypeCode == "url_set" && x.Code == "request_emf"); + var key = _webAccountConfig.GetAccountConfig("DjyCangDan", UserManager.UserId).Result; + List custEDIDtos = new List(); + MDATA mDATA = new MDATA(); + List CTNDATA = new List(); + mDATA = order.Adapt(); + CTNDATA = ctns.Adapt>(); + + custEDIDtos.Add( + new CustEDIDto + { + MDATA = mDATA, + CTNDATA = CTNDATA + } + ); + string strPostObj = custEDIDtos.ToJsonString(); + + var sendObj = new + { + ac = "emf", + uid = UserManager.DjyUserId, + skey = key.Password, + optype = "3", + data = strPostObj + }; + _logger.LogInformation($"调用舱单接口 {dicUrl.Value} 传递数据:{strPostObj}"); + var strResp = await dicUrl.Value.SetContentType("multipart/form-data").SetBody(sendObj).PostAsStringAsync(); + _logger.LogInformation($"调用舱单接口返回:{strResp}"); + + + var jobjResp = JObject.Parse(strResp); + int respCode = jobjResp.GetIntValue("code"); + if (respCode != 200) + { + throw Oops.Bah(BookingErrorCode.BOOK129, jobjResp.GetStringValue("message")); + } + //货运动态 + var bsl = new BookingStatusLog(); + bsl.BookingId = bookingId; + bsl.Status = $"保存舱单"; + bsl.OpTime = DateTime.Now; + bsl.Category = "ship"; + bsl.MBLNO = order.MBLNO; + await _repStatuslog.InsertAsync(bsl); + + } diff --git a/Myshipping.Core/Service/DjyWebsiteAccountConfig/DjyWebsiteAccountConfigService.cs b/Myshipping.Core/Service/DjyWebsiteAccountConfig/DjyWebsiteAccountConfigService.cs index 7d7aa58b..8d3416b2 100644 --- a/Myshipping.Core/Service/DjyWebsiteAccountConfig/DjyWebsiteAccountConfigService.cs +++ b/Myshipping.Core/Service/DjyWebsiteAccountConfig/DjyWebsiteAccountConfigService.cs @@ -171,7 +171,12 @@ namespace Myshipping.Core.Service var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id); await _rep.DeleteAsync(entity); } - + /// + /// 获取接口Key 个人或公司 + /// + /// + /// + /// public async Task GetAccountConfig(string TypeCode, long UserId) { if (string.IsNullOrWhiteSpace(TypeCode)||UserId==0) { From 189c6aa2baea3bd47511a0b64623a774423e4fed Mon Sep 17 00:00:00 2001 From: wanghaomei Date: Tue, 18 Apr 2023 15:10:40 +0800 Subject: [PATCH 2/2] =?UTF-8?q?VGM=E5=8F=91=E9=80=81=E5=8F=96=E7=BD=91?= =?UTF-8?q?=E7=AB=99=E8=B4=A6=E5=8F=B7=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/BookingOrder/BookingOrderService.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index 14cb99d3..481bac6d 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -3300,9 +3300,11 @@ namespace Myshipping.Application var sysconfig = await _cache.GetAllSysConfig(); var urlConfig = sysconfig.FirstOrDefault(x => x.GroupCode == "DJY_CONST" && x.Code == "DjyVgmApiMyshpping"); - var useridConfig = sysconfig.FirstOrDefault(x => x.GroupCode == "DJY_CONST" && x.Code == "DjyVgmApiMyshppingUserId"); - var userSecretConfig = sysconfig.FirstOrDefault(x => x.GroupCode == "DJY_CONST" && x.Code == "DjyVgmApiMyshppingUserSecret"); - + var accConfig = await _webAccountConfig.GetAccountConfig("DjyVgm", UserManager.UserId); + if (accConfig == null) + { + throw Oops.Bah("请在网站账号中维护VGM接口的用户id和秘钥"); + } var objMdata = new { @@ -3341,8 +3343,8 @@ namespace Myshipping.Application var dictParam = new Dictionary { { "ac", "vgm" }, - { "uid", useridConfig.Value}, - { "skey", userSecretConfig.Value}, + { "uid", accConfig.Account}, + { "skey", accConfig.Password}, { "optype", "9"}, { "mdata", JsonConvert.SerializeObject(objMdata)}, { "ctndata", JsonConvert.SerializeObject(listCtn)}