From 075ebb1fec4af45463ec10dc3a049e6e6b5dcd95 Mon Sep 17 00:00:00 2001
From: Falcon <12919280+falconfly@user.noreply.gitee.com>
Date: Fri, 25 Oct 2024 10:46:15 +0800
Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=A6=81=E6=AD=A2=E5=88=A0?=
=?UTF-8?q?=E9=99=A4=E5=88=97=E5=92=8C=E7=A6=81=E6=AD=A2=E8=87=AA=E5=8A=A8?=
=?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=A1=A8=E7=BB=93=E6=9E=84=E7=9A=84=E6=9C=8D?=
=?UTF-8?q?=E5=8A=A1=E3=80=82=E5=8F=AA=E9=9C=80=E8=A6=81=E5=9C=A8=E5=88=97?=
=?UTF-8?q?=E6=A8=A1=E5=9E=8B=E4=B8=8A=E5=A2=9E=E5=8A=A0DisableDeleteColum?=
=?UTF-8?q?mAttribute=E5=92=8CDisableUpdateAttribute=E7=89=B9=E6=80=A7?=
=?UTF-8?q?=E5=8D=B3=E5=8F=AF=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../DisableDeleteColummAttribute.cs | 10 ++++++++++
.../DisableUpdateAttribute.cs | 10 ++++++++++
.../DisableDeleteColummService.cs | 18 ++++++++++++++++++
.../EntityServices/DisableUpdateAllService.cs | 18 ++++++++++++++++++
.../EntityServices/TableNameTableService.cs | 6 +++---
.../DatabaseManager/DbContextBase.cs | 2 ++
6 files changed, 61 insertions(+), 3 deletions(-)
create mode 100644 Falcon.SugarApi/DatabaseDefinitions/DisableDeleteColummAttribute.cs
create mode 100644 Falcon.SugarApi/DatabaseDefinitions/DisableUpdateAttribute.cs
create mode 100644 Falcon.SugarApi/DatabaseDefinitions/EntityServices/DisableDeleteColummService.cs
create mode 100644 Falcon.SugarApi/DatabaseDefinitions/EntityServices/DisableUpdateAllService.cs
diff --git a/Falcon.SugarApi/DatabaseDefinitions/DisableDeleteColummAttribute.cs b/Falcon.SugarApi/DatabaseDefinitions/DisableDeleteColummAttribute.cs
new file mode 100644
index 0000000..2e0a00a
--- /dev/null
+++ b/Falcon.SugarApi/DatabaseDefinitions/DisableDeleteColummAttribute.cs
@@ -0,0 +1,10 @@
+using System;
+
+namespace Falcon.SugarApi.DatabaseDefinitions
+{
+ ///
+ /// 禁止删除表格的列
+ ///
+ [AttributeUsage(AttributeTargets.Class,AllowMultiple = false,Inherited = true)]
+ public class DisableDeleteColummAttribute:Attribute { }
+}
diff --git a/Falcon.SugarApi/DatabaseDefinitions/DisableUpdateAttribute.cs b/Falcon.SugarApi/DatabaseDefinitions/DisableUpdateAttribute.cs
new file mode 100644
index 0000000..d02d380
--- /dev/null
+++ b/Falcon.SugarApi/DatabaseDefinitions/DisableUpdateAttribute.cs
@@ -0,0 +1,10 @@
+using System;
+
+namespace Falcon.SugarApi.DatabaseDefinitions
+{
+ ///
+ /// 禁止更新表结构
+ ///
+ [AttributeUsage(AttributeTargets.Class,AllowMultiple = false,Inherited = true)]
+ public class DisableUpdateAttribute:Attribute { }
+}
diff --git a/Falcon.SugarApi/DatabaseDefinitions/EntityServices/DisableDeleteColummService.cs b/Falcon.SugarApi/DatabaseDefinitions/EntityServices/DisableDeleteColummService.cs
new file mode 100644
index 0000000..b278c47
--- /dev/null
+++ b/Falcon.SugarApi/DatabaseDefinitions/EntityServices/DisableDeleteColummService.cs
@@ -0,0 +1,18 @@
+using SqlSugar;
+using System;
+
+namespace Falcon.SugarApi.DatabaseDefinitions.EntityServices
+{
+ ///
+ /// 设置禁止删除列服务
+ ///
+ public class DisableDeleteColummService:IEntityTableServices
+ {
+ ///
+ public void SetupTable(Type t,EntityInfo e) {
+ if(t.TryGetAttribute(out var _)) {
+ e.IsDisabledDelete = true;
+ }
+ }
+ }
+}
diff --git a/Falcon.SugarApi/DatabaseDefinitions/EntityServices/DisableUpdateAllService.cs b/Falcon.SugarApi/DatabaseDefinitions/EntityServices/DisableUpdateAllService.cs
new file mode 100644
index 0000000..844c9b2
--- /dev/null
+++ b/Falcon.SugarApi/DatabaseDefinitions/EntityServices/DisableUpdateAllService.cs
@@ -0,0 +1,18 @@
+using SqlSugar;
+using System;
+
+namespace Falcon.SugarApi.DatabaseDefinitions.EntityServices
+{
+ ///
+ /// 设置禁止升级表架构服务
+ ///
+ public class DisableUpdateAllService:IEntityTableServices
+ {
+ ///
+ public void SetupTable(Type t,EntityInfo e) {
+ if(t.TryGetAttribute(out var _)) {
+ e.IsDisabledUpdateAll = true;
+ }
+ }
+ }
+}
diff --git a/Falcon.SugarApi/DatabaseDefinitions/EntityServices/TableNameTableService.cs b/Falcon.SugarApi/DatabaseDefinitions/EntityServices/TableNameTableService.cs
index 5ffb647..83cf694 100644
--- a/Falcon.SugarApi/DatabaseDefinitions/EntityServices/TableNameTableService.cs
+++ b/Falcon.SugarApi/DatabaseDefinitions/EntityServices/TableNameTableService.cs
@@ -7,11 +7,11 @@ namespace Falcon.SugarApi.DatabaseDefinitions.EntityServices
///
/// 设置表名服务
///
- public class TableNameTableService : IEntityTableServices
+ public class TableNameTableService:IEntityTableServices
{
///
- public void SetupTable(Type t, EntityInfo e) {
- if (t.TryGetAttribute(out var tn)) {
+ public void SetupTable(Type t,EntityInfo e) {
+ if(t.TryGetAttribute(out var tn)) {
e.DbTableName = tn.Name;
}
}
diff --git a/Falcon.SugarApi/DatabaseManager/DbContextBase.cs b/Falcon.SugarApi/DatabaseManager/DbContextBase.cs
index 10c810c..b9102de 100644
--- a/Falcon.SugarApi/DatabaseManager/DbContextBase.cs
+++ b/Falcon.SugarApi/DatabaseManager/DbContextBase.cs
@@ -42,6 +42,8 @@ namespace Falcon.SugarApi.DatabaseManager
var ces = config.ConfigureExternalServices;
ces.EntityNameService = (t,e) => {
new TableNameTableService().SetupTable(t,e);
+ new DisableDeleteColummService().SetupTable(t,e);
+ new DisableUpdateAllService().SetupTable(t,e);
};
ces.EntityService = (p,c) => {
new SetupKeyColumnServices().SetupColumn(p,c);