GeneralMethod.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. 
  2. using Microsoft.AspNetCore.SignalR;
  3. using Microsoft.International.Converters.PinYinConverter;
  4. using OASystem.API.OAMethodLib.Hub.HubClients;
  5. using OASystem.API.OAMethodLib.Hub.Hubs;
  6. using OASystem.API.OAMethodLib.JuHeAPI;
  7. using OASystem.API.OAMethodLib.SignalR.Hubs;
  8. using OASystem.Domain.Entities.Customer;
  9. using OASystem.Domain.Entities.District;
  10. using OASystem.Domain.Entities.Financial;
  11. using OASystem.Domain.Entities.Groups;
  12. using OASystem.Domain.ViewModels.Financial;
  13. using OASystem.Domain.ViewModels.JuHeExchangeRate;
  14. using OASystem.Infrastructure.Repositories.CRM;
  15. using OASystem.Infrastructure.Repositories.Groups;
  16. using System.IdentityModel.Tokens.Jwt;
  17. using System.Security.Claims;
  18. namespace OASystem.API.OAMethodLib
  19. {
  20. public static class GeneralMethod
  21. {
  22. //团组信息
  23. private readonly static DelegationInfoRepository _dirRep = AutofacIocManager.Instance.GetService<DelegationInfoRepository>();
  24. private readonly static TeamRateRepository _teamRateRep = AutofacIocManager.Instance.GetService<TeamRateRepository>();
  25. private readonly static IJuHeApiService _juHeApiService = AutofacIocManager.Instance.GetService<IJuHeApiService>();
  26. private readonly static SetDataRepository _setDataRep = AutofacIocManager.Instance.GetService<SetDataRepository>();
  27. private readonly static TableOperationRecordRepository _tableOperationRecordRep = AutofacIocManager.Instance.GetService<TableOperationRecordRepository>();
  28. private readonly static MessageRepository _messageRep = AutofacIocManager.Instance.GetService<MessageRepository>();
  29. private readonly static IHubContext<ChatHub, IChatClient> _hubContext = AutofacIocManager.Instance.GetService<IHubContext<ChatHub, IChatClient>>();
  30. #region 消息
  31. /// <summary>
  32. /// 消息 发布And 通知
  33. /// </summary>
  34. /// <param name="msgTypeEnum">
  35. /// 消息类型
  36. /// 1 公告通知
  37. /// 2 团组流程管控通知
  38. /// 3 团组业务操作通知
  39. /// 4 团组费用审核消息
  40. /// 5 团组签证进度通知
  41. /// 6 团组任务进度通知
  42. /// </param>
  43. /// <param name="title">消息标题</param>
  44. /// <param name="content">消息内容</param>
  45. /// <param name="userIds"></param>
  46. /// <param name="diId">团组id</param>
  47. /// <returns></returns>
  48. public static async Task<bool> MessageIssueAndNotification(MessageTypeEnum msgTypeEnum,string title,string content, List<int> userIds,int diId = 0)
  49. {
  50. MessageDto messageDto = new()
  51. {
  52. Type = msgTypeEnum,
  53. IssuerId = 4,//管理员
  54. DiId = diId,
  55. Title = title,
  56. Content = content,
  57. ReleaseTime = DateTime.Now,
  58. UIdList = userIds
  59. };
  60. var status = await _messageRep.AddMsg(messageDto);//添加消息
  61. if (status)
  62. {
  63. //给在线在用户发送消息
  64. List<string> connIds = UserStore.OnlineUser.Where(it => userIds.Contains(it.UserId)).Select(it => it.ConnectionId).ToList();
  65. string notificationTypeStr1 = GetMsgNotificationType(msgTypeEnum);
  66. string notificationTypeStr = JsonConvert.SerializeObject(
  67. new
  68. {
  69. UserIds = userIds,
  70. Msg = $"您有一条{notificationTypeStr1}相关的消息!"
  71. }
  72. );
  73. await _hubContext.Clients.Clients(connIds).ReceiveMessage($"您有一条{notificationTypeStr1}相关的消息!");
  74. return true;
  75. }
  76. return false;
  77. }
  78. /// <summary>
  79. /// 根据消息类型 获取 消息通知类型
  80. /// </summary>
  81. /// <returns></returns>
  82. public static string GetMsgNotificationType(MessageTypeEnum msgTypeEnum)
  83. {
  84. int notificationType = 0;
  85. string notificationStr = "";
  86. List<NotificationTypeView> notificationTypeViews = AppSettingsHelper.Get<NotificationTypeView>("MessageNotificationType");
  87. notificationType = notificationTypeViews.Where(it => it.MsgTypeIds.Contains((int)msgTypeEnum)).Select(it => it.TypeId).FirstOrDefault();
  88. if (notificationType == 1) notificationStr = "操作";
  89. else if (notificationType == 2) notificationStr = "任务";
  90. return notificationStr;
  91. }
  92. #endregion
  93. #region md5 加密
  94. /// <summary>
  95. /// MD5加密,和动网上的16/32位MD5加密结果相同,
  96. /// 使用的UTF8编码
  97. /// </summary>
  98. /// <param name="source">待加密字串</param>
  99. /// <param name="length">16或32值之一,其它则采用.net默认MD5加密算法</param>
  100. /// <returns>加密后的字串</returns>
  101. public static string Encrypt(string source, int length = 32)
  102. {
  103. if (string.IsNullOrWhiteSpace(source))
  104. return string.Empty;
  105. HashAlgorithm hashAlgorithm = CryptoConfig.CreateFromName("MD5") as HashAlgorithm;
  106. byte[] bytes = Encoding.UTF8.GetBytes(source);
  107. byte[] hashValue = hashAlgorithm.ComputeHash(bytes);
  108. StringBuilder sb = new StringBuilder();
  109. switch (length)
  110. {
  111. case 16://16位密文是32位密文的9到24位字符
  112. for (int i = 4; i < 12; i++)
  113. {
  114. sb.Append(hashValue[i].ToString("x2"));
  115. }
  116. break;
  117. case 32:
  118. for (int i = 0; i < 16; i++)
  119. {
  120. sb.Append(hashValue[i].ToString("x2"));
  121. }
  122. break;
  123. default:
  124. for (int i = 0; i < hashValue.Length; i++)
  125. {
  126. sb.Append(hashValue[i].ToString("x2"));
  127. }
  128. break;
  129. }
  130. return sb.ToString();
  131. }
  132. #endregion
  133. #region jwt
  134. /// <summary>
  135. /// 获取token
  136. /// </summary>
  137. /// <param name="_config"></param>
  138. /// <param name="Number"></param>
  139. /// <param name="exp"></param>
  140. /// <returns></returns>
  141. public static async Task<string> GetToken(IConfiguration _config, string Number, int uId, string uName, DateTime exp)
  142. {
  143. string userId = Guid.NewGuid().ToString().Replace("-", "");
  144. var claims = new[] {
  145. new Claim(ClaimTypes.NameIdentifier, uName),
  146. new Claim(ClaimTypes.NameIdentifier, uId.ToString()),
  147. new Claim(ClaimTypes.NameIdentifier, userId),
  148. new Claim("Number",Number)
  149. };
  150. var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["JwtSecurityKey"]));
  151. var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
  152. var token = new JwtSecurityToken(
  153. issuer: "OASystem.com",
  154. audience: "OASystem.com",
  155. claims: claims,
  156. expires: exp,
  157. signingCredentials: creds);
  158. var indentity = new ClaimsIdentity(claims, "formlogin");
  159. var principal = new ClaimsPrincipal(indentity);
  160. // await _httpContext.SignInAsync (CookieAuthenticationDefaults.AuthenticationScheme, principal);
  161. return new JwtSecurityTokenHandler().WriteToken(token);
  162. }
  163. #endregion
  164. #region 数据类型转换
  165. /// <summary>
  166. /// object 转 Int
  167. /// </summary>
  168. /// <param name="obj"></param>
  169. /// <returns></returns>
  170. public static int GetInt(this object obj)
  171. {
  172. if (obj == null)
  173. return 0;
  174. int _number = 0;
  175. bool reslut = Int32.TryParse(obj.ToString(), out _number);
  176. return _number;
  177. }
  178. private static DateTime dateStart = new DateTime(1970, 1, 1, 8, 0, 0);
  179. private static long longTime = 621355968000000000;
  180. private static int samllTime = 10000000;
  181. /// <summary>
  182. /// 时间戳 转 datetime
  183. /// </summary>
  184. /// <param name="timeStamp"></param>
  185. /// <returns></returns>
  186. public static DateTime GetTimeSpmpToDate(this object timeStamp)
  187. {
  188. if (timeStamp == null) return dateStart;
  189. DateTime dateTime = new DateTime(longTime + Convert.ToInt64(timeStamp) * samllTime, DateTimeKind.Utc).ToLocalTime();
  190. return dateTime;
  191. }
  192. #endregion
  193. #region 用户页面操作功能 权限
  194. /// <summary>
  195. /// 用户页面操作功能(可使用)
  196. /// </summary>
  197. /// <param name="userId">用户Id</param>
  198. /// <param name="PageId">页面Id</param>
  199. /// <returns></returns>
  200. public static async Task<PageFunAuthViewBase> PostUserPageFuncDatas(int userId,int PageId)
  201. {
  202. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  203. List<UserPageFuncView> userPageFuncDatas = new List<UserPageFuncView>();
  204. string sql = string.Format(@"Select ua.UId As UserId, u.CnName As UserName, pa.ModuleId,pa.ModuleName,pa.PageId,pa.PageName,pa.PageIsEnable,
  205. pa.PagePhoneIsEnable,pa.FuncId,pa.FuncName,pa.FuncIsEnable
  206. From Sys_UserAuthority ua
  207. Left Join Sys_Users u On ua.UId = u.Id
  208. Left Join (
  209. Select sd.Id As ModuleId,sd.Name As ModuleName, smp.Id As PageId,smp.Name As PageName,smp.IsEnable As PageIsEnable,
  210. smp.phoneIsEnable As PagePhoneIsEnable,pfp.Id As FuncId,pfp.FunctionName As FuncName,pfp.IsEnable As FuncIsEnable
  211. From Sys_SystemMenuAndFunction smaf
  212. Left Join Sys_SystemMenuPermission smp On smaf.SmId = smp.Id
  213. Left Join Sys_SetData sd On sd.STid = 5 And smp.Mid = sd.Id
  214. Left Join Sys_PageFunctionPermission pfp On smaf.FId = pfp.Id
  215. Where smaf.IsDel = 0 And smp.IsDel = 0 And pfp.IsDel = 0 And sd.IsDel = 0 And smp.IsEnable = 1
  216. ) As pa On ua.SmId = pa.PageId And ua.FId = pa.FuncId
  217. Where ua.IsDel = 0 And ua.UId = {0} And pa.PageId = {1}
  218. Order By ModuleId,PageId,FuncId Asc", userId, PageId);
  219. userPageFuncDatas = await _dirRep._sqlSugar.SqlQueryable<UserPageFuncView>(sql).ToListAsync();
  220. if (userPageFuncDatas.Count <= 0)
  221. {
  222. return pageFunAuth;
  223. }
  224. UserPageFuncView userPageFunc = new UserPageFuncView();
  225. //查询 1
  226. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 1).FirstOrDefault();
  227. if (userPageFunc != null) pageFunAuth.CheckAuth = 1;
  228. //删除 2
  229. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 2).FirstOrDefault();
  230. if (userPageFunc != null) pageFunAuth.DeleteAuth = 1;
  231. //编辑 3
  232. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 3).FirstOrDefault();
  233. if (userPageFunc != null) pageFunAuth.EditAuth = 1;
  234. //下载 4
  235. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 4).FirstOrDefault();
  236. if (userPageFunc != null) pageFunAuth.FilesDownloadAuth = 1;
  237. //上传 5
  238. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 5).FirstOrDefault();
  239. if (userPageFunc != null) pageFunAuth.FilesUploadAuth = 1;
  240. //添加 11
  241. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 11).FirstOrDefault();
  242. if (userPageFunc != null) pageFunAuth.AddAuth = 1;
  243. //审核 12
  244. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 12).FirstOrDefault();
  245. if (userPageFunc != null) pageFunAuth.AuditAuth = 1;
  246. return pageFunAuth;
  247. }
  248. #endregion
  249. #region 业务模块 团组权限
  250. /// <summary>
  251. /// 业务模块 团组操作权限
  252. /// 验证
  253. /// </summary>
  254. /// <param name="diId">团组Id</param>
  255. /// <param name="userId">用户Id</param>
  256. /// <param name="CTable">业务模块Id</param>
  257. /// <returns></returns>
  258. public static async Task<Result> PostGroupOperationAuth(int diId, int userId, int CTable )
  259. {
  260. Result _result = new Result { Code = -1,Msg = "No Operation Authorty!" };
  261. if (CTable < 1)
  262. {
  263. _result.Msg = "请填写正确的用户Id!";
  264. return _result;
  265. }
  266. var data = await _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(it => it.DIId == diId && it.UId == userId && it.CTId == CTable && it.IsDel == 0).FirstAsync();
  267. if (data == null)
  268. {
  269. _result.Msg = "你没有本团下的该业务模块操作,请联系主管分配操作权限!";
  270. }
  271. else
  272. {
  273. _result.Code = 0;
  274. }
  275. return _result;
  276. }
  277. #endregion
  278. #region 团组相关
  279. #region 建团按国家默认添加汇率 / 默认权限分配
  280. /// <summary>
  281. /// 团组汇率
  282. /// 建团时 添加基础汇率 CNY
  283. /// 按国家 添加 默认币种
  284. /// </summary>
  285. /// <param name="userId"></param>
  286. /// <param name="diId"></param>
  287. /// <returns></returns>
  288. public static async Task<Result> PostGroupRateAddInit(int userId, int diId)
  289. {
  290. Result result = new() { Code = -2 };
  291. if (userId < 0)
  292. {
  293. result.Msg = string.Format(@"请传入正确的userId");
  294. return result;
  295. }
  296. if (diId < 0)
  297. {
  298. result.Msg = string.Format(@"请传入正确的DiId");
  299. return result;
  300. }
  301. //美元(USD):1.0000|欧元(EUR):1.0000|墨西哥比索(MXN):1.0000
  302. string CNYInit = string.Format(@"人名币(CNY):1.0000");
  303. var gropInfo = await _dirRep._sqlSugar.Queryable<Grp_DelegationInfo>().Where( it => it.IsDel == 0 && it.Id == diId).FirstAsync();
  304. if (gropInfo != null)
  305. {
  306. if (!string.IsNullOrEmpty(gropInfo.VisitCountry))
  307. {
  308. var countryCueencyCodes = await _setDataRep.GetSetDataBySTId(_setDataRep, 66);
  309. string countrys = gropInfo.VisitCountry;
  310. string[] countryItems = new string[] { };
  311. if (countrys.Contains("|"))
  312. {
  313. countryItems = countrys.Split('|');
  314. }
  315. else
  316. {
  317. countryItems = new string[] { countrys };
  318. }
  319. var countryInfos = await _dirRep._sqlSugar.Queryable<Dis_Country>().Where(it => it.IsDel == 0).ToListAsync();
  320. List<string> currencyCodes = new List<string>();
  321. if (countryItems.Length > 0)
  322. {
  323. foreach (var item in countryItems)
  324. {
  325. Dis_Country country = new Dis_Country();
  326. country = countryInfos.Where(it => it.CnShortName.Equals(item)).FirstOrDefault();
  327. if (country != null)
  328. {
  329. if (!item.Equals("中国"))
  330. {
  331. currencyCodes.Add(country.CurrencyCode);
  332. }
  333. }
  334. }
  335. }
  336. if (currencyCodes.Count > 0)
  337. {
  338. List<ExchangeRateModel> exchangeRateModels = await _juHeApiService.PostItemRateAsync(currencyCodes.ToArray());
  339. if (exchangeRateModels.Count > 0)
  340. {
  341. var codes = await _dirRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.IsDel == 0).ToListAsync();
  342. for (int i = 0; i < exchangeRateModels.Count; i++)
  343. {
  344. string currencyName = exchangeRateModels[i].Name;
  345. string code = "";
  346. var currencyData = codes.Where(it => it.IsDel == 0 && it.Remark == currencyName).FirstOrDefault();
  347. if (currencyData != null) {
  348. code = currencyData.Name;
  349. CNYInit += string.Format(@"|{0}({1}):{2}", exchangeRateModels[i].Name, code, exchangeRateModels[i].MSellPri);
  350. }
  351. }
  352. }
  353. }
  354. }
  355. }
  356. List<Grp_TeamRate> grp_TeamRates = new List<Grp_TeamRate>()
  357. {
  358. new Grp_TeamRate(){ DiId = diId,CTable = 76,Remark = CNYInit,CreateUserId = userId, IsDel = 0 }, //76 酒店预订
  359. new Grp_TeamRate(){ DiId = diId,CTable = 77,Remark = CNYInit,CreateUserId = userId, IsDel = 0 }, //77 行程
  360. new Grp_TeamRate(){ DiId = diId,CTable = 79,Remark = CNYInit,CreateUserId = userId, IsDel = 0 }, //79 车/导游地接
  361. new Grp_TeamRate(){ DiId = diId,CTable = 80,Remark = CNYInit,CreateUserId = userId, IsDel = 0 }, //80 签证
  362. new Grp_TeamRate(){ DiId = diId,CTable = 82,Remark = CNYInit,CreateUserId = userId, IsDel = 0 }, //82 团组客户保险
  363. new Grp_TeamRate(){ DiId = diId,CTable = 85,Remark = CNYInit,CreateUserId = userId, IsDel = 0 }, //85 机票预订
  364. new Grp_TeamRate(){ DiId = diId,CTable = 98,Remark = CNYInit,CreateUserId = userId, IsDel = 0 }, //98 其他款项
  365. new Grp_TeamRate(){ DiId = diId,CTable = 285,Remark = CNYInit,CreateUserId = userId, IsDel = 0 }, //285 收款退还
  366. new Grp_TeamRate(){ DiId = diId,CTable = 751,Remark = CNYInit,CreateUserId = userId, IsDel = 0 }, //751 酒店早餐
  367. };
  368. var res = _teamRateRep._sqlSugar.Insertable(grp_TeamRates).ExecuteCommand();
  369. if (res < 0)
  370. {
  371. result.Msg = string.Format(@"添加失败!");
  372. return result;
  373. }
  374. result.Code = 0;
  375. result.Msg = string.Format(@"操作成功!");
  376. return result;
  377. }
  378. /// <summary>
  379. /// 团组汇率
  380. /// 建团时 默认按照岗位分配权限
  381. /// </summary>
  382. /// <param name="userId"></param>
  383. /// <param name="diId"></param>
  384. /// <param name="companyId"></param>
  385. /// <returns></returns>
  386. public static async Task<Result> PostGroupAuthAddInit(int userId, int diId, int companyId = 2)
  387. {
  388. Result result = new() { Code = -2 };
  389. if (userId < 0)
  390. {
  391. result.Msg = string.Format(@"请传入正确的userId");
  392. return result;
  393. }
  394. if (companyId < 0)
  395. {
  396. result.Msg = string.Format(@"请传入正确的companyId");
  397. return result;
  398. }
  399. if (diId < 0)
  400. {
  401. result.Msg = string.Format(@"请传入正确的DiId");
  402. return result;
  403. }
  404. //var depData = await _teamRateRep._sqlSugar.Queryable<Sys_Department>().Where(it => it.IsDel == 0 && it.CompanyId == companyId && it.DepName.Equals("国交部")).FirstAsync();
  405. //if (depData != null)
  406. //{
  407. // var userData = await _teamRateRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && it.CompanyId == companyId && it.DepId == depData.Id).ToListAsync();
  408. //}
  409. result.Code = 0;
  410. result.Msg = string.Format(@"操作成功!");
  411. return result;
  412. }
  413. #endregion
  414. #endregion
  415. #region 团组汇率
  416. /// <summary>
  417. /// 团组汇率
  418. /// 获取板块 币种 及 汇率
  419. /// 76 酒店预订 77 行程 79 车/导游地接
  420. /// 80 签证 82 团组客户保险 85 机票预订
  421. /// 98 其他款项 285 收款退还
  422. /// </summary>
  423. /// <param name="teamRateModels"></param>
  424. /// <param name="cTable"></param>
  425. /// <param name="currencyCode"></param>
  426. /// <returns>
  427. /// string
  428. /// eg: CNY 1.0000
  429. /// </returns>
  430. public static async Task<string> PostGroupRateByCTableAndCurrency(List<TeamRateModelView> teamRateModels,int cTable,List<string> currencyCodes)
  431. {
  432. string str = "";
  433. List<string> currencyRates = new List<string>();
  434. TeamRateModelView hotelRateData = teamRateModels.Where(it => it.CTableId == cTable).FirstOrDefault();
  435. if (hotelRateData != null)
  436. {
  437. var hotelRates = hotelRateData.TeamRates;
  438. foreach (var item in currencyCodes)
  439. {
  440. if (!string.IsNullOrEmpty(item))
  441. {
  442. var hotelRateInfo = hotelRates.Where(it => it.CurrencyCode.Equals(item)).FirstOrDefault();
  443. if (hotelRateInfo != null)
  444. {
  445. string str1 = string.Format("{0} {1}\r\n", hotelRateInfo.CurrencyCode, hotelRateInfo.Rate);
  446. currencyRates.Add(str1);
  447. }
  448. }
  449. }
  450. if (currencyRates != null || currencyRates.Count > 0)
  451. {
  452. currencyRates = currencyRates.Distinct().ToList();
  453. foreach (var item in currencyRates)
  454. {
  455. str += item;
  456. }
  457. }
  458. }
  459. return str;
  460. }
  461. #endregion
  462. #region 汉字转换拼音
  463. private static Dictionary<int, List<string>> GetTotalPingYinDictionary(string text)
  464. {
  465. var chs = text.ToCharArray();
  466. //记录每个汉字的全拼
  467. Dictionary<int, List<string>> totalPingYinList = new Dictionary<int, List<string>>();
  468. for (int i = 0; i < chs.Length; i++)
  469. {
  470. var pinyinList = new List<string>();
  471. //是否是有效的汉字
  472. if (ChineseChar.IsValidChar(chs[i]))
  473. {
  474. ChineseChar cc = new ChineseChar(chs[i]);
  475. pinyinList = cc.Pinyins.Where(p => !string.IsNullOrWhiteSpace(p)).ToList();
  476. }
  477. else
  478. {
  479. pinyinList.Add(chs[i].ToString());
  480. }
  481. //去除声调,转小写
  482. pinyinList = pinyinList.ConvertAll(p => Regex.Replace(p, @"\d", "").ToLower());
  483. //去重
  484. pinyinList = pinyinList.Where(p => !string.IsNullOrWhiteSpace(p)).Distinct().ToList();
  485. if (pinyinList.Any())
  486. {
  487. totalPingYinList[i] = pinyinList;
  488. }
  489. }
  490. return totalPingYinList;
  491. }
  492. /// <summary>
  493. /// 获取汉语拼音全拼
  494. /// </summary>
  495. /// <param name="text">The string.</param>
  496. /// <returns></returns>
  497. public static List<string> GetTotalPingYin(this string text)
  498. {
  499. var result = new List<string>();
  500. foreach (var pys in GetTotalPingYinDictionary(text))
  501. {
  502. var items = pys.Value;
  503. if (result.Count <= 0)
  504. {
  505. result = items;
  506. }
  507. else
  508. {
  509. //全拼循环匹配
  510. var newTotalPingYinList = new List<string>();
  511. foreach (var totalPingYin in result)
  512. {
  513. newTotalPingYinList.AddRange(items.Select(item => totalPingYin + item));
  514. }
  515. newTotalPingYinList = newTotalPingYinList.Distinct().ToList();
  516. result = newTotalPingYinList;
  517. }
  518. }
  519. return result;
  520. }
  521. /// <summary>
  522. /// 获取汉语拼音首字母
  523. /// </summary>
  524. /// <param name="text"></param>
  525. /// <returns></returns>
  526. public static List<string> GetFirstPingYin(this string text)
  527. {
  528. var result = new List<string>();
  529. foreach (var pys in GetTotalPingYinDictionary(text))
  530. {
  531. var items = pys.Value;
  532. if (result.Count <= 0)
  533. {
  534. result = items.ConvertAll(p => p.Substring(0, 1)).Distinct().ToList();
  535. }
  536. else
  537. {
  538. //首字母循环匹配
  539. var newFirstPingYinList = new List<string>();
  540. foreach (var firstPingYin in result)
  541. {
  542. newFirstPingYinList.AddRange(items.Select(item => firstPingYin + item.Substring(0, 1)));
  543. }
  544. newFirstPingYinList = newFirstPingYinList.Distinct().ToList();
  545. result = newFirstPingYinList;
  546. }
  547. }
  548. return result;
  549. }
  550. #endregion
  551. #region 新客户资料表 操作记录
  552. /// <summary>
  553. /// 新客户资料表
  554. /// 操作记录添加
  555. /// </summary>
  556. /// <param name="portType"></param>
  557. /// <param name="operationEnum"></param>
  558. /// <param name="userId"></param>
  559. /// <param name="dataId"></param>
  560. /// <param name="remark"></param>
  561. /// <returns></returns>
  562. public static async Task<bool> NewClientOperationRecord(int portType, OperationEnum operationEnum,int userId,int dataId,string remark )
  563. {
  564. Crm_TableOperationRecord _TableOperationRecord = new Crm_TableOperationRecord()
  565. {
  566. TableName = "Crm_NewClientData",
  567. PortType = portType,
  568. OperationItem = operationEnum,
  569. DataId = dataId,
  570. CreateUserId = userId,
  571. CreateTime = DateTime.Now,
  572. Remark = remark
  573. };
  574. bool add = await _tableOperationRecordRep._Add(_TableOperationRecord);
  575. if (add) return false;
  576. return false;
  577. }
  578. #endregion
  579. }
  580. }