From 9e7cb131441d4da2220653bed9090573bd3265a8 Mon Sep 17 00:00:00 2001 From: xiaochanghai Date: Mon, 15 Apr 2024 17:05:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=A1=A8=E5=A2=9E=E5=88=A0?= =?UTF-8?q?=E6=9F=A5=E6=94=B9=EF=BC=8CDBFirst=E7=94=9F=E6=88=90=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tiobon.Core.Api/appsettings.json | 4 ++-- Tiobon.Core.Common/DB/Aop/SqlsugarAop.cs | 18 ++++---------- Tiobon.Core.Common/DB/RepositorySetting.cs | 4 +--- Tiobon.Core.Model/Base/BasePoco.cs | 5 ++-- .../RootTkey/Interface/IDeleteFilter.cs | 4 ++++ Tiobon.Core.Services/BASE/BaseServices.cs | 1 - Tiobon.Core.Services/BASE/BaseServices1.cs | 24 ++++--------------- 7 files changed, 19 insertions(+), 41 deletions(-) diff --git a/Tiobon.Core.Api/appsettings.json b/Tiobon.Core.Api/appsettings.json index e5aa4467..9cbc2674 100644 --- a/Tiobon.Core.Api/appsettings.json +++ b/Tiobon.Core.Api/appsettings.json @@ -74,8 +74,8 @@ } }, "Date": "2018-08-28", - "SeedDBEnabled": true, //只生成表结构 - "SeedDBDataEnabled": true, //生成表,并初始化数据 + "SeedDBEnabled": false, //只生成表结构 + "SeedDBDataEnabled": false, //生成表,并初始化数据 "Author": "Tiobon.Core", "SvcName": "", // /svc/Tiobon "UseLoadTest": false diff --git a/Tiobon.Core.Common/DB/Aop/SqlsugarAop.cs b/Tiobon.Core.Common/DB/Aop/SqlsugarAop.cs index 60828b88..7a865f07 100644 --- a/Tiobon.Core.Common/DB/Aop/SqlsugarAop.cs +++ b/Tiobon.Core.Common/DB/Aop/SqlsugarAop.cs @@ -91,29 +91,21 @@ public static class SqlSugarAop { case DataFilterType.InsertByObject: var dyCreateBy = getType.GetProperty("CreateBy"); - var dyCreateId = getType.GetProperty("CreateId"); var dyCreateTime = getType.GetProperty("CreateTime"); if (App.User?.ID > 0 && dyCreateBy != null && dyCreateBy.GetValue(entityInfo.EntityValue) == null) - dyCreateBy.SetValue(entityInfo.EntityValue, App.User.Name); - - if (App.User?.ID > 0 && dyCreateId != null && dyCreateId.GetValue(entityInfo.EntityValue) == null) - dyCreateId.SetValue(entityInfo.EntityValue, App.User.ID); + dyCreateBy.SetValue(entityInfo.EntityValue, (int)App.User.ID); if (dyCreateTime != null && dyCreateTime.GetValue(entityInfo.EntityValue) != null && (DateTime)dyCreateTime.GetValue(entityInfo.EntityValue) == DateTime.MinValue) dyCreateTime.SetValue(entityInfo.EntityValue, DateTime.Now); break; case DataFilterType.UpdateByObject: - var dyModifyBy = getType.GetProperty("ModifyBy"); - var dyModifyId = getType.GetProperty("ModifyId"); - var dyModifyTime = getType.GetProperty("ModifyTime"); - - if (App.User?.ID > 0 && dyModifyBy != null) - dyModifyBy.SetValue(entityInfo.EntityValue, App.User.Name); + var UpdateBy = getType.GetProperty("UpdateBy"); + var dyModifyTime = getType.GetProperty("UpdateTime"); - if (App.User?.ID > 0 && dyModifyId != null) - dyModifyId.SetValue(entityInfo.EntityValue, App.User.ID); + if (App.User?.ID > 0 && UpdateBy != null) + UpdateBy.SetValue(entityInfo.EntityValue, (int)App.User.ID); if (dyModifyTime != null) dyModifyTime.SetValue(entityInfo.EntityValue, DateTime.Now); diff --git a/Tiobon.Core.Common/DB/RepositorySetting.cs b/Tiobon.Core.Common/DB/RepositorySetting.cs index f889f3be..011e697c 100644 --- a/Tiobon.Core.Common/DB/RepositorySetting.cs +++ b/Tiobon.Core.Common/DB/RepositorySetting.cs @@ -2,9 +2,6 @@ using Tiobon.Core.Model.Models.RootTkey.Interface; using Tiobon.Core.Model.Tenants; using SqlSugar; -using System; -using System.Collections.Generic; -using System.Linq; namespace Tiobon.Core.Common.DB; @@ -27,6 +24,7 @@ public class RepositorySetting public static void SetDeletedEntityFilter(SqlSugarScopeProvider db) { db.QueryFilter.AddTableFilter(it => it.IsDeleted == false); + db.QueryFilter.AddTableFilter(it => it.IsEnable == 1); } /// diff --git a/Tiobon.Core.Model/Base/BasePoco.cs b/Tiobon.Core.Model/Base/BasePoco.cs index 98883f0a..36737bb2 100644 --- a/Tiobon.Core.Model/Base/BasePoco.cs +++ b/Tiobon.Core.Model/Base/BasePoco.cs @@ -1,10 +1,11 @@ using System.ComponentModel; using System.ComponentModel.DataAnnotations; using SqlSugar; +using Tiobon.Core.Model.Models.RootTkey.Interface; namespace Tiobon.Core.Model { - public class BasePoco + public class BasePoco : IBaseDeleteFilter { /// @@ -24,7 +25,7 @@ namespace Tiobon.Core.Model /// 1:有效,0:未生效 /// [Display(Name = "1:有效,0:未生效")] - public int? IsEnable { get; set; } = 1; + public int IsEnable { get; set; } = 1; /// /// 是否默认 diff --git a/Tiobon.Core.Model/Models/RootTkey/Interface/IDeleteFilter.cs b/Tiobon.Core.Model/Models/RootTkey/Interface/IDeleteFilter.cs index d7bfe739..afbbf682 100644 --- a/Tiobon.Core.Model/Models/RootTkey/Interface/IDeleteFilter.cs +++ b/Tiobon.Core.Model/Models/RootTkey/Interface/IDeleteFilter.cs @@ -6,4 +6,8 @@ public interface IDeleteFilter { public bool IsDeleted { get; set; } +} +public interface IBaseDeleteFilter +{ + public int IsEnable { get; set; } } \ No newline at end of file diff --git a/Tiobon.Core.Services/BASE/BaseServices.cs b/Tiobon.Core.Services/BASE/BaseServices.cs index 998df50a..b59c2284 100644 --- a/Tiobon.Core.Services/BASE/BaseServices.cs +++ b/Tiobon.Core.Services/BASE/BaseServices.cs @@ -55,7 +55,6 @@ namespace Tiobon.Core.Services.BASE /// public async Task Add(TEntity entity) { - var userId = UserContext.Current.User_Id; return await BaseDal.Add(entity); } diff --git a/Tiobon.Core.Services/BASE/BaseServices1.cs b/Tiobon.Core.Services/BASE/BaseServices1.cs index 163d7d1a..d0e1e95e 100644 --- a/Tiobon.Core.Services/BASE/BaseServices1.cs +++ b/Tiobon.Core.Services/BASE/BaseServices1.cs @@ -94,9 +94,7 @@ namespace Tiobon.Core.Services.BASE var ip = GetUserIp(UserContext.Context); BasePoco ent = entity as BasePoco; - if (ent.CreateBy != null) - ent.CreateBy = userId; - ent.CreateTime = DateTime.Now; + ent.CreateIP = ip; ent.CreateProg = api; @@ -117,10 +115,7 @@ namespace Tiobon.Core.Services.BASE var ip = GetUserIp(UserContext.Context); listEntity.ForEach(entity => { - BasePoco ent = entity as BasePoco; - if (ent.CreateBy != null) - ent.CreateBy = userId; - ent.CreateTime = DateTime.Now; + BasePoco ent = entity as BasePoco; ent.CreateIP = ip; ent.CreateProg = api; }); @@ -134,8 +129,7 @@ namespace Tiobon.Core.Services.BASE /// 博文实体类 /// public async Task Update(long Id, TEditDto editModel) - { - var userId = UserContext.Current.User_Id; + { HttpRequest request = UserContext.Context.Request; var api = request.Path.ObjToString().TrimEnd('/').ToLower(); var ip = GetUserIp(UserContext.Context); @@ -146,8 +140,6 @@ namespace Tiobon.Core.Services.BASE var entity = await BaseDal.QueryById(Id); ConvertTEditDto2TEntity(editModel, entity); BasePoco ent = entity as BasePoco; - ent.UpdateBy = userId; - ent.UpdateTime = DateTime.Now; ent.UpdateIP = ip; ent.UpdateProg = api; return await BaseDal.Update(entity); @@ -159,16 +151,12 @@ namespace Tiobon.Core.Services.BASE /// public async Task Update(List listEntity) { - var userId = UserContext.Current.User_Id; HttpRequest request = UserContext.Context.Request; var api = request.Path.ObjToString().TrimEnd('/').ToLower(); var ip = GetUserIp(UserContext.Context); listEntity.ForEach(entity => { BasePoco ent = entity as BasePoco; - if (ent.UpdateBy != null) - ent.UpdateBy = userId; - ent.UpdateTime = DateTime.Now; ent.UpdateIP = ip; ent.UpdateProg = api; }); @@ -176,15 +164,11 @@ namespace Tiobon.Core.Services.BASE } public async Task Update(TEntity entity, string where) - { - var userId = UserContext.Current.User_Id; + { HttpRequest request = UserContext.Context.Request; var api = request.Path.ObjToString().TrimEnd('/').ToLower(); var ip = GetUserIp(UserContext.Context); BasePoco ent = entity as BasePoco; - if (ent.UpdateBy != null) - ent.UpdateBy = userId; - ent.UpdateTime = DateTime.Now; ent.UpdateIP = ip; ent.UpdateProg = api; return await BaseDal.Update(entity, where);