From 3dc9ed6aafa1fb76f3dd96e0c17182a2bfcb5f38 Mon Sep 17 00:00:00 2001 From: lxw Date: Fri, 7 Jun 2024 10:20:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3long=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E5=8C=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/Util/LongJsonConverter.cs | 18 ++++++++++++++++++ Entity/Base/EntityBase.cs | 3 ++- WebStarter/Program.cs | 15 ++++----------- 3 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 Common/Util/LongJsonConverter.cs 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