| | |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | |
| | | 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 |
| | | { |
| | |
| | | /// <param name="analysisCode">è§åç¼å·</param> |
| | | /// <param name="code">éè§£æçå符串</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); |
| | |
| | | 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++) |
| | | { |
| | |
| | | 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($"è§£æé误,{ex.Message}"); |
| | | } |
| | | |
| | | (bool, string, object?) validateResult = ModelValidate.ValidateModelData(result, type); |
| | | if (!validateResult.Item1) |
| | | { |
| | | throw new Exception($"è§£æé误,{validateResult.Item2}"); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | |
| | | /// <param name="analysisCode">è§åç¼å·</param> |
| | | /// <param name="codeList">éè§£æçå符串éå</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>(); |
| | |
| | | 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++) |
| | | { |
| | |
| | | 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)); |
| | | } |
| | |
| | | { |
| | | 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)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |