😎1、增加Guid主键类型 2、升级依赖
This commit is contained in:
parent
6463ccac23
commit
99b911e41c
@ -13,6 +13,12 @@ namespace Admin.NET.Application.Entity;
|
|||||||
[SugarTable(null, "代码自动生成DEMO")]
|
[SugarTable(null, "代码自动生成DEMO")]
|
||||||
public class TestCodeGenDemo : EntityBase
|
public class TestCodeGenDemo : EntityBase
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 重写主键类型
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnName = "Id", ColumnDescription = "主键Id", IsPrimaryKey = true, IsIdentity = false)]
|
||||||
|
public new Guid Id { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 文本
|
/// 文本
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -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.16.3" />
|
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.16.3" />
|
||||||
<PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.6.17" />
|
<PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.6.18" />
|
||||||
<PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.6.17" />
|
<PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.6.18" />
|
||||||
<PackageReference Include="Furion.Pure" Version="4.9.6.17" />
|
<PackageReference Include="Furion.Pure" Version="4.9.6.18" />
|
||||||
<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" />
|
||||||
@ -42,11 +42,11 @@
|
|||||||
<PackageReference Include="SixLabors.ImageSharp.Web" Version="3.1.3" />
|
<PackageReference Include="SixLabors.ImageSharp.Web" Version="3.1.3" />
|
||||||
<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.171" />
|
<PackageReference Include="SqlSugarCore" Version="5.1.4.172" />
|
||||||
<PackageReference Include="SSH.NET" Version="2024.2.0" />
|
<PackageReference Include="SSH.NET" Version="2024.2.0" />
|
||||||
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.5.1" />
|
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.5.1" />
|
||||||
<PackageReference Include="System.Net.Http" Version="4.3.4" />
|
<PackageReference Include="System.Net.Http" Version="4.3.4" />
|
||||||
<PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1148" />
|
<PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1149" />
|
||||||
<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,7 +54,7 @@
|
|||||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
|
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
|
||||||
<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.1.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="8.0.11" />
|
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="8.0.11" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="8.0.11" />
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="8.0.11" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="8.0.11" />
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="8.0.11" />
|
||||||
|
|||||||
@ -14,7 +14,7 @@ public static class YitIdHelperExtension
|
|||||||
private const string MainLockName = "IdGen:WorkerId:Lock";
|
private const string MainLockName = "IdGen:WorkerId:Lock";
|
||||||
private const string MainValueKey = "IdGen:WorkerId:Value";
|
private const string MainValueKey = "IdGen:WorkerId:Value";
|
||||||
|
|
||||||
private static readonly List<string> _workIds = new();
|
private static readonly List<string> _workIds = [];
|
||||||
private static SnowIdOptions _options;
|
private static SnowIdOptions _options;
|
||||||
|
|
||||||
public static void AddYitIdHelper(this IServiceCollection services, SnowIdOptions options)
|
public static void AddYitIdHelper(this IServiceCollection services, SnowIdOptions options)
|
||||||
@ -84,7 +84,7 @@ public static class YitIdHelperExtension
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine($"###########当前应用WorkId:【{workIdStr}】###########");
|
Console.WriteLine($"############ 当前应用雪花WorkId:【{workIdStr}】############");
|
||||||
|
|
||||||
long workId = workIdStr.ParseToLong();
|
long workId = workIdStr.ParseToLong();
|
||||||
if (workId < minWorkId || workId > maxWorkId)
|
if (workId < minWorkId || workId > maxWorkId)
|
||||||
@ -102,7 +102,7 @@ public static class YitIdHelperExtension
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(workIdKey)) throw Oops.Oh("未设置有效的机器码,启动失败");
|
if (string.IsNullOrWhiteSpace(workIdKey)) throw Oops.Oh("未设置有效的机器码,启动失败");
|
||||||
|
|
||||||
// 开一个任务设置当前workId过期时间
|
// 开一个任务设置当前workId过期时间
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
|
|||||||
@ -209,15 +209,26 @@ public static class SqlSugarSetup
|
|||||||
// 若正在处理种子数据则直接返回
|
// 若正在处理种子数据则直接返回
|
||||||
if (_isHandlingSeedData) return;
|
if (_isHandlingSeedData) return;
|
||||||
|
|
||||||
// 新增/插入
|
// 新增/插入 操作
|
||||||
if (entityInfo.OperationType == DataFilterType.InsertByObject)
|
if (entityInfo.OperationType == DataFilterType.InsertByObject)
|
||||||
{
|
{
|
||||||
// 若主键是长整型且空且不是自增类型则赋值雪花Id
|
// 若是主键且非自增类型
|
||||||
if (entityInfo.EntityColumnInfo.IsPrimarykey && !entityInfo.EntityColumnInfo.IsIdentity && entityInfo.EntityColumnInfo.PropertyInfo.PropertyType == typeof(long))
|
if (entityInfo.EntityColumnInfo.IsPrimarykey && !entityInfo.EntityColumnInfo.IsIdentity)
|
||||||
{
|
{
|
||||||
var id = entityInfo.EntityColumnInfo.PropertyInfo.GetValue(entityInfo.EntityValue);
|
// 雪花Id类型(长整型且空则赋值)
|
||||||
if (id == null || (long)id == 0)
|
if (entityInfo.EntityColumnInfo.PropertyInfo.PropertyType == typeof(long))
|
||||||
entityInfo.SetValue(YitIdHelper.NextId());
|
{
|
||||||
|
var id = entityInfo.EntityColumnInfo.PropertyInfo.GetValue(entityInfo.EntityValue);
|
||||||
|
if (id == null || (long)id == 0)
|
||||||
|
entityInfo.SetValue(YitIdHelper.NextId());
|
||||||
|
}
|
||||||
|
// Guid类型(空则赋值)
|
||||||
|
else if (entityInfo.EntityColumnInfo.PropertyInfo.PropertyType == typeof(Guid))
|
||||||
|
{
|
||||||
|
var id = entityInfo.EntityColumnInfo.PropertyInfo.GetValue(entityInfo.EntityValue);
|
||||||
|
if (id == null)
|
||||||
|
entityInfo.SetValue(Guid.NewGuid());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 若创建时间为空则赋值当前时间
|
// 若创建时间为空则赋值当前时间
|
||||||
else if (entityInfo.PropertyName == nameof(EntityBase.CreateTime))
|
else if (entityInfo.PropertyName == nameof(EntityBase.CreateTime))
|
||||||
@ -256,7 +267,7 @@ public static class SqlSugarSetup
|
|||||||
entityInfo.SetValue(App.User.FindFirst(ClaimConst.OrgName)?.Value);
|
entityInfo.SetValue(App.User.FindFirst(ClaimConst.OrgName)?.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 编辑/更新
|
// 编辑/更新 操作
|
||||||
else if (entityInfo.OperationType == DataFilterType.UpdateByObject)
|
else if (entityInfo.OperationType == DataFilterType.UpdateByObject)
|
||||||
{
|
{
|
||||||
if (entityInfo.PropertyName == nameof(EntityBase.UpdateTime))
|
if (entityInfo.PropertyName == nameof(EntityBase.UpdateTime))
|
||||||
|
|||||||
@ -117,6 +117,15 @@ if (@column.WhetherAddUpdate == "Y"){
|
|||||||
public class Delete@(@Model.ClassName)Input : BaseIdInput
|
public class Delete@(@Model.ClassName)Input : BaseIdInput
|
||||||
{
|
{
|
||||||
@foreach (var column in Model.TableField){
|
@foreach (var column in Model.TableField){
|
||||||
|
if (@column.NetType == "Guid" && @column.PropertyName == "Id"){
|
||||||
|
@:/// <summary>
|
||||||
|
@:/// @column.ColumnComment
|
||||||
|
@:/// </summary>
|
||||||
|
@:public @column.NetType @column.PropertyName { get; set; }
|
||||||
|
@:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@foreach (var column in Model.TableField){
|
||||||
if (@column.ColumnKey == "True" && @column.PropertyName != "Id"){
|
if (@column.ColumnKey == "True" && @column.PropertyName != "Id"){
|
||||||
@:/// <summary>
|
@:/// <summary>
|
||||||
@:/// @column.ColumnComment
|
@:/// @column.ColumnComment
|
||||||
@ -139,6 +148,9 @@ if (@column.ColumnKey == "True"){
|
|||||||
@:/// @column.ColumnComment
|
@:/// @column.ColumnComment
|
||||||
@:/// </summary>
|
@:/// </summary>
|
||||||
@:[Required(ErrorMessage = "@(@column.ColumnComment)不能为空")]
|
@:[Required(ErrorMessage = "@(@column.ColumnComment)不能为空")]
|
||||||
|
@if (@column.NetType == "Guid" && @column.PropertyName == "Id"){
|
||||||
|
@:[AdaptIgnore]
|
||||||
|
}
|
||||||
@:public @column.NetType @column.PropertyName { get; set; }
|
@:public @column.NetType @column.PropertyName { get; set; }
|
||||||
@:
|
@:
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
using Admin.NET.Core.Service;
|
using Admin.NET.Core.Service;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
|
||||||
@{
|
@{
|
||||||
string joinTableName = "u";
|
string joinTableName = "u";
|
||||||
Dictionary<string, int> definedObjects = new Dictionary<string, int>();
|
Dictionary<string, int> definedObjects = new Dictionary<string, int>();
|
||||||
@ -35,10 +36,12 @@ namespace @Model.NameSpace;
|
|||||||
public class @(@Model.ClassName)Service : IDynamicApiController, ITransient
|
public class @(@Model.ClassName)Service : IDynamicApiController, ITransient
|
||||||
{
|
{
|
||||||
private readonly SqlSugarRepository<@(@Model.ClassName)> _@(@Model.LowerClassName)Rep;
|
private readonly SqlSugarRepository<@(@Model.ClassName)> _@(@Model.LowerClassName)Rep;
|
||||||
|
private TypeAdapterConfig _typeAdapterConfig = TypeAdapterConfig.GlobalSettings;
|
||||||
|
|
||||||
public @(@Model.ClassName)Service(SqlSugarRepository<@(@Model.ClassName)> @(@Model.LowerClassName)Rep)
|
public @(@Model.ClassName)Service(SqlSugarRepository<@(@Model.ClassName)> @(@Model.LowerClassName)Rep)
|
||||||
{
|
{
|
||||||
_@(@Model.LowerClassName)Rep = @(@Model.LowerClassName)Rep;
|
_@(@Model.LowerClassName)Rep = @(@Model.LowerClassName)Rep;
|
||||||
|
_typeAdapterConfig.ForType<T, @(@Model.ClassName)>().IgnoreNullValues(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -120,7 +123,7 @@ if (@column.QueryWhether == "Y"){
|
|||||||
@:.Select<@(@Model.ClassName)Output>();
|
@:.Select<@(@Model.ClassName)Output>();
|
||||||
}
|
}
|
||||||
@if(@Model.TableField.Any(x=>x.EffectType == "ForeignKey")){
|
@if(@Model.TableField.Any(x=>x.EffectType == "ForeignKey")){
|
||||||
@:return await query.OrderBuilder(input,"u.","@(PKName)").ToPagedListAsync(input.Page, input.PageSize);
|
@:return await query.OrderBuilder(input,"[u].","[@(PKName)]").ToPagedListAsync(input.Page, input.PageSize);
|
||||||
} else {
|
} else {
|
||||||
@:return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize);
|
@:return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize);
|
||||||
}
|
}
|
||||||
@ -133,9 +136,9 @@ if (@column.QueryWhether == "Y"){
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[ApiDescriptionSettings(Name = "add", Description = "增加@(@Model.BusName)", Order = 990), HttpPost]
|
[ApiDescriptionSettings(Name = "add", Description = "增加@(@Model.BusName)", Order = 990), HttpPost]
|
||||||
[DisplayName("增加@(@Model.BusName)")]
|
[DisplayName("增加@(@Model.BusName)")]
|
||||||
public async Task<long> Add(Add@(@Model.ClassName)Input input)
|
public async Task<object> Add(Add@(@Model.ClassName)Input input)
|
||||||
{
|
{
|
||||||
var entity = input.Adapt<@(@Model.ClassName)>();
|
var entity = input.Adapt<@(@Model.ClassName)>(_typeAdapterConfig);
|
||||||
@if(Model.RemoteVerify){
|
@if(Model.RemoteVerify){
|
||||||
@://验证重复值
|
@://验证重复值
|
||||||
@:if (await _@(@Model.LowerClassName)Rep.IsAnyAsync(t => t.@(RemoteField) == entity.@(RemoteField)))
|
@:if (await _@(@Model.LowerClassName)Rep.IsAnyAsync(t => t.@(RemoteField) == entity.@(RemoteField)))
|
||||||
@ -157,7 +160,13 @@ if (@column.QueryWhether == "Y"){
|
|||||||
[DisplayName("删除@(@Model.BusName)")]
|
[DisplayName("删除@(@Model.BusName)")]
|
||||||
public async Task Delete(Delete@(@Model.ClassName)Input input)
|
public async Task Delete(Delete@(@Model.ClassName)Input input)
|
||||||
{
|
{
|
||||||
await _@(@Model.LowerClassName)Rep.DeleteByIdAsync(input.Id); // 真删除
|
@foreach (var column in Model.TableField){
|
||||||
|
if (@column.ColumnKey == "True"){
|
||||||
|
@:var entity = await _@(@Model.LowerClassName)Rep.GetFirstAsync(u => u.@(@column.PropertyName) == input.@(@column.PropertyName)) ?? throw Oops.Oh(ErrorCodeEnum.D1002);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await _@(@Model.LowerClassName)Rep.FakeDeleteAsync(entity); // 假删除
|
||||||
|
//await _@(@Model.LowerClassName)Rep.DeleteAsync(entity); // 真删除
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -169,7 +178,8 @@ if (@column.QueryWhether == "Y"){
|
|||||||
[DisplayName("更新@(@Model.BusName)")]
|
[DisplayName("更新@(@Model.BusName)")]
|
||||||
public async Task Update(Update@(@Model.ClassName)Input input)
|
public async Task Update(Update@(@Model.ClassName)Input input)
|
||||||
{
|
{
|
||||||
var entity = input.Adapt<@(@Model.ClassName)>();
|
var entity = input.Adapt<@(@Model.ClassName)>(_typeAdapterConfig);
|
||||||
|
entity.Id = input.Id;
|
||||||
@if(Model.RemoteVerify){
|
@if(Model.RemoteVerify){
|
||||||
@://验证重复值
|
@://验证重复值
|
||||||
@:if (await _@(@Model.LowerClassName)Rep.IsAnyAsync(t => t.@(RemoteField) == entity.@(RemoteField) && t.@(@PKName) != entity.@(@PKName)))
|
@:if (await _@(@Model.LowerClassName)Rep.IsAnyAsync(t => t.@(RemoteField) == entity.@(RemoteField) && t.@(@PKName) != entity.@(@PKName)))
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"name": "admin.net.pro",
|
"name": "admin.net.pro",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "2.4.33",
|
"version": "2.4.33",
|
||||||
"lastBuildTime": "2024.12.24",
|
"lastBuildTime": "2024.12.25",
|
||||||
"description": "Admin.NET 站在巨人肩膀上的 .NET 通用权限开发框架",
|
"description": "Admin.NET 站在巨人肩膀上的 .NET 通用权限开发框架",
|
||||||
"author": "zuohuaijun",
|
"author": "zuohuaijun",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@ -68,13 +68,13 @@
|
|||||||
"vue-demi": "0.14.10",
|
"vue-demi": "0.14.10",
|
||||||
"vue-draggable-plus": "^0.6.0",
|
"vue-draggable-plus": "^0.6.0",
|
||||||
"vue-grid-layout": "3.0.0-beta1",
|
"vue-grid-layout": "3.0.0-beta1",
|
||||||
"vue-i18n": "^10.0.5",
|
"vue-i18n": "^11.0.0",
|
||||||
"vue-json-pretty": "^2.4.0",
|
"vue-json-pretty": "^2.4.0",
|
||||||
"vue-plugin-hiprint": "^0.0.58-fix",
|
"vue-plugin-hiprint": "^0.0.58-fix",
|
||||||
"vue-router": "^4.5.0",
|
"vue-router": "^4.5.0",
|
||||||
"vue-signature-pad": "^3.0.2",
|
"vue-signature-pad": "^3.0.2",
|
||||||
"vue3-tree-org": "^4.2.2",
|
"vue3-tree-org": "^4.2.2",
|
||||||
"vxe-pc-ui": "^4.3.42",
|
"vxe-pc-ui": "^4.3.44",
|
||||||
"vxe-table": "^4.8.10",
|
"vxe-table": "^4.8.10",
|
||||||
"vxe-table-plugin-element": "^4.0.4",
|
"vxe-table-plugin-element": "^4.0.4",
|
||||||
"vxe-table-plugin-export-xlsx": "^4.0.7",
|
"vxe-table-plugin-export-xlsx": "^4.0.7",
|
||||||
@ -88,8 +88,8 @@
|
|||||||
"@types/node": "^20.17.10",
|
"@types/node": "^20.17.10",
|
||||||
"@types/nprogress": "^0.2.3",
|
"@types/nprogress": "^0.2.3",
|
||||||
"@types/sortablejs": "^1.15.8",
|
"@types/sortablejs": "^1.15.8",
|
||||||
"@typescript-eslint/eslint-plugin": "^8.18.1",
|
"@typescript-eslint/eslint-plugin": "^8.18.2",
|
||||||
"@typescript-eslint/parser": "^8.18.1",
|
"@typescript-eslint/parser": "^8.18.2",
|
||||||
"@vitejs/plugin-vue": "^5.2.1",
|
"@vitejs/plugin-vue": "^5.2.1",
|
||||||
"@vitejs/plugin-vue-jsx": "^4.1.1",
|
"@vitejs/plugin-vue-jsx": "^4.1.1",
|
||||||
"@vue/compiler-sfc": "^3.5.13",
|
"@vue/compiler-sfc": "^3.5.13",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user