GeneralMethod.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  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 _juHeApi = 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. /// <param name="param">团组id</param>
  48. /// <returns></returns>
  49. public static async Task<bool> MessageIssueAndNotification(MessageTypeEnum msgTypeEnum, string title, string content, List<int> userIds, int diId = 0, string param = "")
  50. {
  51. MessageDto messageDto = new()
  52. {
  53. Type = msgTypeEnum,
  54. IssuerId = 4,//管理员
  55. DiId = diId,
  56. Title = title,
  57. Content = content,
  58. ReleaseTime = DateTime.Now,
  59. UIdList = userIds,
  60. Param = param
  61. };
  62. var status = await _messageRep.AddMsg(messageDto);//添加消息
  63. if (status)
  64. {
  65. //给在线在用户发送消息
  66. List<string> connIds = UserStore.OnlineUser.Where(it => userIds.Contains(it.UserId)).Select(it => it.ConnectionId).ToList();
  67. string notificationTypeStr1 = GetMsgNotificationType(msgTypeEnum);
  68. string notificationTypeStr = JsonConvert.SerializeObject(
  69. new
  70. {
  71. UserIds = userIds,
  72. Msg = $"您有一条{notificationTypeStr1}相关的消息!"
  73. }
  74. );
  75. await _hubContext.Clients.Clients(connIds).ReceiveMessage($"您有一条{notificationTypeStr1}相关的消息!");
  76. return true;
  77. }
  78. return false;
  79. }
  80. /// <summary>
  81. /// 根据消息类型 获取 消息通知类型
  82. /// </summary>
  83. /// <returns></returns>
  84. public static string GetMsgNotificationType(MessageTypeEnum msgTypeEnum)
  85. {
  86. int notificationType = 0;
  87. string notificationStr = "";
  88. List<NotificationTypeView> notificationTypeViews = AppSettingsHelper.Get<NotificationTypeView>("MessageNotificationType");
  89. notificationType = notificationTypeViews.Where(it => it.MsgTypeIds.Contains((int)msgTypeEnum)).Select(it => it.TypeId).FirstOrDefault();
  90. if (notificationType == 1021) notificationStr = "操作";
  91. else if (notificationType == 1020) notificationStr = "任务";
  92. return notificationStr;
  93. }
  94. #endregion
  95. #region md5 加密
  96. /// <summary>
  97. /// MD5加密,和动网上的16/32位MD5加密结果相同,
  98. /// 使用的UTF8编码
  99. /// </summary>
  100. /// <param name="source">待加密字串</param>
  101. /// <param name="length">16或32值之一,其它则采用.net默认MD5加密算法</param>
  102. /// <returns>加密后的字串</returns>
  103. public static string Encrypt(string source, int length = 32)
  104. {
  105. if (string.IsNullOrWhiteSpace(source))
  106. return string.Empty;
  107. HashAlgorithm hashAlgorithm = CryptoConfig.CreateFromName("MD5") as HashAlgorithm;
  108. byte[] bytes = Encoding.UTF8.GetBytes(source);
  109. byte[] hashValue = hashAlgorithm.ComputeHash(bytes);
  110. StringBuilder sb = new StringBuilder();
  111. switch (length)
  112. {
  113. case 16://16位密文是32位密文的9到24位字符
  114. for (int i = 4; i < 12; i++)
  115. {
  116. sb.Append(hashValue[i].ToString("x2"));
  117. }
  118. break;
  119. case 32:
  120. for (int i = 0; i < 16; i++)
  121. {
  122. sb.Append(hashValue[i].ToString("x2"));
  123. }
  124. break;
  125. default:
  126. for (int i = 0; i < hashValue.Length; i++)
  127. {
  128. sb.Append(hashValue[i].ToString("x2"));
  129. }
  130. break;
  131. }
  132. return sb.ToString();
  133. }
  134. #endregion
  135. #region jwt
  136. /// <summary>
  137. /// 获取token
  138. /// </summary>
  139. /// <param name="_config"></param>
  140. /// <param name="Number"></param>
  141. /// <param name="exp"></param>
  142. /// <returns></returns>
  143. public static async Task<string> GetToken(IConfiguration _config, string Number, int uId, string uName, DateTime exp)
  144. {
  145. string userId = Guid.NewGuid().ToString().Replace("-", "");
  146. var claims = new[] {
  147. new Claim(ClaimTypes.NameIdentifier, uName),
  148. new Claim(ClaimTypes.NameIdentifier, uId.ToString()),
  149. new Claim(ClaimTypes.NameIdentifier, userId),
  150. new Claim("Number",Number)
  151. };
  152. var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["JwtSecurityKey"]));
  153. var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
  154. var token = new JwtSecurityToken(
  155. issuer: "OASystem.com",
  156. audience: "OASystem.com",
  157. claims: claims,
  158. expires: exp,
  159. signingCredentials: creds);
  160. var indentity = new ClaimsIdentity(claims, "formlogin");
  161. var principal = new ClaimsPrincipal(indentity);
  162. // await _httpContext.SignInAsync (CookieAuthenticationDefaults.AuthenticationScheme, principal);
  163. return new JwtSecurityTokenHandler().WriteToken(token);
  164. }
  165. #endregion
  166. #region 数据类型转换
  167. /// <summary>
  168. /// object 转 Int
  169. /// </summary>
  170. /// <param name="obj"></param>
  171. /// <returns></returns>
  172. public static int GetInt(this object obj)
  173. {
  174. if (obj == null)
  175. return 0;
  176. int _number = 0;
  177. bool reslut = Int32.TryParse(obj.ToString(), out _number);
  178. return _number;
  179. }
  180. private static DateTime dateStart = new DateTime(1970, 1, 1, 8, 0, 0);
  181. private static long longTime = 621355968000000000;
  182. private static int samllTime = 10000000;
  183. /// <summary>
  184. /// 时间戳 转 datetime
  185. /// </summary>
  186. /// <param name="timeStamp"></param>
  187. /// <returns></returns>
  188. public static DateTime GetTimeSpmpToDate(this object timeStamp)
  189. {
  190. if (timeStamp == null) return dateStart;
  191. DateTime dateTime = new DateTime(longTime + Convert.ToInt64(timeStamp) * samllTime, DateTimeKind.Utc).ToLocalTime();
  192. return dateTime;
  193. }
  194. #endregion
  195. #region 用户页面操作功能 权限
  196. /// <summary>
  197. /// 用户页面操作功能(可使用)
  198. /// </summary>
  199. /// <param name="userId">用户Id</param>
  200. /// <param name="PageId">页面Id</param>
  201. /// <returns></returns>
  202. public static async Task<PageFunAuthViewBase> PostUserPageFuncDatas(int userId, int PageId)
  203. {
  204. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  205. List<UserPageFuncView> userPageFuncDatas = new List<UserPageFuncView>();
  206. string sql = string.Format(@"Select ua.UId As UserId, u.CnName As UserName, pa.ModuleId,pa.ModuleName,pa.PageId,pa.PageName,pa.PageIsEnable,
  207. pa.PagePhoneIsEnable,pa.FuncId,pa.FuncName,pa.FuncIsEnable
  208. From Sys_UserAuthority ua
  209. Left Join Sys_Users u On ua.UId = u.Id
  210. Left Join (
  211. Select sd.Id As ModuleId,sd.Name As ModuleName, smp.Id As PageId,smp.Name As PageName,smp.IsEnable As PageIsEnable,
  212. smp.phoneIsEnable As PagePhoneIsEnable,pfp.Id As FuncId,pfp.FunctionName As FuncName,pfp.IsEnable As FuncIsEnable
  213. From Sys_SystemMenuAndFunction smaf
  214. Left Join Sys_SystemMenuPermission smp On smaf.SmId = smp.Id
  215. Left Join Sys_SetData sd On sd.STid = 5 And smp.Mid = sd.Id
  216. Left Join Sys_PageFunctionPermission pfp On smaf.FId = pfp.Id
  217. Where smaf.IsDel = 0 And smp.IsDel = 0 And pfp.IsDel = 0 And sd.IsDel = 0 And smp.IsEnable = 1
  218. ) As pa On ua.SmId = pa.PageId And ua.FId = pa.FuncId
  219. Where ua.IsDel = 0 And ua.UId = {0} And pa.PageId = {1}
  220. Order By ModuleId,PageId,FuncId Asc", userId, PageId);
  221. userPageFuncDatas = await _dirRep._sqlSugar.SqlQueryable<UserPageFuncView>(sql).ToListAsync();
  222. if (userPageFuncDatas.Count <= 0)
  223. {
  224. return pageFunAuth;
  225. }
  226. UserPageFuncView userPageFunc = new UserPageFuncView();
  227. //查询 1
  228. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 1).FirstOrDefault();
  229. if (userPageFunc != null) pageFunAuth.CheckAuth = 1;
  230. //删除 2
  231. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 2).FirstOrDefault();
  232. if (userPageFunc != null) pageFunAuth.DeleteAuth = 1;
  233. //编辑 3
  234. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 3).FirstOrDefault();
  235. if (userPageFunc != null) pageFunAuth.EditAuth = 1;
  236. //下载 4
  237. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 4).FirstOrDefault();
  238. if (userPageFunc != null) pageFunAuth.FilesDownloadAuth = 1;
  239. //上传 5
  240. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 5).FirstOrDefault();
  241. if (userPageFunc != null) pageFunAuth.FilesUploadAuth = 1;
  242. //添加 11
  243. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 11).FirstOrDefault();
  244. if (userPageFunc != null) pageFunAuth.AddAuth = 1;
  245. //审核 12
  246. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 12).FirstOrDefault();
  247. if (userPageFunc != null) pageFunAuth.AuditAuth = 1;
  248. return pageFunAuth;
  249. }
  250. #endregion
  251. #region 业务模块 团组权限
  252. /// <summary>
  253. /// 业务模块 团组操作权限
  254. /// 验证
  255. /// </summary>
  256. /// <param name="diId">团组Id</param>
  257. /// <param name="userId">用户Id</param>
  258. /// <param name="CTable">业务模块Id</param>
  259. /// <returns></returns>
  260. public static async Task<Result> PostGroupOperationAuth(int diId, int userId, int CTable)
  261. {
  262. Result _result = new Result { Code = -1, Msg = "No Operation Authorty!" };
  263. if (CTable < 1)
  264. {
  265. _result.Msg = "请填写正确的用户Id!";
  266. return _result;
  267. }
  268. var data = await _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(it => it.DIId == diId && it.UId == userId && it.CTId == CTable && it.IsDel == 0).FirstAsync();
  269. if (data == null)
  270. {
  271. _result.Msg = "你没有本团下的该业务模块操作,请联系主管分配操作权限!";
  272. }
  273. else
  274. {
  275. _result.Code = 0;
  276. }
  277. return _result;
  278. }
  279. #endregion
  280. #region 团组相关
  281. #region 建团按国家默认添加汇率 / 默认权限分配
  282. /// <summary>
  283. /// 团组汇率
  284. /// 建团时 添加基础汇率 CNY
  285. /// 按国家 添加 默认币种
  286. /// </summary>
  287. /// <param name="userId"></param>
  288. /// <param name="diId"></param>
  289. /// <returns></returns>
  290. public static async Task<Result> PostGroupRateAddInit(int userId, int diId)
  291. {
  292. Result result = new() { Code = -2 };
  293. if (userId < 1)
  294. {
  295. result.Msg = string.Format(@"请传入正确的userId");
  296. return result;
  297. }
  298. if (diId < 1)
  299. {
  300. result.Msg = string.Format(@"请传入正确的DiId");
  301. return result;
  302. }
  303. //美元(USD):1.0000|欧元(EUR):1.0000|墨西哥比索(MXN):1.0000
  304. string rateInit = string.Format(@"人名币(CNY):1.0000");
  305. //var gropInfo = _dirRep._sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == diId).First();
  306. //if (gropInfo == null)
  307. //{
  308. // result.Msg = $@"未查询到团组信息!";
  309. // return result;
  310. //}
  311. var juheRateData = await _juHeApi.GetExchangeRateAsync();
  312. if (juheRateData.Error_code != 0)
  313. {
  314. result.Msg = juheRateData.Reason;
  315. return result;
  316. }
  317. List<ExchangeRateModel> exchangeRateModels = (List<ExchangeRateModel>)juheRateData.Result;
  318. if (exchangeRateModels.Count <= 0)
  319. {
  320. result.Msg = $@"未查询到聚合接口汇率信息!";
  321. return result;
  322. }
  323. if (exchangeRateModels.Count > 0)
  324. {
  325. var codes = _dirRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  326. for (int i = 0; i < exchangeRateModels.Count; i++)
  327. {
  328. string currencyName = exchangeRateModels[i].Name;
  329. string code = "";
  330. var currencyData = codes.Where(it => it.Remark == currencyName).FirstOrDefault();
  331. if (currencyData != null)
  332. {
  333. code = currencyData.Name;
  334. decimal currRate = 0.00M;
  335. string MSellPri = exchangeRateModels[i].MSellPri;
  336. if (!string.IsNullOrEmpty(MSellPri))
  337. {
  338. currRate = Convert.ToDecimal(MSellPri) / 100M;
  339. }
  340. rateInit += $@"|{currencyName}({code}):{currRate.ToString("#0.0000")}";
  341. }
  342. }
  343. }
  344. var cTableIds = _dirRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 16).ToList();
  345. if (cTableIds.Count < 1)
  346. {
  347. result.Msg = $@"未查询到操作模块信息!";
  348. return result;
  349. }
  350. List<Grp_TeamRate> grp_TeamRates = new List<Grp_TeamRate>();
  351. foreach (var item in cTableIds)
  352. {
  353. grp_TeamRates.Add(
  354. new Grp_TeamRate() { DiId = diId, CTable = item.Id, Remark = rateInit, CreateUserId = userId }
  355. );
  356. }
  357. if (grp_TeamRates.Count > 0)
  358. {
  359. var addId = _teamRateRep._sqlSugar.Insertable(grp_TeamRates).ExecuteCommand();
  360. if (addId < 1)
  361. {
  362. result.Msg = string.Format(@"添加失败!");
  363. return result;
  364. }
  365. }
  366. result.Code = 0;
  367. result.Msg = string.Format(@"操作成功!");
  368. return result;
  369. }
  370. /// <summary>
  371. /// 团组汇率
  372. /// 建团时 默认按照岗位分配权限
  373. /// </summary>
  374. /// <param name="userId"></param>
  375. /// <param name="diId"></param>
  376. /// <param name="companyId"></param>
  377. /// <returns></returns>
  378. public static async Task<Result> PostGroupAuthAddInit(int userId, int diId, int companyId = 2)
  379. {
  380. Result result = new() { Code = -2 };
  381. if (userId < 0)
  382. {
  383. result.Msg = string.Format(@"请传入正确的userId");
  384. return result;
  385. }
  386. if (companyId < 0)
  387. {
  388. result.Msg = string.Format(@"请传入正确的companyId");
  389. return result;
  390. }
  391. if (diId < 0)
  392. {
  393. result.Msg = string.Format(@"请传入正确的DiId");
  394. return result;
  395. }
  396. var userDatas = await _teamRateRep._sqlSugar
  397. .Queryable<Sys_Users>()
  398. .LeftJoin<Sys_Department>((su,sd) => su.DepId == sd.Id && sd.IsDel == 0)
  399. .LeftJoin<Sys_JobPost>((su,sd,sjp) => su.JobPostId == sjp.Id && sjp.IsDel == 0)
  400. .Where(su => su.IsDel == 0)
  401. .Select((su,sd,sjp) => new {
  402. su.DepId,
  403. sd.DepName,
  404. su.JobPostId,
  405. sjp.JobName,
  406. su.Id,
  407. su.CnName
  408. })
  409. .ToListAsync();
  410. /*
  411. * 76 酒店预订 --> 国交部门 酒店 岗位
  412. * 77 行程 --> 国交部门 经理,主管 岗位
  413. * 79 车/导游地接 --> 国交部门 OP 岗位
  414. * 80 签证 --> 国交部门 签证 岗位
  415. * 81 邀请/公务活动 --> 国交部门 商邀 岗位
  416. * 82 团组客户保险 --> 国交部 经理,主管 岗位
  417. * 85 机票预订 --> 国交部门 机票 岗位
  418. * 98 其他款项 --> 总经办部门 总经理 岗位/国交部门(ALL) 岗位/财务部门(ALL) 岗位/策划部门(ALL) 岗位/人事部门 采购 岗位
  419. * 1015 超支费用 --> 财务部门(ALL)岗位
  420. */
  421. List<Grp_GroupsTaskAssignment> _GroupsTaskAssignments = new List<Grp_GroupsTaskAssignment>();
  422. // 76 酒店预订 --> 国交部门(7) 酒店(25) 岗位
  423. _GroupsTaskAssignments.AddRange(
  424. userDatas
  425. .Where(it => it.DepId == 7 && it.JobPostId == 25)
  426. .Select(it => new Grp_GroupsTaskAssignment()
  427. {
  428. DIId = diId,
  429. CTId = 76,
  430. UId = it.Id,
  431. CreateUserId = userId
  432. }).ToList()
  433. );
  434. // 77 行程 --> 国交部门(7) 经理(32),主管(22) 岗位
  435. _GroupsTaskAssignments.AddRange(
  436. userDatas
  437. .Where(it => it.DepId == 7 && (it.JobPostId == 22 || it.JobPostId == 32))
  438. .Select(it => new Grp_GroupsTaskAssignment()
  439. {
  440. DIId = diId,
  441. CTId = 77,
  442. UId = it.Id,
  443. CreateUserId = userId
  444. }).ToList()
  445. );
  446. //79 车/导游地接 --> 国交部门(7) OP(28) 岗位
  447. _GroupsTaskAssignments.AddRange(
  448. userDatas.Where(it => it.DepId == 7 && it.JobPostId == 28)
  449. .Select(it => new Grp_GroupsTaskAssignment()
  450. {
  451. DIId = diId,
  452. CTId = 79,
  453. UId = it.Id,
  454. CreateUserId = userId
  455. }).ToList()
  456. );
  457. //81 邀请/公务活动 --> 国交部门(7) 商邀(27) 岗位
  458. _GroupsTaskAssignments.AddRange(
  459. userDatas
  460. .Where(it => it.DepId == 7 && it.JobPostId == 27)
  461. .Select(it => new Grp_GroupsTaskAssignment()
  462. {
  463. DIId = diId,
  464. CTId = 81,
  465. UId = it.Id,
  466. CreateUserId = userId
  467. }).ToList()
  468. );
  469. //80 签证 --> 国交部门(7) 签证(26) 岗位
  470. _GroupsTaskAssignments.AddRange(
  471. userDatas
  472. .Where(it => it.DepId == 7 && it.JobPostId == 26)
  473. .Select(it => new Grp_GroupsTaskAssignment()
  474. {
  475. DIId = diId,
  476. CTId = 80,
  477. UId = it.Id,
  478. CreateUserId = userId
  479. }).ToList()
  480. );
  481. //82 团组客户保险 --> 国交部(7) 经理(32),主管(22) 岗位
  482. _GroupsTaskAssignments.AddRange(
  483. userDatas
  484. .Where(it => it.DepId == 7 && (it.JobPostId == 22 || it.JobPostId == 32))
  485. .Select(it => new Grp_GroupsTaskAssignment()
  486. {
  487. DIId = diId,
  488. CTId = 82,
  489. UId = it.Id,
  490. CreateUserId = userId
  491. }).ToList()
  492. );
  493. //85 机票预订 --> 国交部门(7) 机票(24) 岗位
  494. _GroupsTaskAssignments.AddRange(
  495. userDatas
  496. .Where(it => it.DepId == 7 && it.JobPostId == 24)
  497. .Select(it => new Grp_GroupsTaskAssignment()
  498. {
  499. DIId = diId,
  500. CTId = 85,
  501. UId = it.Id,
  502. CreateUserId = userId
  503. }).ToList()
  504. );
  505. //98 其他款项 --> 总经办部门(1) 总经理(1) 岗位/国交部门(7)(ALL) 岗位/财务部门(3)(ALL) 岗位/策划部门(5)(ALL) 岗位/人事部门(4) 采购(74) 岗位
  506. List<int> depIds = new List<int>() { 7,3,5 };
  507. List<int> jobIds = new List<int>() { 1,74};
  508. _GroupsTaskAssignments.AddRange(
  509. userDatas
  510. .Where(it => depIds.Contains(it.DepId) || jobIds.Contains(it.JobPostId))
  511. .Select(it => new Grp_GroupsTaskAssignment()
  512. {
  513. DIId = diId,
  514. CTId = 98,
  515. UId = it.Id,
  516. CreateUserId = userId
  517. }).ToList()
  518. );
  519. //1015 超支费用 --> 财务部门(3)(ALL)岗位
  520. _GroupsTaskAssignments.AddRange(
  521. userDatas
  522. .Where(it => it.DepId == 3)
  523. .Select(it => new Grp_GroupsTaskAssignment()
  524. {
  525. DIId = diId,
  526. CTId = 1015,
  527. UId = it.Id,
  528. CreateUserId = userId
  529. }).ToList()
  530. );
  531. if (_GroupsTaskAssignments.Count > 0)
  532. {
  533. var addId =_teamRateRep._sqlSugar.Insertable(_GroupsTaskAssignments).ExecuteCommand();
  534. }
  535. result.Code = 0;
  536. result.Msg = string.Format(@"操作成功!");
  537. return result;
  538. }
  539. #endregion
  540. #endregion
  541. #region 团组汇率
  542. /// <summary>
  543. /// 团组汇率
  544. /// 获取板块 币种 及 汇率
  545. /// 76 酒店预订 77 行程 79 车/导游地接
  546. /// 80 签证 82 团组客户保险 85 机票预订
  547. /// 98 其他款项 285 收款退还
  548. /// </summary>
  549. /// <param name="teamRateModels"></param>
  550. /// <param name="cTable"></param>
  551. /// <param name="currencyCode"></param>
  552. /// <returns>
  553. /// string
  554. /// eg: CNY 1.0000
  555. /// </returns>
  556. public static async Task<string> PostGroupRateByCTableAndCurrency(List<TeamRateModelView> teamRateModels, int cTable, List<string> currencyCodes)
  557. {
  558. string str = "";
  559. List<string> currencyRates = new List<string>();
  560. TeamRateModelView hotelRateData = teamRateModels.Where(it => it.CTableId == cTable).FirstOrDefault();
  561. if (hotelRateData != null)
  562. {
  563. var hotelRates = hotelRateData.TeamRates;
  564. foreach (var item in currencyCodes)
  565. {
  566. if (!string.IsNullOrEmpty(item))
  567. {
  568. var hotelRateInfo = hotelRates.Where(it => it.CurrencyCode.Equals(item)).FirstOrDefault();
  569. if (hotelRateInfo != null)
  570. {
  571. string str1 = string.Format("{0} {1}\r\n", hotelRateInfo.CurrencyCode, hotelRateInfo.Rate.ToString("#0.0000"));
  572. currencyRates.Add(str1);
  573. }
  574. }
  575. }
  576. if (currencyRates != null || currencyRates.Count > 0)
  577. {
  578. currencyRates = currencyRates.Distinct().ToList();
  579. foreach (var item in currencyRates)
  580. {
  581. str += item;
  582. }
  583. }
  584. }
  585. return str;
  586. }
  587. /// <summary>
  588. /// 团组汇率 币种 Item (来源:团组汇率)
  589. /// 根据 团组Id And 业务类型(CTable)Id
  590. /// api处理CTable = 285,默认返回CNY
  591. /// </summary>
  592. /// <param name="portType"></param>
  593. /// <param name="diId"></param>
  594. /// <param name="cTable"></param>
  595. /// <returns></returns>
  596. public static async Task<TeamRateModelGeneralView> PostGroupTeamRateByDiIdAndCTableId(int portType, int diId, int cTable)
  597. {
  598. TeamRateModelGeneralView _view = new TeamRateModelGeneralView();
  599. _view = await _teamRateRep.PostGroupTeamRateByDiIdAndCTableId(portType, diId, cTable);
  600. return _view;
  601. }
  602. #endregion
  603. #region 汉字转换拼音
  604. private static Dictionary<int, List<string>> GetTotalPingYinDictionary(string text)
  605. {
  606. var chs = text.ToCharArray();
  607. //记录每个汉字的全拼
  608. Dictionary<int, List<string>> totalPingYinList = new Dictionary<int, List<string>>();
  609. for (int i = 0; i < chs.Length; i++)
  610. {
  611. var pinyinList = new List<string>();
  612. //是否是有效的汉字
  613. if (ChineseChar.IsValidChar(chs[i]))
  614. {
  615. ChineseChar cc = new ChineseChar(chs[i]);
  616. pinyinList = cc.Pinyins.Where(p => !string.IsNullOrWhiteSpace(p)).ToList();
  617. }
  618. else
  619. {
  620. pinyinList.Add(chs[i].ToString());
  621. }
  622. //去除声调,转小写
  623. pinyinList = pinyinList.ConvertAll(p => Regex.Replace(p, @"\d", "").ToLower());
  624. //去重
  625. pinyinList = pinyinList.Where(p => !string.IsNullOrWhiteSpace(p)).Distinct().ToList();
  626. if (pinyinList.Any())
  627. {
  628. totalPingYinList[i] = pinyinList;
  629. }
  630. }
  631. return totalPingYinList;
  632. }
  633. /// <summary>
  634. /// 获取汉语拼音全拼
  635. /// </summary>
  636. /// <param name="text">The string.</param>
  637. /// <returns></returns>
  638. public static List<string> GetTotalPingYin(this string text)
  639. {
  640. var result = new List<string>();
  641. foreach (var pys in GetTotalPingYinDictionary(text))
  642. {
  643. var items = pys.Value;
  644. if (result.Count <= 0)
  645. {
  646. result = items;
  647. }
  648. else
  649. {
  650. //全拼循环匹配
  651. var newTotalPingYinList = new List<string>();
  652. foreach (var totalPingYin in result)
  653. {
  654. newTotalPingYinList.AddRange(items.Select(item => totalPingYin + item));
  655. }
  656. newTotalPingYinList = newTotalPingYinList.Distinct().ToList();
  657. result = newTotalPingYinList;
  658. }
  659. }
  660. return result;
  661. }
  662. /// <summary>
  663. /// 获取汉语拼音首字母
  664. /// </summary>
  665. /// <param name="text"></param>
  666. /// <returns></returns>
  667. public static List<string> GetFirstPingYin(this string text)
  668. {
  669. var result = new List<string>();
  670. foreach (var pys in GetTotalPingYinDictionary(text))
  671. {
  672. var items = pys.Value;
  673. if (result.Count <= 0)
  674. {
  675. result = items.ConvertAll(p => p.Substring(0, 1)).Distinct().ToList();
  676. }
  677. else
  678. {
  679. //首字母循环匹配
  680. var newFirstPingYinList = new List<string>();
  681. foreach (var firstPingYin in result)
  682. {
  683. newFirstPingYinList.AddRange(items.Select(item => firstPingYin + item.Substring(0, 1)));
  684. }
  685. newFirstPingYinList = newFirstPingYinList.Distinct().ToList();
  686. result = newFirstPingYinList;
  687. }
  688. }
  689. return result;
  690. }
  691. #endregion
  692. #region 新客户资料表 操作记录
  693. /// <summary>
  694. /// 新客户资料表
  695. /// 操作记录添加
  696. /// </summary>
  697. /// <param name="portType"></param>
  698. /// <param name="operationEnum"></param>
  699. /// <param name="userId"></param>
  700. /// <param name="dataId"></param>
  701. /// <param name="remark"></param>
  702. /// <returns></returns>
  703. public static async Task<bool> NewClientOperationRecord(int portType, OperationEnum operationEnum, int userId, int dataId, string remark)
  704. {
  705. Crm_TableOperationRecord _TableOperationRecord = new Crm_TableOperationRecord()
  706. {
  707. TableName = "Crm_NewClientData",
  708. PortType = portType,
  709. OperationItem = operationEnum,
  710. DataId = dataId,
  711. CreateUserId = userId,
  712. CreateTime = DateTime.Now,
  713. Remark = remark
  714. };
  715. bool add = await _tableOperationRecordRep._Add(_TableOperationRecord);
  716. if (add) return false;
  717. return false;
  718. }
  719. #endregion
  720. }
  721. }