GeneralMethod.cs 28 KB

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