diff --git a/Common/Util/LongJsonConverter.cs b/Common/Util/LongJsonConverter.cs new file mode 100644 index 0000000..3a05eb0 --- /dev/null +++ b/Common/Util/LongJsonConverter.cs @@ -0,0 +1,18 @@ +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Common.Util; + +public class LongJsonConverter : JsonConverter +{ + public override long Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + string? s = reader.GetString(); + return long.Parse(s); + } + + public override void Write(Utf8JsonWriter writer, long value, JsonSerializerOptions options) + { + writer.WriteStringValue(value.ToString()); + } +} \ No newline at end of file diff --git a/Entity/Base/EntityBase.cs b/Entity/Base/EntityBase.cs index 5bd97e9..96d7e96 100644 --- a/Entity/Base/EntityBase.cs +++ b/Entity/Base/EntityBase.cs @@ -8,9 +8,10 @@ namespace Entity.Base public abstract class EntityBaseId { /// - /// 雪花Id + /// 自增 /// [SugarColumn(ColumnName = "id", ColumnDescription = "主键Id", IsPrimaryKey = true, IsIdentity = false)] + public virtual long Id { get; set; } } /// diff --git a/WebStarter/Program.cs b/WebStarter/Program.cs index a4d681b..b3a4d3b 100644 --- a/WebStarter/Program.cs +++ b/WebStarter/Program.cs @@ -1,6 +1,7 @@ using System.Text; using Autofac; using Autofac.Extensions.DependencyInjection; +using Common.Util; using Entity.Dto.Resp; using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.AutoTask; @@ -25,7 +26,6 @@ builder.Host.ConfigureContainer(cb => { cb.Register(c => { - var db = new SqlSugarScope(new ConnectionConfig { ConfigId = AppSettingsConstVars.ConfigId, @@ -34,13 +34,11 @@ builder.Host.ConfigureContainer(cb => IsAutoCloseConnection = true, InitKeyType = InitKeyType.Attribute // 如果使用实体类的属性进行主键标识,请设置为 InitKeyType.Attr - }); return db; }).As().SingleInstance(); cb.RegisterModule(new AutofacModuleRegister()); - }); // 注册自定义映射 @@ -67,7 +65,7 @@ builder.Services.AddCors(options => //redis var redisConnectionString = AppSettingsHelper.GetContent("Redis", "Connection"); -var instanceName = AppSettingsHelper.GetContent("Redis", "InstanceName");//默认数据库 +var instanceName = AppSettingsHelper.GetContent("Redis", "InstanceName"); //默认数据库 var defaultDb = int.Parse(AppSettingsHelper.GetContent("Redis", "DefaultDB") ?? "0"); if (redisConnectionString != null && instanceName != null) builder.Services.AddSingleton(new RedisHelper(redisConnectionString, instanceName, defaultDb)); @@ -75,6 +73,7 @@ if (redisConnectionString != null && instanceName != null) builder.Services.AddControllers().AddJsonOptions(configure => { configure.JsonSerializerOptions.Converters.Add(new DatetimeJsonConverter()); + configure.JsonSerializerOptions.Converters.Add(new LongJsonConverter()); }); builder.Services.AddControllers(); @@ -89,8 +88,6 @@ builder.Services.AddSwaggerGen(c => c.IncludeXmlComments(Path.Combine(basePath, "WebStarter.xml"), true); c.IncludeXmlComments(Path.Combine(basePath, "Entity.xml"), true); c.IncludeXmlComments(Path.Combine(basePath, "HybirdFrameworkCore.xml"), true); - - }); builder.Services.AddControllers().AddJsonOptions(configure => @@ -120,9 +117,6 @@ builder.Services.AddAuthentication(options => }); - - - var app = builder.Build(); @@ -164,8 +158,7 @@ if (AppSettingsHelper.GetBool("swap", "enable")) } - TaskInit.Init(); -app.Run(); +app.Run(); \ No newline at end of file