diff --git a/Src/Asp.NetCore2/SqlSugar/DistributedSystem/Snowflake/IdWorker.cs b/Src/Asp.NetCore2/SqlSugar/DistributedSystem/Snowflake/IdWorker.cs index 347b4efda..bf2aa5d84 100644 --- a/Src/Asp.NetCore2/SqlSugar/DistributedSystem/Snowflake/IdWorker.cs +++ b/Src/Asp.NetCore2/SqlSugar/DistributedSystem/Snowflake/IdWorker.cs @@ -81,10 +81,14 @@ namespace SqlSugar.DistributedSystem.Snowflake if (timestamp < _lastTimestamp) { + if (StaticConfig.CustomSnowFlakeTimeErrorFunc != null) + { + return StaticConfig.CustomSnowFlakeTimeErrorFunc(); + } //exceptionCounter.incr(1); //log.Error("clock is moving backwards. Rejecting requests until %d.", _lastTimestamp); throw new InvalidSystemClock(String.Format( - "Clock moved backwards. Refusing to generate id for {0} milliseconds", _lastTimestamp - timestamp)); + "服务器时间出现回退你可以使用StaticConfig.CustomSnowFlakeTimeErrorFunc=【自定义方法】处理让他不报错返回新ID,Clock moved backwards. Refusing to generate id for {0} milliseconds", _lastTimestamp - timestamp)); } if (_lastTimestamp == timestamp) diff --git a/Src/Asp.NetCore2/SqlSugar/Infrastructure/StaticConfig.cs b/Src/Asp.NetCore2/SqlSugar/Infrastructure/StaticConfig.cs index f9819ef2c..a42aaecb0 100644 --- a/Src/Asp.NetCore2/SqlSugar/Infrastructure/StaticConfig.cs +++ b/Src/Asp.NetCore2/SqlSugar/Infrastructure/StaticConfig.cs @@ -13,6 +13,7 @@ namespace SqlSugar public const string CodeFirst_BigString = "varcharmax,longtext,text,clob"; public static Func CustomSnowFlakeFunc; + public static Func CustomSnowFlakeTimeErrorFunc; public static Action CompleteQueryableFunc; public static Action CompleteInsertableFunc;