From 8bc00d6fab921823d67e85af9b692f062711264e Mon Sep 17 00:00:00 2001 From: zhangxiaofeng <1939543722@qq.com> Date: Mon, 29 Apr 2024 10:41:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A7=94=E6=89=98=E7=BB=93=E7=AE=97=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=8E=A5=E6=94=B6=E6=8E=A5=E5=8F=A3+=E5=85=AC?= =?UTF-8?q?=E5=8F=B8=E7=A8=8E=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/BaseApiController.cs | 2 +- .../Controllers/OpenController.cs | 110 +++++++++++++++++- .../Controllers/OrderController.cs | 15 ++- .../Properties/launchSettings.json | 2 +- EntrustSettle.Api/appsettings.Staging.json | 18 +-- EntrustSettle.Api/appsettings.json | 8 +- .../Middlewares/RequRespLogMiddleware.cs | 24 ++-- EntrustSettle.Model/Dtos/Hyd/HydSubmitDto.cs | 3 +- EntrustSettle.Model/Models/DJY/CompanyNew.cs | 13 +++ EntrustSettle.Model/Models/Order.cs | 4 + .../QuartzNet/Jobs/JobHydSubmitQuartz.cs | 8 +- 11 files changed, 171 insertions(+), 36 deletions(-) create mode 100644 EntrustSettle.Model/Models/DJY/CompanyNew.cs diff --git a/EntrustSettle.Api/Controllers/BaseApiController.cs b/EntrustSettle.Api/Controllers/BaseApiController.cs index c4fc038..6cc7e67 100644 --- a/EntrustSettle.Api/Controllers/BaseApiController.cs +++ b/EntrustSettle.Api/Controllers/BaseApiController.cs @@ -67,7 +67,7 @@ namespace EntrustSettle.Controllers /// 返回一个错误提示,但不包含数据 /// [NonAction] - protected MessageModel FailedMsg(int code, string msg = "失败") + protected MessageModel FailedMsg(string msg = "失败", int code = 500) { return new MessageModel() { diff --git a/EntrustSettle.Api/Controllers/OpenController.cs b/EntrustSettle.Api/Controllers/OpenController.cs index b0f3a9a..d761db8 100644 --- a/EntrustSettle.Api/Controllers/OpenController.cs +++ b/EntrustSettle.Api/Controllers/OpenController.cs @@ -1,9 +1,12 @@ using EntrustSettle.Common; using EntrustSettle.Controllers; +using EntrustSettle.IServices; using EntrustSettle.Model; using EntrustSettle.Model.Dtos; +using EntrustSettle.Model.Models; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; namespace EntrustSettle.Api.Controllers { @@ -13,8 +16,22 @@ namespace EntrustSettle.Api.Controllers [AllowAnonymous] public class OpenController : BaseApiController { - public OpenController() + private readonly IOrderService orderService; + private readonly ILogger logger; + private readonly IOrderHistoryService orderHistoryService; + private readonly IQueueService queueService; + private readonly IOrderFeeService orderFeeService; + public OpenController(IOrderService orderService, + ILogger logger, + IOrderHistoryService orderHistoryService, + IQueueService queueService, + IOrderFeeService orderFeeService) { + this.orderService = orderService; + this.logger = logger; + this.orderHistoryService = orderHistoryService; + this.queueService = queueService; + this.orderFeeService = orderFeeService; } /// @@ -64,5 +81,96 @@ namespace EntrustSettle.Api.Controllers var result = await App.GetService().DownloadFile(annexId); return result; } + + /// + /// 海运达状态回推接口 + /// + [HttpPost] + [ApiUser(ApiCode = "PushOrderStatus")] + public async Task PushOrderStatus([FromBody] HydQueryResultDto item) + { + var orderList = await orderService.Query(x => x.Bsno == item.id); + if (orderList == null || orderList.Count == 0) + { + string msg = $"订单Id[{item.id}]接收到回推后未查询到本地订单"; + logger.LogInformation(msg); + return FailedMsg(msg); + } + if (orderList.Count > 1) + { + string msg = $"订单Id[{item.id}]接收到回推后根据Id查询到多个本地订单:{string.Join(',', orderList.Select(x => x.Mblno))}"; + logger.LogInformation(msg); + return FailedMsg(msg); + } + var order = orderList[0]; + if (order.Status == item.status) + { + string msg = $"订单Id[{item.id}],提单号[{order.Mblno}]状态不变"; + logger.LogInformation(msg); + return SuccessMsg(msg); + } + order.Status = item.status; + var updateSuccess = await orderService.Update(order, x => new { x.Status }); + logger.LogInformation($"订单Id[{item.id}],提单号[{order.Mblno}]状态更新{(updateSuccess ? "成功" : "失败")},status:{item.status}"); + + // 记录订单状态变更历史 + await orderHistoryService.Add(new OrderHistory() + { + Pid = order.Id, + Status = item.status, + StatusTime = DateTime.Now, + CreateBy = "系统", + Remark = "(状态接收)" + }); + + // 将更新后的状态及费用推送到消息队列 + if (AppSettings.app("RabbitMQ", "Enabled").ObjToBool()) + { + _ = Task.Run(async () => + { + string msg = $"Id:[{order.Id}],提单号[{order.Mblno}],自动更新状态后推送队列"; + try + { + StatusPushDto pushDto = new() + { + OrderId = order.Id, + Mblno = order.Mblno, + MessageType = 1, + MessageDesc = "状态更新推送", + Remark = "", + Status = item.status, + StatusDesc = item.status switch + { + 0 => "已下单", + 1 => "已接单", + 2 => "待缴费", + 3 => "已缴费", + 4 => "已完结", + _ => "未知状态", + } + }; + var feeList = await orderFeeService.Query(x => x.OrderId == order.Id); + if (feeList.Count > 0) + { + pushDto.FeeList = feeList.Select(x => new StatusPushDto.FeeDto() + { + FeeId = x.Id, + FeeName = x.Name, + FeeAmount = x.Amount + }).ToList(); + } + + var json = JsonConvert.SerializeObject(pushDto, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); + queueService.Push(msg, order.CompanyId, json); + } + catch (Exception ex) + { + logger.LogError(ex, $"订单Id[{item.id}],提单号[{order.Mblno}]接收到状态然后推送时发生未知异常:{msg}"); + } + }); + } + + return SuccessMsg($"订单Id[{item.id}],提单号[{order.Mblno}]状态更新成功"); + } } } diff --git a/EntrustSettle.Api/Controllers/OrderController.cs b/EntrustSettle.Api/Controllers/OrderController.cs index e11760b..8e6bb6b 100644 --- a/EntrustSettle.Api/Controllers/OrderController.cs +++ b/EntrustSettle.Api/Controllers/OrderController.cs @@ -11,9 +11,11 @@ using EntrustSettle.Model.Models; using EntrustSettle.Model.Models.DJY; using EntrustSettle.Model.Validator; using EntrustSettle.Repository.UnitOfWorks; +using EntrustSettle.Services; using FluentValidation; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; +using System.Net.NetworkInformation; namespace EntrustSettle.Api.Controllers { @@ -137,6 +139,10 @@ namespace EntrustSettle.Api.Controllers inputDto.MblnoList = inputDto.MblnoList.Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim()).ToArray(); StringHelper.TrimStringProperties(inputDto); + // 查询税号 + var custBalanceService = App.GetService>(); + var taxCode = await custBalanceService.Db.Queryable().Where(x => x.CompId == inputDto.CompanyId).Select(x => x.TaxCode).FirstAsync(); + var orderList = new List(); foreach (var item in inputDto.MblnoList) { @@ -145,6 +151,7 @@ namespace EntrustSettle.Api.Controllers Mblno = item, CompanyId = inputDto.CompanyId, CompanyName = inputDto.CompanyName, + TaxCode = taxCode, ServiceType = inputDto.ServiceType, ProjectType = inputDto.ProjectType, IsSend = false, @@ -252,9 +259,11 @@ namespace EntrustSettle.Api.Controllers registerFlag = 1, registerUser = new HydSubmitDto.RegisterUser() { - phone = orderItem.ContactTel, - userName = orderItem.ContactName, - enterpriseName = orderItem.CompanyName + phone = orderItem.ContactTel?.Trim(), + userName = orderItem.ContactName?.Trim(), + enterpriseName = orderItem.CompanyName?.Trim(), + sex = 1, + dutyNo = orderItem.TaxCode?.Trim() ?? "" } }; // 开始提交 diff --git a/EntrustSettle.Api/Properties/launchSettings.json b/EntrustSettle.Api/Properties/launchSettings.json index 204f91e..b07718e 100644 --- a/EntrustSettle.Api/Properties/launchSettings.json +++ b/EntrustSettle.Api/Properties/launchSettings.json @@ -6,7 +6,7 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, - "applicationUrl": "http://localhost:6002" + "applicationUrl": "http://*:6002" } }, "$schema": "http://json.schemastore.org/launchsettings.json" diff --git a/EntrustSettle.Api/appsettings.Staging.json b/EntrustSettle.Api/appsettings.Staging.json index 13e21a8..043ba27 100644 --- a/EntrustSettle.Api/appsettings.Staging.json +++ b/EntrustSettle.Api/appsettings.Staging.json @@ -47,7 +47,8 @@ "Middleware": { "RequestResponseLog": { "Enabled": true, - "IgnoreApis": "/api/Annex/Upload,/api/Annex/DownloadFile,/api/Annex/Download", + "IgnoreRequestApis": "/api/Annex/Upload,/api/Open/AnnexUpload", + "IgnoreResponseApis": "/api/Annex/DownloadFile,/api/Annex/Download,/api/Open/AnnexDownload", "LogToFile": { "Enabled": true }, @@ -56,14 +57,14 @@ } }, "RecordAccessLogs": { - "Enabled": false, + "Enabled": true, "LogToFile": { - "Enabled": false + "Enabled": true }, "LogToDB": { "Enabled": false }, - "IgnoreApis": "/api/Annex/Upload,/api/Annex/DownloadFile,/api/Annex/Download" + "IgnoreApis": "/api/Annex/Upload,/api/Open/AnnexUpload,/api/Annex/DownloadFile,/api/Annex/Download,/api/Open/AnnexDownload" }, "SignalR": { "Enabled": false @@ -235,10 +236,11 @@ }, "RabbitMQ": { "Enabled": true, - "Connection": "60.209.125.238:40101/audit_booking", - "UserName": "audit_booking_user", - "Password": "djy^2024", - "RetryCount": 3 + "ConnectionString": "amqp://entrust_settle_user:djy^2024@60.209.125.238:40101/entrust_settle" + //"Connection": "60.209.125.238:40101/audit_booking", + //"UserName": "audit_booking_user", + //"Password": "djy^2024", + //"RetryCount": 3 }, "Kafka": { "Enabled": false, diff --git a/EntrustSettle.Api/appsettings.json b/EntrustSettle.Api/appsettings.json index 09ecf68..62e794c 100644 --- a/EntrustSettle.Api/appsettings.json +++ b/EntrustSettle.Api/appsettings.json @@ -48,7 +48,7 @@ "RequestResponseLog": { "Enabled": true, "IgnoreRequestApis": "/api/Annex/Upload,/api/Open/AnnexUpload", - "IgnoreResponseApis": "/api/Annex/DownloadFile,/api/Open/AnnexDownload", + "IgnoreResponseApis": "/api/Annex/DownloadFile,/api/Annex/Download,/api/Open/AnnexDownload", "LogToFile": { "Enabled": true }, @@ -64,7 +64,7 @@ "LogToDB": { "Enabled": false }, - "IgnoreApis": "/api/Annex/Upload,/api/Open/AnnexUpload,/api/Annex/DownloadFile,/api/Open/AnnexDownload" + "IgnoreApis": "/api/Annex/Upload,/api/Open/AnnexUpload,/api/Annex/DownloadFile,/api/Annex/Download,/api/Open/AnnexDownload" }, "SignalR": { "Enabled": false @@ -127,7 +127,7 @@ "Enabled": true }, "SeedDBEnabled": false, //生成表结构 - "RoutePrefix": "", //路由变量前缀配置 + "RoutePrefix": "" //路由变量前缀配置 }, // DBType对应:0=MySql,1=SqlServer,2=Sqlite,3=Oracle,4=PostgreSQL,5=Dm,6=Kdbndp // @@ -230,7 +230,7 @@ "Enabled": false }, "Redis": { - "Enabled": false, + "Enabled": true, "ConnectionString": "127.0.0.1:6379,defaultDatabase=3", "InstanceName": "" //Key前缀 }, diff --git a/EntrustSettle.Extensions/Middlewares/RequRespLogMiddleware.cs b/EntrustSettle.Extensions/Middlewares/RequRespLogMiddleware.cs index 286a98e..94901a5 100644 --- a/EntrustSettle.Extensions/Middlewares/RequRespLogMiddleware.cs +++ b/EntrustSettle.Extensions/Middlewares/RequRespLogMiddleware.cs @@ -52,7 +52,7 @@ namespace EntrustSettle.Extensions.Middlewares // return; //} - // 过滤,只有接口 + // 分别过滤请求和响应要记录日志的接口 var ignoreRequestApis = AppSettings.app("Middleware", "RequestResponseLog", "IgnoreRequestApis").Split(',').ToList(); var ignoreResponseApis = AppSettings.app("Middleware", "RequestResponseLog", "IgnoreResponseApis").Split(',').ToList(); @@ -96,25 +96,21 @@ namespace EntrustSettle.Extensions.Middlewares // 去除 Html //var reg = "<[^>]+>"; + //var isHtml = Regex.IsMatch(responseBody, reg); - //if (!string.IsNullOrEmpty(responseBody)) + var logContent = new string[] { - //var isHtml = Regex.IsMatch(responseBody, reg); - - var logContent = new string[] - { $"● 响应", $"[Path]:{context.Request.Path}", $"[StatusCode]:{context.Response.StatusCode}", $"[Body]:{(isIgnore? "略" : responseBody )}", - }; - Parallel.For(0, 1, e => - { - LogLock.OutLogAOP("RequestResponseLog", - context.TraceIdentifier, - logContent); - }); - } + }; + Parallel.For(0, 1, e => + { + LogLock.OutLogAOP("RequestResponseLog", + context.TraceIdentifier, + logContent); + }); } } } \ No newline at end of file diff --git a/EntrustSettle.Model/Dtos/Hyd/HydSubmitDto.cs b/EntrustSettle.Model/Dtos/Hyd/HydSubmitDto.cs index a03d306..bb73625 100644 --- a/EntrustSettle.Model/Dtos/Hyd/HydSubmitDto.cs +++ b/EntrustSettle.Model/Dtos/Hyd/HydSubmitDto.cs @@ -17,9 +17,10 @@ namespace EntrustSettle.Model.Dtos { public string phone { get; set; } public string userName { get; set; } - public string sex { get; set; } + public int sex { get; set; } public string idNumber { get; set; } public string enterpriseName { get; set; } + public string dutyNo { get; set; } } } } diff --git a/EntrustSettle.Model/Models/DJY/CompanyNew.cs b/EntrustSettle.Model/Models/DJY/CompanyNew.cs new file mode 100644 index 0000000..e9247e2 --- /dev/null +++ b/EntrustSettle.Model/Models/DJY/CompanyNew.cs @@ -0,0 +1,13 @@ +using SqlSugar; + +namespace EntrustSettle.Model.Models.DJY +{ + [Tenant(DBConst.PingTai)] + [SugarTable("company_new")] + public class CompanyNew + { + //[SugarColumn(IsPrimaryKey = true)] + public string CompId { get; set; } + public string TaxCode { get; set; } + } +} \ No newline at end of file diff --git a/EntrustSettle.Model/Models/Order.cs b/EntrustSettle.Model/Models/Order.cs index ec358f0..31941c3 100644 --- a/EntrustSettle.Model/Models/Order.cs +++ b/EntrustSettle.Model/Models/Order.cs @@ -26,6 +26,10 @@ namespace EntrustSettle.Model.Models /// public string CompanyName { get; set; } /// + /// 公司税号 + /// + public string TaxCode { get; set; } + /// /// 联系人Id /// public string ContactId { get; set; } diff --git a/EntrustSettle.Tasks/QuartzNet/Jobs/JobHydSubmitQuartz.cs b/EntrustSettle.Tasks/QuartzNet/Jobs/JobHydSubmitQuartz.cs index 113bab7..cdcc3da 100644 --- a/EntrustSettle.Tasks/QuartzNet/Jobs/JobHydSubmitQuartz.cs +++ b/EntrustSettle.Tasks/QuartzNet/Jobs/JobHydSubmitQuartz.cs @@ -111,9 +111,11 @@ namespace EntrustSettle.Tasks registerFlag = 1, registerUser = new HydSubmitDto.RegisterUser() { - phone = orderItem.ContactTel, - userName = orderItem.ContactName, - enterpriseName = orderItem.CompanyName + phone = orderItem.ContactTel?.Trim(), + userName = orderItem.ContactName?.Trim(), + enterpriseName = orderItem.CompanyName?.Trim(), + sex = 1, + dutyNo = orderItem.TaxCode?.Trim() ?? "" } }; // 开始提交