升级框架
This commit is contained in:
parent
c637a7b9c8
commit
6ba2ca367e
@ -1,6 +1,6 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<!-- All Fake packages -->
|
||||
<FakePackageVersion>8.0.5.6</FakePackageVersion>
|
||||
<FakePackageVersion>8.0.5.13</FakePackageVersion>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
||||
@ -9,9 +9,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\InterfaceForward.Application\InterfaceForward.Application.csproj" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.18" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
|
||||
|
||||
<PackageReference Include="Fake.Consul" Version="$(FakePackageVersion)" />
|
||||
<PackageReference Include="Fake.Autofac" Version="$(FakePackageVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -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<FakeAspNetCoreMvcOptions>(options =>
|
||||
{
|
||||
@ -49,20 +47,12 @@ public class InterfaceForwardApiModule : FakeModule
|
||||
.RequireAuthenticatedUser()
|
||||
.Build();
|
||||
options.Filters.Add(new AuthorizeFilter(policy));
|
||||
}).AddNewtonsoftJson();
|
||||
|
||||
//Json格式化全局处理
|
||||
context.Services.Configure<MvcNewtonsoftJsonOptions>(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 =>
|
||||
{
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -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:
|
||||
|
||||
@ -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;
|
||||
@ -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<CreateAppInput, AppEntity>(input);
|
||||
var appScopeEntitys = ObjectMapper.Map<List<CreateAppScopeInput>, List<AppScopeEntity>>(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<bool> 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<UpdateAppInput, AppEntity>(input);
|
||||
var appScopeEntitys = ObjectMapper.Map<List<CreateAppScopeInput>, List<AppScopeEntity>>(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);
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -50,7 +50,7 @@ public class InterfaceReturnConfigService : ApplicationService
|
||||
{
|
||||
if (!await _interfaceRepository.IsAnyAsync(x => x.Id == input.InterfaceId))
|
||||
{
|
||||
throw new BusinessException(message: "接口不存在");
|
||||
throw new BusinessException("接口不存在");
|
||||
}
|
||||
|
||||
// 开启事务
|
||||
|
||||
@ -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, InterfaceOutput>(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();
|
||||
}
|
||||
|
||||
@ -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<IForwardFlow>()
|
||||
.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<JObject>(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;
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System.Reflection;
|
||||
using InterfaceForward.Domain.Shared.Dtos;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
|
||||
@ -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<bool> 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<bool> 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);
|
||||
|
||||
@ -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<int>(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<MapParameterCascadedOutput>();
|
||||
@ -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<InterfaceMapDetailEntity>();
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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<FixedParameterItem, FixedParameterEntity>(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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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
|
||||
/// <param name="pageSize">页大小</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("ServiceProviderAccount/GetAccountPageList")]
|
||||
public async Task<PagedResult<Dictionary<string, object?>>> GetAccountPageListAsync(
|
||||
public async Task<PagedResult<Dictionary<string, object>>> 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
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -85,7 +85,7 @@ public class ServiceProviderImportExportService : ApplicationService
|
||||
var context = (await _sqlSugarClientProvider.GetDbContextAsync(default)).SqlSugarClient;
|
||||
if (await context.Queryable<ServiceProviderEntity>()
|
||||
.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<ServiceProviderEntity>().AnyAsync(x => x.Id == serviceProviderId))
|
||||
throw new BusinessException(message: "服务商不存在");
|
||||
throw new BusinessException("服务商不存在");
|
||||
|
||||
var data = new ImportExportModel();
|
||||
// 服务商
|
||||
|
||||
@ -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<ServiceProviderInput, ServiceProviderEntity>(input);
|
||||
|
||||
@ -120,9 +120,9 @@ public class ServiceProviderService : ApplicationService
|
||||
public async Task<bool> 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<ServiceProviderInput, ServiceProviderEntity>(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));
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
28
src/InterfaceForward.Domain.Shared/Dtos/PagedResult.cs
Normal file
28
src/InterfaceForward.Domain.Shared/Dtos/PagedResult.cs
Normal file
@ -0,0 +1,28 @@
|
||||
namespace InterfaceForward.Domain.Shared.Dtos;
|
||||
|
||||
public class PagedResult<T>(long totalCount, List<T> items) : ListResponse<T>(items)
|
||||
{
|
||||
/*
|
||||
* 为什么total count是long,而不是int?
|
||||
* in fake,我们的实体倾向用程序生成的long类型自增id、或有序guid作为主键,而不是数据库自增int id。
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// 总条数
|
||||
/// </summary>
|
||||
public long TotalCount { get; set; } = totalCount;
|
||||
|
||||
public PagedResult() : this(0, [])
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 列表响应结果模版
|
||||
/// </summary>
|
||||
/// <param name="items"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class ListResponse<T>(List<T> items)
|
||||
{
|
||||
public List<T> Items { get; set; } = items;
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -11,6 +11,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Fake.Serilog" Version="$(FakePackageVersion)" />
|
||||
<PackageReference Include="Fake.DomainDrivenDesign" Version="$(FakePackageVersion)" />
|
||||
<PackageReference Include="Fake.Ddd.Domain" Version="$(FakePackageVersion)" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
namespace InterfaceForward.Domain.Shared.Options;
|
||||
|
||||
public class FeiShuNoticeOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 飞书通知webhook
|
||||
/// </summary>
|
||||
public string Webhook { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 消息标题前缀
|
||||
/// </summary>
|
||||
public string TitlePrefix { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 超时时间 秒
|
||||
/// </summary>
|
||||
public int Timeout { get; set; } = 20;
|
||||
}
|
||||
@ -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<T> : SqlSugarRepository<InterfaceForwardDbContext,
|
||||
public async Task<bool> SoftDeleteAsync(Expression<Func<T, bool>>? where)
|
||||
{
|
||||
if (!typeof(T).IsAssignableTo<ISoftDelete>())
|
||||
throw new BusinessException(
|
||||
message: $"实体没有实现{nameof(ISoftDelete)}不能调用{nameof(SoftDeleteAsync)}");
|
||||
throw new FakeException($"实体没有实现{nameof(ISoftDelete)}不能调用{nameof(SoftDeleteAsync)}");
|
||||
|
||||
// tips: required where
|
||||
if (where == default) return false;
|
||||
|
||||
@ -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;
|
||||
@ -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;
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using InterfaceForward.Domain.Shared.Dtos;
|
||||
|
||||
namespace InterfaceForward.Repositories.Interface.ValueObjects;
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
using InterfaceForward.Domain.Shared.Dtos;
|
||||
|
||||
namespace InterfaceForward.Repositories.Interface.ValueObjects;
|
||||
namespace InterfaceForward.Repositories.Interface.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// 接口分页
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
using InterfaceForward.Domain.Shared.Dtos;
|
||||
|
||||
namespace InterfaceForward.Repositories.Interface.ValueObjects;
|
||||
namespace InterfaceForward.Repositories.Interface.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// 服务商接口分页
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
///<summary>
|
||||
/// 请求时间
|
||||
///</summary>
|
||||
[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; }
|
||||
|
||||
///<summary>
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using InterfaceForward.Domain.Shared.Dtos;
|
||||
using InterfaceForward.Domain.Shared.Enum;
|
||||
using InterfaceForward.Domain.Shared.Enum;
|
||||
|
||||
namespace InterfaceForward.Repositories.Log.ValueObjects;
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using InterfaceForward.Domain.Shared.Dtos;
|
||||
using InterfaceForward.Domain.Shared.Enum;
|
||||
|
||||
namespace InterfaceForward.Repositories.Log.ValueObjects;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using InterfaceForward.Domain.Shared.Dtos;
|
||||
using InterfaceForward.Domain.Shared.Enum;
|
||||
using InterfaceForward.Domain.Shared.Enum;
|
||||
|
||||
namespace InterfaceForward.Repositories.ServiceProvider.ValueObjects;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user