From 695571c6009ecbc12e7d4a4fb147df7967a1260e Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期一, 07 七月 2025 20:21:19 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/MeiRuiAn/HuaiAn
---
代码管理/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/CodeAnalysisHelper.cs | 75 +++++++++++++++++++++++++++++++------
1 files changed, 62 insertions(+), 13 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 6dbad0f..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;
@@ -7,9 +8,11 @@
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core.Attributes;
+using WIDESEA_Core.CodeConfigEnum;
using WIDESEA_Core.DB;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Seed;
+using WIDESEA_Core.Utilities;
namespace WIDESEA_Core.Helper
{
@@ -22,7 +25,7 @@
/// <param name="analysisCode">瑙勫垯缂栧彿</param>
/// <param name="code">闇�瑙f瀽鐨勫瓧绗︿覆</param>
/// <returns></returns>
- public static T CodeAnalysis<T>(AnalysisCode analysisCode, string code)
+ public static T CodeAnalysis<T>(AnalysisCodeEnum analysisCode, string code)
{
Type type = typeof(T);
object? obj = Activator.CreateInstance(type);
@@ -52,7 +55,7 @@
if (items.Count == codes.Count)
{
PropertyInfo[] propertyInfos = type.GetProperties();
- if (AnalysisRule.Split == analysisRule.AnalysisRule)
+ if (AnalysisRuleEnum.Split == analysisRule.AnalysisRule)
{
for (int i = 0; i < propertyInfos.Length; i++)
{
@@ -60,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;
}
@@ -85,11 +118,11 @@
/// <param name="analysisCode">瑙勫垯缂栧彿</param>
/// <param name="codeList">闇�瑙f瀽鐨勫瓧绗︿覆闆嗗悎</param>
/// <returns></returns>
- public static List<T> CodeAnalysis<T>(AnalysisCode analysisCode, List<string> codeList)
+ public static List<T> CodeAnalysis<T>(AnalysisCodeEnum analysisCode, List<string> codeList)
{
Type type = typeof(T);
List<T> list = new List<T>();
-
+
try
{
AnalysisRuleAttribute? analysisRule = type.GetCustomAttribute<AnalysisRuleAttribute>();
@@ -117,7 +150,7 @@
if (items.Count == codes.Count)
{
PropertyInfo[] propertyInfos = type.GetProperties();
- if (AnalysisRule.Split == analysisRule.AnalysisRule)
+ if (AnalysisRuleEnum.Split == analysisRule.AnalysisRule)
{
for (int i = 0; i < propertyInfos.Length; i++)
{
@@ -125,7 +158,7 @@
AnalysisItemRuleAttribute? analysisItemRule = propertyInfo.GetCustomAttribute<AnalysisItemRuleAttribute>();
if (analysisItemRule != null)
{
- if(analysisItemRule.AnalysisFormaType == AnalysisFormatType.BD)
+ if (analysisItemRule.AnalysisFormaType == AnalysisFormatTypeEnum.BD)
{
propertyInfo.SetValue(result, code.ChangeType(propertyInfo.PropertyType));
}
@@ -133,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