GeneralMethod.cs 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197
  1. 
  2. using Microsoft.AspNetCore.SignalR;
  3. using Microsoft.International.Converters.PinYinConverter;
  4. using NPOI.HSSF.Util;
  5. using OASystem.API.OAMethodLib.Hub.HubClients;
  6. using OASystem.API.OAMethodLib.Hub.Hubs;
  7. using OASystem.API.OAMethodLib.JuHeAPI;
  8. using OASystem.API.OAMethodLib.SignalR.Hubs;
  9. using OASystem.Domain.Entities.Customer;
  10. using OASystem.Domain.Entities.District;
  11. using OASystem.Domain.Entities.Financial;
  12. using OASystem.Domain.Entities.Groups;
  13. using OASystem.Domain.ViewModels.Financial;
  14. using OASystem.Domain.ViewModels.JuHeExchangeRate;
  15. using OASystem.Infrastructure.Repositories.CRM;
  16. using OASystem.Infrastructure.Repositories.Groups;
  17. using System.IdentityModel.Tokens.Jwt;
  18. using System.IO.Compression;
  19. using System.Security.Claims;
  20. using System.Web;
  21. namespace OASystem.API.OAMethodLib
  22. {
  23. public static class GeneralMethod
  24. {
  25. //团组信息
  26. private readonly static DelegationInfoRepository _dirRep = AutofacIocManager.Instance.GetService<DelegationInfoRepository>();
  27. private readonly static TeamRateRepository _teamRateRep = AutofacIocManager.Instance.GetService<TeamRateRepository>();
  28. private readonly static IJuHeApiService _juHeApi = AutofacIocManager.Instance.GetService<IJuHeApiService>();
  29. private readonly static SetDataRepository _setDataRep = AutofacIocManager.Instance.GetService<SetDataRepository>();
  30. private readonly static TableOperationRecordRepository _tableOperationRecordRep = AutofacIocManager.Instance.GetService<TableOperationRecordRepository>();
  31. private readonly static MessageRepository _messageRep = AutofacIocManager.Instance.GetService<MessageRepository>();
  32. private readonly static IHubContext<ChatHub, IChatClient> _hubContext = AutofacIocManager.Instance.GetService<IHubContext<ChatHub, IChatClient>>();
  33. #region 消息
  34. /// <summary>
  35. /// 消息 发布And 通知
  36. /// </summary>
  37. /// <param name="msgTypeEnum">
  38. /// 消息类型
  39. /// 1 公告通知
  40. /// 2 团组流程管控通知
  41. /// 3 团组业务操作通知
  42. /// 4 团组费用审核消息
  43. /// 5 团组签证进度通知
  44. /// 6 团组任务进度通知
  45. /// </param>
  46. /// <param name="title">消息标题</param>
  47. /// <param name="content">消息内容</param>
  48. /// <param name="userIds"></param>
  49. /// <param name="diId">团组id</param>
  50. /// <param name="param">团组id</param>
  51. /// <returns></returns>
  52. public static async Task<bool> MessageIssueAndNotification(MessageTypeEnum msgTypeEnum, string title, string content, List<int> userIds, int diId = 0, string param = "")
  53. {
  54. MessageDto messageDto = new()
  55. {
  56. Type = msgTypeEnum,
  57. IssuerId = 4,//管理员
  58. DiId = diId,
  59. Title = title,
  60. Content = content,
  61. ReleaseTime = DateTime.Now,
  62. UIdList = userIds,
  63. Param = param
  64. };
  65. var status = await _messageRep.AddMsg(messageDto);//添加消息
  66. if (status)
  67. {
  68. //给在线在用户发送消息
  69. List<string> connIds = UserStore.OnlineUser.Where(it => userIds.Contains(it.UserId)).Select(it => it.ConnectionId).ToList();
  70. string notificationTypeStr1 = GetMsgNotificationType(msgTypeEnum);
  71. string notificationTypeStr = JsonConvert.SerializeObject(
  72. new
  73. {
  74. UserIds = userIds,
  75. Msg = $"您有一条{notificationTypeStr1}相关的消息!"
  76. }
  77. );
  78. await _hubContext.Clients.Clients(connIds).ReceiveMessage($"您有一条{notificationTypeStr1}相关的消息!");
  79. return true;
  80. }
  81. return false;
  82. }
  83. /// <summary>
  84. /// 根据消息类型 获取 消息通知类型
  85. /// </summary>
  86. /// <returns></returns>
  87. public static string GetMsgNotificationType(MessageTypeEnum msgTypeEnum)
  88. {
  89. int notificationType = 0;
  90. string notificationStr = "";
  91. List<NotificationTypeView> notificationTypeViews = AppSettingsHelper.Get<NotificationTypeView>("MessageNotificationType");
  92. notificationType = notificationTypeViews.Where(it => it.MsgTypeIds.Contains((int)msgTypeEnum)).Select(it => it.TypeId).FirstOrDefault();
  93. if (notificationType == 1021) notificationStr = "操作";
  94. else if (notificationType == 1020) notificationStr = "任务";
  95. return notificationStr;
  96. }
  97. #endregion
  98. #region md5 加密
  99. /// <summary>
  100. /// MD5加密,和动网上的16/32位MD5加密结果相同,
  101. /// 使用的UTF8编码
  102. /// </summary>
  103. /// <param name="source">待加密字串</param>
  104. /// <param name="length">16或32值之一,其它则采用.net默认MD5加密算法</param>
  105. /// <returns>加密后的字串</returns>
  106. public static string Encrypt(string source, int length = 32)
  107. {
  108. if (string.IsNullOrWhiteSpace(source))
  109. return string.Empty;
  110. HashAlgorithm hashAlgorithm = CryptoConfig.CreateFromName("MD5") as HashAlgorithm;
  111. byte[] bytes = Encoding.UTF8.GetBytes(source);
  112. byte[] hashValue = hashAlgorithm.ComputeHash(bytes);
  113. StringBuilder sb = new StringBuilder();
  114. switch (length)
  115. {
  116. case 16://16位密文是32位密文的9到24位字符
  117. for (int i = 4; i < 12; i++)
  118. {
  119. sb.Append(hashValue[i].ToString("x2"));
  120. }
  121. break;
  122. case 32:
  123. for (int i = 0; i < 16; i++)
  124. {
  125. sb.Append(hashValue[i].ToString("x2"));
  126. }
  127. break;
  128. default:
  129. for (int i = 0; i < hashValue.Length; i++)
  130. {
  131. sb.Append(hashValue[i].ToString("x2"));
  132. }
  133. break;
  134. }
  135. return sb.ToString();
  136. }
  137. #endregion
  138. #region jwt
  139. /// <summary>
  140. /// 获取token
  141. /// </summary>
  142. /// <param name="_config"></param>
  143. /// <param name="Number"></param>
  144. /// <param name="exp"></param>
  145. /// <returns></returns>
  146. public static async Task<string> GetToken(IConfiguration _config, string Number, int uId, string uName, DateTime exp)
  147. {
  148. string userId = Guid.NewGuid().ToString().Replace("-", "");
  149. var claims = new[] {
  150. new Claim(ClaimTypes.NameIdentifier, uName),
  151. new Claim(ClaimTypes.NameIdentifier, uId.ToString()),
  152. new Claim(ClaimTypes.NameIdentifier, userId),
  153. new Claim("Number",Number)
  154. };
  155. var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["JwtSecurityKey"]));
  156. var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
  157. var token = new JwtSecurityToken(
  158. issuer: "OASystem.com",
  159. audience: "OASystem.com",
  160. claims: claims,
  161. expires: exp,
  162. signingCredentials: creds);
  163. var indentity = new ClaimsIdentity(claims, "formlogin");
  164. var principal = new ClaimsPrincipal(indentity);
  165. // await _httpContext.SignInAsync (CookieAuthenticationDefaults.AuthenticationScheme, principal);
  166. return new JwtSecurityTokenHandler().WriteToken(token);
  167. }
  168. #endregion
  169. #region 数据类型转换
  170. /// <summary>
  171. /// object 转 Int
  172. /// </summary>
  173. /// <param name="obj"></param>
  174. /// <returns></returns>
  175. public static int GetInt(this object obj)
  176. {
  177. if (obj == null)
  178. return 0;
  179. int _number = 0;
  180. bool reslut = Int32.TryParse(obj.ToString(), out _number);
  181. return _number;
  182. }
  183. private static DateTime dateStart = new DateTime(1970, 1, 1, 8, 0, 0);
  184. private static long longTime = 621355968000000000;
  185. private static int samllTime = 10000000;
  186. /// <summary>
  187. /// 时间戳 转 datetime
  188. /// </summary>
  189. /// <param name="timeStamp"></param>
  190. /// <returns></returns>
  191. public static DateTime GetTimeSpmpToDate(this object timeStamp)
  192. {
  193. if (timeStamp == null) return dateStart;
  194. DateTime dateTime = new DateTime(longTime + Convert.ToInt64(timeStamp) * samllTime, DateTimeKind.Utc).ToLocalTime();
  195. return dateTime;
  196. }
  197. #endregion
  198. #region 用户页面操作功能 权限
  199. /// <summary>
  200. /// 用户页面操作功能(可使用)
  201. /// </summary>
  202. /// <param name="userId">用户Id</param>
  203. /// <param name="PageId">页面Id</param>
  204. /// <returns></returns>
  205. public static async Task<PageFunAuthViewBase> PostUserPageFuncDatas(int userId, int PageId)
  206. {
  207. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  208. List<UserPageFuncView> userPageFuncDatas = new List<UserPageFuncView>();
  209. string sql = string.Format(@"Select ua.UId As UserId, u.CnName As UserName, pa.ModuleId,pa.ModuleName,pa.PageId,pa.PageName,pa.PageIsEnable,
  210. pa.PagePhoneIsEnable,pa.FuncId,pa.FuncName,pa.FuncIsEnable
  211. From Sys_UserAuthority ua
  212. Left Join Sys_Users u On ua.UId = u.Id
  213. Left Join (
  214. Select sd.Id As ModuleId,sd.Name As ModuleName, smp.Id As PageId,smp.Name As PageName,smp.IsEnable As PageIsEnable,
  215. smp.phoneIsEnable As PagePhoneIsEnable,pfp.Id As FuncId,pfp.FunctionName As FuncName,pfp.IsEnable As FuncIsEnable
  216. From Sys_SystemMenuAndFunction smaf
  217. Left Join Sys_SystemMenuPermission smp On smaf.SmId = smp.Id
  218. Left Join Sys_SetData sd On sd.STid = 5 And smp.Mid = sd.Id
  219. Left Join Sys_PageFunctionPermission pfp On smaf.FId = pfp.Id
  220. Where smaf.IsDel = 0 And smp.IsDel = 0 And pfp.IsDel = 0 And sd.IsDel = 0 And smp.IsEnable = 1
  221. ) As pa On ua.SmId = pa.PageId And ua.FId = pa.FuncId
  222. Where ua.IsDel = 0 And ua.UId = {0} And pa.PageId = {1}
  223. Order By ModuleId,PageId,FuncId Asc", userId, PageId);
  224. userPageFuncDatas = await _dirRep._sqlSugar.SqlQueryable<UserPageFuncView>(sql).ToListAsync();
  225. if (userPageFuncDatas.Count <= 0)
  226. {
  227. return pageFunAuth;
  228. }
  229. UserPageFuncView userPageFunc = new UserPageFuncView();
  230. //查询 1
  231. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 1).FirstOrDefault();
  232. if (userPageFunc != null) pageFunAuth.CheckAuth = 1;
  233. //删除 2
  234. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 2).FirstOrDefault();
  235. if (userPageFunc != null) pageFunAuth.DeleteAuth = 1;
  236. //编辑 3
  237. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 3).FirstOrDefault();
  238. if (userPageFunc != null) pageFunAuth.EditAuth = 1;
  239. //下载 4
  240. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 4).FirstOrDefault();
  241. if (userPageFunc != null) pageFunAuth.FilesDownloadAuth = 1;
  242. //上传 5
  243. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 5).FirstOrDefault();
  244. if (userPageFunc != null) pageFunAuth.FilesUploadAuth = 1;
  245. //添加 11
  246. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 11).FirstOrDefault();
  247. if (userPageFunc != null) pageFunAuth.AddAuth = 1;
  248. //审核 12
  249. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 12).FirstOrDefault();
  250. if (userPageFunc != null) pageFunAuth.AuditAuth = 1;
  251. return pageFunAuth;
  252. }
  253. #endregion
  254. #region 业务模块 团组权限
  255. /// <summary>
  256. /// 业务模块 团组操作权限
  257. /// 验证
  258. /// </summary>
  259. /// <param name="diId">团组Id</param>
  260. /// <param name="userId">用户Id</param>
  261. /// <param name="CTable">业务模块Id</param>
  262. /// <returns></returns>
  263. public static async Task<Result> PostGroupOperationAuth(int diId, int userId, int CTable)
  264. {
  265. Result _result = new Result { Code = -1, Msg = "No Operation Authorty!" };
  266. if (CTable < 1)
  267. {
  268. _result.Msg = "请填写正确的用户Id!";
  269. return _result;
  270. }
  271. var data = await _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(it => it.DIId == diId && it.UId == userId && it.CTId == CTable && it.IsDel == 0).FirstAsync();
  272. if (data == null)
  273. {
  274. _result.Msg = "你没有本团下的该业务模块操作,请联系主管分配操作权限!";
  275. }
  276. else
  277. {
  278. _result.Code = 0;
  279. }
  280. return _result;
  281. }
  282. #endregion
  283. #region 团组相关
  284. #region 建团按国家默认添加汇率 / 默认权限分配
  285. /// <summary>
  286. /// 团组汇率
  287. /// 建团时 添加基础汇率 CNY
  288. /// 按国家 添加 默认币种
  289. /// </summary>
  290. /// <param name="userId"></param>
  291. /// <param name="diId"></param>
  292. /// <returns></returns>
  293. public static async Task<Result> PostGroupRateAddInit(int userId, int diId)
  294. {
  295. Result result = new() { Code = -2 };
  296. if (userId < 1)
  297. {
  298. result.Msg = string.Format(@"请传入正确的userId");
  299. return result;
  300. }
  301. if (diId < 1)
  302. {
  303. result.Msg = string.Format(@"请传入正确的DiId");
  304. return result;
  305. }
  306. //美元(USD):1.0000|欧元(EUR):1.0000|墨西哥比索(MXN):1.0000
  307. string rateInit = string.Format(@"人名币(CNY):1.0000");
  308. //var gropInfo = _dirRep._sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == diId).First();
  309. //if (gropInfo == null)
  310. //{
  311. // result.Msg = $@"未查询到团组信息!";
  312. // return result;
  313. //}
  314. var juheRateData = await _juHeApi.GetExchangeRateAsync();
  315. if (juheRateData.Error_code != 0)
  316. {
  317. result.Msg = juheRateData.Reason;
  318. return result;
  319. }
  320. List<ExchangeRateModel> exchangeRateModels = (List<ExchangeRateModel>)juheRateData.Result;
  321. if (exchangeRateModels.Count <= 0)
  322. {
  323. result.Msg = $@"未查询到聚合接口汇率信息!";
  324. return result;
  325. }
  326. if (exchangeRateModels.Count > 0)
  327. {
  328. var codes = _dirRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  329. for (int i = 0; i < exchangeRateModels.Count; i++)
  330. {
  331. string currencyName = exchangeRateModels[i].Name;
  332. string code = "";
  333. var currencyData = codes.Where(it => it.Remark == currencyName).FirstOrDefault();
  334. if (currencyData != null)
  335. {
  336. code = currencyData.Name;
  337. decimal currRate = 0.00M;
  338. string MSellPri = exchangeRateModels[i].MSellPri;
  339. if (!string.IsNullOrEmpty(MSellPri))
  340. {
  341. currRate = Convert.ToDecimal(MSellPri) / 100M;
  342. }
  343. rateInit += $@"|{currencyName}({code}):{currRate.ToString("#0.0000")}";
  344. }
  345. }
  346. }
  347. var cTableIds = _dirRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 16).ToList();
  348. if (cTableIds.Count < 1)
  349. {
  350. result.Msg = $@"未查询到操作模块信息!";
  351. return result;
  352. }
  353. List<Grp_TeamRate> grp_TeamRates = new List<Grp_TeamRate>();
  354. foreach (var item in cTableIds)
  355. {
  356. grp_TeamRates.Add(
  357. new Grp_TeamRate() { DiId = diId, CTable = item.Id, Remark = rateInit, CreateUserId = userId }
  358. );
  359. }
  360. if (grp_TeamRates.Count > 0)
  361. {
  362. var addId = _teamRateRep._sqlSugar.Insertable(grp_TeamRates).ExecuteCommand();
  363. if (addId < 1)
  364. {
  365. result.Msg = string.Format(@"添加失败!");
  366. return result;
  367. }
  368. }
  369. result.Code = 0;
  370. result.Msg = string.Format(@"操作成功!");
  371. return result;
  372. }
  373. /// <summary>
  374. /// 团组汇率
  375. /// 建团时 默认按照岗位分配权限
  376. /// </summary>
  377. /// <param name="userId"></param>
  378. /// <param name="diId"></param>
  379. /// <param name="companyId"></param>
  380. /// <returns></returns>
  381. public static async Task<Result> PostGroupAuthAddInit(int userId, int diId, int companyId = 2)
  382. {
  383. Result result = new() { Code = -2 };
  384. if (userId < 0)
  385. {
  386. result.Msg = string.Format(@"请传入正确的userId");
  387. return result;
  388. }
  389. if (companyId < 0)
  390. {
  391. result.Msg = string.Format(@"请传入正确的companyId");
  392. return result;
  393. }
  394. if (diId < 0)
  395. {
  396. result.Msg = string.Format(@"请传入正确的DiId");
  397. return result;
  398. }
  399. var userDatas = await _teamRateRep._sqlSugar
  400. .Queryable<Sys_Users>()
  401. .LeftJoin<Sys_Department>((su,sd) => su.DepId == sd.Id && sd.IsDel == 0)
  402. .LeftJoin<Sys_JobPost>((su,sd,sjp) => su.JobPostId == sjp.Id && sjp.IsDel == 0)
  403. .Where(su => su.IsDel == 0)
  404. .Select((su,sd,sjp) => new {
  405. su.DepId,
  406. sd.DepName,
  407. su.JobPostId,
  408. sjp.JobName,
  409. su.Id,
  410. su.CnName
  411. })
  412. .ToListAsync();
  413. /*
  414. * 76 酒店预订 --> 国交部门 酒店 岗位
  415. * 77 行程 --> 国交部门 经理,主管 岗位
  416. * 79 车/导游地接 --> 国交部门 OP 岗位
  417. * 80 签证 --> 国交部门 签证 岗位
  418. * 81 邀请/公务活动 --> 国交部门 商邀 岗位
  419. * 82 团组客户保险 --> 国交部 经理,主管 岗位
  420. * 85 机票预订 --> 国交部门 机票 岗位
  421. * 98 其他款项 --> 总经办部门 总经理 岗位/国交部门(ALL) 岗位/财务部门(ALL) 岗位/策划部门(ALL) 岗位/人事部门 采购 岗位
  422. * 1015 超支费用 --> 财务部门(ALL)岗位
  423. */
  424. List<Grp_GroupsTaskAssignment> _GroupsTaskAssignments = new List<Grp_GroupsTaskAssignment>();
  425. // 76 酒店预订 --> 国交部门(7) 酒店(25) 岗位
  426. _GroupsTaskAssignments.AddRange(
  427. userDatas
  428. .Where(it => it.DepId == 7 && it.JobPostId == 25)
  429. .Select(it => new Grp_GroupsTaskAssignment()
  430. {
  431. DIId = diId,
  432. CTId = 76,
  433. UId = it.Id,
  434. CreateUserId = userId
  435. }).ToList()
  436. );
  437. // 77 行程 --> 国交部门(7) 经理(32),主管(22) 岗位
  438. _GroupsTaskAssignments.AddRange(
  439. userDatas
  440. .Where(it => it.DepId == 7 && (it.JobPostId == 22 || it.JobPostId == 32))
  441. .Select(it => new Grp_GroupsTaskAssignment()
  442. {
  443. DIId = diId,
  444. CTId = 77,
  445. UId = it.Id,
  446. CreateUserId = userId
  447. }).ToList()
  448. );
  449. //79 车/导游地接 --> 国交部门(7) OP(28) 岗位
  450. _GroupsTaskAssignments.AddRange(
  451. userDatas.Where(it => it.DepId == 7 && it.JobPostId == 28)
  452. .Select(it => new Grp_GroupsTaskAssignment()
  453. {
  454. DIId = diId,
  455. CTId = 79,
  456. UId = it.Id,
  457. CreateUserId = userId
  458. }).ToList()
  459. );
  460. //81 邀请/公务活动 --> 国交部门(7) 商邀(27) 岗位
  461. _GroupsTaskAssignments.AddRange(
  462. userDatas
  463. .Where(it => it.DepId == 7 && it.JobPostId == 27)
  464. .Select(it => new Grp_GroupsTaskAssignment()
  465. {
  466. DIId = diId,
  467. CTId = 81,
  468. UId = it.Id,
  469. CreateUserId = userId
  470. }).ToList()
  471. );
  472. //80 签证 --> 国交部门(7) 签证(26) 岗位
  473. _GroupsTaskAssignments.AddRange(
  474. userDatas
  475. .Where(it => it.DepId == 7 && it.JobPostId == 26)
  476. .Select(it => new Grp_GroupsTaskAssignment()
  477. {
  478. DIId = diId,
  479. CTId = 80,
  480. UId = it.Id,
  481. CreateUserId = userId
  482. }).ToList()
  483. );
  484. //82 团组客户保险 --> 国交部(7) 经理(32),主管(22) 岗位
  485. _GroupsTaskAssignments.AddRange(
  486. userDatas
  487. .Where(it => it.DepId == 7 && (it.JobPostId == 22 || it.JobPostId == 32))
  488. .Select(it => new Grp_GroupsTaskAssignment()
  489. {
  490. DIId = diId,
  491. CTId = 82,
  492. UId = it.Id,
  493. CreateUserId = userId
  494. }).ToList()
  495. );
  496. //85 机票预订 --> 国交部门(7) 机票(24) 岗位
  497. _GroupsTaskAssignments.AddRange(
  498. userDatas
  499. .Where(it => it.DepId == 7 && it.JobPostId == 24)
  500. .Select(it => new Grp_GroupsTaskAssignment()
  501. {
  502. DIId = diId,
  503. CTId = 85,
  504. UId = it.Id,
  505. CreateUserId = userId
  506. }).ToList()
  507. );
  508. //98 其他款项 --> 总经办部门(1) 总经理(1) 岗位/国交部门(7)(ALL) 岗位/财务部门(3)(ALL) 岗位/策划部门(5)(ALL) 岗位/人事部门(4) 采购(74) 岗位
  509. List<int> depIds = new List<int>() { 7,3,5 };
  510. List<int> jobIds = new List<int>() { 1,74};
  511. _GroupsTaskAssignments.AddRange(
  512. userDatas
  513. .Where(it => depIds.Contains(it.DepId) || jobIds.Contains(it.JobPostId))
  514. .Select(it => new Grp_GroupsTaskAssignment()
  515. {
  516. DIId = diId,
  517. CTId = 98,
  518. UId = it.Id,
  519. CreateUserId = userId
  520. }).ToList()
  521. );
  522. //1015 超支费用 --> 财务部门(3)(ALL)岗位
  523. _GroupsTaskAssignments.AddRange(
  524. userDatas
  525. .Where(it => it.DepId == 3)
  526. .Select(it => new Grp_GroupsTaskAssignment()
  527. {
  528. DIId = diId,
  529. CTId = 1015,
  530. UId = it.Id,
  531. CreateUserId = userId
  532. }).ToList()
  533. );
  534. if (_GroupsTaskAssignments.Count > 0)
  535. {
  536. var addId =_teamRateRep._sqlSugar.Insertable(_GroupsTaskAssignments).ExecuteCommand();
  537. }
  538. result.Code = 0;
  539. result.Msg = string.Format(@"操作成功!");
  540. return result;
  541. }
  542. #endregion
  543. #endregion
  544. #region 团组汇率
  545. /// <summary>
  546. /// 团组汇率
  547. /// 获取板块 币种 及 汇率
  548. /// 76 酒店预订 77 行程 79 车/导游地接
  549. /// 80 签证 82 团组客户保险 85 机票预订
  550. /// 98 其他款项 285 收款退还
  551. /// </summary>
  552. /// <param name="teamRateModels"></param>
  553. /// <param name="cTable"></param>
  554. /// <param name="currencyCode"></param>
  555. /// <returns>
  556. /// string
  557. /// eg: CNY 1.0000
  558. /// </returns>
  559. public static async Task<string> PostGroupRateByCTableAndCurrency(List<TeamRateModelView> teamRateModels, int cTable, List<string> currencyCodes)
  560. {
  561. string str = "";
  562. List<string> currencyRates = new List<string>();
  563. TeamRateModelView hotelRateData = teamRateModels.Where(it => it.CTableId == cTable).FirstOrDefault();
  564. if (hotelRateData != null)
  565. {
  566. var hotelRates = hotelRateData.TeamRates;
  567. foreach (var item in currencyCodes)
  568. {
  569. if (!string.IsNullOrEmpty(item))
  570. {
  571. var hotelRateInfo = hotelRates.Where(it => it.CurrencyCode.Equals(item)).FirstOrDefault();
  572. if (hotelRateInfo != null)
  573. {
  574. string str1 = string.Format("{0} {1}\r\n", hotelRateInfo.CurrencyCode, hotelRateInfo.Rate.ToString("#0.0000"));
  575. currencyRates.Add(str1);
  576. }
  577. }
  578. }
  579. if (currencyRates != null || currencyRates.Count > 0)
  580. {
  581. currencyRates = currencyRates.Distinct().ToList();
  582. foreach (var item in currencyRates)
  583. {
  584. str += item;
  585. }
  586. }
  587. }
  588. return str;
  589. }
  590. /// <summary>
  591. /// 团组汇率 币种 Item (来源:团组汇率)
  592. /// 根据 团组Id And 业务类型(CTable)Id
  593. /// api处理CTable = 285,默认返回CNY
  594. /// </summary>
  595. /// <param name="portType"></param>
  596. /// <param name="diId"></param>
  597. /// <param name="cTable"></param>
  598. /// <returns></returns>
  599. public static async Task<TeamRateModelGeneralView> PostGroupTeamRateByDiIdAndCTableId(int portType, int diId, int cTable)
  600. {
  601. TeamRateModelGeneralView _view = new TeamRateModelGeneralView();
  602. _view = await _teamRateRep.PostGroupTeamRateByDiIdAndCTableId(portType, diId, cTable);
  603. return _view;
  604. }
  605. /// <summary>
  606. /// 汇率备注拆分
  607. /// (美元(USD):7.2370|日元(JPY):0.0499|欧元(EUR):8.3000|英镑(GBP):9.1996|港币(HKD):0.9291)
  608. /// </summary>
  609. /// <param name="rateRemark"></param>
  610. /// <returns></returns>
  611. public static async Task<List<TeamRateDescAddCurrencyIdView>> SplitExchangeRate(this string rateRemark)
  612. {
  613. List<TeamRateDescAddCurrencyIdView> _view = new List<TeamRateDescAddCurrencyIdView>();
  614. List<SetDataInfoView> currencyDatas = new List<SetDataInfoView>();
  615. #region 获取所有币种
  616. string sql = string.Format(@"select * from Sys_SetData where STid = {0} and isdel = 0", 66);
  617. var DBdata = _setDataRep.GetListBySqlWithNolock(sql);
  618. if (DBdata == null || DBdata.Count == 0)
  619. {
  620. return _view;
  621. }
  622. currencyDatas = DBdata.Select(x => new SetDataInfoView
  623. {
  624. Name = x.Name,
  625. Id = x.Id,
  626. Remark = x.Remark,
  627. }).ToList();
  628. #endregion
  629. #region 拆分remark里的汇率
  630. if (string.IsNullOrEmpty(rateRemark))
  631. {
  632. return _view;
  633. }
  634. if (rateRemark.Contains("|"))
  635. {
  636. string[] currencyArr = rateRemark.Split("|");
  637. foreach (string currency in currencyArr)
  638. {
  639. string[] currency1 = currency.Split(":");
  640. string[] currency2 = currency1[0].Split("(");
  641. string currencyCode = currency2[1].Replace(")", "").TrimEnd();
  642. TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
  643. {
  644. CurrencyId = currencyDatas.Find(it => it.Name == currencyCode).Id,
  645. CurrencyCode = currencyCode,
  646. CurrencyName = currency2[0],
  647. Rate = decimal.Parse(currency1[1]),
  648. };
  649. _view.Add(rateDescView);
  650. }
  651. }
  652. else
  653. {
  654. try
  655. {
  656. string[] currency1 = rateRemark.Split(":");
  657. string[] currency2 = currency1[0].Split("(");
  658. string currencyCode = currency2[1].Replace(")", "").TrimEnd();
  659. TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
  660. {
  661. CurrencyId = currencyDatas.Find(it => it.Name == currencyCode).Id,
  662. CurrencyCode = currencyCode,
  663. CurrencyName = currency2[0],
  664. Rate = decimal.Parse(currency1[1]),
  665. };
  666. _view.Add(rateDescView);
  667. }
  668. catch (Exception)
  669. {
  670. return _view;
  671. }
  672. }
  673. #endregion
  674. return _view;
  675. }
  676. #endregion
  677. #region 汉字转换拼音
  678. private static Dictionary<int, List<string>> GetTotalPingYinDictionary(string text)
  679. {
  680. var chs = text.ToCharArray();
  681. //记录每个汉字的全拼
  682. Dictionary<int, List<string>> totalPingYinList = new Dictionary<int, List<string>>();
  683. for (int i = 0; i < chs.Length; i++)
  684. {
  685. var pinyinList = new List<string>();
  686. //是否是有效的汉字
  687. if (ChineseChar.IsValidChar(chs[i]))
  688. {
  689. ChineseChar cc = new ChineseChar(chs[i]);
  690. pinyinList = cc.Pinyins.Where(p => !string.IsNullOrWhiteSpace(p)).ToList();
  691. }
  692. else
  693. {
  694. pinyinList.Add(chs[i].ToString());
  695. }
  696. //去除声调,转小写
  697. pinyinList = pinyinList.ConvertAll(p => Regex.Replace(p, @"\d", "").ToLower());
  698. //去重
  699. pinyinList = pinyinList.Where(p => !string.IsNullOrWhiteSpace(p)).Distinct().ToList();
  700. if (pinyinList.Any())
  701. {
  702. totalPingYinList[i] = pinyinList;
  703. }
  704. }
  705. return totalPingYinList;
  706. }
  707. /// <summary>
  708. /// 获取汉语拼音全拼
  709. /// </summary>
  710. /// <param name="text">The string.</param>
  711. /// <returns></returns>
  712. public static List<string> GetTotalPingYin(this string text)
  713. {
  714. var result = new List<string>();
  715. foreach (var pys in GetTotalPingYinDictionary(text))
  716. {
  717. var items = pys.Value;
  718. if (result.Count <= 0)
  719. {
  720. result = items;
  721. }
  722. else
  723. {
  724. //全拼循环匹配
  725. var newTotalPingYinList = new List<string>();
  726. foreach (var totalPingYin in result)
  727. {
  728. newTotalPingYinList.AddRange(items.Select(item => totalPingYin + item));
  729. }
  730. newTotalPingYinList = newTotalPingYinList.Distinct().ToList();
  731. result = newTotalPingYinList;
  732. }
  733. }
  734. return result;
  735. }
  736. /// <summary>
  737. /// 获取汉语拼音首字母
  738. /// </summary>
  739. /// <param name="text"></param>
  740. /// <returns></returns>
  741. public static List<string> GetFirstPingYin(this string text)
  742. {
  743. var result = new List<string>();
  744. foreach (var pys in GetTotalPingYinDictionary(text))
  745. {
  746. var items = pys.Value;
  747. if (result.Count <= 0)
  748. {
  749. result = items.ConvertAll(p => p.Substring(0, 1)).Distinct().ToList();
  750. }
  751. else
  752. {
  753. //首字母循环匹配
  754. var newFirstPingYinList = new List<string>();
  755. foreach (var firstPingYin in result)
  756. {
  757. newFirstPingYinList.AddRange(items.Select(item => firstPingYin + item.Substring(0, 1)));
  758. }
  759. newFirstPingYinList = newFirstPingYinList.Distinct().ToList();
  760. result = newFirstPingYinList;
  761. }
  762. }
  763. return result;
  764. }
  765. #endregion
  766. #region 新客户资料表 操作记录
  767. /// <summary>
  768. /// 新客户资料表
  769. /// 操作记录添加
  770. /// </summary>
  771. /// <param name="portType"></param>
  772. /// <param name="operationEnum"></param>
  773. /// <param name="userId"></param>
  774. /// <param name="dataId"></param>
  775. /// <param name="remark"></param>
  776. /// <returns></returns>
  777. public static async Task<bool> NewClientOperationRecord(int portType, OperationEnum operationEnum, int userId, int dataId, string remark)
  778. {
  779. Crm_TableOperationRecord _TableOperationRecord = new Crm_TableOperationRecord()
  780. {
  781. TableName = "Crm_NewClientData",
  782. PortType = portType,
  783. OperationItem = operationEnum,
  784. DataId = dataId,
  785. CreateUserId = userId,
  786. CreateTime = DateTime.Now,
  787. Remark = remark
  788. };
  789. bool add = await _tableOperationRecordRep._Add(_TableOperationRecord);
  790. if (add) return false;
  791. return false;
  792. }
  793. #endregion
  794. #region 金额转大写
  795. /// <summary>
  796. /// 金额转换为大写数字
  797. /// <para>1、支持的最大数字:999999999999.99(玖仟玖佰玖拾玖亿玖仟玖佰玖拾玖万玖仟玖佰玖拾玖元玖角玖分)</para>
  798. /// <para>2、小数点后最多支持两位</para>
  799. /// </summary>
  800. /// <param name="num">数值</param>
  801. /// <returns></returns>
  802. public static string ConvertCNYUpper(this decimal num)
  803. {
  804. if (num == 0)
  805. {
  806. return "零元";
  807. }
  808. // 解决327000000转换后缺少单位万的问题
  809. return ConvertToChinese(num);
  810. }
  811. #region 实例
  812. /// <summary>
  813. /// 要转换的数字
  814. /// </summary>
  815. private static decimal j;
  816. /// <summary>
  817. ///
  818. /// </summary>
  819. private static string[] NumChineseCharacter = new string[] { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
  820. /// <summary>
  821. /// 判断输入的数字是否大于double类型
  822. /// </summary>
  823. private static bool IsNumber
  824. {
  825. get
  826. {
  827. if (j > decimal.MaxValue || j <= 0)
  828. return false;
  829. else
  830. return true;
  831. }
  832. }
  833. /// <summary>
  834. /// 数字转换成大写汉字主函数
  835. /// </summary>
  836. /// <returns>返回转换后的大写汉字</returns>
  837. public static string ConvertToChinese(decimal m)
  838. {
  839. j = m;
  840. string bb = "";
  841. if (IsNumber)
  842. {
  843. string str = j.ToString();
  844. string[] Num = str.Split('.');
  845. if (Num.Length == 1)
  846. {
  847. bb = NumberString(Num[0]) + "元整";
  848. bb = bb.Replace("零零", "零");
  849. }
  850. else
  851. {
  852. bb = NumberString(Num[0]) + "元";
  853. bb += FloatString(Num[1]);
  854. bb = bb.Replace("零零", "零");
  855. }
  856. }
  857. else
  858. {
  859. throw new FormatException("你输入的数字格式不正确或不是数字!");
  860. }
  861. return bb;
  862. }
  863. /// <summary>
  864. /// 小数位转换只支持两位的小数
  865. /// </summary>
  866. /// <param name="Num">转换的小数</param>
  867. /// <returns>小数转换成汉字</returns>
  868. private static string FloatString(string Num)
  869. {
  870. string cc = "";
  871. if (Num.Length > 2)
  872. {
  873. throw new FormatException("小数位数过多.");
  874. }
  875. else
  876. {
  877. string bb = ConvertString(Num);
  878. int len = bb.IndexOf("零");
  879. if (len != 0)
  880. {
  881. bb = bb.Replace("零", "");
  882. if (bb.Length == 1)
  883. {
  884. cc = bb.Substring(0, 1) + "角";
  885. }
  886. else
  887. {
  888. cc = bb.Substring(0, 1) + "角";
  889. cc += bb.Substring(1, 1) + "分";
  890. }
  891. }
  892. else
  893. cc = bb + "分";
  894. }
  895. return cc;
  896. }
  897. /// <summary>
  898. /// 判断数字位数以进行拆分转换
  899. /// </summary>
  900. /// <param name="Num">要进行拆分的数字</param>
  901. /// <returns>转换成的汉字</returns>
  902. private static string NumberString(string Num)
  903. {
  904. string bb = "";
  905. if (Num.Length <= 4)
  906. {
  907. bb = Convert4(Num);
  908. }
  909. else if (Num.Length > 4 && Num.Length <= 8)
  910. {
  911. bb = Convert4(Num.Substring(0, Num.Length - 4)) + "万";
  912. bb += Convert4(Num.Substring(Num.Length - 4, 4));
  913. }
  914. else if (Num.Length > 8 && Num.Length <= 12)
  915. {
  916. bb = Convert4(Num.Substring(0, Num.Length - 8)) + "亿";
  917. if (Convert4(Num.Substring(Num.Length - 8, 4)) == "")
  918. if (Convert4(Num.Substring(Num.Length - 4, 4)) != "")
  919. bb += "零";
  920. else
  921. bb += "";
  922. else
  923. bb += Convert4(Num.Substring(Num.Length - 8, 4)) + "万";
  924. bb += Convert4(Num.Substring(Num.Length - 4, 4));
  925. }
  926. else
  927. {
  928. throw new Exception("整数部分最多支持12位");
  929. }
  930. return bb;
  931. }
  932. /// <summary>
  933. /// 四位数字的转换
  934. /// </summary>
  935. /// <param name="Num">准备转换的四位数字</param>
  936. /// <returns>转换以后的汉字</returns>
  937. private static string Convert4(string Num)
  938. {
  939. string bb = "";
  940. if (Num.Length == 1)
  941. {
  942. bb = ConvertString(Num);
  943. }
  944. else if (Num.Length == 2)
  945. {
  946. bb = ConvertString(Num);
  947. bb = Convert2(bb);
  948. }
  949. else if (Num.Length == 3)
  950. {
  951. bb = ConvertString(Num);
  952. bb = Convert3(bb);
  953. }
  954. else
  955. {
  956. bb = ConvertString(Num);
  957. string cc = "";
  958. string len = bb.Substring(0, 4);
  959. if (len != "零零零零")
  960. {
  961. len = bb.Substring(0, 3);
  962. if (len != "零零零")
  963. {
  964. bb = bb.Replace("零零零", "");
  965. if (bb.Length == 1)
  966. {
  967. bb = bb.Substring(0, 1) + "仟";
  968. }
  969. else
  970. {
  971. if (bb.Substring(0, 1) != "零" && bb.Substring(0, 2) != "零")
  972. cc = bb.Substring(0, 1) + "仟";
  973. else
  974. cc = bb.Substring(0, 1);
  975. bb = cc + Convert3(bb.Substring(1, 3));
  976. }
  977. }
  978. else
  979. {
  980. bb = bb.Replace("零零零", "零");
  981. }
  982. }
  983. else
  984. {
  985. bb = bb.Replace("零零零零", "");
  986. }
  987. }
  988. return bb;
  989. }
  990. /// <summary>
  991. /// 将数字转换成汉字
  992. /// </summary>
  993. /// <param name="Num">需要转换的数字</param>
  994. /// <returns>转换后的汉字</returns>
  995. private static string ConvertString(string Num)
  996. {
  997. string bb = "";
  998. for (int i = 0; i < Num.Length; i++)
  999. {
  1000. bb += NumChineseCharacter[int.Parse(Num.Substring(i, 1))];
  1001. }
  1002. return bb;
  1003. }
  1004. /// <summary>
  1005. /// 两位数字的转换
  1006. /// </summary>
  1007. /// <param name="Num">两位数字</param>
  1008. /// <returns>转换后的汉字</returns>
  1009. private static string Convert2(string Num)
  1010. {
  1011. string bb = ""; string cc = "";
  1012. string len = Num.Substring(0, 1);
  1013. if (len != "零")
  1014. {
  1015. bb = Num.Replace("零", "");
  1016. if (bb.Length == 1)
  1017. {
  1018. cc = bb.Substring(0, 1) + "拾";
  1019. }
  1020. else
  1021. {
  1022. cc = bb.Substring(0, 1) + "拾";
  1023. cc += bb.Substring(1, 1);
  1024. }
  1025. }
  1026. else
  1027. cc = Num;
  1028. return cc;
  1029. }
  1030. /// <summary>
  1031. /// 三位数字的转换
  1032. /// </summary>
  1033. /// <param name="Num">三位数字</param>
  1034. /// <returns>转换后的汉字</returns>
  1035. private static string Convert3(string Num)
  1036. {
  1037. string bb = ""; string cc = "";
  1038. string len = Num.Substring(0, 2);
  1039. if (len != "零零")
  1040. {
  1041. bb = Num.Replace("零零", "");
  1042. if (bb.Length == 1)
  1043. {
  1044. bb = bb.Substring(0, 1) + "佰";
  1045. }
  1046. else
  1047. {
  1048. if (bb.Substring(0, 1) != "零")
  1049. cc = bb.Substring(0, 1) + "佰";
  1050. else
  1051. cc = bb.Substring(0, 1);
  1052. bb = cc + Convert2(bb.Substring(1, 2));
  1053. }
  1054. }
  1055. else
  1056. {
  1057. bb = Num.Replace("零零", "零");
  1058. }
  1059. return bb;
  1060. }
  1061. #endregion
  1062. #endregion
  1063. }
  1064. }