| using SqlSugar; | 
| using System; | 
| using System.Collections.Generic; | 
| using System.Linq; | 
| using System.Reflection; | 
| using System.Text; | 
| using System.Threading.Tasks; | 
| using WIDESEA_Core.Const; | 
| using WIDESEA_Core.DB.Models; | 
| using WIDESEA_Core.Helper; | 
| using WIDESEA_Core.Tenants; | 
|   | 
| namespace WIDESEA_Core.AOP | 
| { | 
|     public static class SqlSugarAop | 
|     { | 
|         public static void DataExecuting(object oldValue, DataFilterModel entityInfo) | 
|         { | 
|             if (entityInfo.EntityValue is BaseEntity baseEntity) | 
|             { | 
|                 // 新增操作 | 
|                 if (entityInfo.OperationType == DataFilterType.InsertByObject) | 
|                 { | 
|                     if (entityInfo.PropertyName == nameof(BaseEntity.CreateDate)) | 
|                     { | 
|                         baseEntity.CreateDate = DateTime.Now; | 
|                     } | 
|                 } | 
|   | 
|                 if (entityInfo.OperationType == DataFilterType.UpdateByObject) | 
|                 { | 
|                     baseEntity.ModifyDate = DateTime.Now; | 
|                 } | 
|   | 
|   | 
|                 if (App.User?.UserId > 0) | 
|                 { | 
|                     switch (entityInfo.OperationType) | 
|                     { | 
|                         case DataFilterType.UpdateByObject: | 
|                             baseEntity.Modifier = App.User.UserName; | 
|                             break; | 
|                         case DataFilterType.InsertByObject: | 
|                                 baseEntity.Creater = App.User.UserName; | 
|                             break; | 
|                     } | 
|                 } | 
|             } | 
|         } | 
|   | 
|         private static string GetWholeSql(SugarParameter[] paramArr, string sql) | 
|         { | 
|             foreach (var param in paramArr) | 
|             { | 
|                 sql = sql.Replace(param.ParameterName, $@"'{param.Value.ObjToString()}'"); | 
|             } | 
|   | 
|             return sql; | 
|         } | 
|   | 
|         private static string GetParas(SugarParameter[] pars) | 
|         { | 
|             string key = "【SQL参数】:"; | 
|             foreach (var param in pars) | 
|             { | 
|                 key += $"{param.ParameterName}:{param.Value}\n"; | 
|             } | 
|   | 
|             return key; | 
|         } | 
|     } | 
| } |