From d30bb1851414b270a515ded44d906c07e319de8a Mon Sep 17 00:00:00 2001 From: xiaolipro <2357729423@qq.com> Date: Thu, 3 Jul 2025 16:23:45 +0800 Subject: [PATCH] tp --- src/InterfaceForward.Api/Dockerfile | 23 ++++--- .../Helpers/RedisHelper.cs | 4 +- .../InterfaceForwardApplicationModule.cs | 8 +++ .../ServiceProviderInterfaceService.cs | 12 ++++ .../Interface/SystemInterfaceService.cs | 13 ++++ .../Services/IInterfaceRepository.cs | 3 + .../Interface/Services/InterfaceRepository.cs | 61 +++++++++++++++++++ ...viderInterfacePaginatedInputObjectValue.cs | 24 ++++++++ ...iderInterfacePaginatedOutputValueObject.cs | 47 ++++++++++++++ ...ystemInterfacePaginatedInputObjectValue.cs | 20 ++++++ ...stemInterfacePaginatedOutputValueObject.cs | 48 +++++++++++++++ 11 files changed, 252 insertions(+), 11 deletions(-) create mode 100644 src/InterfaceForward.Repositories/Interface/ValueObjects/ServiceProviderInterfacePaginatedInputObjectValue.cs create mode 100644 src/InterfaceForward.Repositories/Interface/ValueObjects/ServiceProviderInterfacePaginatedOutputValueObject.cs create mode 100644 src/InterfaceForward.Repositories/Interface/ValueObjects/SystemInterfacePaginatedInputObjectValue.cs create mode 100644 src/InterfaceForward.Repositories/Interface/ValueObjects/SystemInterfacePaginatedOutputValueObject.cs diff --git a/src/InterfaceForward.Api/Dockerfile b/src/InterfaceForward.Api/Dockerfile index f0d4a58..6c9c83a 100644 --- a/src/InterfaceForward.Api/Dockerfile +++ b/src/InterfaceForward.Api/Dockerfile @@ -1,16 +1,19 @@ -FROM mcr.microsoft.com/dotnet/sdk:8.0.303 AS base +# 使用 SDK 镜像进行构建 +FROM mcr.microsoft.com/dotnet/sdk:8.0.303 AS build ARG BUILD_CONFIGURATION=Release WORKDIR /src -COPY . /src -RUN dotnet restore "src/InterfaceForward.Api/InterfaceForward.Api.csproj" -WORKDIR "/src/src/InterfaceForward.Api" -RUN dotnet build "InterfaceForward.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build -FROM base AS publish -ARG BUILD_CONFIGURATION=Release +# 仅复制必要的文件 +COPY src/InterfaceForward.Api/InterfaceForward.Api.csproj src/InterfaceForward.Api/ +RUN dotnet restore "src/InterfaceForward.Api/InterfaceForward.Api.csproj" + +# 复制其余文件并进行构建 +COPY . . +WORKDIR "/src/src/InterfaceForward.Api" RUN dotnet publish "InterfaceForward.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false -FROM base AS final +# 使用运行时镜像 +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime WORKDIR /app -COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "InterfaceForward.Api.dll"] +COPY --from=build /app/publish . +ENTRYPOINT ["dotnet", "InterfaceForward.Api.dll"] \ No newline at end of file diff --git a/src/InterfaceForward.Application/Helpers/RedisHelper.cs b/src/InterfaceForward.Application/Helpers/RedisHelper.cs index 6726303..2fae889 100644 --- a/src/InterfaceForward.Application/Helpers/RedisHelper.cs +++ b/src/InterfaceForward.Application/Helpers/RedisHelper.cs @@ -1,5 +1,7 @@ using FreeRedis; using Newtonsoft.Json; +using Serilog; + namespace InterfaceForward.Application.Helpers; public static class RedisHelper @@ -24,7 +26,7 @@ public static class RedisHelper _client.Serialize = obj => JsonConvert.SerializeObject(obj); _client.Deserialize = (json, type) => JsonConvert.DeserializeObject(json, type); if (showLogInfo) - _client.Notice += (s, e) => Console.WriteLine(Environment.NewLine + e.Log); + _client.Notice += (s, e) => Log.Information(Environment.NewLine + e.Log); } } } diff --git a/src/InterfaceForward.Application/InterfaceForwardApplicationModule.cs b/src/InterfaceForward.Application/InterfaceForwardApplicationModule.cs index 2c0cf24..87886cc 100644 --- a/src/InterfaceForward.Application/InterfaceForwardApplicationModule.cs +++ b/src/InterfaceForward.Application/InterfaceForwardApplicationModule.cs @@ -4,8 +4,11 @@ using Fake.EventBus.RabbitMQ; using Fake.Modularity; using Fake.ObjectMapping.AutoMapper; using Fake.RabbitMQ; +using FreeRedis; using InterfaceForward.Application.Contracts; +using InterfaceForward.Application.Helpers; using InterfaceForward.Repositories; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; namespace InterfaceForward.Application; @@ -28,6 +31,11 @@ public class InterfaceForwardApplicationModule:FakeModule context.Services.Configure(configuration.GetSection("InterfaceRelay")); + var options = configuration.GetSection("Redis").Get(); + if (options == null) + throw new FakeException("未找到Redis相关配置,请检查配置文件中是否包含名为Redis的节点"); + RedisHelper.Init(options, showLogInfo: System.Diagnostics.Debugger.IsAttached); + // 预热 NatashaInitializer.Preheating(); diff --git a/src/InterfaceForward.Application/Services/Interface/ServiceProviderInterfaceService.cs b/src/InterfaceForward.Application/Services/Interface/ServiceProviderInterfaceService.cs index 6f1fc41..f4016ca 100644 --- a/src/InterfaceForward.Application/Services/Interface/ServiceProviderInterfaceService.cs +++ b/src/InterfaceForward.Application/Services/Interface/ServiceProviderInterfaceService.cs @@ -53,6 +53,18 @@ public class ServiceProviderInterfaceService : ApplicationService return tree; } + + /// + /// 服务商接口分页列表 + /// + /// + /// + [HttpPost("Interface/ServiceProviderInterfacePaginatedList")] + public async Task> + ServiceProviderInterfacePaginatedListAsync(ServiceProviderInterfacePaginatedInputObjectValue input) + { + return await InterfaceRepository.GetServiceProviderInterfacePaginatedListAsync(input); + } /// /// 获取服务商接口下拉列表 diff --git a/src/InterfaceForward.Application/Services/Interface/SystemInterfaceService.cs b/src/InterfaceForward.Application/Services/Interface/SystemInterfaceService.cs index 4a69fef..2218d07 100644 --- a/src/InterfaceForward.Application/Services/Interface/SystemInterfaceService.cs +++ b/src/InterfaceForward.Application/Services/Interface/SystemInterfaceService.cs @@ -45,6 +45,19 @@ public class SystemInterfaceService : ApplicationService } #endregion + + + /// + /// 系统接口分页列表 + /// + /// + /// + [HttpPost("Interface/SystemInterfacePaginatedList")] + public async Task> + SystemInterfacePaginatedListAsync(SystemInterfacePaginatedInputObjectValue input) + { + return await _interfaceRepository.GetSystemInterfacePaginatedListAsync(input); + } /// /// 系统接口树形列表 diff --git a/src/InterfaceForward.Repositories/Interface/Services/IInterfaceRepository.cs b/src/InterfaceForward.Repositories/Interface/Services/IInterfaceRepository.cs index dfd0e37..f5bdcce 100644 --- a/src/InterfaceForward.Repositories/Interface/Services/IInterfaceRepository.cs +++ b/src/InterfaceForward.Repositories/Interface/Services/IInterfaceRepository.cs @@ -46,5 +46,8 @@ namespace InterfaceForward.Repositories.Interface.Services /// /// /// Task GetCurrentCodeBySpId(int spId); + + Task> GetSystemInterfacePaginatedListAsync(SystemInterfacePaginatedInputObjectValue input); + Task> GetServiceProviderInterfacePaginatedListAsync(ServiceProviderInterfacePaginatedInputObjectValue input); } } diff --git a/src/InterfaceForward.Repositories/Interface/Services/InterfaceRepository.cs b/src/InterfaceForward.Repositories/Interface/Services/InterfaceRepository.cs index 7fb438a..8902598 100644 --- a/src/InterfaceForward.Repositories/Interface/Services/InterfaceRepository.cs +++ b/src/InterfaceForward.Repositories/Interface/Services/InterfaceRepository.cs @@ -131,4 +131,65 @@ public class InterfaceRepository : BasicRepository, IInterfaceR return code; } + + /// + public async Task> + GetSystemInterfacePaginatedListAsync(SystemInterfacePaginatedInputObjectValue input) + { + // t_interface驱动t_interface_map,数据量上来可以在t_interface_map UpStreamId字段建立索引 + var query = AsQueryable() + .LeftJoin((a, c) => a.Category == c.Id) + .LeftJoin((a, c, d) => (int)a.RequestProtocol == d.Id) + .LeftJoin((a, c, d, e) => a.RequestMethod == e.Id) + .Where(a => a.IsUpStream) + ; + + var keyword = input.NameOrCode?.Trim(); + query.WhereIF(input.Category != 0, a => a.Category == input.Category) // 默认“请选择”对应0,数据源在数据库字典中配置 + .WhereIF(!string.IsNullOrEmpty(keyword), a => a.Name.Contains(keyword) + || a.Code.Contains(keyword)) // 默认为空,支持模糊搜索 + ; + + return await query.Select((a, c, d, e) => new SystemInterfacePaginatedOutputValueObject + { + Id = a.Id, + Category = c.Name, + Name = a.Name, + Code = a.Code, + RequestProtocol = d.Name, + Description = a.Description, + MapCount = SqlFunc.Subqueryable().Where(x => x.UpStreamId == a.Id && !x.IsDeleted) + .DistinctCount(x => x.ServiceProviderId), + UpdateTime = a.UpdateTime, + }).OrderByDescending(a => a.UpdateTime).ToPagedListAsync(input.PageIndex, input.PageSize); + } + + /// + public async Task> + GetServiceProviderInterfacePaginatedListAsync(ServiceProviderInterfacePaginatedInputObjectValue input) + { + var query = AsQueryable() + .LeftJoin((a, b) => (int)a.RequestProtocol == b.Id) + .LeftJoin((a, b, c) => a.RequestMethod == c.Id) + .Where(a => !a.IsUpStream) + .Where(a => a.ServiceProviderId == input.ServiceProviderId); + + query + .WhereIF(!string.IsNullOrEmpty(input.Name), a => a.Name.Contains(input.Name!)) // 默认为空,支持模糊搜索 + .WhereIF(!string.IsNullOrEmpty(input.Code), a => a.Code.Contains(input.Code!)) // 默认为空,支持模糊搜索 + ; + return await query.Select((a, b, c) => new ServiceProviderInterfacePaginatedOutputValueObject + { + Id = a.Id, + Name = a.Name, + Code = a.Code, + RequestProtocol = b.Name, + RequestMethod = c.Name, + RequestAddress = a.RequestAddress, + Description = a.Description, + UpdateTime = a.UpdateTime, + }) + .OrderByDescending(a => a.UpdateTime) + .ToPagedListAsync(input.PageIndex, input.PageSize); + } } \ No newline at end of file diff --git a/src/InterfaceForward.Repositories/Interface/ValueObjects/ServiceProviderInterfacePaginatedInputObjectValue.cs b/src/InterfaceForward.Repositories/Interface/ValueObjects/ServiceProviderInterfacePaginatedInputObjectValue.cs new file mode 100644 index 0000000..e450bfd --- /dev/null +++ b/src/InterfaceForward.Repositories/Interface/ValueObjects/ServiceProviderInterfacePaginatedInputObjectValue.cs @@ -0,0 +1,24 @@ +using InterfaceForward.Domain.Shared.Dtos; + +namespace InterfaceForward.Repositories.Interface.ValueObjects; + +/// +/// 服务商接口分页 +/// +public class ServiceProviderInterfacePaginatedInputObjectValue : PagedQueryInput +{ + /// + /// 服务商Id + /// + public int ServiceProviderId { get; set; } + + /// + /// 接口名 + /// + public string? Name { get; set; } + + /// + /// 接口代码 + /// + public string? Code { get; set; } +} \ No newline at end of file diff --git a/src/InterfaceForward.Repositories/Interface/ValueObjects/ServiceProviderInterfacePaginatedOutputValueObject.cs b/src/InterfaceForward.Repositories/Interface/ValueObjects/ServiceProviderInterfacePaginatedOutputValueObject.cs new file mode 100644 index 0000000..a19a968 --- /dev/null +++ b/src/InterfaceForward.Repositories/Interface/ValueObjects/ServiceProviderInterfacePaginatedOutputValueObject.cs @@ -0,0 +1,47 @@ +namespace InterfaceForward.Repositories.Interface.ValueObjects; + +/// +/// +/// +public class ServiceProviderInterfacePaginatedOutputValueObject +{ + /// + /// 接口Id + /// + public int Id { get; set; } + + /// + /// 接口名 + /// + public string Name { get; set; } + + /// + /// 接口代码 + /// + public string Code { get; set; } + + /// + /// 请求协议 + /// + public string RequestProtocol { get; set; } + + /// + /// 请求方式 + /// + public string RequestMethod { get; set; } + + /// + /// 请求地址 + /// + public string RequestAddress { get; set; } + + /// + /// 接口描述 + /// + public string Description { get; set; } + + /// + /// 更新时间 + /// + public DateTime? UpdateTime { get; set; } +} \ No newline at end of file diff --git a/src/InterfaceForward.Repositories/Interface/ValueObjects/SystemInterfacePaginatedInputObjectValue.cs b/src/InterfaceForward.Repositories/Interface/ValueObjects/SystemInterfacePaginatedInputObjectValue.cs new file mode 100644 index 0000000..dc1e393 --- /dev/null +++ b/src/InterfaceForward.Repositories/Interface/ValueObjects/SystemInterfacePaginatedInputObjectValue.cs @@ -0,0 +1,20 @@ +using InterfaceForward.Domain.Shared.Dtos; + +namespace InterfaceForward.Repositories.Interface.ValueObjects +{ + /// + /// 分页查询系统接口 + /// + public class SystemInterfacePaginatedInputObjectValue : PagedQueryInput + { + /// + /// 接口分组,默认请选择对应0值 + /// + public int Category { get; set; } + + /// + /// 接口名 + /// + public string NameOrCode { get; set; } + } +} \ No newline at end of file diff --git a/src/InterfaceForward.Repositories/Interface/ValueObjects/SystemInterfacePaginatedOutputValueObject.cs b/src/InterfaceForward.Repositories/Interface/ValueObjects/SystemInterfacePaginatedOutputValueObject.cs new file mode 100644 index 0000000..f61f8ff --- /dev/null +++ b/src/InterfaceForward.Repositories/Interface/ValueObjects/SystemInterfacePaginatedOutputValueObject.cs @@ -0,0 +1,48 @@ +namespace InterfaceForward.Repositories.Interface.ValueObjects +{ + /// + /// + /// + public class SystemInterfacePaginatedOutputValueObject + { + /// + /// 接口Id + /// + public int Id { get; set; } + + /// + /// 接口分组 + /// + public string Category { get; set; } + + /// + /// 接口名 + /// + public string Name { get; set; } + + /// + /// 接口代码 + /// + public string Code { get; set; } + + /// + /// 请求协议 + /// + public string RequestProtocol { get; set; } + + /// + /// 接口描述 + /// + public string Description { get; set; } + + /// + /// 映射数 + /// + public int MapCount { get; set; } + + /// + /// 更新时间 + /// + public DateTime? UpdateTime { get; set; } + } +}