From e9918abe6262b33845b4872df20778dc76870377 Mon Sep 17 00:00:00 2001 From: zxxxf <1939543722@qq.com> Date: Wed, 10 Apr 2024 00:10:18 +0800 Subject: [PATCH] 456 --- .../Controllers/OpenController.cs | 2 +- .../Controllers/OrderController.cs | 43 ++++++++++++++----- EntrustSettle.IServices/IQueueService.cs | 2 +- .../Dtos/Order/OrderSubmitResultDto.cs | 14 ++++++ EntrustSettle.Model/Dtos/Queue/BasePushDto.cs | 9 ++++ .../Dtos/Queue/StatusPushDto.cs | 5 ++- EntrustSettle.Services/QueueService.cs | 14 +++--- .../QuartzNet/Jobs/JobHydStatusQuartz.cs | 25 ++++++----- 8 files changed, 81 insertions(+), 33 deletions(-) create mode 100644 EntrustSettle.Model/Dtos/Order/OrderSubmitResultDto.cs diff --git a/EntrustSettle.Api/Controllers/OpenController.cs b/EntrustSettle.Api/Controllers/OpenController.cs index 6e10e36..b0f3a9a 100644 --- a/EntrustSettle.Api/Controllers/OpenController.cs +++ b/EntrustSettle.Api/Controllers/OpenController.cs @@ -22,7 +22,7 @@ namespace EntrustSettle.Api.Controllers /// [HttpPost] [ApiUser(ApiCode = "EntrustSettle")] - public async Task OrderSubmit(OrderSubmitDto inputDto) + public async Task>> OrderSubmit(OrderSubmitDto inputDto) { var result = await App.GetService().Submit(inputDto); return result; diff --git a/EntrustSettle.Api/Controllers/OrderController.cs b/EntrustSettle.Api/Controllers/OrderController.cs index 5b5bbb4..b3009a8 100644 --- a/EntrustSettle.Api/Controllers/OrderController.cs +++ b/EntrustSettle.Api/Controllers/OrderController.cs @@ -121,7 +121,7 @@ namespace EntrustSettle.Api.Controllers /// [HttpPost] //[UseTran] - public async Task Submit(OrderSubmitDto inputDto) + public async Task>> Submit(OrderSubmitDto inputDto) { var validator = new OrderSubmitDtoValidator(); validator.ValidateAndThrow(inputDto); @@ -150,9 +150,13 @@ namespace EntrustSettle.Api.Controllers orderList.Add(order); } unitOfWorkManage.BeginTran(); - var orderHasIdList = await orderService.AsInsertable(orderList.ToArray()).ExecuteCommandAsync(); - //var orderIdList = orderHasIdList - //var orderIdList = await orderService.Add(orderList); + foreach (var item in orderList) + { + var id = await orderService.AsInsertable(item).ExecuteReturnSnowflakeIdAsync(); + item.Id = id; + } + + var orderIdList = orderList.Select(x => x.Id).ToList(); // 附件关联信息保存 if (inputDto.AnnexIdList?.Count > 0) @@ -191,9 +195,11 @@ namespace EntrustSettle.Api.Controllers // 查询所有待处理订单列表 var pendingOrderList = await orderService.Query(x => x.IsSend == false && orderIdList.Contains(x.Id)); + + var result = orderList.Select(x => new OrderSubmitResultDto() { OrderId = x.Id, Mblno = x.Mblno }).ToList(); if (pendingOrderList.Count == 0) { - return SuccessMsg(); + return Success(result); } string domainUrl = AppSettings.app(["Startup", "Domain"]); @@ -270,7 +276,7 @@ namespace EntrustSettle.Api.Controllers } } - return SuccessMsg(); + return Success(result); } /// /// 获取订单附件信息列表 @@ -445,30 +451,43 @@ namespace EntrustSettle.Api.Controllers // 将更新后的状态及费用推送到消息队列 if (AppSettings.app("RabbitMQ", "Enabled").ObjToBool()) { - _ = Task.Run(() => + _ = Task.Run(async () => { string msg = $"Id:[{order.Id}],提单号:[{order.Mblno}],手动更新状态后推送队列"; try { StatusPushDto pushDto = new() { + OrderId = order.Id, + Mblno = order.Mblno, MessageType = 1, MessageDesc = "状态更新推送", Remark = changeStatusDto.Remark, Status = (int)changeStatusDto.Status, StatusDesc = changeStatusDto.Status.ToString() }; - if (changeStatusDto.FeeList != null && changeStatusDto.FeeList.Count > 0) + var feeList = await orderFeeService.Query(x => x.OrderId == order.Id); + if (feeList.Count > 0) { - pushDto.FeeList = changeStatusDto.FeeList.Select(x => new StatusPushDto.FeeDto() + pushDto.FeeList = feeList.Select(x => new StatusPushDto.FeeDto() { + FeeId = x.Id, FeeName = x.Name, FeeAmount = x.Amount }).ToList(); } + //if (changeStatusDto.FeeList != null && changeStatusDto.FeeList.Count > 0) + //{ + // pushDto.FeeList = changeStatusDto.FeeList.Select(x => new StatusPushDto.FeeDto() + // { + // //Id = x. + // FeeName = x.Name, + // FeeAmount = x.Amount + // }).ToList(); + //} var json = JsonConvert.SerializeObject(pushDto, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); - queueService.Push(msg, json); + queueService.Push(msg, order.CompanyId, json); } catch (Exception ex) { @@ -603,6 +622,8 @@ namespace EntrustSettle.Api.Controllers { BillPushDto pushDto = new() { + OrderId = order.Id, + Mblno = order.Mblno, AnnexIdList = bindDto.AnnexIdList, }; if (bindDto.OperType == FileTypeEnum.账单) @@ -619,7 +640,7 @@ namespace EntrustSettle.Api.Controllers } var json = JsonConvert.SerializeObject(pushDto, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); - queueService.Push(msg, json); + queueService.Push(msg, order.CompanyId, json); } catch (Exception ex) { diff --git a/EntrustSettle.IServices/IQueueService.cs b/EntrustSettle.IServices/IQueueService.cs index a9d01e0..1c0b8e0 100644 --- a/EntrustSettle.IServices/IQueueService.cs +++ b/EntrustSettle.IServices/IQueueService.cs @@ -8,6 +8,6 @@ namespace EntrustSettle.IServices { public interface IQueueService { - void Push(string opType, string data); + void Push(string opType, string companyId, string data); } } diff --git a/EntrustSettle.Model/Dtos/Order/OrderSubmitResultDto.cs b/EntrustSettle.Model/Dtos/Order/OrderSubmitResultDto.cs new file mode 100644 index 0000000..e0a0f5e --- /dev/null +++ b/EntrustSettle.Model/Dtos/Order/OrderSubmitResultDto.cs @@ -0,0 +1,14 @@ +namespace EntrustSettle.Model.Dtos +{ + public class OrderSubmitResultDto + { + /// + /// 订单Id + /// + public long OrderId { get; set; } + /// + /// 订单提单号 + /// + public string Mblno { get; set; } + } +} diff --git a/EntrustSettle.Model/Dtos/Queue/BasePushDto.cs b/EntrustSettle.Model/Dtos/Queue/BasePushDto.cs index baaca48..314a86f 100644 --- a/EntrustSettle.Model/Dtos/Queue/BasePushDto.cs +++ b/EntrustSettle.Model/Dtos/Queue/BasePushDto.cs @@ -16,5 +16,14 @@ namespace EntrustSettle.Model.Dtos /// 消息类型说明 /// public string MessageDesc { get; set; } + /// + /// 订单Id + /// + public long OrderId { get; set; } + + /// + /// 提单号 + /// + public string Mblno { get; set; } } } diff --git a/EntrustSettle.Model/Dtos/Queue/StatusPushDto.cs b/EntrustSettle.Model/Dtos/Queue/StatusPushDto.cs index 63ac614..1b6b3bb 100644 --- a/EntrustSettle.Model/Dtos/Queue/StatusPushDto.cs +++ b/EntrustSettle.Model/Dtos/Queue/StatusPushDto.cs @@ -7,7 +7,6 @@ namespace EntrustSettle.Model.Dtos /// public class StatusPushDto : BasePushDto { - /// /// 状态编码 已下单=0 已接单=1 待缴费=2 已缴费=3 已完结=4 /// @@ -34,6 +33,10 @@ namespace EntrustSettle.Model.Dtos public class FeeDto { + /// + /// 费用记录主键 + /// + public long FeeId { get; set; } /// /// 费用名称 /// diff --git a/EntrustSettle.Services/QueueService.cs b/EntrustSettle.Services/QueueService.cs index 48a0279..dbe2752 100644 --- a/EntrustSettle.Services/QueueService.cs +++ b/EntrustSettle.Services/QueueService.cs @@ -15,13 +15,13 @@ namespace EntrustSettle.Services { this.logger = logger; } - public void Push(string opType, string data) + public void Push(string opType, string compId, string data) { var mqUrl = AppSettings.app("RabbitMQ", "ConnectionString"); try { - const string MqActionExchangeName = "amq.direct"; - const string MqActionQueueName = "feedback.output"; + string exchangeName = "amq.direct"; + string queueName = "feedback.output." + compId; ConnectionFactory factory = new ConnectionFactory(); factory.Uri = new Uri(mqUrl); @@ -29,20 +29,18 @@ namespace EntrustSettle.Services using (IConnection conn = factory.CreateConnection()) using (IModel mqModel = conn.CreateModel()) { - mqModel.ExchangeDeclare(MqActionExchangeName, ExchangeType.Direct, true); + mqModel.ExchangeDeclare(exchangeName, ExchangeType.Direct, true); - //var queueName = $"{MqActionQueueName}.{model.TenantId}"; - var queueName = $"{MqActionQueueName}"; mqModel.QueueDeclare(queueName, false, false, false, null); - mqModel.QueueBind(queueName, MqActionExchangeName, queueName, null); + mqModel.QueueBind(queueName, exchangeName, queueName, null); IBasicProperties props = mqModel.CreateBasicProperties(); props.DeliveryMode = 2; byte[] messageBodyBytes = Encoding.UTF8.GetBytes(SharpZipLib.Compress(data)); - mqModel.BasicPublish(MqActionExchangeName, queueName, props, messageBodyBytes); + mqModel.BasicPublish(exchangeName, queueName, props, messageBodyBytes); conn.Close(); diff --git a/EntrustSettle.Tasks/QuartzNet/Jobs/JobHydStatusQuartz.cs b/EntrustSettle.Tasks/QuartzNet/Jobs/JobHydStatusQuartz.cs index e655442..5534e2a 100644 --- a/EntrustSettle.Tasks/QuartzNet/Jobs/JobHydStatusQuartz.cs +++ b/EntrustSettle.Tasks/QuartzNet/Jobs/JobHydStatusQuartz.cs @@ -104,13 +104,15 @@ namespace EntrustSettle.Tasks // 将更新后的状态及费用推送到消息队列 if (AppSettings.app("RabbitMQ", "Enabled").ObjToBool()) { - _ = Task.Run(async () => + _ = Task.Run(() => { string msg = $"Id:[{order.Id}],提单号:[{order.Mblno}],自动更新状态后推送队列"; try { StatusPushDto pushDto = new() { + OrderId = order.Id, + Mblno = order.Mblno, MessageType = 1, MessageDesc = "状态更新推送", Remark = "", @@ -125,18 +127,19 @@ namespace EntrustSettle.Tasks _ => "未知状态", } }; - var feeList = await orderFeeService.Query(x => x.OrderId == order.Id); - if (feeList.Count > 0) - { - pushDto.FeeList = feeList.Select(x => new StatusPushDto.FeeDto() - { - FeeName = x.Name, - FeeAmount = x.Amount - }).ToList(); - } + //var feeList = await orderFeeService.Query(x => x.OrderId == order.Id); + //if (feeList.Count > 0) + //{ + // pushDto.FeeList = feeList.Select(x => new StatusPushDto.FeeDto() + // { + // Id = x.Id, + // FeeName = x.Name, + // FeeAmount = x.Amount + // }).ToList(); + //} var json = JsonConvert.SerializeObject(pushDto, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); - queueService.Push(msg, json); + queueService.Push(msg, order.CompanyId, json); } catch (Exception ex) {