dengjunjie
2025-06-11 2ae5aa151f7b40a082e34aa7ed22b4b64edd1d3c
代码管理/WMS/WIDESEA_WMSServer/WIDESEA_Core/AOP/SqlSugarAop.cs
@@ -11,6 +11,7 @@
using WIDESEA_Core.Const;
using WIDESEA_Core.DB;
using WIDESEA_Core.DB.Models;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_Core.Seed;
using WIDESEA_Core.Tenants;
@@ -46,21 +47,25 @@
                SequenceAttirbute? sequenceAttirbute = propertyInfo.GetCustomAttribute<SequenceAttirbute>();
                if (sequenceAttirbute != null)
                {
                    SqlSugarClient sugarClient = new SqlSugarClient(new ConnectionConfig
                    if (propertyInfo.GetValue(entityInfo.EntityValue)?.ObjToInt() <= 0)
                    {
                        ConfigId = MainDb.CurrentDbConnId,
                        ConnectionString = DBContext.GetMainConnectionDb().Connection,
                        IsAutoCloseConnection = true,
                        DbType = MainDb.DbType,
                    });
                    int count = sugarClient.Ado.GetScalar($"SELECT COUNT(*) FROM sys.sequences WHERE name = '{sequenceAttirbute.SequenceName}'").ObjToInt();
                    if (count == 0)
                    {
                        string sql = $"CREATE SEQUENCE {sequenceAttirbute.SequenceName} AS [int] START WITH {sequenceAttirbute.StartWith} INCREMENT BY {sequenceAttirbute.Increment} MINVALUE {sequenceAttirbute.SeqMinValue} MAXVALUE {sequenceAttirbute.SeqMaxValue} {(sequenceAttirbute.IsCycle ? "CYCLE" : "")} CACHE";
                        sugarClient.Ado.ExecuteCommand(sql);
                        SqlSugarClient sugarClient = new SqlSugarClient(new ConnectionConfig
                        {
                            ConfigId = MainDb.CurrentDbConnId,
                            ConnectionString = DBContext.GetMainConnectionDb().Connection,
                            IsAutoCloseConnection = true,
                            DbType = MainDb.DbType,
                        });
                        int count = sugarClient.Ado.GetScalar($"SELECT COUNT(*) FROM sys.sequences WHERE name = '{sequenceAttirbute.SequenceName}'").ObjToInt();
                        if (count == 0)
                        {
                            string sql = $"CREATE SEQUENCE {sequenceAttirbute.SequenceName} AS [int] START WITH {sequenceAttirbute.StartWith} INCREMENT BY {sequenceAttirbute.Increment} MINVALUE {sequenceAttirbute.SeqMinValue} MAXVALUE {sequenceAttirbute.SeqMaxValue} {(sequenceAttirbute.IsCycle ? "CYCLE" : "")} CACHE";
                            sugarClient.Ado.ExecuteCommand(sql);
                        }
                        int seq = sugarClient.Ado.GetScalar($"SELECT NEXT VALUE FOR {sequenceAttirbute.SequenceName}").ObjToInt();
                        propertyInfo.SetValue(entityInfo.EntityValue, seq, null);
                    }
                    int seq = sugarClient.Ado.GetScalar($"SELECT NEXT VALUE FOR {sequenceAttirbute.SequenceName}").ObjToInt();
                    propertyInfo.SetValue(entityInfo.EntityValue, seq, null);
                }
            }
@@ -137,12 +142,11 @@
                ruleConfig.ModifyDate = DateTime.Now;
                code = ruleConfig.Format;
                code = code.Replace("[YYYY]", now.Year.ToString().PadLeft(4, '0'));
                code = code.Replace("[YY]", now.Year.ToString().Substring(2, 2));
                code = code.Replace("[MM]", now.Month.ToString().PadLeft(2, '0'));
                code = code.Replace("[DD]", now.Day.ToString().PadLeft(2, '0'));
                code = code.Replace("[ST]", ruleConfig.StartStr.ToString());
                code = code.Replace("[NUM]", ruleConfig.CurrentVal.ToString().PadLeft(ruleConfig.Length ?? 0, '0'));
                code = code.Replace($"[{CodeFormat.YYYY}]", now.Year.ToString().PadLeft(4, '0'));
                code = code.Replace($"[{CodeFormat.MM}]", now.Month.ToString().PadLeft(2, '0'));
                code = code.Replace($"[{CodeFormat.DD}]", now.Day.ToString().PadLeft(2, '0'));
                code = code.Replace($"[{CodeFormat.ST}]", ruleConfig.StartStr.ToString());
                code = code.Replace($"[{CodeFormat.NUM}]", ruleConfig.CurrentVal.ToString().PadLeft(ruleConfig.Length ?? 0, '0'));
            }
            catch (Exception ex)
            {