GeneralMethod.cs 45 KB

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