From aad7cb83f2cc6aa478d81dcd6b786ff7fa1ee2f7 Mon Sep 17 00:00:00 2001
From: falcon <9504402@qq.com>
Date: Fri, 2 Sep 2022 14:32:43 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE=E5=9F=BA?=
=?UTF-8?q?=E7=A1=80=E8=A1=A8=E5=AE=9A=E4=B9=89=E3=80=82=E6=AF=94SugarTabl?=
=?UTF-8?q?eBase=E6=9B=B4=E5=8A=A0=E7=AE=80=E6=B4=81=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../DatabaseDefinitions/SugarBasicTable.cs | 49 +++++++++++++++++++
1 file changed, 49 insertions(+)
create mode 100644 Falcon.SugarApi/DatabaseDefinitions/SugarBasicTable.cs
diff --git a/Falcon.SugarApi/DatabaseDefinitions/SugarBasicTable.cs b/Falcon.SugarApi/DatabaseDefinitions/SugarBasicTable.cs
new file mode 100644
index 0000000..a089d67
--- /dev/null
+++ b/Falcon.SugarApi/DatabaseDefinitions/SugarBasicTable.cs
@@ -0,0 +1,49 @@
+using SqlSugar;
+using System;
+
+namespace Falcon.SugarApi.DatabaseDefinitions
+{
+ ///
+ /// 基础表,定义表基础数据结构和构造方法
+ ///
+ public abstract class SugarBasicTable
+ {
+ ///
+ /// 主键
+ ///
+ [SugarColumn(IsPrimaryKey = true, ColumnDescription = "主键")]
+ public Guid Id { get; set; } = Guid.NewGuid();
+ ///
+ /// 创建时间
+ ///
+ [SugarColumn(IsOnlyIgnoreUpdate = true, IsNullable = true, ColumnDescription = "创建时间")]
+ public DateTime? CreateTime { get; set; } = DateTime.Now;
+
+ ///
+ /// 记录状态
+ ///
+ [SugarColumn(IsNullable = false, ColumnDescription = "记录状态。有效 无效")]
+ public string Status { get; set; } = "有效";
+
+ ///
+ /// 将数据设置为新数据。
+ /// 主要更新Id、创建时间和记录状态
+ ///
+ /// 本条数据
+ public virtual SugarBasicTable SetNew() {
+ this.Id = Guid.NewGuid();
+ this.CreateTime = DateTime.Now;
+ this.Status = "有效";
+ return this;
+ }
+ ///
+ /// 设置本条记录有效状态
+ ///
+ /// 有效还是无效,默认有效
+ /// 本条数据
+ public virtual SugarBasicTable SetEnable(bool enable = true) {
+ this.Status = enable ? "有效" : "无效";
+ return this;
+ }
+ }
+}