From dab0a583302f306d8c0ec37fbae37c9b4e37e473 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期一, 29 十二月 2025 18:46:15 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/MeiRuiAn/JiAnLiKu
---
WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/CodeAnalysisHelper.cs | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 156 insertions(+), 14 deletions(-)
diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/CodeAnalysisHelper.cs b/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/CodeAnalysisHelper.cs
index 6dbad0f..3be55df 100644
--- a/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/CodeAnalysisHelper.cs
+++ b/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
{
@@ -21,8 +24,8 @@
/// <typeparam name="T">娉涘瀷</typeparam>
/// <param name="analysisCode">瑙勫垯缂栧彿</param>
/// <param name="code">闇�瑙f瀽鐨勫瓧绗︿覆</param>
- /// <returns></returns>
- public static T CodeAnalysis<T>(AnalysisCode analysisCode, string code)
+ /// <returns></returns>
+ 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,144 @@
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;
+ }
+
+ /// <summary>
+ /// 瑙f瀽缂栫爜鎴愬璞¢泦
+ /// </summary>
+ /// <typeparam name="T">娉涘瀷</typeparam>
+ /// <param name="analysisCode">瑙勫垯缂栧彿</param>
+ /// <param name="code">闇�瑙f瀽鐨勫瓧绗︿覆</param>
+ /// <returns></returns>
+ public static T CodeAnalysisCP<T>(AnalysisCodeEnum analysisCode, string code)
+ {
+ Type type = typeof(T);
+ object? obj = Activator.CreateInstance(type);
+ if (obj == null)
+ throw new Exception("瀹炰緥鍖栧璞¢敊璇�");
+ T result = (T)obj;
+ try
+ {
+ AnalysisRuleAttribute? analysisRule = type.GetCustomAttribute<AnalysisRuleAttribute>();
+ if (analysisRule != null)
+ {
+ SqlSugarClient sugarClient = new SqlSugarClient(new ConnectionConfig
+ {
+ ConfigId = MainDb.CurrentDbConnId,
+ ConnectionString = DBContext.GetMainConnectionDb().Connection,
+ IsAutoCloseConnection = true,
+ DbType = MainDb.DbType,
+ });
+
+ dynamic ruleConfig = sugarClient.Queryable(MainDb.AnalysisRuleConfig, "x").Where(MainDb.AnalysisCode, "=", analysisCode.ToString()).First();
+ if (ruleConfig != null)
+ {
+ string format = ruleConfig.Format;
+ string splitStr = ruleConfig.SplitStr;
+ List<string> items = format.Split(splitStr).ToList();
+ List<string> codes = code.Split(splitStr).ToList();
+ if (items.Count == codes.Count)
+ {
+ PropertyInfo[] propertyInfos = type.GetProperties();
+ if (AnalysisRuleEnum.Split == analysisRule.AnalysisRule)
+ {
+ for (int i = 0; i < propertyInfos.Length; i++)
+ {
+ PropertyInfo propertyInfo = propertyInfos[i];
+ AnalysisItemRuleAttribute? analysisItemRule = propertyInfo.GetCustomAttribute<AnalysisItemRuleAttribute>();
+ if (analysisItemRule != null)
+ {
+ 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 +211,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 +243,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 +251,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 +259,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