From 587f0335544a6a0be00de5f56cb31af81169121e Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期四, 04 十二月 2025 15:58:17 +0800
Subject: [PATCH] 提交
---
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_Core/BaseRepository/RepositoryBase.cs | 426 ++++++++++++++++++++++++++--------------------------
1 files changed, 213 insertions(+), 213 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_Core/BaseRepository/RepositoryBase.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_Core/BaseRepository/RepositoryBase.cs"
index dc57ad4..2d08e68 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_Core/BaseRepository/RepositoryBase.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_Core/BaseRepository/RepositoryBase.cs"
@@ -869,237 +869,237 @@
.WhereIF(whereExpression != null, whereExpression).ToListAsync();
}
- //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));
- // }
- // }
- // }
- // if (obj != null)
- // _db.InsertableByObject(obj).AS(type.Name + "_Hty").ExecuteCommand();
- // }
- // }
- // return DeleteData(entity);
-
- //}
-
public bool DeleteAndMoveIntoHty(TEntity entity, OperateTypeEnum operateType)
{
- // 鏍稿績閫昏緫锛氱敤浜嬪姟淇濊瘉鍘熷瓙鎬э紝寮傚父鎹曡幏閬垮厤娴佺▼涓柇锛屾棩蹇楄緟鍔╂帓鏌�
- bool isSuccess = false;
- string entityTypeName = entity?.GetType().Name ?? "鏈煡瀹炰綋";
-
- try
+ Type type = entity.GetType();
+ Assembly assembly = type.Assembly;
+ Type? htyType = assembly.GetType(type.FullName + "_Hty");
+ if (htyType != null)
{
- // 鍓嶇疆鏍¢獙锛氬疄浣撲笉鑳戒负绌�
- if (entity == 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)
{
- return false;
- }
+ operateTypePro.SetValue(obj, operateType.ToString());
+ sourceIdPro.SetValue(obj, keyPro.GetValue(entity));
- Type entityType = entity.GetType();
- Assembly assembly = entityType.Assembly;
- string htyTypeName = $"{entityType.FullName}_Hty";
- Type? htyType = assembly.GetType(htyTypeName);
+ List<PropertyInfo> propertyInfos = htyType.GetProperties().Where(x => x.Name != operateTypePro.Name && x.Name != sourceIdPro.Name && x.Name != keyPro.Name).ToList();
- // 1. 妫�鏌ュ巻鍙茶〃绫诲瀷鏄惁瀛樺湪
- if (htyType == null)
- {
-
- return false;
- }
-
- // 2. 鍒涘缓鍘嗗彶琛ㄥ疄渚嬶紙澶勭悊鏃犲弬鏋勯�犲嚱鏁颁笉瀛樺湪鐨勬儏鍐碉級
- object? htyObj;
- try
- {
- htyObj = Activator.CreateInstance(htyType);
- }
- catch (Exception ex)
- {
- // _logger.LogError(ex, "DeleteAndMoveIntoHty锛氬垱寤哄巻鍙茶〃瀹炰緥 {HtyTypeName} 澶辫触", htyTypeName);
- return false;
- }
- if (htyObj == null)
- {
- // _logger.LogWarning("DeleteAndMoveIntoHty锛氬巻鍙茶〃瀹炰緥 {HtyTypeName} 鍒涘缓缁撴灉涓簄ull", htyTypeName);
- return false;
- }
-
- // 3. 鑾峰彇鏍稿績灞炴�э紙鎸囧畾BindingFlags纭繚鑾峰彇鍏叡瀹炰緥灞炴�э級
- BindingFlags propFlags = BindingFlags.Public | BindingFlags.Instance;
- PropertyInfo? keyPro = typeof(TEntity).GetKeyProperty(); // 鑷畾涔夋柟娉曢渶纭繚杩斿洖闈炵┖锛屾澶勫鍔犲垽绌�
- PropertyInfo? operateTypePro = htyType.GetProperty(nameof(IBaseHistoryEntity.OperateType), propFlags);
- PropertyInfo? sourceIdPro = htyType.GetProperty(nameof(IBaseHistoryEntity.SourceId), propFlags);
-
- // 鏍¢獙鏍稿績灞炴�ф槸鍚﹀瓨鍦�
- if (keyPro == null)
- {
- //_logger.LogError("DeleteAndMoveIntoHty锛氬疄浣� {EntityType} 鏈壘鍒颁富閿睘鎬�", entityType.FullName);
- return false;
- }
- if (operateTypePro == null)
- {
- //_logger.LogError("DeleteAndMoveIntoHty锛氬巻鍙茶〃 {HtyTypeName} 鏈壘鍒癘perateType灞炴��", htyTypeName);
- return false;
- }
- if (sourceIdPro == null)
- {
- // _logger.LogError("DeleteAndMoveIntoHty锛氬巻鍙茶〃 {HtyTypeName} 鏈壘鍒癝ourceId灞炴��", htyTypeName);
- return false;
- }
-
- // 4. 璧嬪�兼牳蹇冨睘鎬э紙鏍¢獙绫诲瀷鍖归厤锛岄伩鍏峉etValue鎶涘紓甯革級
- try
- {
- // 澶勭悊OperateType绫诲瀷鍖归厤锛氳嫢鍘嗗彶琛ㄥ睘鎬ф槸鏋氫妇绫诲瀷锛岀洿鎺ヤ紶鏋氫妇鑰岄潪瀛楃涓�
- if (operateTypePro.PropertyType == typeof(OperateTypeEnum))
+ for (int i = 0; i < propertyInfos.Count; i++)
{
- operateTypePro.SetValue(htyObj, operateType);
- }
- else if (operateTypePro.PropertyType == typeof(string))
- {
- operateTypePro.SetValue(htyObj, operateType.ToString());
- }
- else
- {
- //_logger.LogError("DeleteAndMoveIntoHty锛氬巻鍙茶〃 {HtyTypeName} 鐨凮perateType灞炴�х被鍨� {PropType} 涓嶅尮閰嶏紙浠呮敮鎸佹灇涓�/瀛楃涓诧級", htyTypeName, operateTypePro.PropertyType.FullName);
- return false;
- }
+ PropertyInfo propertyInfo = propertyInfos[i];
+ PropertyInfo? property = type.GetProperty(propertyInfo.Name);
- // 璧嬪�糞ourceId锛堟牎楠岀被鍨嬪尮閰嶏級
- object sourceIdValue = keyPro.GetValue(entity)!;
- if (sourceIdPro.PropertyType != sourceIdValue.GetType())
- {
- sourceIdValue = Convert.ChangeType(sourceIdValue, sourceIdPro.PropertyType); // 绫诲瀷杞崲
- }
- sourceIdPro.SetValue(htyObj, sourceIdValue);
- }
- catch (Exception ex)
- {
- // _logger.LogError(ex, "DeleteAndMoveIntoHty锛氬巻鍙茶〃 {HtyTypeName} 鏍稿績灞炴�ц祴鍊煎け璐�", htyTypeName);
- return false;
- }
-
- // 5. 璧嬪�煎叾浠栧睘鎬э紙鎺掗櫎鏍稿績灞炴�э級
- List<PropertyInfo> htyProperties = htyType.GetProperties(propFlags)
- .Where(x => x.Name != operateTypePro.Name
- && x.Name != sourceIdPro.Name
- && x.Name != keyPro.Name)
- .ToList();
-
- foreach (PropertyInfo htyProp in htyProperties)
- {
- PropertyInfo? entityProp = entityType.GetProperty(htyProp.Name, propFlags);
- if (entityProp == null) continue; // 瀹炰綋鏃犺灞炴�у垯璺宠繃
-
- try
- {
- object propValue;
- // 澶勭悊淇敼浜猴細閬垮厤App.User绌哄紩鐢�
- if (htyProp.Name == nameof(BaseEntity.Modifier))
+ if (property != null)
{
- propValue = App.User?.UserId > 0 ? App.User?.UserName : "System";
+ 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));
+ }
}
- // 澶勭悊淇敼鏃堕棿
- else if (htyProp.Name == nameof(BaseEntity.ModifyDate))
- {
- propValue = DateTime.Now;
- }
- // 鍏朵粬灞炴�т粠鍘熷疄浣撳彇鍊�
- else
- {
- propValue = entityProp.GetValue(entity) ?? DBNull.Value; // 澶勭悊null鍊�
- }
-
- // 绫诲瀷杞崲鍚庤祴鍊硷紙閬垮厤绫诲瀷涓嶅尮閰嶏級
- if (propValue != DBNull.Value && propValue != null)
- {
- propValue = Convert.ChangeType(propValue, htyProp.PropertyType);
- }
- htyProp.SetValue(htyObj, propValue);
}
- catch (Exception ex)
- {
- // _logger.LogWarning(ex, "DeleteAndMoveIntoHty锛氬巻鍙茶〃 {HtyTypeName} 灞炴�� {PropName} 璧嬪�煎け璐ワ紝璺宠繃璇ュ睘鎬�", htyTypeName, htyProp.Name);
- }
+ if (obj != null)
+ _db.InsertableByObject(obj).AS(type.Name + "_Hty").ExecuteCommand();
}
- try
- {
- // 鎵ц鎻掑叆鍘嗗彶琛�
- int insertRows = _db.InsertableByObject(htyObj).AS(entityType.Name + "_Hty").ExecuteCommand();
-
- if (insertRows <= 0)
- {
- // _logger.LogError("DeleteAndMoveIntoHty锛氬巻鍙茶〃 {HtyTypeName} 鎻掑叆澶辫触锛堝奖鍝嶈鏁�0锛�", htyTypeName);
- _db.InsertableByObject(htyObj).AS(entityType.Name + "_Hty").ExecuteCommand();
- return false;
- }
- // 鎻掑叆鎴愬姛鍚庢墽琛屽垹闄�
- bool deleteSuccess = DeleteData(entity);
- if (!deleteSuccess)
- {
- //_logger.LogError("DeleteAndMoveIntoHty锛氬疄浣� {EntityType} 鍒犻櫎澶辫触", entityType.FullName);
- DeleteData(entity);
- return false;
- }
- // 鎻愪氦浜嬪姟
-
- isSuccess = true;
- //_logger.LogInformation("DeleteAndMoveIntoHty锛氬疄浣� {EntityType} 宸叉垚鍔熺Щ鍏ュ巻鍙茶〃骞跺垹闄ゅ師鏁版嵁", entityType.FullName);
- }
- catch (Exception ex)
- {
-
- // _logger.LogError(ex, "DeleteAndMoveIntoHty锛氫簨鍔℃墽琛屽け璐ワ紙鎻掑叆鍘嗗彶琛�/鍒犻櫎鍘熸暟鎹級", entityType.FullName);
- return false;
- }
}
- catch (Exception ex)
- {
- // _logger.LogError(ex, "DeleteAndMoveIntoHty锛氬鐞嗗疄浣� {EntityTypeName} 鏃跺彂鐢熸湭鎹曡幏寮傚父", entityTypeName);
- return false;
- }
+ return DeleteData(entity);
- return isSuccess;
}
+ //public bool DeleteAndMoveIntoHty(TEntity entity, OperateTypeEnum operateType)
+ //{
+ // // 鏍稿績閫昏緫锛氱敤浜嬪姟淇濊瘉鍘熷瓙鎬э紝寮傚父鎹曡幏閬垮厤娴佺▼涓柇锛屾棩蹇楄緟鍔╂帓鏌�
+ // bool isSuccess = false;
+ // string entityTypeName = entity?.GetType().Name ?? "鏈煡瀹炰綋";
+
+ // try
+ // {
+ // // 鍓嶇疆鏍¢獙锛氬疄浣撲笉鑳戒负绌�
+ // if (entity == null)
+ // {
+ // return false;
+ // }
+
+ // Type entityType = entity.GetType();
+ // Assembly assembly = entityType.Assembly;
+ // string htyTypeName = $"{entityType.FullName}_Hty";
+ // Type? htyType = assembly.GetType(htyTypeName);
+
+ // // 1. 妫�鏌ュ巻鍙茶〃绫诲瀷鏄惁瀛樺湪
+ // if (htyType == null)
+ // {
+
+ // return false;
+ // }
+
+ // // 2. 鍒涘缓鍘嗗彶琛ㄥ疄渚嬶紙澶勭悊鏃犲弬鏋勯�犲嚱鏁颁笉瀛樺湪鐨勬儏鍐碉級
+ // object? htyObj;
+ // try
+ // {
+ // htyObj = Activator.CreateInstance(htyType);
+ // }
+ // catch (Exception ex)
+ // {
+ // // _logger.LogError(ex, "DeleteAndMoveIntoHty锛氬垱寤哄巻鍙茶〃瀹炰緥 {HtyTypeName} 澶辫触", htyTypeName);
+ // return false;
+ // }
+ // if (htyObj == null)
+ // {
+ // // _logger.LogWarning("DeleteAndMoveIntoHty锛氬巻鍙茶〃瀹炰緥 {HtyTypeName} 鍒涘缓缁撴灉涓簄ull", htyTypeName);
+ // return false;
+ // }
+
+ // // 3. 鑾峰彇鏍稿績灞炴�э紙鎸囧畾BindingFlags纭繚鑾峰彇鍏叡瀹炰緥灞炴�э級
+ // BindingFlags propFlags = BindingFlags.Public | BindingFlags.Instance;
+ // PropertyInfo? keyPro = typeof(TEntity).GetKeyProperty(); // 鑷畾涔夋柟娉曢渶纭繚杩斿洖闈炵┖锛屾澶勫鍔犲垽绌�
+ // PropertyInfo? operateTypePro = htyType.GetProperty(nameof(IBaseHistoryEntity.OperateType), propFlags);
+ // PropertyInfo? sourceIdPro = htyType.GetProperty(nameof(IBaseHistoryEntity.SourceId), propFlags);
+
+ // // 鏍¢獙鏍稿績灞炴�ф槸鍚﹀瓨鍦�
+ // if (keyPro == null)
+ // {
+ // //_logger.LogError("DeleteAndMoveIntoHty锛氬疄浣� {EntityType} 鏈壘鍒颁富閿睘鎬�", entityType.FullName);
+ // return false;
+ // }
+ // if (operateTypePro == null)
+ // {
+ // //_logger.LogError("DeleteAndMoveIntoHty锛氬巻鍙茶〃 {HtyTypeName} 鏈壘鍒癘perateType灞炴��", htyTypeName);
+ // return false;
+ // }
+ // if (sourceIdPro == null)
+ // {
+ // // _logger.LogError("DeleteAndMoveIntoHty锛氬巻鍙茶〃 {HtyTypeName} 鏈壘鍒癝ourceId灞炴��", htyTypeName);
+ // return false;
+ // }
+
+ // // 4. 璧嬪�兼牳蹇冨睘鎬э紙鏍¢獙绫诲瀷鍖归厤锛岄伩鍏峉etValue鎶涘紓甯革級
+ // try
+ // {
+ // // 澶勭悊OperateType绫诲瀷鍖归厤锛氳嫢鍘嗗彶琛ㄥ睘鎬ф槸鏋氫妇绫诲瀷锛岀洿鎺ヤ紶鏋氫妇鑰岄潪瀛楃涓�
+ // if (operateTypePro.PropertyType == typeof(OperateTypeEnum))
+ // {
+ // operateTypePro.SetValue(htyObj, operateType);
+ // }
+ // else if (operateTypePro.PropertyType == typeof(string))
+ // {
+ // operateTypePro.SetValue(htyObj, operateType.ToString());
+ // }
+ // else
+ // {
+ // //_logger.LogError("DeleteAndMoveIntoHty锛氬巻鍙茶〃 {HtyTypeName} 鐨凮perateType灞炴�х被鍨� {PropType} 涓嶅尮閰嶏紙浠呮敮鎸佹灇涓�/瀛楃涓诧級", htyTypeName, operateTypePro.PropertyType.FullName);
+ // return false;
+ // }
+
+ // // 璧嬪�糞ourceId锛堟牎楠岀被鍨嬪尮閰嶏級
+ // object sourceIdValue = keyPro.GetValue(entity)!;
+ // if (sourceIdPro.PropertyType != sourceIdValue.GetType())
+ // {
+ // sourceIdValue = Convert.ChangeType(sourceIdValue, sourceIdPro.PropertyType); // 绫诲瀷杞崲
+ // }
+ // sourceIdPro.SetValue(htyObj, sourceIdValue);
+ // }
+ // catch (Exception ex)
+ // {
+ // // _logger.LogError(ex, "DeleteAndMoveIntoHty锛氬巻鍙茶〃 {HtyTypeName} 鏍稿績灞炴�ц祴鍊煎け璐�", htyTypeName);
+ // return false;
+ // }
+
+ // // 5. 璧嬪�煎叾浠栧睘鎬э紙鎺掗櫎鏍稿績灞炴�э級
+ // List<PropertyInfo> htyProperties = htyType.GetProperties(propFlags)
+ // .Where(x => x.Name != operateTypePro.Name
+ // && x.Name != sourceIdPro.Name
+ // && x.Name != keyPro.Name)
+ // .ToList();
+
+ // foreach (PropertyInfo htyProp in htyProperties)
+ // {
+ // PropertyInfo? entityProp = entityType.GetProperty(htyProp.Name, propFlags);
+ // if (entityProp == null) continue; // 瀹炰綋鏃犺灞炴�у垯璺宠繃
+
+ // try
+ // {
+ // object propValue;
+ // // 澶勭悊淇敼浜猴細閬垮厤App.User绌哄紩鐢�
+ // if (htyProp.Name == nameof(BaseEntity.Modifier))
+ // {
+ // propValue = App.User?.UserId > 0 ? App.User?.UserName : "System";
+ // }
+ // // 澶勭悊淇敼鏃堕棿
+ // else if (htyProp.Name == nameof(BaseEntity.ModifyDate))
+ // {
+ // propValue = DateTime.Now;
+ // }
+ // // 鍏朵粬灞炴�т粠鍘熷疄浣撳彇鍊�
+ // else
+ // {
+ // propValue = entityProp.GetValue(entity) ?? DBNull.Value; // 澶勭悊null鍊�
+ // }
+
+ // // 绫诲瀷杞崲鍚庤祴鍊硷紙閬垮厤绫诲瀷涓嶅尮閰嶏級
+ // if (propValue != DBNull.Value && propValue != null)
+ // {
+ // propValue = Convert.ChangeType(propValue, htyProp.PropertyType);
+ // }
+ // htyProp.SetValue(htyObj, propValue);
+ // }
+ // catch (Exception ex)
+ // {
+ // // _logger.LogWarning(ex, "DeleteAndMoveIntoHty锛氬巻鍙茶〃 {HtyTypeName} 灞炴�� {PropName} 璧嬪�煎け璐ワ紝璺宠繃璇ュ睘鎬�", htyTypeName, htyProp.Name);
+ // }
+ // }
+ // try
+ // {
+ // // 鎵ц鎻掑叆鍘嗗彶琛�
+ // int insertRows = _db.InsertableByObject(htyObj).AS(entityType.Name + "_Hty").ExecuteCommand();
+
+ // if (insertRows <= 0)
+ // {
+ // // _logger.LogError("DeleteAndMoveIntoHty锛氬巻鍙茶〃 {HtyTypeName} 鎻掑叆澶辫触锛堝奖鍝嶈鏁�0锛�", htyTypeName);
+ // _db.InsertableByObject(htyObj).AS(entityType.Name + "_Hty").ExecuteCommand();
+ // return false;
+ // }
+ // // 鎻掑叆鎴愬姛鍚庢墽琛屽垹闄�
+ // bool deleteSuccess = DeleteData(entity);
+ // if (!deleteSuccess)
+ // {
+ // //_logger.LogError("DeleteAndMoveIntoHty锛氬疄浣� {EntityType} 鍒犻櫎澶辫触", entityType.FullName);
+ // DeleteData(entity);
+ // return false;
+ // }
+ // // 鎻愪氦浜嬪姟
+
+ // isSuccess = true;
+ // //_logger.LogInformation("DeleteAndMoveIntoHty锛氬疄浣� {EntityType} 宸叉垚鍔熺Щ鍏ュ巻鍙茶〃骞跺垹闄ゅ師鏁版嵁", entityType.FullName);
+ // }
+ // catch (Exception ex)
+ // {
+
+ // // _logger.LogError(ex, "DeleteAndMoveIntoHty锛氫簨鍔℃墽琛屽け璐ワ紙鎻掑叆鍘嗗彶琛�/鍒犻櫎鍘熸暟鎹級", entityType.FullName);
+ // return false;
+ // }
+ // }
+ // catch (Exception ex)
+ // {
+ // // _logger.LogError(ex, "DeleteAndMoveIntoHty锛氬鐞嗗疄浣� {EntityTypeName} 鏃跺彂鐢熸湭鎹曡幏寮傚父", entityTypeName);
+ // return false;
+ // }
+
+ // return isSuccess;
+ //}
-public bool DeleteAndMoveIntoHty(List<TEntity> entities, OperateTypeEnum operateType)
+
+ public bool DeleteAndMoveIntoHty(List<TEntity> entities, OperateTypeEnum operateType)
{
Type type = typeof(TEntity);
Assembly assembly = type.Assembly;
--
Gitblit v1.9.3