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