From 75d16a23d059439c7478f8d3f6372c29072ba84e Mon Sep 17 00:00:00 2001
From: xiaojiao <xiaojiao@kaokeziliao.com>
Date: 星期三, 06 五月 2026 16:27:14 +0800
Subject: [PATCH] 完善任务执行步骤
---
项目代码/WIDESEA_WCSServer/WIDESEAWCS_Core/BaseRepository/RepositoryBase.cs | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 103 insertions(+), 2 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WCSServer/WIDESEAWCS_Core/BaseRepository/RepositoryBase.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WCSServer/WIDESEAWCS_Core/BaseRepository/RepositoryBase.cs"
index 2bfd6fa..ec3e62b 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WCSServer/WIDESEAWCS_Core/BaseRepository/RepositoryBase.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WCSServer/WIDESEAWCS_Core/BaseRepository/RepositoryBase.cs"
@@ -16,6 +16,9 @@
using WIDESEAWCS_Core.Const;
using WIDESEAWCS_Core.AOP;
using OfficeOpenXml.FormulaParsing.ExpressionGraph;
+using WIDESEAWCS_Core.DB.Models;
+using WIDESEAWCS_Core.Utilities;
+using WIDESEAWCS_Core.Enums;
namespace WIDESEAWCS_Core.BaseRepository
{
@@ -243,7 +246,7 @@
}
public virtual TEntity QueryFirst(Expression<Func<TEntity, bool>> whereExpression)
-
+
{
return _db.CopyNew().Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).First();
}
@@ -537,7 +540,7 @@
public virtual List<TResult> QueryTabs<T, T2, TResult>(
Expression<Func<T, T2, object[]>> joinExpression,
Expression<Func<T, T2, TResult>> selectExpression,
- Expression<Func<T,T2, bool>> whereExpressionT1,
+ Expression<Func<T, T2, bool>> whereExpressionT1,
Expression<Func<TResult, bool>> whereExpression)
{
List<TResult> list = _db.CopyNew().Queryable(joinExpression).WhereIF(whereExpressionT1 != null, whereExpressionT1)
@@ -852,5 +855,103 @@
// Expression<Func<T, T2, T3, TResult>> selectExpression,
// Expression<Func<T, T2, T3, bool>> whereLambda = null) where T : class, new(){throw new NotImplementedException();}
//Task<PageModel<TEntity>> QueryPage(PaginationModel pagination){throw new NotImplementedException();}
+
+ public bool DeleteAndMoveIntoHty(TEntity entity, OperateTypeEnum operateType)
+ {
+ Type type = entity.GetType();
+ 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).ToList();
+
+ for (int i = 0; i < propertyInfos.Count; i++)
+ {
+ PropertyInfo propertyInfo = propertyInfos[i];
+ PropertyInfo? property = type.GetProperty(propertyInfo.Name);
+
+ if (property != null)
+ {
+ 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));
+ }
+ }
+ }
+ _db.InsertableByObject(obj).AS(type.Name + "_Hty").ExecuteCommand();
+ }
+ }
+ return DeleteData(entity);
+ }
+
+ public bool DeleteAndMoveIntoHty(List<TEntity> entities, OperateTypeEnum operateType)
+ {
+ Type type = typeof(TEntity);
+ Assembly assembly = type.Assembly;
+ Type? htyType = assembly.GetType(type.FullName + "_Hty");
+ if (htyType != null)
+ {
+ object? obj2 = Activator.CreateInstance(htyType);
+ PropertyInfo keyPro = typeof(TEntity).GetKeyProperty();
+ PropertyInfo? operateTypePro = htyType.GetProperty(nameof(IBaseHistoryEntity.OperateType));
+ PropertyInfo? sourceIdPro = htyType.GetProperty(nameof(IBaseHistoryEntity.SourceId));
+ if (obj2 != null && keyPro != null && operateTypePro != null && sourceIdPro != null)
+ {
+ List<PropertyInfo> propertyInfos = htyType.GetProperties().Where(x => x.Name != operateTypePro.Name && x.Name != sourceIdPro.Name && x.Name != keyPro.Name).ToList();
+ List<object> list = new List<object>();
+ foreach (var item in entities)
+ {
+ object? obj = Activator.CreateInstance(htyType);
+ if (obj != null)
+ {
+ operateTypePro.SetValue(obj, operateType.ToString());
+ sourceIdPro.SetValue(obj, keyPro.GetValue(item));
+ for (int i = 0; i < propertyInfos.Count; i++)
+ {
+ PropertyInfo propertyInfo = propertyInfos[i];
+ PropertyInfo? property = type.GetProperty(propertyInfo.Name);
+
+ if (property != null)
+ {
+ 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(item));
+ }
+ }
+ }
+ list.Add(obj);
+ }
+ }
+ _db.InsertableByObject(list).AS(type.Name + "_Hty").ExecuteCommand();
+
+ }
+ }
+ return DeleteData(entities);
+ }
}
}
--
Gitblit v1.9.3