diff --git a/Directory.Build.props b/Directory.Build.props index 6e6a1a0..06710a8 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 8.0.5.6 + 8.0.5.13 diff --git a/src/InterfaceForward.Api/InterfaceForward.Api.csproj b/src/InterfaceForward.Api/InterfaceForward.Api.csproj index 2275f77..3e6205e 100644 --- a/src/InterfaceForward.Api/InterfaceForward.Api.csproj +++ b/src/InterfaceForward.Api/InterfaceForward.Api.csproj @@ -9,9 +9,7 @@ - - diff --git a/src/InterfaceForward.Api/InterfaceForwardApiModule.cs b/src/InterfaceForward.Api/InterfaceForwardApiModule.cs index e13002b..6b08b83 100644 --- a/src/InterfaceForward.Api/InterfaceForwardApiModule.cs +++ b/src/InterfaceForward.Api/InterfaceForwardApiModule.cs @@ -1,17 +1,18 @@ using Fake.AspNetCore; using Fake.AspNetCore.Auditing; -using Fake.AspNetCore.Mvc; +using Fake.AspNetCore.Authentication; +using Fake.AspNetCore.ExceptionHandling; +using Fake.AspNetCore.Newtonsoft; +using Fake.AspNetCore.Swagger; using Fake.Authorization; using Fake.Autofac; using Fake.FeiShu; using Fake.Modularity; using Fake.Security.Claims; -using Fake.Serilog.Sink.FeiShu; +using Fake.Serilog; using InterfaceForward.Application; -using InterfaceForward.Domain.Shared; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.HttpOverrides; -using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Authorization; namespace InterfaceForward.Api; @@ -19,7 +20,7 @@ namespace InterfaceForward.Api; [DependsOn(typeof(FakeAuthorizationModule))] [DependsOn(typeof(FakeAutofacModule))] [DependsOn(typeof(InterfaceForwardApplicationModule))] -[DependsOn(typeof(FakeSerilogSinkFeiShuModule))] +[DependsOn(typeof(FakeSerilogModule))] public class InterfaceForwardApiModule : FakeModule { private const string DefaultCorsPolicyName = "default"; @@ -33,9 +34,6 @@ public class InterfaceForwardApiModule : FakeModule { var services = context.Services; var configuration = context.Services.GetConfiguration(); - - // Add services to the container. - services.AddProblemDetails(); services.Configure(options => { @@ -49,20 +47,12 @@ public class InterfaceForwardApiModule : FakeModule .RequireAuthenticatedUser() .Build(); options.Filters.Add(new AuthorizeFilter(policy)); - }).AddNewtonsoftJson(); - - //Json格式化全局处理 - context.Services.Configure(options => - { - options.SerializerSettings.ContractResolver = - new Newtonsoft.Json.Serialization. - CamelCasePropertyNamesContractResolver(); // 首字母小写(驼峰样式) - options.SerializerSettings.Converters.Add(new DateTimeJsonConverter("yyyy-MM-dd HH:mm:ss")); - options.SerializerSettings.Converters.Add(new LongJsonConverter()); }); services.AddFakeSwaggerGen(addSecurity: true) - .AddFakeAspNetCoreAuditing(); + .AddFakeAspNetCoreAuditing() + .AddFakeNewtonsoft() + .AddFeiShuNotification(); services.AddCors(options => { diff --git a/src/InterfaceForward.Application/AutoMapper/InterfaceProfile.cs b/src/InterfaceForward.Application/AutoMapper/InterfaceProfile.cs index ef76fb0..d5cc9f8 100644 --- a/src/InterfaceForward.Application/AutoMapper/InterfaceProfile.cs +++ b/src/InterfaceForward.Application/AutoMapper/InterfaceProfile.cs @@ -1,7 +1,6 @@ using AutoMapper; using InterfaceForward.Application.Contracts.Dtos.Interface; using InterfaceForward.Application.Contracts.Dtos.ServiceProvider; -using InterfaceForward.Domain.Shared.Dtos; using InterfaceForward.Repositories.Interface.Entitys; using InterfaceForward.Repositories.Interface.ValueObjects; using InterfaceForward.Repositories.Parameter.Entities; diff --git a/src/InterfaceForward.Application/AutoMapper/ParameterProfile.cs b/src/InterfaceForward.Application/AutoMapper/ParameterProfile.cs index d0f2c29..5e3d6c6 100644 --- a/src/InterfaceForward.Application/AutoMapper/ParameterProfile.cs +++ b/src/InterfaceForward.Application/AutoMapper/ParameterProfile.cs @@ -1,7 +1,6 @@ using AutoMapper; using InterfaceForward.Application.Contracts.Dtos.Interface; using InterfaceForward.Application.Contracts.Dtos.ServiceProvider; -using InterfaceForward.Domain.Shared.Dtos; using InterfaceForward.Repositories.Interface.Entitys; using InterfaceForward.Repositories.Interface.ValueObjects; using InterfaceForward.Repositories.Parameter.Entities; diff --git a/src/InterfaceForward.Application/Filters/ForwardAuthorizeFilter.cs b/src/InterfaceForward.Application/Filters/ForwardAuthorizeFilter.cs index 47cd239..a98d0b8 100644 --- a/src/InterfaceForward.Application/Filters/ForwardAuthorizeFilter.cs +++ b/src/InterfaceForward.Application/Filters/ForwardAuthorizeFilter.cs @@ -45,22 +45,22 @@ public class ForwardAuthorizeFilter( string? appKey = headers["appKey"], appSecret = headers["appSecret"]; if (appKey.IsNullOrWhiteSpace() || appSecret.IsNullOrWhiteSpace()) { - throw new BusinessException(message: "应用授权失败,AppKey和AppSecret是必填的"); + throw new BusinessException("应用授权失败,AppKey和AppSecret是必填的"); } var app = await interfaceForwardQuery.FindAppAsync(appKey!, appSecret!); if (app == null) - throw new BusinessException(message: "应用授权失败,请检查AppKey或AppSecret是否正确"); + throw new BusinessException("应用授权失败,请检查AppKey或AppSecret是否正确"); log.Name = app.Name; if (!app.IsOnline) - throw new BusinessException(message: "应用已被禁用,请检查应用状态"); + throw new BusinessException("应用已被禁用,请检查应用状态"); logRepository.AppId = app.Id; var upStreamCode = httpContext.Request.Query["standardCode"].ToString(); var systemInterface = await interfaceRepository.GetFirstAsync(x => x.Code == upStreamCode, x => new { x.Code, x.Name }); - if (systemInterface == null) throw new BusinessException(message: "系统接口不存在"); + if (systemInterface == null) throw new BusinessException("系统接口不存在"); logRepository.AppRequestLog.InterfaceCode = systemInterface.Code; logRepository.AppRequestLog.InterfaceName = systemInterface.Name; diff --git a/src/InterfaceForward.Application/ForwardCore/DefaultForwardFlow.cs b/src/InterfaceForward.Application/ForwardCore/DefaultForwardFlow.cs index 1b6c470..523732c 100644 --- a/src/InterfaceForward.Application/ForwardCore/DefaultForwardFlow.cs +++ b/src/InterfaceForward.Application/ForwardCore/DefaultForwardFlow.cs @@ -239,7 +239,7 @@ public class DefaultForwardFlow : IForwardFlow, ITransientDependency context.ServiceProviderRequestLog.Address = context.TargetInterface.RequestAddress; context.ServiceProviderRequestLog.IsSuccess = false; - throw new BusinessException(message: msg); + throw new BusinessException(msg); } /// @@ -440,7 +440,7 @@ public class DefaultForwardFlow : IForwardFlow, ITransientDependency break; case ContentType.FormData: default: - throw new BusinessException(message: "暂时不支持该ContentType"); + throw new BusinessException("暂时不支持该ContentType"); } msg.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType); @@ -474,7 +474,7 @@ public class DefaultForwardFlow : IForwardFlow, ITransientDependency break; case ContentType.FormData: default: - throw new BusinessException(message: "暂时不支持该ContentType"); + throw new BusinessException("暂时不支持该ContentType"); } return data; @@ -498,7 +498,7 @@ public class DefaultForwardFlow : IForwardFlow, ITransientDependency { case GlobalConst.FromBody: var val = context.OriginalInterfaceMappedInput.SelectToken(fieldName); - if (val == null) throw new BusinessException(message: $"映射后的body中找不到该路径{fieldName}"); + if (val == null) throw new BusinessException($"映射后的body中找不到该路径{fieldName}"); item.FieldValue = val.ToString(); break; case GlobalConst.TimeStamp: diff --git a/src/InterfaceForward.Application/GlobalUsings.cs b/src/InterfaceForward.Application/GlobalUsings.cs index f038792..796f3ab 100644 --- a/src/InterfaceForward.Application/GlobalUsings.cs +++ b/src/InterfaceForward.Application/GlobalUsings.cs @@ -3,4 +3,5 @@ global using Fake; global using Fake.Application; global using Fake.Application.Dtos; +global using InterfaceForward.Domain.Shared.Dtos; global using InterfaceForward.Domain.Shared.Helpers; \ No newline at end of file diff --git a/src/InterfaceForward.Application/Services/App/AppsService.cs b/src/InterfaceForward.Application/Services/App/AppsService.cs index dd0bb77..93136ae 100644 --- a/src/InterfaceForward.Application/Services/App/AppsService.cs +++ b/src/InterfaceForward.Application/Services/App/AppsService.cs @@ -4,7 +4,6 @@ using Fake.UnitOfWork; using InterfaceForward.Application.Contracts.Dtos.App; using InterfaceForward.Application.Helpers; using InterfaceForward.Application.OSS; -using InterfaceForward.Domain.Shared.Dtos; using InterfaceForward.Repositories; using InterfaceForward.Repositories.App.Entitys; using InterfaceForward.Repositories.App.Services; @@ -134,7 +133,7 @@ public class AppsService : ApplicationService var res = await _appRepository.AsQueryable() .Select(x => new AppOutput { Id = x.Id.SelectAll() }) .SingleAsync(x => x.Id == id); - _ = res ?? throw new BusinessException(message: "在指定的编号下找不到数据"); + _ = res ?? throw new BusinessException("在指定的编号下找不到数据"); // if (res.LogoKey != null) res.LogoUrl = OSSHelper.GetUrlByKey(res.LogoKey); res.AppScope = await _appScopeRepository.AsQueryable() @@ -158,12 +157,12 @@ public class AppsService : ApplicationService public async Task Create(CreateAppInput input) { if (await _appRepository.IsAnyAsync(x => x.Name == input.Name)) - throw new BusinessException(message: "应用名称已存在"); + throw new BusinessException("应用名称已存在"); if (await _appRepository.IsAnyAsync(x => x.AppKey == input.AppKey)) - throw new BusinessException(message: "appkey已存在"); + throw new BusinessException("appkey已存在"); input.LogoKey = String.Empty; if (await _appRepository.IsAnyAsync(x => x.AppSecret == input.AppSecret)) - throw new BusinessException(message: "appsecret已存在"); + throw new BusinessException("appsecret已存在"); var entity = ObjectMapper.Map(input); var appScopeEntitys = ObjectMapper.Map, List>(input.AppScopeList); @@ -174,7 +173,7 @@ public class AppsService : ApplicationService if (interfaceDic.Count != interfaceIds.Count) { - throw new BusinessException(message: "有接口不存在,请检查"); + throw new BusinessException("有接口不存在,请检查"); } using (var ts = TransacationHelper.GetReadCommitted()) @@ -202,11 +201,11 @@ public class AppsService : ApplicationService public async Task Update(UpdateAppInput input) { if (await _appRepository.IsAnyAsync(x => x.Name == input.Name && x.Id != input.Id)) - throw new BusinessException(message: "应用名称已存在"); + throw new BusinessException("应用名称已存在"); if (await _appRepository.IsAnyAsync(x => x.AppKey == input.AppKey && x.Id != input.Id)) - throw new BusinessException(message: "appkey已存在"); + throw new BusinessException("appkey已存在"); if (await _appRepository.IsAnyAsync(x => x.AppSecret == input.AppSecret && x.Id != input.Id)) - throw new BusinessException(message: "appsecret已存在"); + throw new BusinessException("appsecret已存在"); var entity = ObjectMapper.Map(input); var appScopeEntitys = ObjectMapper.Map, List>(input.AppScopeList); @@ -283,11 +282,11 @@ public class AppsService : ApplicationService var appEntity = await _appRepository.GetFirstAsync(x => x.AppKey == input.AppKey && x.AppSecret == input.AppSecret && x.IsOnline == true); if (appEntity is null) - throw new BusinessException(message: "在指定的编号下找不到数据"); + throw new BusinessException("在指定的编号下找不到数据"); var appScopeEntity = await _appScopeRepository.GetAppScopeAsync(appEntity.Id, input.InterfaceCode); if (appScopeEntity is null) - throw new BusinessException(message: "应用不可访问该接口"); + throw new BusinessException("应用不可访问该接口"); string redisKey = input.AppKey + input.InterfaceCode; @@ -297,7 +296,7 @@ public class AppsService : ApplicationService if (num < appScopeEntity.QPS) await RedisHelper.Client.IncrByAsync(redisKey, 1); else - throw new BusinessException(message: "超过流量限制"); + throw new BusinessException("超过流量限制"); } else await RedisHelper.Client.SetAsync(redisKey, 1, 1); diff --git a/src/InterfaceForward.Application/Services/Customized/ShopeeForwardAuthorizeFilter.cs b/src/InterfaceForward.Application/Services/Customized/ShopeeForwardAuthorizeFilter.cs index 634172e..ff41dbe 100644 --- a/src/InterfaceForward.Application/Services/Customized/ShopeeForwardAuthorizeFilter.cs +++ b/src/InterfaceForward.Application/Services/Customized/ShopeeForwardAuthorizeFilter.cs @@ -44,25 +44,25 @@ public class ShopeeForwardAuthorizeFilter( // string? appKey = headers["appKey"], appSecret = headers["appSecret"]; // if (appKey.IsNullOrWhiteSpace() || appSecret.IsNullOrWhiteSpace()) // { - // throw new BusinessException(message: "应用授权失败,AppKey和AppSecret是必填的"); + // throw new BusinessException("应用授权失败,AppKey和AppSecret是必填的"); // } // // var app = await interfaceForwardQuery.FindAppAsync(appKey!, appSecret!); // if (app == null) - // throw new BusinessException(message: "应用授权失败,请检查AppKey或AppSecret是否正确"); + // throw new BusinessException("应用授权失败,请检查AppKey或AppSecret是否正确"); // 先写死的 var app = await interfaceForwardQuery.FindAppAsync("W2507080", "G1rA80mAfGovH7j53t5bIH425M4vKreT"); log.Name = app.Name; if (!app.IsOnline) - throw new BusinessException(message: "应用已被禁用,请检查应用状态"); + throw new BusinessException("应用已被禁用,请检查应用状态"); logRepository.AppId = app.Id; var upStreamCode = httpContext.Request.Path.ToUriComponent().Split('/')[1]; var systemInterface = await interfaceRepository.GetFirstAsync(x => x.Code == upStreamCode, x => new { x.Code, x.Name }); - if (systemInterface == null) throw new BusinessException(message: "系统接口不存在"); + if (systemInterface == null) throw new BusinessException("系统接口不存在"); logRepository.AppRequestLog.InterfaceCode = systemInterface.Code; logRepository.AppRequestLog.InterfaceName = systemInterface.Name; diff --git a/src/InterfaceForward.Application/Services/Interface/InterfaceReturnConfigService.cs b/src/InterfaceForward.Application/Services/Interface/InterfaceReturnConfigService.cs index 3ea9901..0d6075b 100644 --- a/src/InterfaceForward.Application/Services/Interface/InterfaceReturnConfigService.cs +++ b/src/InterfaceForward.Application/Services/Interface/InterfaceReturnConfigService.cs @@ -50,7 +50,7 @@ public class InterfaceReturnConfigService : ApplicationService { if (!await _interfaceRepository.IsAnyAsync(x => x.Id == input.InterfaceId)) { - throw new BusinessException(message: "接口不存在"); + throw new BusinessException("接口不存在"); } // 开启事务 diff --git a/src/InterfaceForward.Application/Services/Interface/InterfaceService.cs b/src/InterfaceForward.Application/Services/Interface/InterfaceService.cs index 8293697..2cb11c5 100644 --- a/src/InterfaceForward.Application/Services/Interface/InterfaceService.cs +++ b/src/InterfaceForward.Application/Services/Interface/InterfaceService.cs @@ -101,7 +101,7 @@ public class InterfaceService : ApplicationService var interfaceEntity = await InterfaceRepository.GetFirstAsync(x => x.Id == id); if (interfaceEntity == null) { - throw new BusinessException(message: "接口不存在"); + throw new BusinessException("接口不存在"); } var res = ObjectMapper.Map(interfaceEntity); @@ -237,7 +237,7 @@ public class InterfaceService : ApplicationService x.IsUpStream == input.IsUpStream && (x.Name.Equals(input.Name) || x.Code.Equals(input.Code)) && x.ServiceProviderId == input.ServiceProviderId)) { - throw new BusinessException(message: $"接口名或code:{input.Name} 已存在"); + throw new BusinessException($"接口名或code:{input.Name} 已存在"); } #endregion @@ -260,7 +260,7 @@ public class InterfaceService : ApplicationService // 接口代码生成时并发兜底方案 if (await InterfaceRepository.CountAsync(x => x.Code.Equals(interfaceEntity.Code)) > 1) { - throw new BusinessException(message: "接口代码生成异常,请稍后重试"); + throw new BusinessException("接口代码生成异常,请稍后重试"); } // 提交事务 @@ -274,7 +274,7 @@ public class InterfaceService : ApplicationService // 系统生成,由服务商代码+3位数字组成(0-999按顺序生成) // tips:唯一性 var entity = await ServiceProviderRepository.GetFirstAsync(x => x.Id == serviceProviderId); - if (entity == null) throw new BusinessException(message: "服务商不存在,系统接口自己定义code谢谢配合"); + if (entity == null) throw new BusinessException("服务商不存在,系统接口自己定义code谢谢配合"); string res = entity.Code; @@ -293,14 +293,14 @@ public class InterfaceService : ApplicationService if (!await InterfaceRepository.IsAnyAsync(x => x.Id == input.Id)) { - throw new BusinessException(message: "接口不存在"); + throw new BusinessException("接口不存在"); } if (await InterfaceRepository.IsAnyAsync(x => x.Name.Equals(input.Name) && x.Id != input.Id && x.IsUpStream == input.IsUpStream && x.ServiceProviderId == input.ServiceProviderId)) { - throw new BusinessException(message: $"接口名:{input.Name} 已存在"); + throw new BusinessException($"接口名:{input.Name} 已存在"); } #endregion @@ -360,7 +360,7 @@ public class InterfaceService : ApplicationService if (input.IsUpStream) { if (input.RequestBodyParameterList.Count > 0 || input.MappingBodyParameterList.Count > 0 || input.BodyFormParameterList.Count > 0) - throw new BusinessException(message: "上游接口只能维护 inParameterList"); + throw new BusinessException("上游接口只能维护 inParameterList"); return; } @@ -368,19 +368,19 @@ public class InterfaceService : ApplicationService { case ContentType.None: if (input.InParameterList.Count > 0 || input.RequestBodyParameterList.Count > 0 || input.BodyFormParameterList.Count > 0) - throw new BusinessException(message: "None 下游接口只能维护 Query/Header/MappingBody/Response"); + throw new BusinessException("None 下游接口只能维护 Query/Header/MappingBody/Response"); break; case ContentType.Json: case ContentType.Xml: if (input.InParameterList.Count > 0 || input.MappingBodyParameterList.Count > 0 || input.BodyFormParameterList.Count > 0) - throw new BusinessException(message: "Json/Xml 下游接口只能维护 requestBodyParameterList"); + throw new BusinessException("Json/Xml 下游接口只能维护 requestBodyParameterList"); break; case ContentType.FormUrlEncoded: if (input.InParameterList.Count > 0 || input.RequestBodyParameterList.Count > 0) - throw new BusinessException(message: "FormUrlEncoded 下游接口只能维护 bodyFormParameterList 和 mappingBodyParameterList"); + throw new BusinessException("FormUrlEncoded 下游接口只能维护 bodyFormParameterList 和 mappingBodyParameterList"); break; case ContentType.FormData: - throw new BusinessException(message: "暂时不支持该ContentType"); + throw new BusinessException("暂时不支持该ContentType"); default: throw new ArgumentOutOfRangeException(); } diff --git a/src/InterfaceForward.Application/Services/InterfaceForwardCommon.cs b/src/InterfaceForward.Application/Services/InterfaceForwardCommon.cs index 3728f70..48c6b3d 100644 --- a/src/InterfaceForward.Application/Services/InterfaceForwardCommon.cs +++ b/src/InterfaceForward.Application/Services/InterfaceForwardCommon.cs @@ -8,7 +8,6 @@ using InterfaceForward.Application.Contracts.ForwardCore; using InterfaceForward.Application.ForwardCore; using InterfaceForward.Application.Helpers; using InterfaceForward.Domain.Shared; -using InterfaceForward.Domain.Shared.Dtos; using InterfaceForward.Domain.Shared.Enum; using InterfaceForward.Repositories; using InterfaceForward.Repositories.Log.Services; @@ -46,13 +45,13 @@ public class InterfaceForwardCommon( if (cacheContext == null) { var systemInterface = await interfaceForwardQuery.GetInterfaceByCodeAsync(upStreamCode); - if (systemInterface == null) throw new BusinessException(message: "系统接口不存在"); + if (systemInterface == null) throw new BusinessException("系统接口不存在"); logRepository.AppRequestLog.InterfaceCode = systemInterface.Code; logRepository.AppRequestLog.InterfaceName = systemInterface.Name; var serviceProviderDto = await interfaceForwardQuery.GetServiceProviderByCodeAsync(serviceProviderCode); - if (serviceProviderDto == null) throw new BusinessException(message: "服务商不存在"); + if (serviceProviderDto == null) throw new BusinessException("服务商不存在"); cacheContext = await interfaceForwardQuery.BuildForwardCoreContext(systemInterface, serviceProviderDto); await RedisHelper.Client.SetAsync(contextCacheKey, cacheContext.ToJson(), DefaultCacheTtl); } @@ -72,7 +71,7 @@ public class InterfaceForwardCommon( // 服务商授权 if (!serviceProviderDto.IsDisableAuth && accountId == default) { - throw new BusinessException(message: $"服务商:{serviceProviderDto.Name} 下不存在此账户,请联系管理员或前往接口通创建"); + throw new BusinessException($"服务商:{serviceProviderDto.Name} 下不存在此账户,请联系管理员或前往接口通创建"); } accountFieldCache = await interfaceForwardQuery.GetAccountFieldListAsync(accountId); @@ -145,7 +144,7 @@ public class InterfaceForwardCommon( var flow = serviceProvider.GetServices() .FirstOrDefault(x => x.GetType().Name == flowCode); if (flow == null) - throw new BusinessException(message: "找不到接口转发流程" + flowCode); + throw new BusinessException("找不到接口转发流程" + flowCode); return flow; } @@ -399,7 +398,7 @@ public class InterfaceForwardCommon( { if (JToken.FromObject(data) is not JArray jarray) { - throw new BusinessException(message: "非法结构,请传对象数组"); + throw new BusinessException("非法结构,请传对象数组"); } var objectArray = new List(jarray.Count); @@ -407,7 +406,7 @@ public class InterfaceForwardCommon( { if (item is not JObject jobect) { - throw new BusinessException(message: "批量处理必须传递对象数组"); + throw new BusinessException("批量处理必须传递对象数组"); } objectArray.Add(jobect); @@ -415,7 +414,7 @@ public class InterfaceForwardCommon( if (objectArray.Count < 1) { - throw new BusinessException(message: "请勿传递空数组"); + throw new BusinessException("请勿传递空数组"); } return objectArray; diff --git a/src/InterfaceForward.Application/Services/InterfaceForwardService.cs b/src/InterfaceForward.Application/Services/InterfaceForwardService.cs index ac7d73c..9de453e 100644 --- a/src/InterfaceForward.Application/Services/InterfaceForwardService.cs +++ b/src/InterfaceForward.Application/Services/InterfaceForwardService.cs @@ -121,7 +121,7 @@ public class InterfaceForwardService : ApplicationService { if (JToken.FromObject(data) is not JObject jobject) { - throw new BusinessException(message: "非法结构,请传对象"); + throw new BusinessException("非法结构,请传对象"); } var contextList = await _forwardCommon.VerifyBusinessAndBuildForwardContexts(standardCode, supplierCode); @@ -159,7 +159,7 @@ public class InterfaceForwardService : ApplicationService var logs = await _logRepository.GetRequestLogsAsync(requestId); var failedLog = logs.FirstOrDefault(x => !x.IsSuccess); - if (failedLog == default) throw new BusinessException(message: "找不到失败日志,无法重试"); + if (failedLog == default) throw new BusinessException("找不到失败日志,无法重试"); var contextList = await _forwardCommon.VerifyBusinessAndBuildForwardContexts(standardCode, supplierCode); diff --git a/src/InterfaceForward.Application/Services/InterfaceMap/CustomContractResolver.cs b/src/InterfaceForward.Application/Services/InterfaceMap/CustomContractResolver.cs index 306a071..8fb05f1 100644 --- a/src/InterfaceForward.Application/Services/InterfaceMap/CustomContractResolver.cs +++ b/src/InterfaceForward.Application/Services/InterfaceMap/CustomContractResolver.cs @@ -1,5 +1,4 @@ using System.Reflection; -using InterfaceForward.Domain.Shared.Dtos; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; diff --git a/src/InterfaceForward.Application/Services/InterfaceMap/InterfaceMapPublishService.cs b/src/InterfaceForward.Application/Services/InterfaceMap/InterfaceMapPublishService.cs index 94402ac..23db9ce 100644 --- a/src/InterfaceForward.Application/Services/InterfaceMap/InterfaceMapPublishService.cs +++ b/src/InterfaceForward.Application/Services/InterfaceMap/InterfaceMapPublishService.cs @@ -4,7 +4,6 @@ using DiffPlex.DiffBuilder; using DiffPlex.DiffBuilder.Model; using InterfaceForward.Application.Contracts.Dtos.Interface; using InterfaceForward.Application.Helpers; -using InterfaceForward.Domain.Shared.Dtos; using InterfaceForward.Repositories; using InterfaceForward.Repositories.Interface.Entitys; using InterfaceForward.Repositories.Interface.Services; @@ -60,10 +59,10 @@ public class InterfaceMapPublishService( [Required] int serviceProviderId, string? version) { var systemInterface = await interfaceForwardQuery.GetInterfaceByCodeAsync(interfaceCode); - if (systemInterface == null) throw new BusinessException(message: "系统接口不存在"); + if (systemInterface == null) throw new BusinessException("系统接口不存在"); var serviceProvider = await interfaceForwardQuery.GetServiceProviderByIdAsync(serviceProviderId); - if (serviceProvider == null) throw new BusinessException(message: "服务商不存在"); + if (serviceProvider == null) throw new BusinessException("服务商不存在"); // 没有指定比对的版本,就是比对数据库最新数据 var dbContent = version.IsNullOrWhiteSpace() @@ -99,10 +98,10 @@ public class InterfaceMapPublishService( public async Task PublishAsync(InterfaceMapPublishInput input) { var systemInterface = await interfaceForwardQuery.GetInterfaceByCodeAsync(input.InterfaceCode); - if (systemInterface == null) throw new BusinessException(message: "系统接口不存在"); + if (systemInterface == null) throw new BusinessException("系统接口不存在"); var serviceProvider = await interfaceForwardQuery.GetServiceProviderByIdAsync(input.ServiceProviderId); - if (serviceProvider == null) throw new BusinessException(message: "服务商不存在"); + if (serviceProvider == null) throw new BusinessException("服务商不存在"); // 确认比对期间数据是否被篡改 var differ = new Differ(); @@ -110,7 +109,7 @@ public class InterfaceMapPublishService( var context = await interfaceForwardQuery.BuildForwardCoreContext(systemInterface, serviceProvider); var content = JsonConvert.SerializeObject(context, Settings); var diffResult = inlineBuilder.BuildDiffModel(content, input.DBContent); - if (diffResult.HasDifferences) throw new BusinessException(message: "数据库已经发生变更,请重新获取最新数据进行比对"); + if (diffResult.HasDifferences) throw new BusinessException("数据库已经发生变更,请重新获取最新数据进行比对"); var mapsEntities = await interfaceMapRepository.GetListAsync(x => x.UpStreamId == systemInterface.Id && x.ServiceProviderId == serviceProvider.Id); @@ -152,22 +151,22 @@ public class InterfaceMapPublishService( public async Task PublishRollbackAsync(InterfaceMapRollbackInput input) { var systemInterface = await interfaceForwardQuery.GetInterfaceByCodeAsync(input.InterfaceCode); - if (systemInterface == null) throw new BusinessException(message: "系统接口不存在"); + if (systemInterface == null) throw new BusinessException("系统接口不存在"); var serviceProvider = await interfaceForwardQuery.GetServiceProviderByIdAsync(input.ServiceProviderId); - if (serviceProvider == null) throw new BusinessException(message: "服务商不存在"); + if (serviceProvider == null) throw new BusinessException("服务商不存在"); var mapsEntities = await interfaceMapRepository.GetListAsync(x => x.UpStreamId == systemInterface.Id && x.ServiceProviderId == input.ServiceProviderId); if (mapsEntities == null || mapsEntities.Count == 0) { - throw new BusinessException(message: "映射不存在"); + throw new BusinessException("映射不存在"); } var targetVersionContent = await interfaceMapPublishRepository.GetFirstAsync(a => a.InterfaceId == systemInterface.Id && a.ServiceProviderId == input.ServiceProviderId && a.PublishedVersion == input.Version, a => a.PublishedContent); // tips:空是合法的,虽然在业务上不存在 - if (targetVersionContent == null) throw new BusinessException(message: "要回滚的版本不存在"); + if (targetVersionContent == null) throw new BusinessException("要回滚的版本不存在"); // tips:回滚是缓存覆盖行为,不考虑脏数据问题 var redisKey = InterfaceForwardCommon.GetContextCacheKey(input.InterfaceCode, serviceProvider.Code); diff --git a/src/InterfaceForward.Application/Services/InterfaceMap/InterfaceMapService.Details.cs b/src/InterfaceForward.Application/Services/InterfaceMap/InterfaceMapService.Details.cs index 3bd560e..2a15d65 100644 --- a/src/InterfaceForward.Application/Services/InterfaceMap/InterfaceMapService.Details.cs +++ b/src/InterfaceForward.Application/Services/InterfaceMap/InterfaceMapService.Details.cs @@ -26,7 +26,7 @@ public partial class InterfaceMapService x => new { x.Id, x.DownStreamId, x.PrefixScript, x.PostfixScript, x.FreeMap }); if (maps == null || maps.Count == 0) { - throw new BusinessException(message: "映射不存在"); + throw new BusinessException("映射不存在"); } var serviceProviderInterfaceIds = maps.Select(x => x.DownStreamId).ToList(); @@ -75,7 +75,7 @@ public partial class InterfaceMapService x => x.DownStreamId); if (serviceProviderInterfaceIds == null || serviceProviderInterfaceIds.Count == 0) { - throw new BusinessException(message: "映射不存在"); + throw new BusinessException("映射不存在"); } var interfaceIds = new List(serviceProviderInterfaceIds) { interfaceId }; @@ -88,7 +88,7 @@ public partial class InterfaceMapService }); if (interfaces == null || interfaces.Count != interfaceIds.Count) { - throw new BusinessException(message: "映射接口已丢失,请联系管理员"); + throw new BusinessException("映射接口已丢失,请联系管理员"); } var res = new List(); @@ -141,7 +141,7 @@ public partial class InterfaceMapService var mapIds = input.InParaMapList.Select(x => x.InterfaceMapId).ToList(); if (mapIds.Count == 0 || mapIds.Count != await _interfaceMapRepository.CountAsync(x => mapIds.Contains(x.Id))) { - throw new BusinessException(message: "非法保存"); + throw new BusinessException("非法保存"); } var entitiesForUpdate = new List(); @@ -206,7 +206,7 @@ public partial class InterfaceMapService if (x.IsRequired) { if (x.MappedParaId == null && x.FixedValue.IsNullOrEmpty()) - throw new BusinessException(message: $"{x.Alias}必填不能空"); + throw new BusinessException($"{x.Alias}必填不能空"); } if (x.InterfaceMapDetailId == null) diff --git a/src/InterfaceForward.Application/Services/InterfaceMap/InterfaceMapService.cs b/src/InterfaceForward.Application/Services/InterfaceMap/InterfaceMapService.cs index 1950088..eb382b1 100644 --- a/src/InterfaceForward.Application/Services/InterfaceMap/InterfaceMapService.cs +++ b/src/InterfaceForward.Application/Services/InterfaceMap/InterfaceMapService.cs @@ -52,7 +52,7 @@ public partial class InterfaceMapService : Fake.Application.ApplicationService var systemInterfaceCode = await _interfaceRepository.GetFirstAsync(x => x.Id == input.UpStreamId, x => x.Code); if (systemInterfaceCode.IsNullOrEmpty()) { - throw new BusinessException(message: "系统接口不存在"); + throw new BusinessException("系统接口不存在"); } var serviceProviderInterfaces = @@ -62,7 +62,7 @@ public partial class InterfaceMapService : Fake.Application.ApplicationService || serviceProviderInterfaces.Count != input.DownStreamIds.Length || serviceProviderInterfaces.DistinctBy(x => x.ServiceProviderId).Count() != 1) { - throw new BusinessException(message: "请传入合法服务商接口(同一服务商下的一个或多个接口)"); + throw new BusinessException("请传入合法服务商接口(同一服务商下的一个或多个接口)"); } Debug.Assert(serviceProviderInterfaces.Count > 0, "interfaces.Count > 0"); @@ -70,7 +70,7 @@ public partial class InterfaceMapService : Fake.Application.ApplicationService x.UpStreamId == input.UpStreamId && x.ServiceProviderId == serviceProviderInterfaces.First().ServiceProviderId)) { - throw new BusinessException(message: "映射已存在"); + throw new BusinessException("映射已存在"); } var maps = serviceProviderInterfaces.Select(serviceProviderInterface => new InterfaceMapEntity @@ -114,19 +114,19 @@ public partial class InterfaceMapService : Fake.Application.ApplicationService var systemInterfaceCode = await _interfaceRepository.GetFirstAsync(x => x.Id == interfaceId, x => x.Code); if (systemInterfaceCode.IsNullOrEmpty()) { - throw new BusinessException(message: "系统接口不存在"); + throw new BusinessException("系统接口不存在"); } var serviceProviderCode = await _serviceProviderQueries.GetFirstAsync(x => x.Id == serviceProviderId, x => x.Code); if (serviceProviderCode.IsNullOrEmpty()) { - throw new BusinessException(message: "服务商不存在!"); + throw new BusinessException("服务商不存在!"); } var mapIds = await _interfaceMapRepository.GetListAsync(x => x.UpStreamId == interfaceId && x.ServiceProviderId == serviceProviderId, x => x.Id); - if (mapIds == null || mapIds.Count == 0) throw new BusinessException(message: "映射不存在"); + if (mapIds == null || mapIds.Count == 0) throw new BusinessException("映射不存在"); using var ts = TransacationHelper.GetReadCommitted(); foreach (var mapId in mapIds) diff --git a/src/InterfaceForward.Application/Services/Parameter/FixedParameterService.cs b/src/InterfaceForward.Application/Services/Parameter/FixedParameterService.cs index 6699ff4..cc0db18 100644 --- a/src/InterfaceForward.Application/Services/Parameter/FixedParameterService.cs +++ b/src/InterfaceForward.Application/Services/Parameter/FixedParameterService.cs @@ -71,7 +71,7 @@ public class FixedParameterService : ApplicationService, IAuditingEnabled // 校验服务商是否存在 if (!await _serviceProviderRepository.IsAnyAsync(x => x.Id == input.ServiceProviderId)) { - throw new BusinessException(message: "服务商不存在"); + throw new BusinessException("服务商不存在"); } // 校验账户字段是否合法 @@ -107,7 +107,7 @@ public class FixedParameterService : ApplicationService, IAuditingEnabled input.InterfaceId == x.InterfaceId && x.FieldName == item.FieldName && x.Id != item.Id)) { - throw new BusinessException(message: $"参数{item.FieldName}已存在"); + throw new BusinessException($"参数{item.FieldName}已存在"); } } else @@ -116,7 +116,7 @@ public class FixedParameterService : ApplicationService, IAuditingEnabled input.ServiceProviderId == x.ServiceProviderId && x.FieldName == item.FieldName && x.Id != item.Id)) { - throw new BusinessException(message: $"参数{item.FieldName}已存在"); + throw new BusinessException($"参数{item.FieldName}已存在"); } } @@ -148,7 +148,7 @@ public class FixedParameterService : ApplicationService, IAuditingEnabled input.ServiceProviderId == x.ServiceProviderId && x.FieldName == item.FieldName)) ) { - throw new BusinessException(message: $"参数{item.FieldName}已存在"); + throw new BusinessException($"参数{item.FieldName}已存在"); } var entity = ObjectMapper.Map(item); @@ -190,7 +190,7 @@ public class FixedParameterService : ApplicationService, IAuditingEnabled if (accountFields.All(x => x.Value != fieldName)) { - throw new BusinessException(message: $"账户中不存在字段:{fieldName}"); + throw new BusinessException($"账户中不存在字段:{fieldName}"); } } } diff --git a/src/InterfaceForward.Application/Services/Parameter/FormParameterService.cs b/src/InterfaceForward.Application/Services/Parameter/FormParameterService.cs index a29425e..dcb4bd7 100644 --- a/src/InterfaceForward.Application/Services/Parameter/FormParameterService.cs +++ b/src/InterfaceForward.Application/Services/Parameter/FormParameterService.cs @@ -1,6 +1,5 @@ using System.ComponentModel.DataAnnotations; using InterfaceForward.Application.Helpers; -using InterfaceForward.Domain.Shared.Dtos; using InterfaceForward.Domain.Shared.Enum; using InterfaceForward.Repositories; using InterfaceForward.Repositories.Parameter.Entities; diff --git a/src/InterfaceForward.Application/Services/Parameter/ParameterService.cs b/src/InterfaceForward.Application/Services/Parameter/ParameterService.cs index d0da268..72229ed 100644 --- a/src/InterfaceForward.Application/Services/Parameter/ParameterService.cs +++ b/src/InterfaceForward.Application/Services/Parameter/ParameterService.cs @@ -64,7 +64,7 @@ public class ParameterService : ApplicationService { if (!await _interfaceRepository.IsAnyAsync(x => x.Id == input.InterfaceId)) { - throw new BusinessException(message: "接口不存在"); + throw new BusinessException("接口不存在"); } return await MaintainParametersAsync(input.ParameterList, input.InterfaceId, input.IsInPara); @@ -81,7 +81,7 @@ public class ParameterService : ApplicationService { if (!await _interfaceRepository.IsAnyAsync(x => x.Id == input.InterfaceId)) { - throw new BusinessException(message: "接口不存在"); + throw new BusinessException("接口不存在"); } var entities = input.ParameterSortList.Select(x => @@ -131,7 +131,7 @@ public class ParameterService : ApplicationService case ParameterParseTypeEnum.Xml: return ParseXml(input.ParameterContent); default: - throw new BusinessException(message: "暂不支持该格式解析"); + throw new BusinessException("暂不支持该格式解析"); } } @@ -153,7 +153,7 @@ public class ParameterService : ApplicationService } catch (Exception) { - throw new BusinessException(message: "无法正常解析,请传入合法xml"); + throw new BusinessException("无法正常解析,请传入合法xml"); } return ParseJson(json); @@ -181,7 +181,7 @@ public class ParameterService : ApplicationService } catch (Exception) { - throw new BusinessException(message: "无法正常解析,请传入合法json"); + throw new BusinessException("无法正常解析,请传入合法json"); } Debug.Assert(jtoken != null, nameof(jtoken) + " != null"); @@ -563,22 +563,22 @@ public class ParameterService : ApplicationService // 校验唯一性 if (!set.Add(cur.Alias)) - throw new BusinessException(message: $"不能存在相同路径的参数({cur.Name})"); + throw new BusinessException($"不能存在相同路径的参数({cur.Name})"); if (cur.Type == ParameterType.Object) { if (list.All(x => x.PId != cur.Id)) - throw new BusinessException(message: $"非法结构,空对象({cur.Name})"); + throw new BusinessException($"非法结构,空对象({cur.Name})"); } else if (cur.Type == ParameterType.Array) { if (list.Count(x => x.PId == cur.Id) != 1) - throw new BusinessException(message: $"非法结构,数组元素(数组的子级)只能是一个对象或基本类型({cur.Name})"); + throw new BusinessException($"非法结构,数组元素(数组的子级)只能是一个对象或基本类型({cur.Name})"); } else { if (list.Any(x => x.PId == cur.Id)) - throw new BusinessException(message: $"非法结构,基本类型不能拥有下级({cur.Name})"); + throw new BusinessException($"非法结构,基本类型不能拥有下级({cur.Name})"); continue; } diff --git a/src/InterfaceForward.Application/Services/ScriptAssistant/ScriptAssistantService.cs b/src/InterfaceForward.Application/Services/ScriptAssistant/ScriptAssistantService.cs index ac6327a..7a18312 100644 --- a/src/InterfaceForward.Application/Services/ScriptAssistant/ScriptAssistantService.cs +++ b/src/InterfaceForward.Application/Services/ScriptAssistant/ScriptAssistantService.cs @@ -4,7 +4,6 @@ using System.Text.RegularExpressions; using InterfaceForward.Application.Contracts.Dtos.ScriptAssistant; using InterfaceForward.Application.Contracts.ForwardCore; using InterfaceForward.Application.ForwardCore; -using InterfaceForward.Domain.Shared.Dtos; using InterfaceForward.Domain.Shared.Enum; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json.Linq; @@ -27,7 +26,7 @@ public class ScriptAssistantService : ApplicationService var requirement = input.Requirement.Trim(); if (requirement.IsNullOrWhiteSpace()) { - throw new BusinessException(message: "请输入脚本需求"); + throw new BusinessException("请输入脚本需求"); } var script = GenerateTemplateScript(input); diff --git a/src/InterfaceForward.Application/Services/ServiceProvider/ServiceProviderAccountService.cs b/src/InterfaceForward.Application/Services/ServiceProvider/ServiceProviderAccountService.cs index 93eca4a..8f5e293 100644 --- a/src/InterfaceForward.Application/Services/ServiceProvider/ServiceProviderAccountService.cs +++ b/src/InterfaceForward.Application/Services/ServiceProvider/ServiceProviderAccountService.cs @@ -46,7 +46,7 @@ public class ServiceProviderAccountService : ApplicationService { var accountInfo = await _serviceProviderAccountRepository.GetSingleAccountAsync(accountId); - if (accountInfo == null) throw new BusinessException(message: "账户不存在!"); + if (accountInfo == null) throw new BusinessException("账户不存在!"); var res = new SaveServiceProviderAccountOutput(); res.ServiceProviderId = accountInfo.ServiceProviderId; res.MainBodyId = accountInfo.MainBodyId; @@ -91,14 +91,14 @@ public class ServiceProviderAccountService : ApplicationService var serviceProvider = await _serviceProviderRepository.GetFirstAsync(x => x.Id == input.ServiceProviderId); if (serviceProvider == null) { - throw new BusinessException(message: "服务商不存在!"); + throw new BusinessException("服务商不存在!"); } if (await _serviceProviderAccountRepository.IsAnyAsync(x => x.ServiceProviderId == input.ServiceProviderId && x.AppId == input.AppId && (input.OptionType == OptionType.新增 || x.Id != input.AccountId))) { - throw new BusinessException(message: $"服务商:{serviceProvider.Name} 下已存在此应用的账户!"); + throw new BusinessException($"服务商:{serviceProvider.Name} 下已存在此应用的账户!"); } #endregion @@ -191,7 +191,7 @@ public class ServiceProviderAccountService : ApplicationService /// 页大小 /// [HttpGet("ServiceProviderAccount/GetAccountPageList")] - public async Task>> GetAccountPageListAsync( + public async Task>> GetAccountPageListAsync( [Required] int serviceProviderId , int pageIndex = 1 , int pageSize = 50) @@ -274,7 +274,7 @@ public class ServiceProviderAccountService : ApplicationService var serviceProvider = await _serviceProviderRepository.GetFirstAsync(x => x.Id == serviceProviderId); if (serviceProvider == null) { - throw new BusinessException(message: "服务商不存在!"); + throw new BusinessException("服务商不存在!"); } #endregion diff --git a/src/InterfaceForward.Application/Services/ServiceProvider/ServiceProviderAuthService.cs b/src/InterfaceForward.Application/Services/ServiceProvider/ServiceProviderAuthService.cs index 455471b..d7c2b35 100644 --- a/src/InterfaceForward.Application/Services/ServiceProvider/ServiceProviderAuthService.cs +++ b/src/InterfaceForward.Application/Services/ServiceProvider/ServiceProviderAuthService.cs @@ -46,7 +46,7 @@ public class ServiceProviderAuthService : ApplicationService x.Id == input.ServiceProviderId); if (serviceProvider == null) { - throw new BusinessException(message: "服务商不存在"); + throw new BusinessException("服务商不存在"); } serviceProvider.AuthInterfaceCode = input.InterfaceCode; @@ -125,7 +125,7 @@ public class ServiceProviderAuthService : ApplicationService x.Id == input.ServiceProviderId); if (serviceProvider == null) { - throw new BusinessException(message: "服务商不存在"); + throw new BusinessException("服务商不存在"); } var authConfigsEntities = BuildServiceProviderAuthConfigEntities(input); diff --git a/src/InterfaceForward.Application/Services/ServiceProvider/ServiceProviderImportExportService.cs b/src/InterfaceForward.Application/Services/ServiceProvider/ServiceProviderImportExportService.cs index a487b50..3ee4e12 100644 --- a/src/InterfaceForward.Application/Services/ServiceProvider/ServiceProviderImportExportService.cs +++ b/src/InterfaceForward.Application/Services/ServiceProvider/ServiceProviderImportExportService.cs @@ -85,7 +85,7 @@ public class ServiceProviderImportExportService : ApplicationService var context = (await _sqlSugarClientProvider.GetDbContextAsync(default)).SqlSugarClient; if (await context.Queryable() .AnyAsync(x => x.Name == input.Name && x.Code == input.Code)) - throw new BusinessException(message: "服务商Name或Code已经存在"); + throw new BusinessException("服务商Name或Code已经存在"); var data = await GetServiceProviderExportModel(input.Id ?? 0); data.ServiceProviderEntity.Name = input.Name; @@ -121,7 +121,7 @@ public class ServiceProviderImportExportService : ApplicationService var context = (await _sqlSugarClientProvider.GetDbContextAsync(default)).SqlSugarClient; if (!await context.Queryable().AnyAsync(x => x.Id == serviceProviderId)) - throw new BusinessException(message: "服务商不存在"); + throw new BusinessException("服务商不存在"); var data = new ImportExportModel(); // 服务商 diff --git a/src/InterfaceForward.Application/Services/ServiceProvider/ServiceProviderService.cs b/src/InterfaceForward.Application/Services/ServiceProvider/ServiceProviderService.cs index 77b0b3f..f638d29 100644 --- a/src/InterfaceForward.Application/Services/ServiceProvider/ServiceProviderService.cs +++ b/src/InterfaceForward.Application/Services/ServiceProvider/ServiceProviderService.cs @@ -84,7 +84,7 @@ public class ServiceProviderService : ApplicationService if (entity == null) { - throw new BusinessException(message: "服务商不存在"); + throw new BusinessException("服务商不存在"); } if (entity.FlowCode.IsNullOrWhiteSpace()) entity.FlowCode = nameof(DefaultForwardFlow); @@ -102,9 +102,9 @@ public class ServiceProviderService : ApplicationService public async Task AddAsync(ServiceProviderInput input) { if (await _serviceProviderRepository.IsAnyAsync(x => x.Name == input.Name)) - throw new BusinessException(message: $"服务商名称:{input.Name} 已存在"); + throw new BusinessException($"服务商名称:{input.Name} 已存在"); if (await _serviceProviderRepository.IsAnyAsync(x => x.Code == input.Code)) - throw new BusinessException(message: $"服务商代码:{input.Code} 已存在"); + throw new BusinessException($"服务商代码:{input.Code} 已存在"); var entity = ObjectMapper.Map(input); @@ -120,9 +120,9 @@ public class ServiceProviderService : ApplicationService public async Task UpdateAsync(ServiceProviderInput input) { if (await _serviceProviderRepository.IsAnyAsync(x => x.Name == input.Name && x.Id != input.Id)) - throw new BusinessException(message: $"服务商名称:{input.Name} 已存在"); + throw new BusinessException($"服务商名称:{input.Name} 已存在"); if (await _serviceProviderRepository.IsAnyAsync(x => x.Code == input.Code && x.Id != input.Id)) - throw new BusinessException(message: $"服务商代码:{input.Code} 已存在"); + throw new BusinessException($"服务商代码:{input.Code} 已存在"); var entity = ObjectMapper.Map(input); return await _serviceProviderRepository.UpdateColumnAsync(entity, x => new @@ -145,7 +145,7 @@ public class ServiceProviderService : ApplicationService { if (await _interfaceRepository.IsAnyAsync(x => ids.Contains(x.ServiceProviderId))) { - throw new BusinessException(message: "请勿删除存在接口的服务商"); + throw new BusinessException("请勿删除存在接口的服务商"); } await _serviceProviderRepository.SoftDeleteAsync(x => ids.Contains(x.Id)); diff --git a/src/InterfaceForward.Domain.Shared/CustomDateTimeConverter.cs b/src/InterfaceForward.Domain.Shared/CustomDateTimeConverter.cs new file mode 100644 index 0000000..7c54b0e --- /dev/null +++ b/src/InterfaceForward.Domain.Shared/CustomDateTimeConverter.cs @@ -0,0 +1,11 @@ +using Newtonsoft.Json.Converters; + +namespace InterfaceForward.Domain.Shared; + +public class CustomDateTimeConverter: IsoDateTimeConverter +{ + public CustomDateTimeConverter(string dateTimeFormat = "yyyy-MM-dd HH:mm:ss") + { + DateTimeFormat = dateTimeFormat; + } +} \ No newline at end of file diff --git a/src/InterfaceForward.Domain.Shared/DateTimeJsonConverter.cs b/src/InterfaceForward.Domain.Shared/DateTimeJsonConverter.cs deleted file mode 100644 index 1a41ecf..0000000 --- a/src/InterfaceForward.Domain.Shared/DateTimeJsonConverter.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Newtonsoft.Json; - -namespace InterfaceForward.Domain.Shared; - -public class DateTimeJsonConverter: JsonConverter -{ - private readonly string _format; - - public DateTimeJsonConverter(string format = "yyyy-MM-dd HH:mm:ss") => this._format = format; - - public override bool CanConvert(Type objectType) - { - return objectType == typeof (DateTime) || objectType == typeof (DateTime?); - } - - public override object? ReadJson( - JsonReader reader, - Type objectType, - object? existingValue, - JsonSerializer serializer) - { - if (reader.Value == null || string.IsNullOrEmpty(reader.Value.ToString())) - return (object) null; - DateTime result; - return DateTime.TryParse(reader.Value.ToString(), out result) ? (object) result : (object) new DateTime(); - } - - public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) - { - writer.WriteValue(((DateTime) value).ToString(this._format)); - } -} diff --git a/src/InterfaceForward.Domain.Shared/Dtos/PagedResult.cs b/src/InterfaceForward.Domain.Shared/Dtos/PagedResult.cs new file mode 100644 index 0000000..8313cdc --- /dev/null +++ b/src/InterfaceForward.Domain.Shared/Dtos/PagedResult.cs @@ -0,0 +1,28 @@ +namespace InterfaceForward.Domain.Shared.Dtos; + +public class PagedResult(long totalCount, List items) : ListResponse(items) +{ + /* + * 为什么total count是long,而不是int? + * in fake,我们的实体倾向用程序生成的long类型自增id、或有序guid作为主键,而不是数据库自增int id。 + */ + + /// + /// 总条数 + /// + public long TotalCount { get; set; } = totalCount; + + public PagedResult() : this(0, []) + { + } +} + +/// +/// 列表响应结果模版 +/// +/// +/// +public class ListResponse(List items) +{ + public List Items { get; set; } = items; +} \ No newline at end of file diff --git a/src/InterfaceForward.Domain.Shared/Helpers/JsonHelper.cs b/src/InterfaceForward.Domain.Shared/Helpers/JsonHelper.cs index 50503c7..2bf5891 100644 --- a/src/InterfaceForward.Domain.Shared/Helpers/JsonHelper.cs +++ b/src/InterfaceForward.Domain.Shared/Helpers/JsonHelper.cs @@ -1,7 +1,6 @@ using System.Text; using System.Text.RegularExpressions; -using Fake; -using Fake.Application; +using Fake.Domain.Exceptions; using InterfaceForward.Domain.Shared.Dtos; using InterfaceForward.Domain.Shared.Enum; using Newtonsoft.Json.Linq; @@ -291,7 +290,7 @@ public static class JsonHelper if (item.Type == ParameterType.Array) continue; var len = GetLength(jobject, item, idxList); if (len == 0) continue; - if (res != 0 && res != len) throw new BusinessException(message: $"组成元素数量不对等,请检查{node.Alias}的组成"); + if (res != 0 && res != len) throw new DomainException($"组成元素数量不对等,请检查{node.Alias}的组成"); res = Math.Max(len, res); } @@ -322,13 +321,13 @@ public static class JsonHelper if (string.IsNullOrEmpty(item.MapAlias)) { if (item.IsRequired) - throw new BusinessException(message: $"必填参数{item.Name}({item.Alias})必须建立映射或传入固定值"); + throw new DomainException($"必填参数{item.Name}({item.Alias})必须建立映射或传入固定值"); return JValue.CreateNull(); } if (item.Alias.Split("[*]").Length != item.MapAlias.Split("[*]").Length) { - throw new BusinessException(message: $"{item.Alias}<-{item.MapAlias}是不对等映射"); + throw new DomainException($"{item.Alias}<-{item.MapAlias}是不对等映射"); } string path = BuildPath(item.MapAlias, idxList); @@ -526,13 +525,13 @@ public static class JsonHelper if (string.IsNullOrEmpty(item.MapAlias)) { if (item.IsRequired) - throw new BusinessException(message: $"必填参数{item.Name}({item.Alias})必须建立映射或传入固定值"); + throw new DomainException($"必填参数{item.Name}({item.Alias})必须建立映射或传入固定值"); return JValue.CreateNull(); } if (item.Alias.Split("[*]").Length != item.MapAlias.Split("[*]").Length) { - throw new BusinessException(message: $"{item.Alias}<-{item.MapAlias}是不对等映射"); + throw new DomainException($"{item.Alias}<-{item.MapAlias}是不对等映射"); } string path = BuildPathV2(item.MapAlias, arrIndex,parentArrItemPath); @@ -544,7 +543,7 @@ public static class JsonHelper private static JToken ValidateValue(ParameterNode node, JToken val) { if (node.IsRequired && val.Type is JTokenType.Null) - throw new BusinessException(message: $"服务商参数{node.Name}是必填的(系统{node.MapAlias}->服务商{node.Alias})"); + throw new DomainException($"服务商参数{node.Name}是必填的(系统{node.MapAlias}->服务商{node.Alias})"); if (val.Type is JTokenType.Null) return val; @@ -585,8 +584,7 @@ public static class JsonHelper } if (!equal) - throw new BusinessException(message: - $"服务商参数{node.Name}({node.Alias})期望的类型是{node.Type},但实际分配的是{val.Type}类型的{val}({val.Path})"); + throw new DomainException($"服务商参数{node.Name}({node.Alias})期望的类型是{node.Type},但实际分配的是{val.Type}类型的{val}({val.Path})"); return val; } diff --git a/src/InterfaceForward.Domain.Shared/InterfaceForward.Domain.Shared.csproj b/src/InterfaceForward.Domain.Shared/InterfaceForward.Domain.Shared.csproj index 11b0309..d0902d0 100644 --- a/src/InterfaceForward.Domain.Shared/InterfaceForward.Domain.Shared.csproj +++ b/src/InterfaceForward.Domain.Shared/InterfaceForward.Domain.Shared.csproj @@ -11,6 +11,6 @@ - + diff --git a/src/InterfaceForward.Domain.Shared/InterfaceForwardDomainSharedModule.cs b/src/InterfaceForward.Domain.Shared/InterfaceForwardDomainSharedModule.cs index 765c79c..08a396d 100644 --- a/src/InterfaceForward.Domain.Shared/InterfaceForwardDomainSharedModule.cs +++ b/src/InterfaceForward.Domain.Shared/InterfaceForwardDomainSharedModule.cs @@ -3,7 +3,7 @@ using Fake.Modularity; namespace InterfaceForward.Domain.Shared { - [DependsOn(typeof(FakeDomainDrivenDesignModule))] + [DependsOn(typeof(FakeDddDomainModule))] public class InterfaceForwardDomainSharedModule : FakeModule { public override void ConfigureServices(ServiceConfigurationContext context) diff --git a/src/InterfaceForward.Domain.Shared/LongJsonConverter.cs b/src/InterfaceForward.Domain.Shared/LongJsonConverter.cs deleted file mode 100644 index 40c8e42..0000000 --- a/src/InterfaceForward.Domain.Shared/LongJsonConverter.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Newtonsoft.Json; - -namespace InterfaceForward.Domain.Shared; - -public class LongJsonConverter : JsonConverter -{ - public override bool CanConvert(Type objectType) - { - return objectType == typeof (long) || objectType == typeof (long?); - } - - public override object? ReadJson( - JsonReader reader, - Type objectType, - object? existingValue, - JsonSerializer serializer) - { - long result; - return reader.Value == null || string.IsNullOrEmpty(reader.Value.ToString()) ? (object) null : (long.TryParse(reader.Value.ToString(), out result) ? (object) result : (object) new DateTime()); - } - - public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) - { - writer.WriteValue(((long) value).ToString()); - } -} diff --git a/src/InterfaceForward.Domain.Shared/Options/FeiShuNoticeOptions.cs b/src/InterfaceForward.Domain.Shared/Options/FeiShuNoticeOptions.cs deleted file mode 100644 index 2c87952..0000000 --- a/src/InterfaceForward.Domain.Shared/Options/FeiShuNoticeOptions.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace InterfaceForward.Domain.Shared.Options; - -public class FeiShuNoticeOptions -{ - /// - /// 飞书通知webhook - /// - public string Webhook { get; set; } - - /// - /// 消息标题前缀 - /// - public string TitlePrefix { get; set; } - - /// - /// 超时时间 秒 - /// - public int Timeout { get; set; } = 20; -} \ No newline at end of file diff --git a/src/InterfaceForward.Repositories/BasicRepository.cs b/src/InterfaceForward.Repositories/BasicRepository.cs index f1aaa01..3e324b2 100644 --- a/src/InterfaceForward.Repositories/BasicRepository.cs +++ b/src/InterfaceForward.Repositories/BasicRepository.cs @@ -1,4 +1,5 @@ using System.Linq.Expressions; +using Fake; using Fake.Domain.Entities; using Fake.DomainDrivenDesign.Repositories.SqlSugarCore; @@ -81,8 +82,7 @@ public class BasicRepository : SqlSugarRepository SoftDeleteAsync(Expression>? where) { if (!typeof(T).IsAssignableTo()) - throw new BusinessException( - message: $"实体没有实现{nameof(ISoftDelete)}不能调用{nameof(SoftDeleteAsync)}"); + throw new FakeException($"实体没有实现{nameof(ISoftDelete)}不能调用{nameof(SoftDeleteAsync)}"); // tips: required where if (where == default) return false; diff --git a/src/InterfaceForward.Repositories/GlobalUsings.cs b/src/InterfaceForward.Repositories/GlobalUsings.cs index 3216b85..2280b53 100644 --- a/src/InterfaceForward.Repositories/GlobalUsings.cs +++ b/src/InterfaceForward.Repositories/GlobalUsings.cs @@ -1,8 +1,7 @@ // Global using directives -global using Fake.Application; -global using Fake.Application.Dtos; global using Fake.DependencyInjection; global using Fake.Domain.Entities.Auditing; global using Fake.DomainDrivenDesign; +global using InterfaceForward.Domain.Shared.Dtos; global using SqlSugar; \ No newline at end of file diff --git a/src/InterfaceForward.Repositories/Interface/Services/IInterfaceRepository.cs b/src/InterfaceForward.Repositories/Interface/Services/IInterfaceRepository.cs index c80fb8e..76e0823 100644 --- a/src/InterfaceForward.Repositories/Interface/Services/IInterfaceRepository.cs +++ b/src/InterfaceForward.Repositories/Interface/Services/IInterfaceRepository.cs @@ -1,5 +1,4 @@ using InterfaceForward.Application.Contracts.Dtos.Interface; -using InterfaceForward.Domain.Shared.Dtos; using InterfaceForward.Repositories.Interface.Entitys; using InterfaceForward.Repositories.Interface.ValueObjects; using InterfaceForward.Repositories.Parameter.VO; diff --git a/src/InterfaceForward.Repositories/Interface/ValueObjects/GetMapListInputVO.cs b/src/InterfaceForward.Repositories/Interface/ValueObjects/GetMapListInputVO.cs index 7e5719c..3d99085 100644 --- a/src/InterfaceForward.Repositories/Interface/ValueObjects/GetMapListInputVO.cs +++ b/src/InterfaceForward.Repositories/Interface/ValueObjects/GetMapListInputVO.cs @@ -1,5 +1,4 @@ using System.ComponentModel.DataAnnotations; -using InterfaceForward.Domain.Shared.Dtos; namespace InterfaceForward.Repositories.Interface.ValueObjects; diff --git a/src/InterfaceForward.Repositories/Interface/ValueObjects/InterfaceOutput.cs b/src/InterfaceForward.Repositories/Interface/ValueObjects/InterfaceOutput.cs index 32dcdcf..5b98f85 100644 --- a/src/InterfaceForward.Repositories/Interface/ValueObjects/InterfaceOutput.cs +++ b/src/InterfaceForward.Repositories/Interface/ValueObjects/InterfaceOutput.cs @@ -1,5 +1,4 @@ -using InterfaceForward.Domain.Shared.Dtos; -using InterfaceForward.Domain.Shared.Enum; +using InterfaceForward.Domain.Shared.Enum; using InterfaceForward.Repositories.Parameter.VO; namespace InterfaceForward.Repositories.Interface.ValueObjects; diff --git a/src/InterfaceForward.Repositories/Interface/ValueObjects/InterfacePaginatedInputObjectValue.cs b/src/InterfaceForward.Repositories/Interface/ValueObjects/InterfacePaginatedInputObjectValue.cs index 07deaeb..10d2a8a 100644 --- a/src/InterfaceForward.Repositories/Interface/ValueObjects/InterfacePaginatedInputObjectValue.cs +++ b/src/InterfaceForward.Repositories/Interface/ValueObjects/InterfacePaginatedInputObjectValue.cs @@ -1,6 +1,4 @@ -using InterfaceForward.Domain.Shared.Dtos; - -namespace InterfaceForward.Repositories.Interface.ValueObjects; +namespace InterfaceForward.Repositories.Interface.ValueObjects; /// /// 接口分页 diff --git a/src/InterfaceForward.Repositories/Interface/ValueObjects/InterfaceTreeListInputObjectValue.cs b/src/InterfaceForward.Repositories/Interface/ValueObjects/InterfaceTreeListInputObjectValue.cs index 8f48f64..f6f586b 100644 --- a/src/InterfaceForward.Repositories/Interface/ValueObjects/InterfaceTreeListInputObjectValue.cs +++ b/src/InterfaceForward.Repositories/Interface/ValueObjects/InterfaceTreeListInputObjectValue.cs @@ -1,6 +1,4 @@ -using InterfaceForward.Domain.Shared.Dtos; - -namespace InterfaceForward.Repositories.Interface.ValueObjects; +namespace InterfaceForward.Repositories.Interface.ValueObjects; /// /// 服务商接口分页 diff --git a/src/InterfaceForward.Repositories/InterfaceForwardQuery.cs b/src/InterfaceForward.Repositories/InterfaceForwardQuery.cs index 4919618..9d17a46 100644 --- a/src/InterfaceForward.Repositories/InterfaceForwardQuery.cs +++ b/src/InterfaceForward.Repositories/InterfaceForwardQuery.cs @@ -1,4 +1,4 @@ -using InterfaceForward.Domain.Shared.Dtos; +using Fake.Domain.Exceptions; using InterfaceForward.Domain.Shared.Enum; using InterfaceForward.Domain.Shared.Helpers; using InterfaceForward.Repositories.App.Entitys; @@ -163,12 +163,12 @@ ORDER BY `b`.`Sort` ASC").ToListAsync(); .Where(x => x.UpStreamCode == systemInterface.Code && x.ServiceProviderId == serviceProvider.Id) .Select(x => new { x.Id, x.DownStreamCode, x.PrefixScript, x.PostfixScript }) .ToArrayAsync(); - if (maps == null || maps.Length == 0) throw new BusinessException(message: "映射不存在"); + if (maps == null || maps.Length == 0) throw new EntityNotFoundException("映射不存在"); var downStreamIds = maps.Select(x => x.DownStreamCode).ToArray(); var targetInterfaceList = await GetInterfaceByCodesAsync(downStreamIds); if (targetInterfaceList == null || targetInterfaceList.Count != downStreamIds.Length) - throw new BusinessException(message: "服务商一个或多个接口不存在"); + throw new EntityNotFoundException("服务商一个或多个接口不存在"); var mapIds = maps.Select(x => x.Id).ToList(); var context = new ForwardCoreContextCache diff --git a/src/InterfaceForward.Repositories/Log/Entitys/LogIndex.cs b/src/InterfaceForward.Repositories/Log/Entitys/LogIndex.cs index 8e2439b..e94695d 100644 --- a/src/InterfaceForward.Repositories/Log/Entitys/LogIndex.cs +++ b/src/InterfaceForward.Repositories/Log/Entitys/LogIndex.cs @@ -2,6 +2,7 @@ using InterfaceForward.Repositories.Log.ES; using Nest; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace InterfaceForward.Repositories.Log.Entitys; @@ -16,7 +17,7 @@ public class LogIndex : IdBaseIndex /// /// 请求时间 /// - [JsonConverter(typeof(DateTimeJsonConverter), "yyyy-MM-dd HH:mm:ss fff")] + [JsonConverter(typeof(CustomDateTimeConverter), "yyyy-MM-dd HH:mm:ss fff")] public DateTime RequestTime { get; set; } /// diff --git a/src/InterfaceForward.Repositories/Log/Services/ILogRepository.cs b/src/InterfaceForward.Repositories/Log/Services/ILogRepository.cs index d87fe46..f085a39 100644 --- a/src/InterfaceForward.Repositories/Log/Services/ILogRepository.cs +++ b/src/InterfaceForward.Repositories/Log/Services/ILogRepository.cs @@ -1,5 +1,4 @@ -using InterfaceForward.Domain.Shared.Dtos; -using InterfaceForward.Repositories.Log.Entitys; +using InterfaceForward.Repositories.Log.Entitys; using InterfaceForward.Repositories.Log.ES; using InterfaceForward.Repositories.Log.ValueObjects; using Nest; diff --git a/src/InterfaceForward.Repositories/Log/Services/LogRepository.cs b/src/InterfaceForward.Repositories/Log/Services/LogRepository.cs index 425bcb5..006147d 100644 --- a/src/InterfaceForward.Repositories/Log/Services/LogRepository.cs +++ b/src/InterfaceForward.Repositories/Log/Services/LogRepository.cs @@ -1,5 +1,4 @@ -using InterfaceForward.Domain.Shared.Dtos; -using InterfaceForward.Domain.Shared.Enum; +using InterfaceForward.Domain.Shared.Enum; using InterfaceForward.Domain.Shared.Helpers; using InterfaceForward.Repositories.Log.Entitys; using InterfaceForward.Repositories.Log.ES; diff --git a/src/InterfaceForward.Repositories/Log/ValueObjects/LogGetListInputValueObject.cs b/src/InterfaceForward.Repositories/Log/ValueObjects/LogGetListInputValueObject.cs index 3bdca6f..e18e185 100644 --- a/src/InterfaceForward.Repositories/Log/ValueObjects/LogGetListInputValueObject.cs +++ b/src/InterfaceForward.Repositories/Log/ValueObjects/LogGetListInputValueObject.cs @@ -1,5 +1,4 @@ -using InterfaceForward.Domain.Shared.Dtos; -using InterfaceForward.Domain.Shared.Enum; +using InterfaceForward.Domain.Shared.Enum; namespace InterfaceForward.Repositories.Log.ValueObjects; diff --git a/src/InterfaceForward.Repositories/Log/ValueObjects/LogStatisticsInputValueObject.cs b/src/InterfaceForward.Repositories/Log/ValueObjects/LogStatisticsInputValueObject.cs index 28c7e91..13df077 100644 --- a/src/InterfaceForward.Repositories/Log/ValueObjects/LogStatisticsInputValueObject.cs +++ b/src/InterfaceForward.Repositories/Log/ValueObjects/LogStatisticsInputValueObject.cs @@ -1,5 +1,4 @@ using System.ComponentModel.DataAnnotations; -using InterfaceForward.Domain.Shared.Dtos; using InterfaceForward.Domain.Shared.Enum; namespace InterfaceForward.Repositories.Log.ValueObjects; diff --git a/src/InterfaceForward.Repositories/ServiceProvider/Services/IServiceProviderRepository.cs b/src/InterfaceForward.Repositories/ServiceProvider/Services/IServiceProviderRepository.cs index 9b21902..3138ed9 100644 --- a/src/InterfaceForward.Repositories/ServiceProvider/Services/IServiceProviderRepository.cs +++ b/src/InterfaceForward.Repositories/ServiceProvider/Services/IServiceProviderRepository.cs @@ -1,5 +1,4 @@ -using InterfaceForward.Domain.Shared.Dtos; -using InterfaceForward.Repositories.ServiceProvider.Entitys; +using InterfaceForward.Repositories.ServiceProvider.Entitys; using InterfaceForward.Repositories.ServiceProvider.ValueObjects; namespace InterfaceForward.Repositories.ServiceProvider.Services diff --git a/src/InterfaceForward.Repositories/ServiceProvider/Services/ServiceProviderAccountRepository.cs b/src/InterfaceForward.Repositories/ServiceProvider/Services/ServiceProviderAccountRepository.cs index 7834c9d..296b4aa 100644 --- a/src/InterfaceForward.Repositories/ServiceProvider/Services/ServiceProviderAccountRepository.cs +++ b/src/InterfaceForward.Repositories/ServiceProvider/Services/ServiceProviderAccountRepository.cs @@ -1,5 +1,4 @@ -using InterfaceForward.Domain.Shared.Dtos; -using InterfaceForward.Repositories.App.Entitys; +using InterfaceForward.Repositories.App.Entitys; using InterfaceForward.Repositories.ServiceProvider.Entitys; using InterfaceForward.Repositories.ServiceProvider.ValueObjects; diff --git a/src/InterfaceForward.Repositories/ServiceProvider/Services/ServiceProviderRepository.cs b/src/InterfaceForward.Repositories/ServiceProvider/Services/ServiceProviderRepository.cs index cc7a58d..bd41c6c 100644 --- a/src/InterfaceForward.Repositories/ServiceProvider/Services/ServiceProviderRepository.cs +++ b/src/InterfaceForward.Repositories/ServiceProvider/Services/ServiceProviderRepository.cs @@ -1,5 +1,4 @@ -using InterfaceForward.Domain.Shared.Dtos; -using InterfaceForward.Domain.Shared.Enum; +using InterfaceForward.Domain.Shared.Enum; using InterfaceForward.Repositories.Interface.Entitys; using InterfaceForward.Repositories.ServiceProvider.Entitys; using InterfaceForward.Repositories.ServiceProvider.ValueObjects; diff --git a/src/InterfaceForward.Repositories/ServiceProvider/ValueObjects/ServiceProviderPaginatedInputObjectValue.cs b/src/InterfaceForward.Repositories/ServiceProvider/ValueObjects/ServiceProviderPaginatedInputObjectValue.cs index 88e0942..896ef24 100644 --- a/src/InterfaceForward.Repositories/ServiceProvider/ValueObjects/ServiceProviderPaginatedInputObjectValue.cs +++ b/src/InterfaceForward.Repositories/ServiceProvider/ValueObjects/ServiceProviderPaginatedInputObjectValue.cs @@ -1,5 +1,4 @@ -using InterfaceForward.Domain.Shared.Dtos; -using InterfaceForward.Domain.Shared.Enum; +using InterfaceForward.Domain.Shared.Enum; namespace InterfaceForward.Repositories.ServiceProvider.ValueObjects;