😎1、代码优化 2、升级依赖及升级.NET9.0

This commit is contained in:
zuohuaijun 2024-11-15 15:19:53 +08:00
parent 0ea36ba9cb
commit e75edd5536
15 changed files with 426 additions and 436 deletions

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks> <TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
<NoWarn>1701;1702;1591;8632</NoWarn> <NoWarn>1701;1702;1591;8632</NoWarn>
<DocumentationFile></DocumentationFile> <DocumentationFile></DocumentationFile>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>

View File

@ -22,8 +22,7 @@
"ThrowBah": true, // Oops.Oh "ThrowBah": true, // Oops.Oh
"LogError": false // "LogError": false //
}, },
// (访) // (访)".*": "application/octet-stream"访
// ".*": "application/octet-stream"访
"StaticContentTypeMappings": { "StaticContentTypeMappings": {
".dll": "application/octet-stream", ".dll": "application/octet-stream",
".exe": "application/octet-stream", ".exe": "application/octet-stream",

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks> <TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
<NoWarn>1701;1702;1591;8632</NoWarn> <NoWarn>1701;1702;1591;8632</NoWarn>
<DocumentationFile></DocumentationFile> <DocumentationFile></DocumentationFile>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
@ -18,9 +18,9 @@
<PackageReference Include="AspectCore.Extensions.Reflection" Version="2.4.0" /> <PackageReference Include="AspectCore.Extensions.Reflection" Version="2.4.0" />
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" /> <PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.15.10" /> <PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.15.10" />
<PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.5.18" /> <PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.5.21" />
<PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.5.18" /> <PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.5.21" />
<PackageReference Include="Furion.Pure" Version="4.9.5.18" /> <PackageReference Include="Furion.Pure" Version="4.9.5.21" />
<PackageReference Include="Hardware.Info" Version="101.0.0" /> <PackageReference Include="Hardware.Info" Version="101.0.0" />
<PackageReference Include="Hashids.net" Version="1.7.0" /> <PackageReference Include="Hashids.net" Version="1.7.0" />
<PackageReference Include="IPTools.China" Version="1.6.0" /> <PackageReference Include="IPTools.China" Version="1.6.0" />
@ -43,9 +43,9 @@
<PackageReference Include="SKIT.FlurlHttpClient.Wechat.Api" Version="3.6.0" /> <PackageReference Include="SKIT.FlurlHttpClient.Wechat.Api" Version="3.6.0" />
<PackageReference Include="SKIT.FlurlHttpClient.Wechat.TenpayV3" Version="3.9.0" /> <PackageReference Include="SKIT.FlurlHttpClient.Wechat.TenpayV3" Version="3.9.0" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.170" /> <PackageReference Include="SqlSugarCore" Version="5.1.4.170" />
<PackageReference Include="SSH.NET" Version="2024.1.0" /> <PackageReference Include="SSH.NET" Version="2024.2.0" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.4.8" /> <PackageReference Include="System.Linq.Dynamic.Core" Version="1.4.8" />
<PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1120" /> <PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1123" />
<PackageReference Include="UAParser" Version="3.1.47" /> <PackageReference Include="UAParser" Version="3.1.47" />
<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" /> <PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
</ItemGroup> </ItemGroup>
@ -54,9 +54,9 @@
<PackageReference Include="AspNet.Security.OAuth.Gitee" Version="6.0.15" /> <PackageReference Include="AspNet.Security.OAuth.Gitee" Version="6.0.15" />
<PackageReference Include="AspNet.Security.OAuth.Weixin" Version="6.0.15" /> <PackageReference Include="AspNet.Security.OAuth.Weixin" Version="6.0.15" />
<PackageReference Include="Lazy.Captcha.Core" Version="2.0.6" /> <PackageReference Include="Lazy.Captcha.Core" Version="2.0.6" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="6.0.33" /> <PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="6.0.36" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="6.0.33" /> <PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="6.0.36" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="6.0.33" /> <PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="6.0.36" />
<PackageReference Include="OnceMi.AspNetCore.OSS" Version="1.1.9" /> <PackageReference Include="OnceMi.AspNetCore.OSS" Version="1.1.9" />
</ItemGroup> </ItemGroup>
@ -64,9 +64,19 @@
<PackageReference Include="AspNet.Security.OAuth.Gitee" Version="8.3.0" /> <PackageReference Include="AspNet.Security.OAuth.Gitee" Version="8.3.0" />
<PackageReference Include="AspNet.Security.OAuth.Weixin" Version="8.3.0" /> <PackageReference Include="AspNet.Security.OAuth.Weixin" Version="8.3.0" />
<PackageReference Include="Lazy.Captcha.Core" Version="2.0.9" /> <PackageReference Include="Lazy.Captcha.Core" Version="2.0.9" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="8.0.10" /> <PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="8.0.11" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="8.0.10" /> <PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="8.0.11" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="8.0.10" /> <PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="8.0.11" />
<PackageReference Include="OnceMi.AspNetCore.OSS" Version="1.2.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
<PackageReference Include="AspNet.Security.OAuth.Gitee" Version="9.0.0" />
<PackageReference Include="AspNet.Security.OAuth.Weixin" Version="9.0.0" />
<PackageReference Include="Lazy.Captcha.Core" Version="2.0.9" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="9.0.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="9.0.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="9.0.0" />
<PackageReference Include="OnceMi.AspNetCore.OSS" Version="1.2.0" /> <PackageReference Include="OnceMi.AspNetCore.OSS" Version="1.2.0" />
</ItemGroup> </ItemGroup>

View File

@ -11,25 +11,21 @@ public class CreateEntityInput
/// <summary> /// <summary>
/// 表名 /// 表名
/// </summary> /// </summary>
/// <example>student</example>
public string TableName { get; set; } public string TableName { get; set; }
/// <summary> /// <summary>
/// 实体名 /// 实体名
/// </summary> /// </summary>
/// <example>Student</example>
public string EntityName { get; set; } public string EntityName { get; set; }
/// <summary> /// <summary>
/// 基类名 /// 基类名
/// </summary> /// </summary>
/// <example>AutoIncrementEntity</example>
public string BaseClassName { get; set; } public string BaseClassName { get; set; }
/// <summary> /// <summary>
/// 导出位置 /// 导出位置
/// </summary> /// </summary>
/// <example>Web.Application</example>
public string Position { get; set; } public string Position { get; set; }
/// <summary> /// <summary>

View File

@ -16,38 +16,33 @@ public class CreateSeedDataInput
/// <summary> /// <summary>
/// 表名 /// 表名
/// </summary> /// </summary>
/// <example>student</example>
public string TableName { get; set; } public string TableName { get; set; }
/// <summary> /// <summary>
/// 实体名称 /// 实体名称
/// </summary> /// </summary>
/// <example>Student</example>
public string EntityName { get; set; } public string EntityName { get; set; }
/// <summary> /// <summary>
/// 种子名称 /// 种子名称
/// </summary> /// </summary>
/// <example>Student</example>
public string SeedDataName { get; set; } public string SeedDataName { get; set; }
/// <summary> /// <summary>
/// 导出位置 /// 导出位置
/// </summary> /// </summary>
/// <example>Web.Application</example>
public string Position { get; set; } public string Position { get; set; }
/// <summary> /// <summary>
/// 后缀 /// 后缀
/// </summary> /// </summary>
/// <example>Web.Application</example>
public string Suffix { get; set; } public string Suffix { get; set; }
/// <summary> /// <summary>
/// 过滤已有数据 /// 过滤已有数据
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// 如果数据在其它不同名的已有的种子类型的数据中出现过,就不生成这个数据 /// 如果数据在其它不同名的已有的种子类型的数据中出现过,就不生成这个数据
/// 主要用于生成菜单功能,菜单功能往往与子项目绑定,如果生成完整数据就会导致菜单项多处理重复。 /// 主要用于生成菜单功能,菜单功能往往与子项目绑定,如果生成完整数据就会导致菜单项多处理重复。
/// </remarks> /// </remarks>
public bool FilterExistingData { get; set; } public bool FilterExistingData { get; set; }

View File

@ -4,11 +4,9 @@
// //
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任! // 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Mapster.Adapters;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
using Npgsql; using Npgsql;
using System.Linq;
namespace Admin.NET.Core.Service; namespace Admin.NET.Core.Service;
@ -358,26 +356,21 @@ public class SysDatabaseService : IDynamicApiController, ITransient
query.OrderBy(orderField.DbColumnName); query.OrderBy(orderField.DbColumnName);
IEnumerable recordsTmp = (IEnumerable)query.ToList(); IEnumerable recordsTmp = (IEnumerable)query.ToList();
List<dynamic> records = recordsTmp.ToDynamicList(); List<dynamic> records = recordsTmp.ToDynamicList();
//这里要过滤已存在的数据 // 过滤已存在的数据
if (input.FilterExistingData && records.Count() > 0) if (input.FilterExistingData && records.Count() > 0)
{ {
// 获取实体类型 // 获取实体类型
//获取所有种数据数据类型
var entityTypes = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.IsDefined(typeof(SugarTable), false) && u.FullName.EndsWith("." + input.EntityName)) var entityTypes = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.IsDefined(typeof(SugarTable), false) && u.FullName.EndsWith("." + input.EntityName))
.Where(u => !u.GetCustomAttributes<IgnoreTableAttribute>().Any()) .Where(u => !u.GetCustomAttributes<IgnoreTableAttribute>().Any()).ToList();
.ToList(); // 只有一个实体匹配才能过滤
if (entityTypes.Count == 1) //只有一个实体匹配才能过滤 if (entityTypes.Count == 1)
{ {
// 获取实体的主键对应的属性名称 // 获取实体的主键对应的属性名称
var pkInfo = entityTypes[0].GetProperties().Where(u => u.GetCustomAttribute<SugarColumn>() != null && u.GetCustomAttribute<SugarColumn>().IsPrimaryKey).First(); var pkInfo = entityTypes[0].GetProperties().Where(u => u.GetCustomAttribute<SugarColumn>() != null && u.GetCustomAttribute<SugarColumn>().IsPrimaryKey).First();
if (pkInfo != null) if (pkInfo != null)
{ {
var seedDataTypes = App.EffectiveTypes var seedDataTypes = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass
.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.GetInterfaces().Any( && u.GetInterfaces().Any(i => i.HasImplementedRawGeneric(typeof(ISqlSugarEntitySeedData<>)) && i.GenericTypeArguments[0] == entityTypes[0])).ToList();
i => i.HasImplementedRawGeneric(typeof(ISqlSugarEntitySeedData<>)) && i.GenericTypeArguments[0] == entityTypes[0]
)
)
.ToList();
// 可能会重名的种子数据不作为过滤项 // 可能会重名的种子数据不作为过滤项
string doNotFilterfullName1 = $"{input.Position}.SeedData.{input.SeedDataName}"; string doNotFilterfullName1 = $"{input.Position}.SeedData.{input.SeedDataName}";
string doNotFilterfullName2 = $"{input.Position}.{input.SeedDataName}"; // Core中的命名空间没有SeedData string doNotFilterfullName2 = $"{input.Position}.{input.SeedDataName}"; // Core中的命名空间没有SeedData
@ -395,7 +388,7 @@ public class SysDatabaseService : IDynamicApiController, ITransient
var seedData = ((IEnumerable)hasDataMethod?.Invoke(instance, null))?.Cast<object>(); var seedData = ((IEnumerable)hasDataMethod?.Invoke(instance, null))?.Cast<object>();
if (seedData == null) continue; if (seedData == null) continue;
List<object> recordsToRemove = new List<object>(); var recordsToRemove = new List<object>();
foreach (var record in records) foreach (var record in records)
{ {
object recordId = pkInfo.GetValue(record); object recordId = pkInfo.GetValue(record);

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks> <TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
<NoWarn>1701;1702;1591</NoWarn> <NoWarn>1701;1702;1591</NoWarn>
<DocumentationFile></DocumentationFile> <DocumentationFile></DocumentationFile>
<GenerateDocumentationFile>True</GenerateDocumentationFile> <GenerateDocumentationFile>True</GenerateDocumentationFile>
@ -11,7 +11,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="IGeekFan.AspNetCore.Knife4jUI" Version="0.0.16" /> <PackageReference Include="IGeekFan.AspNetCore.Knife4jUI" Version="0.0.16" />
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="8.0.1" /> <PackageReference Include="System.Security.Cryptography.Pkcs" Version="9.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -294,9 +294,7 @@ public class Startup : AppStartup
else else
{ {
foreach (var key in cpMappings.Keys) foreach (var key in cpMappings.Keys)
{
contentTypeProvider.Mappings[key] = cpMappings[key]; contentTypeProvider.Mappings[key] = cpMappings[key];
}
app.UseStaticFiles(new StaticFileOptions app.UseStaticFiles(new StaticFileOptions
{ {
ContentTypeProvider = contentTypeProvider ContentTypeProvider = contentTypeProvider
@ -311,7 +309,6 @@ public class Startup : AppStartup
}); });
} }
//// 启用HTTPS //// 启用HTTPS
//app.UseHttpsRedirection(); //app.UseHttpsRedirection();

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks> <TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<SatelliteResourceLanguages>zh-Hans</SatelliteResourceLanguages> <SatelliteResourceLanguages>zh-Hans</SatelliteResourceLanguages>
<PublishReadyToRunComposite>true</PublishReadyToRunComposite> <PublishReadyToRunComposite>true</PublishReadyToRunComposite>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks> <TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
<NoWarn>1701;1702;1591;8632</NoWarn> <NoWarn>1701;1702;1591;8632</NoWarn>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable> <Nullable>disable</Nullable>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks> <TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
<NoWarn>1701;1702;1591;8632</NoWarn> <NoWarn>1701;1702;1591;8632</NoWarn>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable> <Nullable>disable</Nullable>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks> <TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
<NoWarn>1701;1702;1591;8632</NoWarn> <NoWarn>1701;1702;1591;8632</NoWarn>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable> <Nullable>disable</Nullable>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks> <TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
<NoWarn>1701;1702;1591;8632</NoWarn> <NoWarn>1701;1702;1591;8632</NoWarn>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable> <Nullable>disable</Nullable>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks> <TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
<NoWarn>1701;1702;1591;8632</NoWarn> <NoWarn>1701;1702;1591;8632</NoWarn>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable> <Nullable>disable</Nullable>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks> <TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
<NoWarn>1701;1702;1591;8632</NoWarn> <NoWarn>1701;1702;1591;8632</NoWarn>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable> <Nullable>disable</Nullable>