From 65e3fbff004347ac814fe71c2122ce463a2dc178 Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Mon, 6 Feb 2023 15:14:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=91=E7=9A=84=E4=BB=BB=E5=8A=A1-LARA?= =?UTF-8?q?=E7=BA=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TaskManagePlat/TaskLARAPaperInfo.cs | 5 + .../Interface/ITaskManageService.cs | 5 +- .../TaskManagePlat/TaskManageService.cs | 179 +++++++----------- 3 files changed, 75 insertions(+), 114 deletions(-) diff --git a/Myshipping.Application/Entity/TaskManagePlat/TaskLARAPaperInfo.cs b/Myshipping.Application/Entity/TaskManagePlat/TaskLARAPaperInfo.cs index 3d60754a..efaeb6e7 100644 --- a/Myshipping.Application/Entity/TaskManagePlat/TaskLARAPaperInfo.cs +++ b/Myshipping.Application/Entity/TaskManagePlat/TaskLARAPaperInfo.cs @@ -91,5 +91,10 @@ namespace Myshipping.Application /// 状态 succ-成功 failure-失败 timeout-超时 /// public string STATUS { get; set; } + + /// + /// 提单纸页数 + /// + public int DRAFT_NUM { get; set; } } } diff --git a/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageService.cs b/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageService.cs index 43c8f955..73b8c6dd 100644 --- a/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageService.cs @@ -93,10 +93,9 @@ namespace Myshipping.Application /// /// 请求提单纸登记 /// - /// 任务主键 - /// 提单纸登记请求参数 + /// 提单纸登记请求参数列表 /// 返回结果 - Task LaraPaperRegistPost(string taskPKId, LaraPaperRegistPostDto model); + Task LaraPaperRegistPost(List laraPaperList); /// /// 下载任务附件 diff --git a/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs b/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs index 5fc8cde8..745a7b7b 100644 --- a/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs @@ -59,6 +59,7 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Xml.Linq; using static Aliyun.OSS.Model.CreateSelectObjectMetaInputFormatModel; +using static Aliyun.OSS.Model.ListPartsResult; namespace Myshipping.Application { @@ -1368,17 +1369,16 @@ namespace Myshipping.Application /// /// 请求提单纸登记 /// - /// 任务主键 - /// 提单纸登记请求参数 - /// + /// 提单纸登记请求参数列表 + /// 返回结果 [HttpPost("/TaskManage/LaraPaperRegistPost")] - public async Task LaraPaperRegistPost(string taskPKId, LaraPaperRegistPostDto model) + public async Task LaraPaperRegistPost(List laraPaperList) { TaskManageOrderResultDto result = new TaskManageOrderResultDto(); string batchNo = IDGen.NextID().ToString(); - _logger.LogInformation("批次={no} id={id} LARA提单纸登记开始", batchNo, taskPKId); + _logger.LogInformation("批次={no} num={num} LARA提单纸登记开始", batchNo, laraPaperList.Count); /* 1、读取LARA网站的配置账户。 @@ -1392,7 +1392,10 @@ namespace Myshipping.Application try { - var taskInfo = _taskBaseInfoRepository.AsQueryable().First(t => t.PK_ID == taskPKId); + var taskArg = laraPaperList.Select(t => t.TaskId).Distinct().ToArray(); + + var taskList = _taskBaseInfoRepository.AsQueryable().Where(t => taskArg.Contains(t.PK_ID)).ToList(); + _logger.LogInformation("批次={no} 获取任务完成", batchNo); @@ -1404,130 +1407,84 @@ namespace Myshipping.Application if (userWebAccountConfig == null) throw Oops.Bah($"个人/公司网站【{CONST_WEB_LARA_ACCOUNT_TYPE}】获取失败,请维护个人/公司网站账户信息"); - await InnerDownloadOriginalTask(batchNo, taskInfo, userWebAccountConfig); - } - catch (Exception ex) - { - throw Oops.Bah("请求提单纸登记异常,{0}", ex.Message); - } - - return result; - } - #endregion - - - //LaraPaperPostUrl - private async Task InnerLaraPaperRegistPost(string batchNo, TaskBaseInfo taskBaseInfo, LaraPaperRegistPostDto model, - DjyWebsiteAccountConfig webAccountConfig) - { - - TaskManageOrderResultDto result = new TaskManageOrderResultDto(); - //正本下载URL - string originalUrl = string.Empty; - - try - { - DateTime startDate = DateTime.Now; - var downloadUrl = _cache.GetAllDictData().GetAwaiter().GetResult() .First(t => t.Code.Equals(CONST_LARA_DOWN_URL_CODE, StringComparison.OrdinalIgnoreCase))?.Value; if (string.IsNullOrWhiteSpace(downloadUrl)) - throw Oops.Bah($"正本下载URL不存在,请确认字典是否配置 code={CONST_BOOK_ORIGINAL_DOWN_URL_CODE}"); - - TaskLARAPaperInfo taskLARAPaperInfo = new TaskLARAPaperInfo - { - PK_ID = IDGen.NextID().ToString(), - TASK_ID = taskBaseInfo.PK_ID, - BOOKING_ORDER_NO = "", - CreatedUserId = UserManager.UserId, - CreatedUserName = UserManager.Name, - STATUS = "temp", - IS_TIMEOUT = 0, - START_DATE = startDate, - TenantId = UserManager.TENANT_ID, - TenantName = UserManager.TENANT_NAME - }; - - //写入记录 - _taskLARAPaperInfoRepository.Insert(taskLARAPaperInfo); - - //请求远程链接 - Dictionary formDict = new Dictionary { - {"bno", taskBaseInfo.MBL_NO }, - {"num_from", model.NumberFrom }, - {"num_to", model.NumberTo }, - {"numbers", model.PageNumbers }, - {"vessel_code", "" }, - {"voyage_code", "" }, - {"bl_status", "All" }, - {"bl_type", "Original Bill" }, - {"issue_code", "ALL" }, - {"web_user", webAccountConfig.Account }, - {"web_pwd", webAccountConfig.Password }, - {"customer_user", "myshipping" }, - {"customer_pwd", "" }, - }; + throw Oops.Bah($"LARA纸下载URL不存在,请确认字典是否配置 code={CONST_LARA_DOWN_URL_CODE}"); - //请求 - var postResult = await InnerRemoteDownLaraPaper(batchNo, downloadUrl, formDict); + JObject jobjPost = new JObject(); + jobjPost.Add("customer_user", "myshipping"); + jobjPost.Add("customer_pwd", ""); + JArray jarr = new JArray(); + jobjPost.Add("lara_list", jarr); - //重新获取下载历史 - var downloadHisInfo = _taskOriginalDownloadHisInfoRepository.AsQueryable() - .First(t => t.PK_ID == taskLARAPaperInfo.PK_ID); + laraPaperList.ForEach(async lara => + { + TaskLARAPaperInfo taskLARAPaperInfo = new TaskLARAPaperInfo + { + PK_ID = IDGen.NextID().ToString(), + TASK_ID = lara.TaskId, + BOOKING_ORDER_NO = "", + CreatedUserId = UserManager.UserId, + CreatedUserName = UserManager.Name, + STATUS = "temp", + IS_TIMEOUT = 0, + START_DATE = DateTime.Now, + TenantId = UserManager.TENANT_ID, + TenantName = UserManager.TENANT_NAME, + PAGE_NUMBERS = lara.PageNumbers, + PAGE_SUM = lara.PageSum, + ISSUE_TYPE = lara.ISSUETYPE, + MBL_NO = lara.MBLNO, + NUMBER_FROM = lara.NumberFrom, + NUMBER_TO = lara.NumberTo, + DRAFT_NUM = lara.DraftNum, + }; - //更新任务状态 - var taskModel = _taskBaseInfoRepository.AsQueryable().First(t => t.PK_ID == taskBaseInfo.PK_ID); + //写入记录 + await _taskLARAPaperInfoRepository.InsertAsync(taskLARAPaperInfo); + + JObject jobjItem = new JObject(); + jobjItem.Add("customer_user", "myshipping"); + jobjItem.Add("customer_pwd", ""); + jobjItem.Add("web_user", userWebAccountConfig.Account); + jobjItem.Add("web_pwd", userWebAccountConfig.Password); + jobjItem.Add("bno", lara.MBLNO); + jobjItem.Add("num_from", lara.NumberFrom); + jobjItem.Add("num_to", lara.NumberTo); + jobjItem.Add("numbers", lara.PageNumbers); + jobjItem.Add("vessel_code", ""); + jobjItem.Add("voyage_code", ""); + jobjItem.Add("bl_status", "All"); + jobjItem.Add("bl_type", "Original Bill"); + jobjItem.Add("issue_code", "ALL"); + jarr.Add(jobjItem); - downloadHisInfo.END_DATE = (DateTime)postResult.ext; - downloadHisInfo.RESULT_NOTE = postResult.msg; + }); + //await InnerDownloadOriginalTask(batchNo, taskInfo, userWebAccountConfig); - bool isDownSucc = false; + var postResult = await InnerRemoteDownLaraPaper(batchNo, downloadUrl, JSON.Serialize(jobjPost)); - //下载返回成功后,更新记录并生成扣费记录 if (postResult.succ) { - downloadHisInfo.STATUS = "succ"; - downloadHisInfo.RESULT_URL = postResult.msg; - - taskModel.COMPLETE_DEAL = TaskCompleteDealEnum.MANUAL.ToString(); - taskModel.COMPLETE_DEAL_NAME = TaskCompleteDealEnum.MANUAL.GetDescription(); - taskModel.COMPLETE_DATE = DateTime.Now; - taskModel.STATUS = TaskStatusEnum.Complete.ToString(); - taskModel.IS_COMPLETE = 1; - - isDownSucc = true; + result.succ = true; + result.msg = "成功"; } else { - if (postResult.isTimeout) - { - downloadHisInfo.STATUS = "timeout"; - } - else - { - downloadHisInfo.STATUS = "failure"; - } + result.succ = false; + result.msg = postResult.msg; } - - //更新下载历史 - await _taskOriginalDownloadHisInfoRepository.AsUpdateable(downloadHisInfo).IgnoreColumns(it => new - { - it.TenantId, - it.CreatedUserId, - it.CreatedUserName - }).ExecuteCommandAsync(); - - } catch (Exception ex) { - result.succ = false; - result.msg = ex.Message; + throw Oops.Bah("请求提单纸登记异常,{0}", ex.Message); } return result; } + #endregion #region 远程请求请求提单纸登记 /// @@ -1535,9 +1492,9 @@ namespace Myshipping.Application /// /// 批次号 /// 请求URL - /// 请求参数 + /// 请求参数 /// - private async Task InnerRemoteDownLaraPaper(string batchNo, string url, Dictionary dic) + private async Task InnerRemoteDownLaraPaper(string batchNo, string url, string jsonMsg) { var result = new TaskManageOrderResultDto(); @@ -1548,7 +1505,7 @@ namespace Myshipping.Application _logger.LogInformation("批次={no} 请求报文开始", batchNo); var res = await url.SetHttpMethod(HttpMethod.Post) - .SetBody(dic, "application/x-www-form-urlencoded") + .SetBody(jsonMsg, "application/json") .SetContentEncoding(Encoding.UTF8) .PostAsync(); @@ -1597,7 +1554,7 @@ namespace Myshipping.Application /// 任务主键数组 /// 返回结果 [HttpPost("/TaskManage/LaraPaperRegist")] - public async Task LaraPaperRegist(string[] PKIds) + public async Task LaraPaperRegist([FromQuery]string[] PKIds) { LaraPaperRegistDto result = new LaraPaperRegistDto();