diff --git a/src/InterfaceForward.Application.Contracts/ForwardCore/InterfaceRelayUnifyResultDto.cs b/src/InterfaceForward.Application.Contracts/ForwardCore/InterfaceRelayUnifyResultDto.cs index 583dcab..b2950eb 100644 --- a/src/InterfaceForward.Application.Contracts/ForwardCore/InterfaceRelayUnifyResultDto.cs +++ b/src/InterfaceForward.Application.Contracts/ForwardCore/InterfaceRelayUnifyResultDto.cs @@ -3,9 +3,21 @@ [Serializable] public class InterfaceRelayUnifyResultDto { + public InterfaceRelayUnifyResultDto() + { + + } + public InterfaceRelayUnifyResultDto(bool isSuccess, object data) + { + this.Code = isSuccess? 200.ToString(): 400.ToString(); + this.Data = data; + this.Msg = isSuccess? "成功": "失败"; + } public string Code { get; set; } public string Msg { get; set; } + + public object Data { get; set; } /// /// 请求Id diff --git a/src/InterfaceForward.Application/Rabbit/BatchForwardEvent.cs b/src/InterfaceForward.Application/Rabbit/BatchForwardEvent.cs index e676102..166fcdc 100644 --- a/src/InterfaceForward.Application/Rabbit/BatchForwardEvent.cs +++ b/src/InterfaceForward.Application/Rabbit/BatchForwardEvent.cs @@ -10,9 +10,9 @@ public class BatchForwardEvent public string ServiceProviderCode { get; set; } = null!; - public string Attach { get; set; } + public string? Attach { get; set; } - public string ResSubscribeName { get; set; } + public string? ResSubscribeName { get; set; } public bool IsReturnMessage { get; set; } diff --git a/src/InterfaceForward.Application/Services/InterfaceForwardService.cs b/src/InterfaceForward.Application/Services/InterfaceForwardService.cs index 71b7f7a..4f957ac 100644 --- a/src/InterfaceForward.Application/Services/InterfaceForwardService.cs +++ b/src/InterfaceForward.Application/Services/InterfaceForwardService.cs @@ -1,8 +1,6 @@ using System.ComponentModel.DataAnnotations; using Microsoft.AspNetCore.Authorization; -using Microsoft.Extensions.Options; using Newtonsoft.Json.Linq; -using InterfaceForward.Application.Contracts; using InterfaceForward.Application.Contracts.ForwardCore; using InterfaceForward.Application.Filters; using InterfaceForward.Application.Rabbit; @@ -39,7 +37,6 @@ public class InterfaceForwardService : ApplicationService, IInterfaceForwardServ _httpContextAccessor = httpContextAccessor; } - /// [HttpPost("BatchForwardThenPushToQueue")] public async Task BatchForwardThenPushToQueueAsync( [FromQuery] [Required] string upStreamCode, @@ -105,7 +102,7 @@ public class InterfaceForwardService : ApplicationService, IInterfaceForwardServ _rabbitClient.Publish(GlobalConst.InterfaceRelayExchange, queueName, eventBytes); } - return new InterfaceRelayUnifyResultDto + return new InterfaceRelayUnifyResultDto(true, _logRepository.AppRequestLog.RequestId) { RequestId = _logRepository.AppRequestLog.RequestId, OriginalMessage = null, @@ -118,9 +115,9 @@ public class InterfaceForwardService : ApplicationService, IInterfaceForwardServ [FromQuery] [Required] string upStreamCode, [FromQuery] [Required] string serviceProviderCode, [FromBody] [Required] object data, - [FromHeader] string attach = null, + [FromHeader] string? attach = null, [FromHeader] bool isReturnMessage = false, - [FromHeader] string failedSubscribeName = null) + [FromHeader] string? failedSubscribeName = null) { if (JToken.FromObject(data) is not JObject jobject) { @@ -134,14 +131,14 @@ public class InterfaceForwardService : ApplicationService, IInterfaceForwardServ ? jobject : new JObject { - [upStreamCode!] = jobject + [upStreamCode] = jobject }; var res = contextList.Count == 1 ? await _forwardCommon.InternalForwardAsync(context) : await _forwardCommon.InternalForward2Async(contextList); - return new InterfaceRelayUnifyResultDto + return new InterfaceRelayUnifyResultDto(true, res) { RequestId = context.ServiceProviderRequestLog.RequestId, OriginalMessage = isReturnMessage ? context.ServiceProviderRequestLog.Response : null, @@ -155,15 +152,10 @@ public class InterfaceForwardService : ApplicationService, IInterfaceForwardServ [FromQuery] [Required] string serviceProviderCode, [FromHeader] [Required] Guid requestId, [FromBody] [Required] object data, - [FromHeader] string attach = null, + [FromHeader] string? attach = null, [FromHeader] bool isReturnMessage = false, - [FromHeader] string failedSubscribeName = null) + [FromHeader] string? failedSubscribeName = null) { - if (JToken.FromObject(data) is not JObject jobject) - { - throw new BusinessException(message: "非法结构,请传对象"); - } - var logs = await _logRepository.GetRequestLogsAsync(requestId); var failedLog = logs.FirstOrDefault(x => !x.IsSuccess); @@ -173,11 +165,8 @@ public class InterfaceForwardService : ApplicationService, IInterfaceForwardServ var context = contextList.First(); context.OriginalInterfaceInput = contextList.Count == 1 - ? jobject - : new JObject - { - [upStreamCode!] = jobject - }; + ? JObject.FromObject(data) + : JArray.FromObject(data); // 从第一个失败的开始重试 var requestLogs = logs.Where(x => !x.IsApp).ToList(); @@ -185,7 +174,7 @@ public class InterfaceForwardService : ApplicationService, IInterfaceForwardServ ? await _forwardCommon.InternalForwardAsync(context) : await _forwardCommon.InternalForward3Async(contextList, requestLogs); - return new InterfaceRelayUnifyResultDto + return new InterfaceRelayUnifyResultDto(true, res) { RequestId = context.ServiceProviderRequestLog.RequestId, OriginalMessage = isReturnMessage ? _logRepository.ServiceProviderRequestLog.Response : null,