From 6a18ca31a53cfcec87701f8e75177f943de2c28e Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Mon, 27 Feb 2023 16:15:47 +0800 Subject: [PATCH] Support custom snowid --- Src/Asp.Net/SqlSugar/DistributedSystem/Snowflake/IdWorker.cs | 4 ++++ Src/Asp.Net/SqlSugar/Infrastructure/StaticConfig.cs | 1 + 2 files changed, 5 insertions(+) diff --git a/Src/Asp.Net/SqlSugar/DistributedSystem/Snowflake/IdWorker.cs b/Src/Asp.Net/SqlSugar/DistributedSystem/Snowflake/IdWorker.cs index 6ee473ccf..347b4efda 100644 --- a/Src/Asp.Net/SqlSugar/DistributedSystem/Snowflake/IdWorker.cs +++ b/Src/Asp.Net/SqlSugar/DistributedSystem/Snowflake/IdWorker.cs @@ -71,6 +71,10 @@ namespace SqlSugar.DistributedSystem.Snowflake } public virtual long NextId() { + if (StaticConfig.CustomSnowFlakeFunc != null) + { + return StaticConfig.CustomSnowFlakeFunc(); + } lock(_lock) { var timestamp = TimeGen(); diff --git a/Src/Asp.Net/SqlSugar/Infrastructure/StaticConfig.cs b/Src/Asp.Net/SqlSugar/Infrastructure/StaticConfig.cs index 0ffac75a2..da8f5301a 100644 --- a/Src/Asp.Net/SqlSugar/Infrastructure/StaticConfig.cs +++ b/Src/Asp.Net/SqlSugar/Infrastructure/StaticConfig.cs @@ -9,5 +9,6 @@ namespace SqlSugar public static Func Encode { get; set; } public static Func Decode{ get; set; } public const string CodeFirst_BigString = "varcharmax,longtext,text,clob"; + public static Func CustomSnowFlakeFunc; } }