From d9ffa460e3684a42f8e90dc4d82faad8ec501388 Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Wed, 17 May 2023 17:13:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9TSL=20EDI=20=E5=92=8C?= =?UTF-8?q?=E8=BD=A6=E9=98=9F=E6=A3=80=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Myshipping.Application/EDI/TSLEdiHelper.cs | 4 +- .../BookingOrder/BookingValueAddedService.cs | 118 +++++++++++++----- .../BookingOrder/Dto/BCAPIBaseResult.cs | 31 ++++- .../Service/DjyCustomer/DjyCustomerService.cs | 19 ++- 4 files changed, 123 insertions(+), 49 deletions(-) diff --git a/Myshipping.Application/EDI/TSLEdiHelper.cs b/Myshipping.Application/EDI/TSLEdiHelper.cs index 48cd78cd..fe6d0cdc 100644 --- a/Myshipping.Application/EDI/TSLEdiHelper.cs +++ b/Myshipping.Application/EDI/TSLEdiHelper.cs @@ -1339,9 +1339,9 @@ namespace Myshipping.Application.EDI.TSL if (bill.CARGOID == "R") { - if (string.IsNullOrWhiteSpace(bill.REEFERF)) + if (!string.IsNullOrWhiteSpace(bill.REEFERF)) r.WriteLine("MEA+AAE+AAS+CBM:" + bill.REEFERF + "'"); - if (string.IsNullOrWhiteSpace(bill.HUMIDITY)) + if (!string.IsNullOrWhiteSpace(bill.HUMIDITY)) r.WriteLine("MEA+AAE+AAO+HMD:" + bill.HUMIDITY + "'"); r.WriteLine("TMP+2+" + bill.TEMPSET + ":CEL'"); icount = icount + 2; diff --git a/Myshipping.Application/Service/BookingOrder/BookingValueAddedService.cs b/Myshipping.Application/Service/BookingOrder/BookingValueAddedService.cs index e0a7f0ad..1e3ad0ed 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingValueAddedService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingValueAddedService.cs @@ -169,10 +169,10 @@ namespace Myshipping.Application if (bcOrDraftRouteCfg == null) { - _logger.LogInformation("提单号【{mbl}】根据订舱的船公司代码{ca} 提取船公司映射失败", + _logger.LogInformation("提单号{mbl} 根据订舱的船公司代码{ca} 提取船公司映射失败", bookingOrder.MBLNO, bookingOrder.CARRIERID); - throw Oops.Bah("提单号={mbl} 船公司={ca} 未配置BC和DRAFT下载路由请联系管理员配置", bookingOrder.MBLNO, bookingOrder.CARRIERID); + throw Oops.Oh("提单号={0} 船公司={1} 未配置BC和DRAFT下载路由请联系管理员配置", bookingOrder.MBLNO, bookingOrder.CARRIERID); } string urlKey = string.Format(CONST_FORMAT_BC_URL, bcOrDraftRouteCfg.MapCode.ToLower()); @@ -180,23 +180,28 @@ namespace Myshipping.Application var bcUrl = _cache.GetAllDictData().GetAwaiter().GetResult() .FirstOrDefault(x => x.TypeCode == "url_set" && x.Code.Equals(urlKey, StringComparison.OrdinalIgnoreCase))?.Value; - _logger.LogInformation("提单号【{mbl}】根据订舱的船公司代码{ca} 提取BC下载URL完成,结果={rlt}", + _logger.LogInformation("提单号{mbl} 根据订舱的船公司代码{ca} 提取BC下载URL完成,结果={rlt}", bookingOrder.MBLNO, bookingOrder.CARRIERID, bcUrl); if (string.IsNullOrWhiteSpace(bcUrl)) { - _logger.LogInformation("提单号【{mbl}】根据订舱的船公司代码{ca} 提取BC下载URL失败,未取到配置key={key}", + _logger.LogInformation("提单号{0} 根据订舱的船公司代码{1} 提取BC下载URL失败,未取到配置key={key}", + bookingOrder.MBLNO, bookingOrder.CARRIERID, urlKey); + + throw Oops.Oh("提单号{0} 根据订舱的船公司代码{1} 提取BC下载URL失败,未取到配置key={key}", bookingOrder.MBLNO, bookingOrder.CARRIERID, urlKey); } + string webKey = string.Format(CONST_FORMAT_WEB, bcOrDraftRouteCfg.MapCode.ToLower()); + //获取个人对应的账户,这里GetAccountConfig逻辑优先取个人,个人没有配置取公司对应配置 - var userWebAccountConfig = _webAccountConfig.GetAccountConfig(CONST_FORMAT_WEB, UserManager.UserId).GetAwaiter() + var userWebAccountConfig = _webAccountConfig.GetAccountConfig(webKey, UserManager.UserId).GetAwaiter() .GetResult(); _logger.LogInformation("批次={no} 获取获取网站的账户完成,result={Num}", batchNo, JSON.Serialize(userWebAccountConfig)); if (userWebAccountConfig == null) - throw Oops.Bah($"个人/公司网站【{CONST_FORMAT_WEB}】获取失败,请维护个人/公司网站账户信息"); + throw Oops.Oh($"个人/公司网站【{webKey}】获取失败,请维护个人/公司网站账户信息"); BCOrDraftRequestDto requestDto = new BCOrDraftRequestDto { @@ -357,20 +362,20 @@ namespace Myshipping.Application foreach (var bk in list) { - taskList.Add(InnerDownloadBookingConfirm(bk, batchNo)); + taskList.Add(InnerDownloadDraft(bk, batchNo)); } Task.WaitAll(taskList.ToArray()); result.succ = true; - result.msg = "批量下载BC成功"; + result.msg = "下载Draft成功"; var downResultList = taskList.Select(x => x.Result).ToList(); if (downResultList.Any(x => !x.succ)) { result.succ = false; - result.msg = "BC下载失败"; + result.msg = "Draft下载失败"; } else { @@ -397,7 +402,7 @@ namespace Myshipping.Application catch (Exception ex) { result.succ = false; - result.msg = $"批量下载Draft异常,原因:{ex.Message}"; + result.msg = $"下载Draft异常,原因:{ex.Message}"; } return result; @@ -429,15 +434,15 @@ namespace Myshipping.Application .FirstOrDefault(t => t.Module.Equals(CONST_MAPPING_CARRIER_MODULE_ROUTE, StringComparison.OrdinalIgnoreCase) && t.Code.Equals(bookingOrder.CARRIERID?.Trim(), StringComparison.OrdinalIgnoreCase)); - _logger.LogInformation("提单号【{mbl}】根据订舱的船公司代码{ca} 提取船公司映射完成,结果={rlt}", + _logger.LogInformation("提单号{mbl} 根据订舱的船公司代码{ca} 提取船公司映射完成,结果={rlt}", bookingOrder.MBLNO, bookingOrder.CARRIERID, bcOrDraftRouteCfg); if (bcOrDraftRouteCfg == null) { - _logger.LogInformation("提单号【{mbl}】根据订舱的船公司代码{ca} 提取船公司映射失败", + _logger.LogInformation("提单号{0} 根据订舱的船公司代码{1} 提取船公司映射失败", bookingOrder.MBLNO, bookingOrder.CARRIERID); - throw Oops.Bah("提单号={mbl} 船公司={ca} 未配置BC和DRAFT下载路由请联系管理员配置", bookingOrder.MBLNO, bookingOrder.CARRIERID); + throw Oops.Oh("提单号={0} 船公司={1} 未配置BC和DRAFT下载路由请联系管理员配置", bookingOrder.MBLNO, bookingOrder.CARRIERID); } string urlKey = string.Format(CONST_FORMAT_DRAFT_URL, bcOrDraftRouteCfg.MapCode.ToLower()); @@ -445,26 +450,28 @@ namespace Myshipping.Application var bcUrl = _cache.GetAllDictData().GetAwaiter().GetResult() .FirstOrDefault(x => x.TypeCode == "url_set" && x.Code.Equals(urlKey, StringComparison.OrdinalIgnoreCase))?.Value; - _logger.LogInformation("提单号【{mbl}】根据订舱的船公司代码{ca} 提取DRAFT下载URL完成,结果={rlt}", + _logger.LogInformation("提单号{mbl} 根据订舱的船公司代码{ca} 提取DRAFT下载URL完成,结果={rlt}", bookingOrder.MBLNO, bookingOrder.CARRIERID, bcUrl); if (string.IsNullOrWhiteSpace(bcUrl)) { - _logger.LogInformation("提单号【{mbl}】根据订舱的船公司代码{ca} 提取BC下载URL失败,未取到配置key={key}", + _logger.LogInformation("提单号{0} 根据订舱的船公司代码{1} 提取BC下载URL失败,未取到配置key={key}", bookingOrder.MBLNO, bookingOrder.CARRIERID, urlKey); - } - string accountTypeCode = string.Empty; + throw Oops.Oh("提单号{0} 根据订舱的船公司代码{1} 提取BC下载URL失败,未取到配置key={key}", + bookingOrder.MBLNO, bookingOrder.CARRIERID, urlKey); + } + string webKey = string.Format(CONST_FORMAT_WEB, bcOrDraftRouteCfg.MapCode.ToLower()); //获取个人对应的账户,这里GetAccountConfig逻辑优先取个人,个人没有配置取公司对应配置 - var userWebAccountConfig = _webAccountConfig.GetAccountConfig(CONST_FORMAT_WEB, UserManager.UserId).GetAwaiter() + var userWebAccountConfig = _webAccountConfig.GetAccountConfig(webKey, UserManager.UserId).GetAwaiter() .GetResult(); _logger.LogInformation("批次={no} 获取获取网站的账户完成,result={Num}", batchNo, JSON.Serialize(userWebAccountConfig)); if (userWebAccountConfig == null) - throw Oops.Bah($"个人/公司网站【{CONST_FORMAT_WEB}】获取失败,请维护个人/公司网站账户信息"); + throw Oops.Oh($"个人/公司网站【{webKey}】获取失败,请维护个人/公司网站账户信息"); BCOrDraftRequestDto requestDto = new BCOrDraftRequestDto { @@ -480,7 +487,7 @@ namespace Myshipping.Application DateTime bDate = DateTime.Now; //开始请求BC - var rlt = await ExcuteBCDownload(bcUrl, requestDto, batchNo); + var rlt = await ExcuteDraftDownload(bcUrl, requestDto, batchNo); DateTime eDate = DateTime.Now; TimeSpan ts = eDate.Subtract(bDate); @@ -495,13 +502,13 @@ namespace Myshipping.Application string currFilePath = rlt.data.path; - string fileTypeCode = "bc"; - string fileTypeName = "Booking Confirmation"; + string fileTypeCode = "draft"; + string fileTypeName = "Draft"; //读取文件配置 var fileCfg = App.GetOptions(); - string relativePath = $"{fileCfg.relativePath}\\bcfiles\\{bookingOrder.Id}"; + string relativePath = $"{fileCfg.relativePath}\\draftfiles\\{bookingOrder.Id}"; string filePath = $"{(!string.IsNullOrWhiteSpace(fileCfg.basePath) ? fileCfg.basePath : App.WebHostEnvironment.WebRootPath)}\\{relativePath}"; string fileFullName = $"{filePath}\\{new System.IO.FileInfo(currFilePath).Name}"; @@ -546,36 +553,85 @@ namespace Myshipping.Application fileTypeCode, fileTypeName); result.succ = true; - result.msg = "BC下载成功"; + result.msg = "Draft下载成功"; } else { result.succ = false; - result.msg = $"BC下载失败,原因={rlt.msg}"; + result.msg = $"Draft下载失败,原因={rlt.msg}"; } } catch (Exception ex) { result.succ = false; - result.msg = $"BC下载失败,原因:{ex.Message}"; + result.msg = $"Draft下载失败,原因:{ex.Message}"; } return result; } #endregion - #region 请求远端下载 + #region BC请求远端下载 + /// + /// BC请求远端下载 + /// + /// 请求URL + /// 请求详情 + /// 批次号 + /// 返回结果 + [NonAction] + private async Task ExcuteBCDownload(string url, BCOrDraftRequestDto info, string batchNo) + { + BCAPIBaseResult model = null; + /* + 1、填充请求的类,并生成JSON报文 + 2、POST请求接口,并记录回执。 + 3、返回信息。 + */ + try + { + _logger.LogInformation("批次={no} 对应请求报文 request={res}", batchNo, JSON.Serialize(info)); + + var res = await url.SetHttpMethod(HttpMethod.Post) + .SetBody(JSON.Serialize(info), "application/json") + .SetContentEncoding(Encoding.UTF8) + .PostAsync(); + + _logger.LogInformation("批次={no} 对应请求报文完成 res={res}", batchNo, JSON.Serialize(res)); + + if (res.StatusCode == System.Net.HttpStatusCode.OK) + { + var userResult = await res.Content.ReadAsStringAsync(); + + System.Text.Json.JsonSerializerOptions jsonOptions = new JsonSerializerOptions(); + jsonOptions.Converters.Add(new DateTimeJsonConverter("yyyy-MM-dd HH:mm:ss")); + + model = JSON.Deserialize(userResult, jsonOptions); + } + } + catch (Exception ex) + { + //写日志 + if (ex is HttpRequestException) + throw Oops.Oh(10000002); + } + + return model; + } + #endregion + + #region Draft请求远端下载 /// - /// 请求远端下载 + /// Draft请求远端下载 /// /// 请求URL /// 请求详情 /// 批次号 /// 返回结果 [NonAction] - private async Task> ExcuteBCDownload(string url, BCOrDraftRequestDto info, string batchNo) + private async Task ExcuteDraftDownload(string url, BCOrDraftRequestDto info, string batchNo) { - BCAPIBaseResult model = null; + DraftAPIBaseResult model = null; /* 1、填充请求的类,并生成JSON报文 2、POST请求接口,并记录回执。 @@ -599,7 +655,7 @@ namespace Myshipping.Application System.Text.Json.JsonSerializerOptions jsonOptions = new JsonSerializerOptions(); jsonOptions.Converters.Add(new DateTimeJsonConverter("yyyy-MM-dd HH:mm:ss")); - model = JSON.Deserialize>(userResult, jsonOptions); + model = JSON.Deserialize(userResult, jsonOptions); } } catch (Exception ex) diff --git a/Myshipping.Application/Service/BookingOrder/Dto/BCAPIBaseResult.cs b/Myshipping.Application/Service/BookingOrder/Dto/BCAPIBaseResult.cs index 5e46e194..eaea2d04 100644 --- a/Myshipping.Application/Service/BookingOrder/Dto/BCAPIBaseResult.cs +++ b/Myshipping.Application/Service/BookingOrder/Dto/BCAPIBaseResult.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Myshipping.Application { - public class BCAPIBaseResult + public class BCAPIBaseResult { /// /// 回执代码 @@ -21,20 +21,23 @@ namespace Myshipping.Application /// /// 数据集 /// - public BCAPIBaseData data { get; set; } + public BCAPIBaseData data { get; set; } } - public class BCAPIBaseData + public class BCOrDraftAPIBaseData { /// /// 文件下载路径 /// public string path { get; set; } + } + public class BCAPIBaseData : BCOrDraftAPIBaseData + { /// /// 解析详情 /// - public T parse { get; set; } + public BCAPIBaseDataParse parse { get; set; } } public class BCAPIBaseDataParse @@ -73,5 +76,25 @@ namespace Myshipping.Application public List BCList { get; set; } } + public class DraftAPIBaseResult + { + /// + /// 回执代码 + /// + public int code { get; set; } + /// + /// 提示信息 + /// + public string msg { get; set; } + + /// + /// 数据集 + /// + public DraftAPIBaseData data { get; set; } + } + + public class DraftAPIBaseData : BCOrDraftAPIBaseData + { + } } diff --git a/Myshipping.Core/Service/DjyCustomer/DjyCustomerService.cs b/Myshipping.Core/Service/DjyCustomer/DjyCustomerService.cs index 1421c23c..2d569830 100644 --- a/Myshipping.Core/Service/DjyCustomer/DjyCustomerService.cs +++ b/Myshipping.Core/Service/DjyCustomer/DjyCustomerService.cs @@ -14,6 +14,7 @@ using Microsoft.Extensions.Logging; using System; using System.Text.RegularExpressions; using NPOI.Util; +using StackExchange.Profiling.Internal; namespace Myshipping.Core.Service { @@ -221,19 +222,13 @@ namespace Myshipping.Core.Service try { - string sqlWhere = "1=1"; - if (!string.IsNullOrWhiteSpace(queryItem)) - { - sqlWhere += $" and (CodeName like '%{queryItem.Trim()}%' or ShortName like '%{queryItem.Trim()}%' or FullName like '%{queryItem.Trim()}%')"; - } - - if (queryType.Length > 0) - { - sqlWhere += $" and PropString REGEXP '" + string.Join("|", queryType) + "'"; - } - - var entityList = await _rep.AsQueryable().Where(sqlWhere).Take(top).OrderBy(a => a.FullName) + var entityList = await _rep.AsQueryable() + .WhereIF(!string.IsNullOrWhiteSpace(queryItem), x => + x.CodeName.Contains(queryItem)|| x.ShortName.Contains(queryItem) || x.FullName.Contains(queryItem)) + .WhereIF(queryType.Length > 0, x => + x.PropString.Contains(queryType.FirstOrDefault())) + .Take(top).OrderBy(a => a.FullName) .ToListAsync(); if (entityList.Count > 0)