From fefc6d1d636dc27d0cb9f4a9a9894adf1cdffb36 Mon Sep 17 00:00:00 2001 From: xiaolipro <2357729423@qq.com> Date: Fri, 1 Aug 2025 10:56:07 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9Asupport=20array=20root?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Interface/ServiceProviderInterfaceService.cs | 12 ++++++++++++ .../Services/Interface/SystemInterfaceService.cs | 12 ++++++++++++ .../Services/Parameter/ParameterService.cs | 4 +++- src/InterfaceForward.Domain.Shared/GlobalConst.cs | 5 +++++ .../Interface/Services/InterfaceRepository.cs | 11 ++++++++++- 5 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/InterfaceForward.Application/Services/Interface/ServiceProviderInterfaceService.cs b/src/InterfaceForward.Application/Services/Interface/ServiceProviderInterfaceService.cs index 2dc308d..1435abf 100644 --- a/src/InterfaceForward.Application/Services/Interface/ServiceProviderInterfaceService.cs +++ b/src/InterfaceForward.Application/Services/Interface/ServiceProviderInterfaceService.cs @@ -4,6 +4,7 @@ using Newtonsoft.Json; using InterfaceForward.Application.Contracts.Dtos.Interface; using InterfaceForward.Application.Helpers; using InterfaceForward.Application.Services.Parameter; +using InterfaceForward.Domain.Shared; using InterfaceForward.Domain.Shared.Enum; using InterfaceForward.Repositories; using InterfaceForward.Repositories.Interface.Entitys; @@ -130,6 +131,17 @@ public class ServiceProviderInterfaceService : ApplicationService [HttpPost("Interface/SaveServiceProviderInterface")] public async Task SaveServiceProviderInterfaceAsync(ServiceProviderInterfaceInput input) { + input.InParameterList.ForEach(x => + { + if (x.PId == 0 && x.Type == ParameterType.Array && x.Name == GlobalConst.RootParameterName) + x.Name = string.Empty; + }); + input.OutParameterList.ForEach(x => + { + if (x.PId == 0 && x.Type == ParameterType.Array && x.Name == GlobalConst.RootParameterName) + x.Name = string.Empty; + }); + switch (input.OptionType) { case OptionType.新增: diff --git a/src/InterfaceForward.Application/Services/Interface/SystemInterfaceService.cs b/src/InterfaceForward.Application/Services/Interface/SystemInterfaceService.cs index 186bbb2..a9963ab 100644 --- a/src/InterfaceForward.Application/Services/Interface/SystemInterfaceService.cs +++ b/src/InterfaceForward.Application/Services/Interface/SystemInterfaceService.cs @@ -4,6 +4,7 @@ using Newtonsoft.Json; using InterfaceForward.Application.Contracts.Dtos.Interface; using InterfaceForward.Application.Helpers; using InterfaceForward.Application.Services.Parameter; +using InterfaceForward.Domain.Shared; using InterfaceForward.Domain.Shared.Enum; using InterfaceForward.Repositories; using InterfaceForward.Repositories.Interface.Entitys; @@ -139,6 +140,17 @@ public class SystemInterfaceService : ApplicationService [HttpPost("Interface/SaveSystemInterface")] public async Task SaveSystemInterfaceAsync(SystemInterfaceInput input) { + input.InParameterList.ForEach(x => + { + if (x.PId == 0 && x.Type == ParameterType.Array && x.Name == GlobalConst.RootParameterName) + x.Name = string.Empty; + }); + input.OutParameterList.ForEach(x => + { + if (x.PId == 0 && x.Type == ParameterType.Array && x.Name == GlobalConst.RootParameterName) + x.Name = string.Empty; + }); + switch (input.OptionType) { case OptionType.新增: diff --git a/src/InterfaceForward.Application/Services/Parameter/ParameterService.cs b/src/InterfaceForward.Application/Services/Parameter/ParameterService.cs index 958dd2c..fe77d5c 100644 --- a/src/InterfaceForward.Application/Services/Parameter/ParameterService.cs +++ b/src/InterfaceForward.Application/Services/Parameter/ParameterService.cs @@ -5,6 +5,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using InterfaceForward.Application.Contracts.Dtos.Interface; using InterfaceForward.Application.Helpers; +using InterfaceForward.Domain.Shared; using InterfaceForward.Domain.Shared.Enum; using InterfaceForward.Repositories.Interface.Entitys; using InterfaceForward.Repositories.Interface.Services; @@ -195,7 +196,8 @@ public class ParameterService : ApplicationService { idx++; var res = JArray2List(arr, ref idx, 1); - res.Insert(0, new(1, 0, "arr", ParameterType.Array, annotation)); + var name = pid == 0 ? GlobalConst.RootParameterName : "arr"; + res.Insert(0, new(1, 0, name, ParameterType.Array, annotation)); return res; } diff --git a/src/InterfaceForward.Domain.Shared/GlobalConst.cs b/src/InterfaceForward.Domain.Shared/GlobalConst.cs index 17c3ac7..b42c910 100644 --- a/src/InterfaceForward.Domain.Shared/GlobalConst.cs +++ b/src/InterfaceForward.Domain.Shared/GlobalConst.cs @@ -24,6 +24,11 @@ public static class GlobalConst /// 应用id /// public const string AppId = nameof(AppId); + + /// + /// 参数根类型为数组时,参数的命名 + /// + public const string RootParameterName = "array"; /// /// 服务商接口qps redis key前缀 diff --git a/src/InterfaceForward.Repositories/Interface/Services/InterfaceRepository.cs b/src/InterfaceForward.Repositories/Interface/Services/InterfaceRepository.cs index 5533c00..d40827a 100644 --- a/src/InterfaceForward.Repositories/Interface/Services/InterfaceRepository.cs +++ b/src/InterfaceForward.Repositories/Interface/Services/InterfaceRepository.cs @@ -1,5 +1,6 @@ using InterfaceForward.Domain.Shared.Enum; using InterfaceForward.Application.Contracts.Dtos.Interface; +using InterfaceForward.Domain.Shared; using InterfaceForward.Repositories.Interface.Entitys; using InterfaceForward.Repositories.Interface.ValueObjects; using InterfaceForward.Repositories.Parameter.VO; @@ -70,7 +71,15 @@ public class InterfaceRepository : BasicRepository, IInterfaceR .WhereIF(onlyLeafs, x => x.Type != ParameterType.Object && x.Type != ParameterType.Array) .OrderBy(x => x.Sort); - return await query.Select().ToListAsync(); + var res = await query.Select().ToListAsync(); + + res.ForEach(x => + { + if (x.PId == 0 && x.Type == (int)ParameterType.Array && x.Name == string.Empty) + x.Name = GlobalConst.RootParameterName; + }); + + return res; } ///