From a9a3f943efb083de8ed88b293897886b3ef612a2 Mon Sep 17 00:00:00 2001
From: helongyang <647556386@qq.com>
Date: 星期一, 11 八月 2025 17:37:09 +0800
Subject: [PATCH] 功能增添优化
---
代码管理/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/CodeAnalysisHelper.cs | 66 ++++++++++++++++++++++++++++----
1 files changed, 57 insertions(+), 9 deletions(-)
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/CodeAnalysisHelper.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/CodeAnalysisHelper.cs"
index 4bfa6e3..dd90e9b 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/CodeAnalysisHelper.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/CodeAnalysisHelper.cs"
@@ -1,4 +1,5 @@
锘縰sing OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using SqlSugar;
using System;
using System.Collections.Generic;
@@ -11,6 +12,7 @@
using WIDESEA_Core.DB;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Seed;
+using WIDESEA_Core.Utilities;
namespace WIDESEA_Core.Helper
{
@@ -61,21 +63,51 @@
AnalysisItemRuleAttribute? analysisItemRule = propertyInfo.GetCustomAttribute<AnalysisItemRuleAttribute>();
if (analysisItemRule != null)
{
- int index = items.IndexOf($"[{analysisItemRule.AnalysisFormaType}]");
- if (index != -1)
- propertyInfo.SetValue(result, codes[index]);
+ if (analysisItemRule.AnalysisFormaType == AnalysisFormatTypeEnum.BD)
+ {
+ propertyInfo.SetValue(result, code.ChangeType(propertyInfo.PropertyType));
+ }
+ else
+ {
+ int index = items.IndexOf($"[{analysisItemRule.AnalysisFormaType}]");
+ if (index != -1)
+ {
+ propertyInfo.SetValue(result, codes[index]);
+ }
+ else
+ {
+ string? codeItem = items.FirstOrDefault(x => x.Contains($"[{analysisItemRule.AnalysisFormaType}]"));
+ if (!string.IsNullOrEmpty(codeItem))
+ {
+ index = items.IndexOf(codeItem);
+ if (index != -1)
+ {
+ string value = codes[index];
+ string replaceStr = codeItem.Replace($"[{analysisItemRule.AnalysisFormaType}]", "");
+
+ propertyInfo.SetValue(result, value.Replace(replaceStr, "").ChangeType(propertyInfo.PropertyType));
+ }
+ }
+ }
+ }
}
}
}
}
-
}
}
}
catch (Exception ex)
{
-
+ throw new Exception($"瑙f瀽閿欒,{ex.Message}");
}
+
+ (bool, string, object?) validateResult = ModelValidate.ValidateModelData(result, type);
+ if (!validateResult.Item1)
+ {
+ throw new Exception($"瑙f瀽閿欒,{validateResult.Item2}");
+ }
+
return result;
}
@@ -90,7 +122,7 @@
{
Type type = typeof(T);
List<T> list = new List<T>();
-
+
try
{
AnalysisRuleAttribute? analysisRule = type.GetCustomAttribute<AnalysisRuleAttribute>();
@@ -126,7 +158,7 @@
AnalysisItemRuleAttribute? analysisItemRule = propertyInfo.GetCustomAttribute<AnalysisItemRuleAttribute>();
if (analysisItemRule != null)
{
- if(analysisItemRule.AnalysisFormaType == AnalysisFormatTypeEnum.BD)
+ if (analysisItemRule.AnalysisFormaType == AnalysisFormatTypeEnum.BD)
{
propertyInfo.SetValue(result, code.ChangeType(propertyInfo.PropertyType));
}
@@ -134,9 +166,25 @@
{
int index = items.IndexOf($"[{analysisItemRule.AnalysisFormaType}]");
if (index != -1)
- propertyInfo.SetValue(result, codes[index].ChangeType(propertyInfo.PropertyType));
+ {
+ propertyInfo.SetValue(result, codes[index]);
+ }
+ else
+ {
+ string? codeItem = items.FirstOrDefault(x => x.Contains($"[{analysisItemRule.AnalysisFormaType}]"));
+ if (!string.IsNullOrEmpty(codeItem))
+ {
+ index = items.IndexOf(codeItem);
+ if (index != -1)
+ {
+ string value = codes[index];
+ string replaceStr = codeItem.Replace($"[{analysisItemRule.AnalysisFormaType}]", "");
+
+ propertyInfo.SetValue(result, value.Replace(replaceStr, "").ChangeType(propertyInfo.PropertyType));
+ }
+ }
+ }
}
-
}
}
}
--
Gitblit v1.9.3