@@ -43,11 +43,6 @@ ProjectSection(SolutionItems) = preProject | |||
src\nuget.config = src\nuget.config | |||
EndProjectSection | |||
EndProject | |||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".pack", ".pack", "{5CE18647-CEFB-483A-B384-99D4FB47DA29}" | |||
ProjectSection(SolutionItems) = preProject | |||
src\.pack\pack.sh = src\.pack\pack.sh | |||
EndProjectSection | |||
EndProject | |||
Global | |||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | |||
Debug|Any CPU = Debug|Any CPU | |||
@@ -114,9 +109,8 @@ Global | |||
{4F48E97A-2DC3-4720-98F7-25935258D79C} = {0265A6CF-0D40-4A59-B6DF-2F25099DA95B} | |||
{CFDFD099-D03F-441A-A3CD-28C7320742C5} = {71207855-D2BE-48D3-86AD-D1E5BC389E64} | |||
{FBE0E584-BF1F-498D-BBFC-66B790EAFC7C} = {FEDACFF6-C6AF-4C34-9575-9456856AEACC} | |||
{5CE18647-CEFB-483A-B384-99D4FB47DA29} = {0265A6CF-0D40-4A59-B6DF-2F25099DA95B} | |||
EndGlobalSection | |||
GlobalSection(ExtensibilityGlobals) = postSolution | |||
SolutionGuid = {7A177DC6-A13E-4628-97F6-40DC7573252A} | |||
EndGlobalSection | |||
EndGlobal | |||
EndGlobal |
@@ -1,4 +1,4 @@ | |||
<?xml version="1.0"?> | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
@@ -11,9 +11,10 @@ | |||
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.2.3" /> | |||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.2.3" /> | |||
<PackageReference Include="BPA.Component.CAP.RabbitMQ" Version="1.0.2" /> | |||
<PackageReference Include="BPA.Component.DTOCommon" Version="1.0.6" /> | |||
<PackageReference Include="BPA.Component.Extensions" Version="1.0.3" /> | |||
<PackageReference Include="BPA.Component.WebApiExtensions" Version="1.0.8" /> | |||
<PackageReference Include="BPA.Component.DTOCommon" Version="1.0.12" /> | |||
<PackageReference Include="BPA.Component.Extensions" Version="1.0.4" /> | |||
<PackageReference Include="BPA.Component.WebApiExtensions" Version="1.0.23" /> | |||
<ProjectReference Include="..\BPA.SaaS.Annex.Api.DTO\BPA.SaaS.Annex.Api.DTO.csproj" /> | |||
<ProjectReference Include="..\BPA.SaaS.Annex.Api.Model\BPA.SaaS.Annex.Api.Model.csproj" /> | |||
<ProjectReference Include="..\BPA.SaaS.Annex.Api.Service\BPA.SaaS.Annex.Api.Service.csproj" /> | |||
@@ -0,0 +1,132 @@ | |||
using System.Net.NetworkInformation; | |||
using System.Net.Sockets; | |||
using System.Text; | |||
using Autofac; | |||
using BPA.Component.ApolloClient; | |||
using BPA.Component.CAP; | |||
using BPA.Component.Extensions; | |||
using BPA.Component.LogClient.Extensions; | |||
using BPA.Component.SDKCommon; | |||
using BPA.Component.WebApiExtensions.Extensions; | |||
using BPA.SaaS.Annex.Api.Model; | |||
using Microsoft.AspNetCore.Builder; | |||
using Microsoft.AspNetCore.Diagnostics.HealthChecks; | |||
using Microsoft.AspNetCore.Http; | |||
using Microsoft.Extensions.Configuration; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using Microsoft.OpenApi.Models; | |||
using IPAddress = System.Net.IPAddress; | |||
namespace BPA.SaaS.Annex.Api.Bootstrap; | |||
/// <summary> | |||
/// 启动配置 | |||
/// </summary> | |||
public static class SetupBootstrap | |||
{ | |||
private static IConfiguration _configuration; | |||
/// <summary> | |||
/// 添加配置中心 | |||
/// </summary> | |||
/// <param name="configuration"></param> | |||
public static IConfiguration SetupConfiguration(this IConfiguration configuration) | |||
{ | |||
_configuration = configuration; | |||
// 初始化化 apollo配置 | |||
return configuration.AddApolloConfiguration(); | |||
} | |||
/// <summary> | |||
/// DI Inject | |||
/// </summary> | |||
public static IServiceCollection AddBPAMiddlewareServices(this IServiceCollection services, string[] args) | |||
{ | |||
if (services == null) throw new ArgumentNullException(nameof(services)); | |||
services.AddApollo<AnnexApiConfig>(); | |||
services.AddBPALog(); | |||
services.AddRedis(); | |||
services.AddRabbitMQ(); | |||
services.AddTransient(typeof(Lazy<>), typeof(BPADefaultLazy<>)); | |||
services.AddHttpContextAccessor(); | |||
services.AddControllers(options => { options.AddDefaultMvcOptions(); }); | |||
services.AddEndpointsApiExplorer(); | |||
services.AddServiceSDK(_configuration); | |||
services.AddHealthChecks(); | |||
services.AddSwaggerGen(options => | |||
{ | |||
options.SwaggerDoc("v1", new OpenApiInfo | |||
{ | |||
Title = AppDomain.CurrentDomain.FriendlyName, | |||
Description = AppDomain.CurrentDomain.FriendlyName, | |||
Version = "v1" | |||
}); | |||
options.CustomSchemaIds(type => type.GetDescribe(true, "BPA.", "BPA.SaaS.")); | |||
}); | |||
return services; | |||
} | |||
/// <summary> | |||
/// DI Register | |||
/// </summary> | |||
public static ContainerBuilder SetupConfigureContainer(this ContainerBuilder builder) | |||
{ | |||
// // 注入DB | |||
// builder.RegisterType<BasicDbSugarClient>().InstancePerLifetimeScope(); | |||
// | |||
// // 服务层 | |||
// builder.RegisterAssemblyTypes(typeof(HomeService).Assembly) | |||
// .Where(t => t.Name.EndsWith("Service")) | |||
// .AsImplementedInterfaces(); | |||
// | |||
// // 仓储层 | |||
// builder.RegisterAssemblyTypes(typeof(HomeRepository).Assembly) | |||
// .Where(t => t.Name.EndsWith("Repository")) | |||
// .AsImplementedInterfaces(); | |||
return builder; | |||
} | |||
/// <summary> | |||
/// pre run | |||
/// </summary> | |||
/// <param name="serviceProvider"></param> | |||
public static void PreHeatRun(this IServiceProvider serviceProvider) | |||
{ | |||
serviceProvider.GetService<AnnexApiConfig>(); | |||
serviceProvider.PreHeatRunRedis(); | |||
serviceProvider.PreHeatRunRabbitMQ(); | |||
serviceProvider.SetDebug(true); | |||
serviceProvider.GetService<ICapPublisher>(); | |||
} | |||
/// <summary> | |||
/// APP健康检查 | |||
/// </summary> | |||
/// <param name="app"></param> | |||
public static void UseBpaHealthChecks(this IApplicationBuilder app) | |||
{ | |||
var ips = new List<dynamic>(); | |||
foreach (var network in NetworkInterface.GetAllNetworkInterfaces()) | |||
{ | |||
var ipAddress = network.GetIPProperties() | |||
.UnicastAddresses | |||
.FirstOrDefault(p => p.Address.AddressFamily == AddressFamily.InterNetwork && !IPAddress.IsLoopback(p.Address)) | |||
?.Address.ToString(); | |||
if (ipAddress == null) | |||
continue; | |||
ips.Add(new {name = network.Name, ip = ipAddress}); | |||
} | |||
var ipsJson = ips.ToJson(); | |||
app.UseHealthChecks("/health", new HealthCheckOptions | |||
{ | |||
ResponseWriter = (httpContext, _) => httpContext.Response.WriteAsync(ipsJson, Encoding.UTF8) | |||
}); | |||
} | |||
} |
@@ -0,0 +1,46 @@ | |||
using BPA.Common.Infrastructure.BizLogs; | |||
using BPA.Common.Infrastructure.Queue; | |||
using BPA.Component.RabbitMQClient.Extensions; | |||
using BPA.Component.RabbitMQClient.Provider; | |||
using BPA.SaaS.Annex.Api.Model; | |||
using Microsoft.Extensions.DependencyInjection; | |||
namespace BPA.SaaS.Annex.Api.Bootstrap | |||
{ | |||
/// <summary> | |||
/// RabbitMQ配置 | |||
/// </summary> | |||
public static class SetupRabbitMqConfig | |||
{ | |||
/// <summary> | |||
/// 使用消息队列 | |||
/// </summary> | |||
/// <param name="services"></param> | |||
/// <returns></returns> | |||
public static IServiceCollection AddRabbitMQ(this IServiceCollection services) | |||
{ | |||
//注入 RabbitMQProvider | |||
services.AddRabbitMQProvider(sp => sp.GetService<AnnexApiConfig>()?.RabbitMqConfig); | |||
//注入 业务日志 生产者 | |||
services.AddRabbitMQProducer<BizLogProducer, BaseBizLogMsgBody>(); | |||
return services; | |||
} | |||
/// <summary> | |||
/// 预热消息队列 | |||
/// </summary> | |||
/// <param name="serviceProvider"></param> | |||
/// <returns></returns> | |||
public static IServiceProvider PreHeatRunRabbitMQ(this IServiceProvider serviceProvider) | |||
{ | |||
var rabbitMqProvider = serviceProvider.UseRabbitMQProvider<RabbitMQProvider>(); | |||
var exchangeConfig = rabbitMqProvider.BuildExchangeConfig(MqNameConfig.BizLogExchange); | |||
exchangeConfig.UseExchange(); | |||
exchangeConfig.UseProducer<BaseBizLogMsgBody, BizLogProducer>(); | |||
return serviceProvider; | |||
} | |||
} | |||
} |
@@ -0,0 +1,47 @@ | |||
using BPA.Component.RedisClient; | |||
using BPA.SaaS.Annex.Api.Model; | |||
using Microsoft.Extensions.DependencyInjection; | |||
namespace BPA.SaaS.Annex.Api.Bootstrap; | |||
/// <summary> | |||
/// redis DI配置 | |||
/// </summary> | |||
public static class SetupRedisConfig | |||
{ | |||
/// <summary> | |||
/// 注入redis | |||
/// </summary> | |||
/// <param name="services"></param> | |||
public static void AddRedis(this IServiceCollection services) | |||
{ | |||
services.UseRedisSingleton(sp => GetRedisSingletonConnectionString(sp.GetService<AnnexApiConfig>()!)); | |||
} | |||
/// <summary> | |||
/// 预热redis | |||
/// </summary> | |||
/// <param name="serviceProvider"></param> | |||
public static void PreHeatRunRedis(this IServiceProvider serviceProvider) | |||
{ | |||
var config = serviceProvider.GetService<AnnexApiConfig>(); | |||
// 添加配置改变时的事件 | |||
if (config != null) | |||
config.OnConfigChange += (stockWebApiConfig, key, _, _, _) => | |||
{ | |||
if (nameof(stockWebApiConfig.RedisConfig) != key) return; | |||
var conStr = GetRedisSingletonConnectionString(stockWebApiConfig); | |||
//单个redis时 配置变化 触发生成新的实例 | |||
RedisConfigExtensions.OnRedisSingletonConnectionStringChange(conStr); | |||
}; | |||
} | |||
/// <summary> | |||
/// 获取单例 Redis 连接字符串 | |||
/// </summary> | |||
/// <param name="config"></param> | |||
/// <returns></returns> | |||
private static string GetRedisSingletonConnectionString(AnnexApiConfig config) => config.RedisConfig[new Random().Next(0, config.RedisConfig.Count)]; | |||
} |
@@ -0,0 +1,47 @@ | |||
using BPA.Component.DTOCommon.Langs; | |||
using BPA.Component.SDKCommon; | |||
using Microsoft.Extensions.Configuration; | |||
using Microsoft.Extensions.DependencyInjection; | |||
namespace BPA.SaaS.Annex.Api.Bootstrap; | |||
/// <summary> | |||
/// 其他SDK服务 | |||
/// </summary> | |||
public static class SetupServiceSDK | |||
{ | |||
/// <summary> | |||
/// 注入其他SDK | |||
/// </summary> | |||
/// <param name="services"></param> | |||
/// <param name="configuration"></param> | |||
public static void AddServiceSDK(this IServiceCollection services, IConfiguration configuration) | |||
{ | |||
// 初始化sdk配置和语言获取 | |||
services.AddApiSDK(_ => /*sp.GetService<IHttpContextAccessor>()?.HttpContext?.Request.GetLanguage() ??*/ LangType.Zn); | |||
// 获取当前API启动时定义的环境 | |||
var environment = configuration.GetValue<string>("ASPNETCORE_ENVIRONMENT"); | |||
// 环境选择 | |||
switch (environment) | |||
{ | |||
case "Development": | |||
// 开发本地连集群 | |||
// services.AddApiSDK<WebApi2SDK>(_ => "http://[IP]:[port]"); | |||
// 开发集群环境内 | |||
// services.UseApiSDK<WebApi2SDK>(_ => "http://serviceName"); | |||
break; | |||
case "Production": | |||
// services.AddApiSDK<WebApi2SDK>(_ => "http://[domainName].com:[80]/[serviceName]"); | |||
break; | |||
case "Testing": | |||
// services.AddApiSDK<WebApi2SDK>(_ => "http://test.[domainName].com:[80]/[serviceName]/"); | |||
break; | |||
} | |||
} | |||
} |
@@ -0,0 +1,35 @@ | |||
using BPA.Component.DTOCommon.Langs; | |||
namespace BPA.SaaS.Annex.Api.DTO | |||
{ | |||
/// <summary> | |||
/// 基础信息服务多语言包,注入单例,不需要用lazy | |||
/// </summary> | |||
public class AnnexApiLangPackage : BaseLangPackge | |||
{ | |||
/// <summary> | |||
/// 企业附件空间不足 | |||
/// </summary> | |||
public Lang SpaceInadequate = Lang.Build(nameof(SpaceInadequate), "企业附件空间不足", "insufficient attachment space"); | |||
/// <summary> | |||
/// 签名已经过期 | |||
/// </summary> | |||
public Lang SignExpired = Lang.Build(nameof(SignExpired), "签名过期", "signature has expired"); | |||
/// <summary> | |||
/// 签名无效 | |||
/// </summary> | |||
public Lang SignInvalid = Lang.Build(nameof(SignInvalid), "签名无效", "signature is invalid"); | |||
/// <summary> | |||
/// 附件不存在 | |||
/// </summary> | |||
public Lang AnnexNotExist = Lang.Build(nameof(AnnexNotExist), "附件不存在", "annex not exist"); | |||
/// <summary> | |||
/// 删除附件错误 | |||
/// </summary> | |||
public Lang DeleteAnnexError = Lang.Build(nameof(DeleteAnnexError), "删除附件错误", "delete annex not error"); | |||
} | |||
} |
@@ -0,0 +1,26 @@ | |||
using BPA.Common.Enums.Annex; | |||
namespace BPA.SaaS.Annex.Api.DTO | |||
{ | |||
/// <summary> | |||
/// 根据附件ID获取base64 | |||
/// </summary> | |||
public class AnnexBase64ByAnnexIdReq | |||
{ | |||
/// <summary> | |||
/// 附件id | |||
/// </summary> | |||
public long AnnexId { get; set; } | |||
/// <summary> | |||
/// 业务类型 | |||
/// </summary> | |||
public EnumAnnexBusinessType BusinessType { set; get; } | |||
/// <summary> | |||
/// 业务ID | |||
/// </summary> | |||
public long BusinessId { set; get; } | |||
} | |||
} |
@@ -1,11 +1,15 @@ | |||
<?xml version="1.0"?> | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<Nullable>enable</Nullable> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
<VersionPrefix>1.0.2</VersionPrefix> | |||
<PackageReleaseNotes /> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="BPA.Component.DTOCommon" Version="1.0.5" /> | |||
<PackageReference Include="BPA.Common.Enums" Version="1.0.9" /> | |||
<PackageReference Include="BPA.Component.DTOCommon" Version="1.0.12" /> | |||
<PackageReference Include="Nuget.Tools.V2" Version="1.1.7" /> | |||
</ItemGroup> | |||
</Project> |
@@ -0,0 +1,13 @@ | |||
namespace BPA.SaaS.Annex.Api.DTO | |||
{ | |||
/// <summary> | |||
/// 验证附件是否真实有效 | |||
/// </summary> | |||
public class CheckFileIsVaildedReq | |||
{ | |||
/// <summary> | |||
/// 附件id | |||
/// </summary> | |||
public long Id { get; set; } | |||
} | |||
} |
@@ -0,0 +1,28 @@ | |||
namespace BPA.SaaS.Annex.Api.DTO | |||
{ | |||
/// <summary> | |||
/// 检查签名是否合法有效 | |||
/// </summary> | |||
public class CheckSignReq | |||
{ | |||
/// <summary> | |||
/// 企业ID Hex | |||
/// </summary> | |||
public string CorpIdHex { get; set; } | |||
/// <summary> | |||
/// 附件id | |||
/// </summary> | |||
public string AnnexId { get; set; } | |||
/// <summary> | |||
/// 时间戳 | |||
/// </summary> | |||
public string TimeSpan { get; set; } | |||
/// <summary> | |||
/// 签名key | |||
/// </summary> | |||
public string SignKey { get; set; } | |||
} | |||
} |
@@ -0,0 +1,25 @@ | |||
using BPA.Common.Enums.Annex; | |||
namespace BPA.SaaS.Annex.Api.DTO | |||
{ | |||
/// <summary> | |||
/// 删除附件 | |||
/// </summary> | |||
public class DeleteAnnexReq | |||
{ | |||
/// <summary> | |||
/// 附件关联业务类型 | |||
/// </summary> | |||
public EnumAnnexBusinessType BusinessType { set; get; } | |||
/// <summary> | |||
/// 关联业务对象ID | |||
/// </summary> | |||
public long BusinessId { set; get; } | |||
/// <summary> | |||
/// 是否物理删除 | |||
/// </summary> | |||
public bool IsPhysicalDelete { get; set; } = true; | |||
} | |||
} |
@@ -0,0 +1,13 @@ | |||
namespace BPA.SaaS.Annex.Api.DTO | |||
{ | |||
/// <summary> | |||
/// 根据附件id下载附件 | |||
/// </summary> | |||
public class DownloadFileByAnnexIdReq | |||
{ | |||
/// <summary> | |||
/// 附件id | |||
/// </summary> | |||
public long Id { get; set; } | |||
} | |||
} |
@@ -0,0 +1,13 @@ | |||
namespace BPA.SaaS.Annex.Api.DTO | |||
{ | |||
/// <summary> | |||
/// 下载附件 ,供系统内部使用不需要计算权限以及过期时间等等 | |||
/// </summary> | |||
public class DownloadFileForInsideReq | |||
{ | |||
/// <summary> | |||
/// 附件id | |||
/// </summary> | |||
public long AnnexId { get; set; } | |||
} | |||
} |
@@ -0,0 +1,14 @@ | |||
namespace BPA.SaaS.Annex.Api.DTO | |||
{ | |||
/// <summary> | |||
/// 获取指定附件详情 | |||
/// </summary> | |||
public class GetAnnexInfoReq | |||
{ | |||
/// <summary> | |||
/// 附件id | |||
/// </summary> | |||
public long Id { get; set; } | |||
} | |||
} |
@@ -0,0 +1,20 @@ | |||
using BPA.Common.Enums.Annex; | |||
namespace BPA.SaaS.Annex.Api.DTO | |||
{ | |||
/// <summary> | |||
/// 获取列表请求参数 | |||
/// </summary> | |||
public class GetListReq | |||
{ | |||
/// <summary> | |||
/// 业务类型 | |||
/// </summary> | |||
public EnumAnnexBusinessType BusinessType { set; get; } | |||
/// <summary> | |||
/// 业务ID | |||
/// </summary> | |||
public long BusinessId { set; get; } | |||
} | |||
} |
@@ -0,0 +1,27 @@ | |||
namespace BPA.SaaS.Annex.Api.DTO | |||
{ | |||
/// <summary> | |||
/// 添加文件时需要的参数 | |||
/// </summary> | |||
public class NewAnnexDTO | |||
{ | |||
/// <summary> | |||
/// 文件资URL | |||
/// </summary> | |||
public string Url { get; set; } | |||
/// <summary> | |||
/// 文件大小 | |||
/// </summary> | |||
public long FileSize { get; set; } | |||
/// <summary> | |||
/// 文件名称 | |||
/// </summary> | |||
public string FileName { get; set; } | |||
} | |||
} |
@@ -0,0 +1,25 @@ | |||
using BPA.Common.Enums.Annex; | |||
namespace BPA.SaaS.Annex.Api.DTO | |||
{ | |||
/// <summary> | |||
/// 删除指定的附件信息 | |||
/// </summary> | |||
public class RemoveAnnexByAnnexIdReq | |||
{ | |||
/// <summary> | |||
/// 附件id | |||
/// </summary> | |||
public long AnnexId { get; set; } | |||
/// <summary> | |||
/// 业务类型 | |||
/// </summary> | |||
public EnumAnnexBusinessType BusinessType { set; get; } | |||
/// <summary> | |||
/// 业务ID | |||
/// </summary> | |||
public long BusinessId { set; get; } | |||
} | |||
} |
@@ -0,0 +1,20 @@ | |||
using BPA.Common.Enums.Annex; | |||
namespace BPA.SaaS.Annex.Api.DTO | |||
{ | |||
/// <summary> | |||
/// 按照业务id来删除该业务数据下的所有附件 | |||
/// </summary> | |||
public class RemoveAnnexByBusinessIdReq | |||
{ | |||
/// <summary> | |||
/// 业务类型 | |||
/// </summary> | |||
public EnumAnnexBusinessType BusinessType { set; get; } | |||
/// <summary> | |||
/// 业务ID | |||
/// </summary> | |||
public long BusinessId { set; get; } | |||
} | |||
} |
@@ -0,0 +1,18 @@ | |||
namespace BPA.SaaS.Annex.Api.DTO | |||
{ | |||
/// <summary> | |||
/// 存储空间信息 | |||
/// </summary> | |||
public class StoreSpaceDTO | |||
{ | |||
/// <summary> | |||
/// 总共空间大小 | |||
/// </summary> | |||
public long TotalSize { get; set; } | |||
/// <summary> | |||
/// 已使用空间大小 | |||
/// </summary> | |||
public long UsedSize { get; set; } | |||
} | |||
} |
@@ -0,0 +1,55 @@ | |||
using BPA.Common.Enums.Annex; | |||
namespace BPA.SaaS.Annex.Api.DTO | |||
{ | |||
/// <summary> | |||
/// 详情或者其他场景上直接上传文件并转正 | |||
/// </summary> | |||
public class UploadAndConfirmReq | |||
{ | |||
/// <summary> | |||
/// 业务类型 | |||
/// </summary> | |||
public EnumAnnexBusinessType BusinessType { set; get; } | |||
/// <summary> | |||
/// 业务数据 | |||
/// </summary> | |||
public long BusinessId { get; set; } | |||
/// <summary> | |||
/// 职员id | |||
/// </summary> | |||
public long EmployeeId { get; set; } | |||
/// <summary> | |||
/// 职员名称 | |||
/// </summary> | |||
public string EmployeeName { get; set; } | |||
/// <summary> | |||
/// 微信id | |||
/// </summary> | |||
public string WeixinId { get; set; } | |||
/// <summary> | |||
/// 文件流 | |||
/// </summary> | |||
public Stream FileStream { get; set; } | |||
/// <summary> | |||
/// 文件流类型 | |||
/// </summary> | |||
public string ContentType { get; set; } | |||
/// <summary> | |||
/// 文件名称 | |||
/// </summary> | |||
public string FileName { get; set; } | |||
/// <summary> | |||
/// 文件容量 | |||
/// </summary> | |||
public long Length { get; set; } | |||
} | |||
} |
@@ -0,0 +1,40 @@ | |||
using BPA.Common.Enums.Annex; | |||
namespace BPA.SaaS.Annex.Api.DTO | |||
{ | |||
/// <summary> | |||
/// 数据保存的时候处理附件保存请求参数 | |||
/// </summary> | |||
public class UploadAnnexReq | |||
{ | |||
/// <summary> | |||
/// 企业ID | |||
/// </summary> | |||
public long CorpId { get; set; } | |||
/// <summary> | |||
/// 职员ID | |||
/// </summary> | |||
public long EmployeeId { get; set; } | |||
/// <summary> | |||
/// 附件关联业务类型 | |||
/// </summary> | |||
public EnumAnnexBusinessType BusinessType { set; get; } | |||
/// <summary> | |||
/// 关联业务对象ID | |||
/// </summary> | |||
public long BusinessId { set; get; } | |||
/// <summary> | |||
/// 新增的附件 | |||
/// </summary> | |||
public List<long> NewFiles { set; get; } | |||
/// <summary> | |||
/// 需要被删除的附件ID | |||
/// </summary> | |||
public List<long> RemoveFileIds { set; get; } | |||
} | |||
} |
@@ -0,0 +1,49 @@ | |||
namespace BPA.SaaS.Annex.Api.DTO | |||
{ | |||
/// <summary> | |||
/// 上传临时文件 | |||
/// </summary> | |||
public class UploadTemporaryFileReq | |||
{ | |||
/// <summary> | |||
/// 企业id | |||
/// </summary> | |||
public long CorpId { get; set; } | |||
/// <summary> | |||
/// 职员id | |||
/// </summary> | |||
public long EmployeeId { get; set; } | |||
/// <summary> | |||
/// 职员名称 | |||
/// </summary> | |||
public string EmployeeName { get; set; } | |||
/// <summary> | |||
/// 微信id | |||
/// </summary> | |||
public string WeixinId { get; set; } | |||
/// <summary> | |||
/// 文件流 | |||
/// </summary> | |||
public Stream FileStream { get; set; } | |||
/// <summary> | |||
/// 文件流类型 | |||
/// </summary> | |||
public string ContentType { get; set; } | |||
/// <summary> | |||
/// 文件名称 | |||
/// </summary> | |||
public string FileName { get; set; } | |||
/// <summary> | |||
/// 文件容量 | |||
/// </summary> | |||
public long Length { get; set; } | |||
} | |||
} |
@@ -0,0 +1,45 @@ | |||
using BPA.Common.Enums.Annex; | |||
namespace BPA.SaaS.Annex.Api.Entity | |||
{ | |||
/// <summary> | |||
/// 附件表 | |||
/// </summary> | |||
public class BPA_Annex | |||
{ | |||
/// <summary> | |||
/// 业务类型 | |||
/// </summary> | |||
public EnumAnnexBusinessType BusinessType { set; get; } | |||
/// <summary> | |||
/// 业务ID | |||
/// </summary> | |||
public long BusinessId { set; get; } | |||
/// <summary> | |||
/// 文件名称 | |||
/// </summary> | |||
public string FileName { get; set; } | |||
/// <summary> | |||
/// 文件类型 | |||
/// </summary> | |||
public EnumAnnexType FileType { get; set; } | |||
/// <summary> | |||
/// 文件扩展名 | |||
/// </summary> | |||
public string FileExtName { get; set; } | |||
/// <summary> | |||
/// 文件容量 | |||
/// </summary> | |||
public long FileSize { get; set; } | |||
/// <summary> | |||
/// cos文件key | |||
/// </summary> | |||
public string CosFileKey { get; set; } | |||
} | |||
} |
@@ -1,11 +1,17 @@ | |||
<?xml version="1.0"?> | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<Nullable>enable</Nullable> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="BPA.Common.Entity" Version="1.0.2" /> | |||
</ItemGroup> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<Nullable>enable</Nullable> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> | |||
<NoWarn>1701;1702;8618</NoWarn> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="BPA.Common.Entity" Version="1.0.6" /> | |||
<PackageReference Include="BPA.Common.Enums" Version="1.0.9" /> | |||
<PackageReference Include="BPA.Component.DbClient" Version="1.0.27" /> | |||
<PackageReference Include="BPA.Component.MongoClient" Version="1.0.12" /> | |||
</ItemGroup> | |||
</Project> |
@@ -1,4 +1,4 @@ | |||
<?xml version="1.0"?> | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
@@ -6,7 +6,8 @@ | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="BPA.Component.DbClient" Version="1.0.6" /> | |||
<PackageReference Include="BPA.Component.DbClient" Version="1.0.27" /> | |||
<ProjectReference Include="..\BPA.SaaS.Annex.Api.DTO\BPA.SaaS.Annex.Api.DTO.csproj" /> | |||
<ProjectReference Include="..\BPA.SaaS.Annex.Api.Model\BPA.SaaS.Annex.Api.Model.csproj" /> | |||
<ProjectReference Include="..\BPA.SaaS.Annex.Api.Entity\BPA.SaaS.Annex.Api.Entity.csproj" /> | |||
@@ -0,0 +1,8 @@ | |||
using BPA.Component.MongoClient.Repository; | |||
using BPA.SaaS.Annex.Api.Entity; | |||
namespace BPA.SaaS.Annex.Api.IRepository; | |||
public interface IAnnexRepository : IBaseMongoDbRepository<BPA_Annex> | |||
{ | |||
} |
@@ -1,11 +1,14 @@ | |||
<?xml version="1.0"?> | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<Nullable>enable</Nullable> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\BPA.SaaS.Annex.Api.DTO\BPA.SaaS.Annex.Api.DTO.csproj" /> | |||
</ItemGroup> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<Nullable>enable</Nullable> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\BPA.SaaS.Annex.Api.DTO\BPA.SaaS.Annex.Api.DTO.csproj" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<PackageReference Include="BPA.Component.DTOCommon" Version="1.0.12" /> | |||
</ItemGroup> | |||
</Project> |
@@ -0,0 +1,66 @@ | |||
using BPA.Component.DTOCommon.BaseDTOs; | |||
using BPA.SaaS.Annex.Api.DTO; | |||
namespace BPA.SaaS.Annex.Api.IService | |||
{ | |||
/// <summary> | |||
/// 附件服务 | |||
/// </summary> | |||
public interface IAnnexService | |||
{ | |||
/// <summary> | |||
/// 获取附件列表 | |||
/// </summary> | |||
/// <param name="req"></param> | |||
/// <returns></returns> | |||
BaseResult<List<AnnexInfoDTO>> GetList(GetListReq req); | |||
/// <summary> | |||
/// 删除指定业务数据的所有附件信息 | |||
/// </summary> | |||
/// <param name="req"></param> | |||
/// <returns></returns> | |||
BaseResult<bool> RemoveAnnexByBusinessId(RemoveAnnexByBusinessIdReq req); | |||
/// <summary> | |||
/// 删除指定的附件信息 | |||
/// </summary> | |||
/// <param name="req"></param> | |||
/// <returns></returns> | |||
BaseResult<bool> RemoveAnnexByAnnexId(RemoveAnnexByAnnexIdReq req); | |||
/// <summary> | |||
/// 上传附件 | |||
/// </summary> | |||
/// <param name="req"></param> | |||
/// <returns></returns> | |||
BaseResult<bool> Upload(UploadAnnexReq req); | |||
/// <summary> | |||
/// 获取附件详情 | |||
/// </summary> | |||
/// <param name="req"></param> | |||
/// <returns></returns> | |||
BaseResult<AnnexInfoDTO> GetAnnexInfo(GetAnnexInfoReq req); | |||
/// <summary> | |||
/// 清理无效的文件 | 定时任务调用 | |||
/// </summary> | |||
/// <returns></returns> | |||
BaseResult<bool> ClearTemporaryFile(); | |||
/// <summary> | |||
/// 验证文件是否真实有效 | 定时任务调用 | |||
/// </summary> | |||
/// <param name="req"></param> | |||
/// <returns></returns> | |||
BaseResult<bool> CheckFileIsVailded(CheckFileIsVaildedReq req); | |||
/// <summary> | |||
/// 根据附件id下载附件 | |||
/// </summary> | |||
/// <param name="Id">附件id</param> | |||
/// <returns></returns> | |||
(byte[], string) DownloadFileByAnnexId(long Id); | |||
} | |||
} |
@@ -0,0 +1,118 @@ | |||
using BPA.Component.ApolloClient; | |||
using BPA.Component.MongoClient; | |||
using Com.Ctrip.Framework.Apollo; | |||
using Microsoft.Extensions.Configuration; | |||
namespace BPA.SaaS.Annex.Api.Model | |||
{ | |||
/// <summary> | |||
/// 全局配置 | |||
/// </summary> | |||
public class AnnexApiConfig : ApolloBPAConfig<AnnexApiConfig> | |||
{ | |||
/// <summary> | |||
/// MongoDB [附件] 库群 | |||
/// </summary> | |||
[AutoWrite] | |||
public List<MongoConfig> MongoDBAnnexs { get; protected set; } | |||
/// <summary> | |||
/// 腾讯Cos AppId | |||
/// </summary> | |||
[AutoWrite] | |||
public string TencentCosAppId { protected set; get; } | |||
/// <summary> | |||
/// 腾讯Cos secretId | |||
/// </summary> | |||
[AutoWrite] | |||
public string TencentCosSecretId { protected set; get; } | |||
/// <summary> | |||
/// 腾讯Cos secretKey | |||
/// </summary> | |||
[AutoWrite] | |||
public string TencentCosSecretKey { protected set; get; } | |||
/// <summary> | |||
/// 腾讯Cos bucket | |||
/// </summary> | |||
[AutoWrite] | |||
public string TencentCosBucket { protected set; get; } | |||
/// <summary> | |||
/// 腾讯Cos region | |||
/// </summary> | |||
[AutoWrite] | |||
public string TencentCosRegion { protected set; get; } | |||
/// <summary> | |||
/// 腾讯Cos 每次请求签名有效时长,单位为秒 | |||
/// </summary> | |||
public long TencentCosDurationSecond { protected set; get; } = 600; | |||
/// <summary> | |||
/// 文档文件扩展名集合 | |||
/// </summary> | |||
[AutoWrite] | |||
public List<string> DocFileExtensions { get; protected set; } = new(); | |||
/// <summary> | |||
/// 压缩文件扩展名集合 | |||
/// </summary> | |||
[AutoWrite] | |||
public List<string> CompressFieldExtensions { get; protected set; } = new(); | |||
/// <summary> | |||
/// 图片文件扩展名集合 | |||
/// </summary> | |||
[AutoWrite] | |||
public List<string> ImageFieldExtensions { get; protected set; } = new(); | |||
/// <summary> | |||
/// 视频文件扩展名集合 | |||
/// </summary> | |||
[AutoWrite] | |||
public List<string> VideoFileExtensions { get; protected set; } = new(); | |||
/// <summary> | |||
/// 音频文件扩展名集合 | |||
/// </summary> | |||
[AutoWrite] | |||
public List<string> AudioFileExtensions { get; protected set; } = new(); | |||
/// <summary> | |||
/// 附件url加密key | |||
/// </summary> | |||
[AutoWrite] | |||
public string SignKey { get; set; } | |||
/// <summary> | |||
/// 附件下载地址 | |||
/// </summary> | |||
[AutoWrite] | |||
public string DownloadUrl { get; set; } | |||
/// <summary> | |||
/// 预览地址 | |||
/// </summary> | |||
[AutoWrite] | |||
public string PreviewUrl { get; set; } | |||
/// <summary> | |||
/// 浏览器可预览的附件类型 | |||
/// </summary> | |||
[AutoWrite] | |||
public List<string> PreviewInBrowserFile { get; set; } | |||
/// <summary> | |||
/// CRMBasicApiConfig | |||
/// </summary> | |||
/// <param name="apolloConfigurationManager"></param> | |||
/// <param name="configuration"></param> | |||
public AnnexApiConfig(ApolloConfigurationManager apolloConfigurationManager, IConfiguration configuration) | |||
: base(apolloConfigurationManager, configuration) | |||
{ | |||
} | |||
} | |||
} |
@@ -1,17 +1,27 @@ | |||
<?xml version="1.0"?> | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<Nullable>enable</Nullable> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> | |||
<NoWarn>1701;1702;0618;8618</NoWarn> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> | |||
<NoWarn>1701;1702;0618</NoWarn> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="BPA.Component.ApolloClient" Version="1.0.3" /> | |||
<PackageReference Include="BPA.Common.Enums" Version="1.0.9" /> | |||
<PackageReference Include="BPA.Common.Infrastructure" Version="1.0.12" /> | |||
<PackageReference Include="BPA.Component.ApolloClient" Version="1.0.9" /> | |||
<PackageReference Include="BPA.Component.DTOCommon" Version="1.0.12" /> | |||
<PackageReference Include="BPA.Component.LogClient" Version="1.0.3" /> | |||
<PackageReference Include="BPA.Component.MongoClient" Version="1.0.3" /> | |||
<PackageReference Include="BPA.Component.MongoClient" Version="1.0.12" /> | |||
<PackageReference Include="BPA.Component.RabbitMQClient" Version="1.0.7" /> | |||
<PackageReference Include="BPA.Component.RedisClient" Version="1.0.3" /> | |||
<PackageReference Include="BPA.Component.Extensions" Version="1.0.3" /> | |||
<PackageReference Include="BPA.Component.DbClient" Version="1.0.6" /> | |||
<PackageReference Include="BPA.Component.Extensions" Version="1.0.4" /> | |||
<PackageReference Include="BPA.Component.DbClient" Version="1.0.27" /> | |||
<PackageReference Include="BPA.Component.WebApiExtensions" Version="1.0.23" /> | |||
</ItemGroup> | |||
</Project> |
@@ -1,4 +1,4 @@ | |||
<?xml version="1.0"?> | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
@@ -6,9 +6,13 @@ | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="BPA.Component.Extensions" Version="1.0.3" /> | |||
<PackageReference Include="BPA.Common.Enums" Version="1.0.9" /> | |||
<PackageReference Include="BPA.Component.DbClient" Version="1.0.27" /> | |||
<PackageReference Include="BPA.Component.DTOCommon" Version="1.0.12" /> | |||
<PackageReference Include="BPA.Component.Extensions" Version="1.0.4" /> | |||
<PackageReference Include="BPA.Component.SDKCommon" Version="1.0.3" /> | |||
<PackageReference Include="BPA.Common.Entity" Version="1.0.2" /> | |||
<PackageReference Include="BPA.Common.Entity" Version="1.0.6" /> | |||
<ProjectReference Include="..\BPA.SaaS.Annex.Api.DTO\BPA.SaaS.Annex.Api.DTO.csproj" /> | |||
<ProjectReference Include="..\BPA.SaaS.Annex.Api.Model\BPA.SaaS.Annex.Api.Model.csproj" /> | |||
<ProjectReference Include="..\BPA.SaaS.Annex.Api.Entity\BPA.SaaS.Annex.Api.Entity.csproj" /> | |||
@@ -1,4 +1,4 @@ | |||
<?xml version="1.0"?> | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
@@ -6,8 +6,9 @@ | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\BPA.SaaS.Annex.Api.DTO\BPA.SaaS.Annex.Api.DTO.csproj" /> | |||
<ProjectReference Include="..\BPA.SaaS.Annex.Api.IService\BPA.SaaS.Annex.Api.IService.csproj" /> | |||
<PackageReference Include="BPA.SaaS.Annex.Api.DTO" Version="1.0.1" /> | |||
<PackageReference Include="BPA.Component.DTOCommon" Version="1.0.12" /> | |||
<PackageReference Include="BPA.Component.SDKCommon" Version="1.0.3" /> | |||
<PackageReference Include="Nuget.Tools.V2" Version="1.1.7" /> | |||
</ItemGroup> | |||
</Project> |
@@ -1,4 +1,4 @@ | |||
<?xml version="1.0"?> | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
@@ -6,8 +6,15 @@ | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="BPA.Component.Extensions" Version="1.0.3" /> | |||
<PackageReference Include="BPA.Common.Infrastructure" Version="1.0.12" /> | |||
<PackageReference Include="BPA.Component.DTOCommon" Version="1.0.12" /> | |||
<PackageReference Include="BPA.Component.Extensions" Version="1.0.4" /> | |||
<PackageReference Include="BPA.Component.SDKCommon" Version="1.0.3" /> | |||
<PackageReference Include="BPA.Component.WebApiExtensions" Version="1.0.23" /> | |||
<PackageReference Include="BPA.SaaS.Basic.Api.DTO" Version="1.0.1" /> | |||
<PackageReference Include="BPA.SaaS.Basic.Api.SDK" Version="1.0.8" /> | |||
<PackageReference Include="Tencent.QCloud.Cos.Sdk" Version="5.4.22" /> | |||
<ProjectReference Include="..\BPA.SaaS.Annex.Api.DTO\BPA.SaaS.Annex.Api.DTO.csproj" /> | |||
<ProjectReference Include="..\BPA.SaaS.Annex.Api.Model\BPA.SaaS.Annex.Api.Model.csproj" /> | |||
<ProjectReference Include="..\BPA.SaaS.Annex.Api.IRepository\BPA.SaaS.Annex.Api.IRepository.csproj" /> | |||
@@ -0,0 +1,159 @@ | |||
using BPA.Common.Enums.Annex; | |||
using BPA.Component.DTOCommon.BaseDTOs; | |||
using BPA.Component.Extensions; | |||
using BPA.SaaS.Annex.Api.DTO; | |||
using BPA.SaaS.Annex.Api.IRepository; | |||
using BPA.SaaS.Annex.Api.IService; | |||
using BPA.SaaS.Annex.Api.Model; | |||
using BPA.SaaS.Basic.Api.SDK; | |||
using COSXML; | |||
using Microsoft.Extensions.Logging; | |||
namespace BPA.SaaS.Annex.Api.Service; | |||
/// <summary> | |||
/// 附件服务 | |||
/// </summary> | |||
public class CorpAnnexService : IAnnexService | |||
{ | |||
private readonly ILogger<CorpAnnexService> _logger; | |||
private readonly AnnexApiLangPackage _langPackage; | |||
private readonly Lazy<CosXml> _cosXml; | |||
private readonly AnnexApiConfig _annexApiConfig; | |||
private readonly Lazy<IAnnexRepository> _annexRepository; | |||
private readonly Lazy<BasicWebApiSDK> _basicWebApiSDK; | |||
public CorpAnnexService(ILogger<CorpAnnexService> logger, | |||
AnnexApiLangPackage langPackage, | |||
AnnexApiConfig annexApiConfig, | |||
Lazy<CosXml> cosXml, | |||
Lazy<IAnnexRepository> annexRepository, | |||
Lazy<BasicWebApiSDK> basicWebApiSDK) | |||
{ | |||
_logger = logger; | |||
_langPackage = langPackage; | |||
_cosXml = cosXml; | |||
_annexApiConfig = annexApiConfig; | |||
_annexRepository = annexRepository; | |||
_basicWebApiSDK = basicWebApiSDK; | |||
} | |||
public BaseResult<List<AnnexInfoDTO>> GetList(GetListReq req) | |||
{ | |||
var result = _annexRepository.Value.Queryable() | |||
.Where(a => a.BusinessType == req.BusinessType && a.BusinessId == req.BusinessId) | |||
.Select(a => new AnnexInfoDTO | |||
{ | |||
BusinessId = a.BusinessId, | |||
BusinessType = a.BusinessType, | |||
CreateDate = a.CreateDate, | |||
CreatorName = a.Creator.Name, | |||
CreatorWeChatId = a.Creator.WeChatId, | |||
FileExtName = a.FileExtName, | |||
FileName = a.FileName, | |||
FileSize = a.FileSize, | |||
FileType = a.FileType, | |||
Id = a.Id, | |||
}).ToList(); | |||
throw new NotImplementedException(); | |||
} | |||
public BaseResult<bool> RemoveAnnexByBusinessId(RemoveAnnexByBusinessIdReq req) | |||
{ | |||
throw new NotImplementedException(); | |||
} | |||
public BaseResult<bool> RemoveAnnexByAnnexId(RemoveAnnexByAnnexIdReq req) | |||
{ | |||
throw new NotImplementedException(); | |||
} | |||
public BaseResult<bool> Upload(UploadAnnexReq req) | |||
{ | |||
throw new NotImplementedException(); | |||
} | |||
public BaseResult<AnnexInfoDTO> GetAnnexInfo(GetAnnexInfoReq req) | |||
{ | |||
throw new NotImplementedException(); | |||
} | |||
public BaseResult<bool> ClearTemporaryFile() | |||
{ | |||
throw new NotImplementedException(); | |||
} | |||
public BaseResult<bool> CheckFileIsVailded(CheckFileIsVaildedReq req) | |||
{ | |||
throw new NotImplementedException(); | |||
} | |||
public (byte[], string) DownloadFileByAnnexId(long Id) | |||
{ | |||
throw new NotImplementedException(); | |||
} | |||
#region private | |||
/// <summary> | |||
/// 获取文件类型 | |||
/// </summary> | |||
/// <param name="extension"></param> | |||
/// <returns></returns> | |||
private EnumAnnexType GetAnnexType(string extension) | |||
{ | |||
extension = extension.ToLower(); | |||
if (_annexApiConfig.DocFileExtensions.Contains(extension)) | |||
return EnumAnnexType.Doc; | |||
if (_annexApiConfig.AudioFileExtensions.Contains(extension)) | |||
return EnumAnnexType.Audio; | |||
if (_annexApiConfig.VideoFileExtensions.Contains(extension)) | |||
return EnumAnnexType.Video; | |||
if (_annexApiConfig.ImageFieldExtensions.Contains(extension)) | |||
return EnumAnnexType.Image; | |||
return _annexApiConfig.CompressFieldExtensions.Contains(extension) | |||
? EnumAnnexType.Compress | |||
: EnumAnnexType.Unknow; | |||
} | |||
/// <summary> | |||
/// 处理文件容量大小的字符串 | |||
/// </summary> | |||
/// <param name="fileSize"></param> | |||
/// <returns></returns> | |||
private string GetFileSizeChar(long fileSize) | |||
{ | |||
var size = (double) fileSize / 1024; | |||
if (size < 1024) return Math.Round(size, 2) + "KB"; | |||
size /= 1024; | |||
if (size < 1024) return Math.Round(size, 2) + "MB"; | |||
size /= 1024; | |||
return Math.Round(size, 2) + "GB"; | |||
} | |||
/// <summary> | |||
/// 附件url签名 | |||
/// </summary> | |||
/// <returns></returns> | |||
private string Sign(AnnexInfoDTO annexInfo, long corpId, long? timespan) | |||
{ | |||
return $"{corpId.ToHex()}{annexInfo.Id.ToHex()}{annexInfo.FileExtName}{timespan}{_annexApiConfig.SignKey}".Md5(); | |||
} | |||
/// <summary> | |||
/// 附件url签名 | |||
/// </summary> | |||
/// <returns></returns> | |||
private string Sign(string annexId, string corpIdHex, string timespan) | |||
{ | |||
return $"{corpIdHex}{annexId}{timespan}{_annexApiConfig.SignKey}".Md5(); | |||
} | |||
#endregion | |||
} |
@@ -1,4 +1,4 @@ | |||
<?xml version="1.0"?> | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project Sdk="Microsoft.NET.Sdk.Web"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
@@ -1,8 +1,40 @@ | |||
using Autofac; | |||
using Autofac.Extensions.DependencyInjection; | |||
using BPA.Component.WebApiExtensions.Extensions; | |||
using BPA.Component.WebApiExtensions.Middlewares; | |||
using BPA.SaaS.Annex.Api.Bootstrap; | |||
using Microsoft.AspNetCore.Mvc; | |||
var builder = WebApplication.CreateBuilder(args); | |||
builder.Services.AddControllers(); | |||
builder.Configuration.SetupConfiguration(); | |||
// DI | |||
builder.Services.AddBPAMiddlewareServices(args); | |||
// DI config | |||
builder.Services.Configure<ApiBehaviorOptions>(options => { options.AddDefaultBehaviorOptions(); }); | |||
// Use Autofac | |||
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory()); | |||
builder.Host.ConfigureContainer<ContainerBuilder>(containerBuilder => { containerBuilder.SetupConfigureContainer(); }); | |||
var app = builder.Build(); | |||
if (app.Environment.IsDevelopment()) | |||
{ | |||
app.UseSwagger(); | |||
app.UseSwaggerUI(); | |||
} | |||
// Use module | |||
app.UseRouting(); | |||
app.UseHttpsRedirection(); | |||
app.UseAuthorization(); | |||
app.UseBpaHealthChecks(); | |||
app.MapControllers(); | |||
app.Run(); | |||
app.UseGlobalErrorHandler(); | |||
app.UseMiddleware<BizLogQueryMiddleware>(); | |||
// PreRun | |||
((IApplicationBuilder) app).ApplicationServices.PreHeatRun(); | |||
app.Run(); |
@@ -1,30 +1,17 @@ | |||
{ | |||
"$schema": "https://json.schemastore.org/launchsettings.json", | |||
"iisSettings": { | |||
"windowsAuthentication": false, | |||
"anonymousAuthentication": true, | |||
"iisExpress": { | |||
"applicationUrl": "http://localhost:11305", | |||
"sslPort": 44315 | |||
} | |||
}, | |||
"profiles": { | |||
"BPA.SaaS.Stock.Api": { | |||
"BPA.SaaS.Annex.Api": { | |||
"commandName": "Project", | |||
"dotnetRunMessages": true, | |||
"launchBrowser": true, | |||
"launchUrl": "weatherforecast", | |||
"applicationUrl": "https://localhost:7047;http://localhost:5047", | |||
"environmentVariables": { | |||
"ASPNETCORE_ENVIRONMENT": "Development" | |||
} | |||
}, | |||
"IIS Express": { | |||
"commandName": "IISExpress", | |||
"launchBrowser": true, | |||
"launchUrl": "weatherforecast", | |||
"launchUrl": "swagger", | |||
"applicationUrl": "http://localhost:5047", | |||
"environmentVariables": { | |||
"ASPNETCORE_ENVIRONMENT": "Development" | |||
"ASPNETCORE_ENVIRONMENT": "Development", | |||
"APOLLO_META_SERVER_URL": "http://10.2.1.21:28080", | |||
"APOLLO_COMMON_NAMESPACE": "DEV.Common", | |||
"APP_NAME": "BPA.SaaS.Annex.Api" | |||
} | |||
} | |||
} | |||
@@ -1,8 +0,0 @@ | |||
{ | |||
"Logging": { | |||
"LogLevel": { | |||
"Default": "Information", | |||
"Microsoft.AspNetCore": "Warning" | |||
} | |||
} | |||
} |
@@ -1,9 +0,0 @@ | |||
{ | |||
"Logging": { | |||
"LogLevel": { | |||
"Default": "Information", | |||
"Microsoft.AspNetCore": "Warning" | |||
} | |||
}, | |||
"AllowedHosts": "*" | |||
} |