From f82511343cf2c8ecf3981954e7eb92172d72a905 Mon Sep 17 00:00:00 2001
From: Huangxiaoqiang-03 <1247017146@qq.com>
Date: 星期二, 05 十一月 2024 17:26:08 +0800
Subject: [PATCH] 1
---
代码管理/WMS/WIDESEA_WMSServer/WIDESEA_Core/AOP/SqlSugarAop.cs | 42 +++++++++++++++++++++++-------------------
1 files changed, 23 insertions(+), 19 deletions(-)
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/AOP/SqlSugarAop.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/AOP/SqlSugarAop.cs"
index 330bb8b..dac84c9 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/AOP/SqlSugarAop.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/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)
{
--
Gitblit v1.9.3