| | |
| | | using SqlSugar; |
| | | using System.Data; |
| | | using System.Linq.Expressions; |
| | | using Microsoft.Data.SqlClient; |
| | | using OfficeOpenXml.FormulaParsing.ExpressionGraph; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | | using System.Drawing.Printing; |
| | | using System.Linq; |
| | | using System.Linq.Expressions; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.Reflection; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using Microsoft.Data.SqlClient; |
| | | using System.Drawing.Printing; |
| | | using WIDESEAWCS_Core.Tenants; |
| | | using WIDESEAWCS_Core.Seed; |
| | | using WIDESEAWCS_Core.DB; |
| | | using WIDESEAWCS_Core.Const; |
| | | using WIDESEA_Core.DB.Models; |
| | | using WIDESEAWCS_Core.AOP; |
| | | using OfficeOpenXml.FormulaParsing.ExpressionGraph; |
| | | using WIDESEAWCS_Core.Const; |
| | | using WIDESEAWCS_Core.DB; |
| | | using WIDESEAWCS_Core.DB.Models; |
| | | using WIDESEAWCS_Core.Enums; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.Seed; |
| | | using WIDESEAWCS_Core.Tenants; |
| | | using WIDESEAWCS_Core.Utilities; |
| | | |
| | | namespace WIDESEAWCS_Core.BaseRepository |
| | | { |
| | |
| | | .WhereIF(whereExpression != null, whereExpression).ToListAsync(); |
| | | } |
| | | |
| | | public bool DeleteAndMoveIntoHty(TEntity entity, OperateTypeEnum operateType) |
| | | { |
| | | Type type = typeof(TEntity); |
| | | Assembly assembly = type.Assembly; |
| | | Type? htyType = assembly.GetType(type.FullName + "_Hty"); |
| | | |
| | | if (htyType != null) |
| | | { |
| | | object? obj = Activator.CreateInstance(htyType); |
| | | PropertyInfo keyPro = typeof(TEntity).GetKeyProperty(); |
| | | PropertyInfo? operateTypePro = htyType.GetProperty(nameof(IBaseHistoryEntity.OperateType)); |
| | | PropertyInfo? sourceIdPro = htyType.GetProperty(nameof(IBaseHistoryEntity.SourceId)); |
| | | |
| | | if (obj != null && keyPro != null && operateTypePro != null && sourceIdPro != null) |
| | | { |
| | | operateTypePro.SetValue(obj, operateType.ToString()); |
| | | sourceIdPro.SetValue(obj, keyPro.GetValue(entity)); |
| | | |
| | | // 过滤掉导航属性和集合属性 |
| | | List<PropertyInfo> propertyInfos = htyType.GetProperties() |
| | | .Where(x => x.Name != operateTypePro.Name |
| | | && x.Name != sourceIdPro.Name |
| | | && x.Name != keyPro.Name |
| | | && !IsNavigationOrCollectionProperty(x)) // 新增过滤条件 |
| | | .ToList(); |
| | | |
| | | for (int i = 0; i < propertyInfos.Count; i++) |
| | | { |
| | | PropertyInfo propertyInfo = propertyInfos[i]; |
| | | PropertyInfo? property = type.GetProperty(propertyInfo.Name); |
| | | |
| | | if (property != null) |
| | | { |
| | | // 跳过导航属性和集合类型 |
| | | if (IsNavigationOrCollectionProperty(property)) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | if (propertyInfo.Name == nameof(BaseEntity.Modifier)) |
| | | { |
| | | propertyInfo.SetValue(obj, App.User.UserId > 0 ? App.User.UserName : "System"); |
| | | } |
| | | else if (propertyInfo.Name == nameof(BaseEntity.ModifyDate)) |
| | | { |
| | | propertyInfo.SetValue(obj, DateTime.Now); |
| | | } |
| | | else |
| | | { |
| | | propertyInfo.SetValue(obj, property.GetValue(entity)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (obj != null) |
| | | _db.InsertableByObject(obj).AS(type.Name + "_Hty").ExecuteCommand(); |
| | | } |
| | | } |
| | | return DeleteData(entity); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 判断是否为导航属性或集合属性 |
| | | /// </summary> |
| | | private bool IsNavigationOrCollectionProperty(PropertyInfo property) |
| | | { |
| | | // 检查是否有 Navigate 特性(导航属性) |
| | | if (property.GetCustomAttribute<Navigate>() != null) |
| | | return true; |
| | | |
| | | // 检查是否为集合类型(一对多) |
| | | if (property.PropertyType.IsGenericType && |
| | | (property.PropertyType.GetGenericTypeDefinition() == typeof(List<>) || |
| | | property.PropertyType.GetGenericTypeDefinition() == typeof(ICollection<>) || |
| | | property.PropertyType.GetGenericTypeDefinition() == typeof(IEnumerable<>))) |
| | | return true; |
| | | |
| | | // 检查是否为非基元类型的复杂对象(一对一导航) |
| | | if (property.PropertyType.IsClass && |
| | | property.PropertyType != typeof(string) && |
| | | !property.PropertyType.IsValueType) |
| | | { |
| | | // 排除系统类型 |
| | | if (property.PropertyType.Namespace?.StartsWith("System") == false) |
| | | return true; |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | //List<TResult> QueryMuch<T, T2, T3, TResult>( |
| | | // Expression<Func<T, T2, T3, object[]>> joinExpression, |
| | | // Expression<Func<T, T2, T3, TResult>> selectExpression, |