|
@@ -1,4 +1,6 @@
|
|
|
-using NPOI.SS.Formula.Functions;
|
|
|
+using Newtonsoft.Json.Linq;
|
|
|
+using Newtonsoft.Json;
|
|
|
+using NPOI.SS.Formula.Functions;
|
|
|
using OASystem.Domain.ViewModels.Financial;
|
|
|
using OASystem.Domain.ViewModels.Groups;
|
|
|
using System.Collections;
|
|
@@ -6,6 +8,8 @@ using System.Globalization;
|
|
|
using System.Reflection;
|
|
|
using System.Reflection.Metadata;
|
|
|
using System.Security.Cryptography;
|
|
|
+using Pinyin4net.Format;
|
|
|
+using Pinyin4net;
|
|
|
|
|
|
namespace OASystem.Infrastructure.Tools;
|
|
|
|
|
@@ -34,11 +38,11 @@ public static class CommonFun
|
|
|
}
|
|
|
public static string ToJson(this object obj)
|
|
|
{
|
|
|
- return JsonSerializer.Serialize(obj);
|
|
|
+ return System.Text.Json.JsonSerializer.Serialize(obj);
|
|
|
}
|
|
|
public static T ToObject<T>(this string json)
|
|
|
{
|
|
|
- return JsonSerializer.Deserialize<T>(json);
|
|
|
+ return System.Text.Json.JsonSerializer.Deserialize<T>(json);
|
|
|
}
|
|
|
public static object GetDefaultVal(string typename)
|
|
|
{
|
|
@@ -594,5 +598,97 @@ public static class CommonFun
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+ /// <summary>
|
|
|
+ /// 验证json字符串是否合法
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonString"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static bool IsValidJson(string jsonString)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ JToken.Parse(jsonString);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ catch (JsonReaderException)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 常见的双字姓氏列表
|
|
|
+ /// </summary>
|
|
|
+ private static readonly HashSet<string> commonDoubleSurnames = new HashSet<string>
|
|
|
+ {
|
|
|
+ "欧阳", "司马", "上官", "夏侯", "诸葛", "东方", "赫连", "皇甫", "尉迟", "公羊",
|
|
|
+ "澹台", "公冶", "宗政", "濮阳", "淳于", "单于", "太叔", "申屠", "公孙", "仲孙",
|
|
|
+ "轩辕", "令狐", "钟离", "宇文", "长孙", "慕容", "鲜于", "闾丘", "司徒", "司空",
|
|
|
+ "亓官", "司寇", "仉督", "子车", "颛孙", "端木", "巫马", "公西", "漆雕", "乐正",
|
|
|
+ "壤驷", "公良", "拓跋", "夹谷", "宰父", "谷梁", "晋楚", "闫法", "汝鄢", "涂钦",
|
|
|
+ "段干", "百里", "东郭", "南门", "呼延", "归海", "羊舌", "微生", "岳帅", "缑亢",
|
|
|
+ "况后", "有琴", "梁丘", "左丘", "东门", "西门", "商牟", "佘佴", "伯赏", "南宫"
|
|
|
+ };
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 中文名字取姓氏和名字
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="fullName"></param>
|
|
|
+ /// <returns>姓:lastName 名:firstName</returns>
|
|
|
+ public static (string lastName, string firstName) GetLastNameAndFirstName(string fullName)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(fullName) || fullName.Length < 2) return ("", "");
|
|
|
+
|
|
|
+ // 尝试匹配双字姓氏
|
|
|
+ if (fullName.Length > 2)
|
|
|
+ {
|
|
|
+ string potentialDoubleSurname = fullName.Substring(0, 2);
|
|
|
+ if (commonDoubleSurnames.Contains(potentialDoubleSurname))
|
|
|
+ {
|
|
|
+ string lastName = potentialDoubleSurname;
|
|
|
+ string firstName = fullName.Substring(2);
|
|
|
+ return (lastName, firstName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 默认单字姓氏
|
|
|
+ string singleSurname = fullName.Substring(0, 1);
|
|
|
+ string remainingName = fullName.Substring(1);
|
|
|
+ return (singleSurname, remainingName);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 中文名字转拼音
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="chineseName"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ /// <exception cref="ArgumentException"></exception>
|
|
|
+ public static string ConvertToPinyin(string chineseName)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(chineseName)) return "";
|
|
|
+
|
|
|
+ HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat
|
|
|
+ {
|
|
|
+ ToneType = HanyuPinyinToneType.WITHOUT_TONE,
|
|
|
+ VCharType = HanyuPinyinVCharType.WITH_V,
|
|
|
+ CaseType = HanyuPinyinCaseType.UPPERCASE
|
|
|
+ };
|
|
|
+
|
|
|
+ string pinyin = string.Empty;
|
|
|
+ foreach (char ch in chineseName)
|
|
|
+ {
|
|
|
+ if (PinyinHelper.ToHanyuPinyinStringArray(ch) != null)
|
|
|
+ {
|
|
|
+ pinyin += PinyinHelper.ToHanyuPinyinStringArray(ch, format)[0];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pinyin += ch;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return pinyin;
|
|
|
+ }
|
|
|
+
|
|
|
}
|