From 960b33fa24c47a330e51a2c24859d681ae62caeb Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期四, 16 四月 2026 10:09:49 +0800
Subject: [PATCH] 重构任务与库存模型,增强日志管理与区域接口
---
Code Management/WCS/WIDESEA_WCSServer/WIDESEAWCS_Core/BaseRepository/RepositoryBase.cs | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 106 insertions(+), 12 deletions(-)
diff --git a/Code Management/WCS/WIDESEA_WCSServer/WIDESEAWCS_Core/BaseRepository/RepositoryBase.cs b/Code Management/WCS/WIDESEA_WCSServer/WIDESEAWCS_Core/BaseRepository/RepositoryBase.cs
index 2bfd6fa..857d138 100644
--- a/Code Management/WCS/WIDESEA_WCSServer/WIDESEAWCS_Core/BaseRepository/RepositoryBase.cs
+++ b/Code Management/WCS/WIDESEA_WCSServer/WIDESEAWCS_Core/BaseRepository/RepositoryBase.cs
@@ -1,21 +1,25 @@
-锘縰sing SqlSugar;
-using System.Data;
-using System.Linq.Expressions;
+锘縰sing 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
{
@@ -847,6 +851,96 @@
.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,
--
Gitblit v1.9.3