GeneralMethod.cs 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135
  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.Data;
  19. using System.IdentityModel.Tokens.Jwt;
  20. using System.IO.Compression;
  21. using System.Security.Claims;
  22. using System.Web;
  23. using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
  24. namespace OASystem.API.OAMethodLib
  25. {
  26. public static class GeneralMethod
  27. {
  28. //团组信息
  29. private readonly static DelegationInfoRepository _dirRep = AutofacIocManager.Instance.GetService<DelegationInfoRepository>();
  30. private readonly static TeamRateRepository _teamRateRep = AutofacIocManager.Instance.GetService<TeamRateRepository>();
  31. private readonly static IJuHeApiService _juHeApi = AutofacIocManager.Instance.GetService<IJuHeApiService>();
  32. private readonly static SetDataRepository _setDataRep = AutofacIocManager.Instance.GetService<SetDataRepository>();
  33. private readonly static TableOperationRecordRepository _tableOperationRecordRep = AutofacIocManager.Instance.GetService<TableOperationRecordRepository>();
  34. private readonly static MessageRepository _messageRep = AutofacIocManager.Instance.GetService<MessageRepository>();
  35. private readonly static IHubContext<ChatHub, IChatClient> _hubContext = AutofacIocManager.Instance.GetService<IHubContext<ChatHub, IChatClient>>();
  36. #region 员工注册默认添加基础页面
  37. /// <summary>
  38. /// 默认职位权限
  39. /// </summary>
  40. public static bool DefaultPostAuth(int depId,int postId, int userId,int createUserId)
  41. {
  42. if (depId < 1) return false;
  43. if (postId < 1) return false;
  44. if (userId < 1) return false;
  45. if (userId < 1) return false;
  46. List<DefaultPostPageAuthView> _defaultData = AppSettingsHelper.Get<DefaultPostPageAuthView>("DefaultPostPageData");
  47. if (_defaultData.Count < 1) return false;
  48. var postJobDatas = _dirRep._sqlSugar.Queryable<Sys_JobPost>().Where(it => it.IsDel == 0).ToList();
  49. List<int> pageData = new List<int>();
  50. //添加公司公共页面
  51. pageData.AddRange(_defaultData.Find(it => it.DepId == -1)?.PostPageAuths[0].PageIds ?? new List<int>());
  52. //添加部门页面
  53. var depPublicPageData = _defaultData.Find(it => it.DepId == depId);
  54. var jobPublicPageData = postJobDatas.Find(it => it.DepId == depId && it.Id == postId);
  55. if (depPublicPageData != null) //特殊部门
  56. {
  57. //公共页面
  58. pageData.AddRange(depPublicPageData.PostPageAuths.Find(it => it.PostId == -1)?.PageIds ?? new List<int>());
  59. if (depId == 7) //国交部特殊处理
  60. {
  61. List<string> postNames = new List<string>() { "主管","经理" };
  62. //岗位页面
  63. if (jobPublicPageData != null)
  64. {
  65. if (postNames.Contains(jobPublicPageData.JobName))
  66. {
  67. pageData.AddRange(depPublicPageData.PostPageAuths.Find(it => it.PostId == 0)?.PageIds ?? new List<int>());
  68. }
  69. else
  70. {
  71. pageData.AddRange(depPublicPageData.PostPageAuths.Find(it => it.PostId == postId)?.PageIds ?? new List<int>());
  72. }
  73. }
  74. }
  75. }
  76. else //通用部门
  77. {
  78. pageData.AddRange(_defaultData.Find(it => it.DepId == 0)?.PostPageAuths[0].PageIds ?? new List<int>());
  79. }
  80. if (pageData.Count > 0)
  81. {
  82. //页面操作权限数据(添加修改等...)
  83. var pageFunctionData = _dirRep._sqlSugar.Queryable<Sys_SystemMenuAndFunction>().Where(it => pageData.Contains(it.SmId) && it.IsDel == 0 ).ToList();
  84. var defaultPageData = pageFunctionData.Select(it => new Sys_UserAuthority() {
  85. UId = userId,
  86. SmId = it.SmId,
  87. FId = it.FId,
  88. CreateUserId = createUserId, //管理员
  89. CreateTime = DateTime.Now,
  90. IsDel = 0,
  91. IsTemp = 1
  92. }).ToList();
  93. if (defaultPageData.Count > 0)
  94. {
  95. //移除每个页面的审核权限,审核权限需要单独开启
  96. defaultPageData = defaultPageData.Where(it => it.FId != 12).ToList();
  97. //添加页面操作权限
  98. var s = _dirRep._sqlSugar.Fastest<Sys_UserAuthority>().PageSize(100000).BulkCopy(defaultPageData);
  99. if (s > 0)
  100. {
  101. return true;
  102. }
  103. }
  104. }
  105. return false;
  106. }
  107. #endregion
  108. #region 消息
  109. /// <summary>
  110. /// 消息 发布And 通知
  111. /// </summary>
  112. /// <param name="msgTypeEnum">
  113. /// 消息类型
  114. /// 1 公告通知
  115. /// 2 团组流程管控通知
  116. /// 3 团组业务操作通知
  117. /// 4 团组费用审核消息
  118. /// 5 团组签证进度通知
  119. /// 6 团组任务进度通知
  120. /// </param>
  121. /// <param name="title">消息标题</param>
  122. /// <param name="content">消息内容</param>
  123. /// <param name="userIds"></param>
  124. /// <param name="diId">团组id</param>
  125. /// <param name="param">团组id</param>
  126. /// <returns></returns>
  127. public static async Task<bool> MessageIssueAndNotification(MessageTypeEnum msgTypeEnum, string title, string content, List<int> userIds, int diId = 0, string param = "")
  128. {
  129. MessageDto messageDto = new()
  130. {
  131. Type = msgTypeEnum,
  132. IssuerId = 4,//管理员
  133. DiId = diId,
  134. Title = title,
  135. Content = content,
  136. ReleaseTime = DateTime.Now,
  137. UIdList = userIds,
  138. Param = param
  139. };
  140. var status = await _messageRep.AddMsg(messageDto);//添加消息
  141. if (status)
  142. {
  143. //给在线在用户发送消息
  144. List<string> connIds = UserStore.OnlineUser.Where(it => userIds.Contains(it.UserId)).Select(it => it.ConnectionId).ToList();
  145. string notificationTypeStr1 = GetMsgNotificationType(msgTypeEnum);
  146. string notificationTypeStr = JsonConvert.SerializeObject(
  147. new
  148. {
  149. UserIds = userIds,
  150. Msg = $"您有一条{notificationTypeStr1}相关的消息!"
  151. }
  152. );
  153. await _hubContext.Clients.Clients(connIds).ReceiveMessage($"您有一条{notificationTypeStr1}相关的消息!");
  154. return true;
  155. }
  156. return false;
  157. }
  158. /// <summary>
  159. /// 根据消息类型 获取 消息通知类型
  160. /// </summary>
  161. /// <returns></returns>
  162. public static string GetMsgNotificationType(MessageTypeEnum msgTypeEnum)
  163. {
  164. int notificationType = 0;
  165. string notificationStr = "";
  166. List<NotificationTypeView> notificationTypeViews = AppSettingsHelper.Get<NotificationTypeView>("MessageNotificationType");
  167. notificationType = notificationTypeViews.Where(it => it.MsgTypeIds.Contains((int)msgTypeEnum)).Select(it => it.TypeId).FirstOrDefault();
  168. if (notificationType == 1021) notificationStr = "操作";
  169. else if (notificationType == 1020) notificationStr = "任务";
  170. return notificationStr;
  171. }
  172. #endregion
  173. #region md5 加密
  174. /// <summary>
  175. /// MD5加密,和动网上的16/32位MD5加密结果相同,
  176. /// 使用的UTF8编码
  177. /// </summary>
  178. /// <param name="source">待加密字串</param>
  179. /// <param name="length">16或32值之一,其它则采用.net默认MD5加密算法</param>
  180. /// <returns>加密后的字串</returns>
  181. public static string Encrypt(string source, int length = 32)
  182. {
  183. if (string.IsNullOrWhiteSpace(source))
  184. return string.Empty;
  185. HashAlgorithm hashAlgorithm = CryptoConfig.CreateFromName("MD5") as HashAlgorithm;
  186. byte[] bytes = Encoding.UTF8.GetBytes(source);
  187. byte[] hashValue = hashAlgorithm.ComputeHash(bytes);
  188. StringBuilder sb = new StringBuilder();
  189. switch (length)
  190. {
  191. case 16://16位密文是32位密文的9到24位字符
  192. for (int i = 4; i < 12; i++)
  193. {
  194. sb.Append(hashValue[i].ToString("x2"));
  195. }
  196. break;
  197. case 32:
  198. for (int i = 0; i < 16; i++)
  199. {
  200. sb.Append(hashValue[i].ToString("x2"));
  201. }
  202. break;
  203. default:
  204. for (int i = 0; i < hashValue.Length; i++)
  205. {
  206. sb.Append(hashValue[i].ToString("x2"));
  207. }
  208. break;
  209. }
  210. return sb.ToString();
  211. }
  212. #endregion
  213. #region jwt
  214. /// <summary>
  215. /// 获取token
  216. /// </summary>
  217. /// <param name="_config"></param>
  218. /// <param name="Number"></param>
  219. /// <param name="exp"></param>
  220. /// <returns></returns>
  221. public static async Task<string> GetToken(IConfiguration _config, string Number, int uId, string uName, DateTime exp)
  222. {
  223. string userId = Guid.NewGuid().ToString().Replace("-", "");
  224. var claims = new[] {
  225. new Claim(ClaimTypes.NameIdentifier, uName),
  226. new Claim(ClaimTypes.NameIdentifier, uId.ToString()),
  227. new Claim(ClaimTypes.NameIdentifier, userId),
  228. new Claim("Number",Number)
  229. };
  230. var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["JwtSecurityKey"]));
  231. var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
  232. var token = new JwtSecurityToken(
  233. issuer: "OASystem.com",
  234. audience: "OASystem.com",
  235. claims: claims,
  236. expires: exp,
  237. signingCredentials: creds);
  238. var indentity = new ClaimsIdentity(claims, "formlogin");
  239. var principal = new ClaimsPrincipal(indentity);
  240. // await _httpContext.SignInAsync (CookieAuthenticationDefaults.AuthenticationScheme, principal);
  241. return new JwtSecurityTokenHandler().WriteToken(token);
  242. }
  243. #endregion
  244. #region 数据类型转换
  245. /// <summary>
  246. /// object 转 Int
  247. /// </summary>
  248. /// <param name="obj"></param>
  249. /// <returns></returns>
  250. public static int GetInt(this object obj)
  251. {
  252. if (obj == null)
  253. return 0;
  254. int _number = 0;
  255. bool reslut = Int32.TryParse(obj.ToString(), out _number);
  256. return _number;
  257. }
  258. private static DateTime dateStart = new DateTime(1970, 1, 1, 8, 0, 0);
  259. private static long longTime = 621355968000000000;
  260. private static int samllTime = 10000000;
  261. /// <summary>
  262. /// 时间戳 转 datetime
  263. /// </summary>
  264. /// <param name="timeStamp"></param>
  265. /// <returns></returns>
  266. public static DateTime GetTimeSpmpToDate(this object timeStamp)
  267. {
  268. if (timeStamp == null) return dateStart;
  269. DateTime dateTime = new DateTime(longTime + Convert.ToInt64(timeStamp) * samllTime, DateTimeKind.Utc).ToLocalTime();
  270. return dateTime;
  271. }
  272. #endregion
  273. #region 用户页面操作功能 权限
  274. /// <summary>
  275. /// 用户页面操作功能(可使用)
  276. /// </summary>
  277. /// <param name="userId">用户Id</param>
  278. /// <param name="PageId">页面Id</param>
  279. /// <returns></returns>
  280. public static async Task<PageFunAuthViewBase> PostUserPageFuncDatas(int userId, int PageId)
  281. {
  282. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  283. List<UserPageFuncView> userPageFuncDatas = new List<UserPageFuncView>();
  284. string sql = string.Format(@"Select ua.UId As UserId, u.CnName As UserName, pa.ModuleId,pa.ModuleName,pa.PageId,pa.PageName,pa.PageIsEnable,
  285. pa.PagePhoneIsEnable,pa.FuncId,pa.FuncName,pa.FuncIsEnable
  286. From Sys_UserAuthority ua
  287. Left Join Sys_Users u On ua.UId = u.Id
  288. Left Join (
  289. Select sd.Id As ModuleId,sd.Name As ModuleName, smp.Id As PageId,smp.Name As PageName,smp.IsEnable As PageIsEnable,
  290. smp.phoneIsEnable As PagePhoneIsEnable,pfp.Id As FuncId,pfp.FunctionName As FuncName,pfp.IsEnable As FuncIsEnable
  291. From Sys_SystemMenuAndFunction smaf
  292. Left Join Sys_SystemMenuPermission smp On smaf.SmId = smp.Id
  293. Left Join Sys_SetData sd On sd.STid = 5 And smp.Mid = sd.Id
  294. Left Join Sys_PageFunctionPermission pfp On smaf.FId = pfp.Id
  295. Where smaf.IsDel = 0 And smp.IsDel = 0 And pfp.IsDel = 0 And sd.IsDel = 0 And smp.IsEnable = 1
  296. ) As pa On ua.SmId = pa.PageId And ua.FId = pa.FuncId
  297. Where ua.IsDel = 0 And ua.UId = {0} And pa.PageId = {1}
  298. Order By ModuleId,PageId,FuncId Asc", userId, PageId);
  299. userPageFuncDatas = await _dirRep._sqlSugar.SqlQueryable<UserPageFuncView>(sql).ToListAsync();
  300. if (userPageFuncDatas.Count <= 0)
  301. {
  302. return pageFunAuth;
  303. }
  304. UserPageFuncView userPageFunc = new UserPageFuncView();
  305. //查询 1
  306. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 1).FirstOrDefault();
  307. if (userPageFunc != null) pageFunAuth.CheckAuth = 1;
  308. //删除 2
  309. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 2).FirstOrDefault();
  310. if (userPageFunc != null) pageFunAuth.DeleteAuth = 1;
  311. //编辑 3
  312. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 3).FirstOrDefault();
  313. if (userPageFunc != null) pageFunAuth.EditAuth = 1;
  314. //下载 4
  315. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 4).FirstOrDefault();
  316. if (userPageFunc != null) pageFunAuth.FilesDownloadAuth = 1;
  317. //上传 5
  318. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 5).FirstOrDefault();
  319. if (userPageFunc != null) pageFunAuth.FilesUploadAuth = 1;
  320. //添加 11
  321. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 11).FirstOrDefault();
  322. if (userPageFunc != null) pageFunAuth.AddAuth = 1;
  323. //审核 12
  324. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 12).FirstOrDefault();
  325. if (userPageFunc != null) pageFunAuth.AuditAuth = 1;
  326. return pageFunAuth;
  327. }
  328. #endregion
  329. #region 业务模块 团组权限
  330. /// <summary>
  331. /// 业务模块 团组操作权限
  332. /// 验证 并返回可操作的团
  333. /// </summary>
  334. /// <param name="diId">团组Id</param>
  335. /// <param name="userId">用户Id</param>
  336. /// <param name="CTable">业务模块Id</param>
  337. /// <returns></returns>
  338. public static async Task<Result> PostGroupOperationAuth(int diId, int userId, int CTable)
  339. {
  340. Result _result = new Result { Code = -1, Msg = "No Operation Authorty!" };
  341. if (CTable < 1)
  342. {
  343. _result.Msg = "请填写正确的用户Id!";
  344. return _result;
  345. }
  346. var data = _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(it => it.DIId == diId && it.UId == userId && it.CTId == CTable && it.IsDel == 0).First();
  347. if (data == null)
  348. {
  349. _result.Msg = "你没有本团下的该业务模块操作,请联系主管分配操作权限!";
  350. }
  351. else
  352. {
  353. _result.Code = 0;
  354. }
  355. return _result;
  356. }
  357. /// <summary>
  358. /// 业务模块 团组操作权限
  359. /// 返回可操作的团
  360. /// </summary>
  361. /// <param name="diId">团组Id</param>
  362. /// <param name="userId">用户Id</param>
  363. /// <param name="CTable">业务模块Id</param>
  364. /// <returns></returns>
  365. public static async Task<List<Web_ShareGroupInfoView>> PostOperationAuthReturnGroupInfosAsync(int userId, int CTable)
  366. {
  367. List<Web_ShareGroupInfoView> _ShareGroupInfoViews = new List<Web_ShareGroupInfoView>();
  368. var taskDatas = _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(it => it.UId == userId && it.CTId == CTable && it.IsDel == 0).ToList();
  369. if (taskDatas.Count < 1) return _ShareGroupInfoViews;
  370. string diIds = string.Join(",", taskDatas.Select(it => it.DIId).ToList());
  371. string sql = string.Format(@"Select Id,TeamName,TourCode,ClientName,VisitCountry,VisitStartDate,VisitEndDate,VisitDays,VisitPNumber
  372. From Grp_DelegationInfo Where Id In({0}) And IsDel = 0 Order By Id Desc", diIds);
  373. _ShareGroupInfoViews = await _dirRep._sqlSugar.SqlQueryable<Web_ShareGroupInfoView>(sql).ToListAsync();
  374. return _ShareGroupInfoViews;
  375. }
  376. #endregion
  377. #region 团组相关
  378. #region 建团按国家默认添加汇率 / 默认权限分配
  379. /// <summary>
  380. /// 团组汇率
  381. /// 建团时 添加基础汇率 CNY
  382. /// 按国家 添加 默认币种
  383. /// </summary>
  384. /// <param name="userId"></param>
  385. /// <param name="diId"></param>
  386. /// <returns></returns>
  387. public static async Task<Result> PostGroupRateAddInit(int userId, int diId)
  388. {
  389. Result result = new() { Code = -2 };
  390. if (userId < 1)
  391. {
  392. result.Msg = string.Format(@"请传入正确的userId");
  393. return result;
  394. }
  395. if (diId < 1)
  396. {
  397. result.Msg = string.Format(@"请传入正确的DiId");
  398. return result;
  399. }
  400. //美元(USD):1.0000|欧元(EUR):1.0000|墨西哥比索(MXN):1.0000
  401. string rateInit = string.Format(@"人民币(CNY):1.0000");
  402. //var gropInfo = _dirRep._sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == diId).First();
  403. //if (gropInfo == null)
  404. //{
  405. // result.Msg = $@"未查询到团组信息!";
  406. // return result;
  407. //}
  408. var juheRateData = await _juHeApi.GetExchangeRateAsync();
  409. if (juheRateData.Error_code != 0)
  410. {
  411. result.Msg = juheRateData.Reason;
  412. return result;
  413. }
  414. List<ExchangeRateModel> exchangeRateModels = (List<ExchangeRateModel>)juheRateData.Result;
  415. if (exchangeRateModels.Count <= 0)
  416. {
  417. result.Msg = $@"未查询到聚合接口汇率信息!";
  418. return result;
  419. }
  420. if (exchangeRateModels.Count > 0)
  421. {
  422. var codes = _dirRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  423. for (int i = 0; i < exchangeRateModels.Count; i++)
  424. {
  425. string currencyName = exchangeRateModels[i].Name;
  426. string code = "";
  427. var currencyData = codes.Where(it => it.Remark == currencyName).FirstOrDefault();
  428. if (currencyData != null)
  429. {
  430. code = currencyData.Name;
  431. decimal currRate = 0.00M;
  432. string MSellPri = exchangeRateModels[i].MSellPri;
  433. if (!string.IsNullOrEmpty(MSellPri))
  434. {
  435. currRate = Convert.ToDecimal(MSellPri) / 100M;
  436. }
  437. rateInit += $@"|{currencyName}({code}):{currRate.ToString("#0.0000")}";
  438. }
  439. }
  440. }
  441. var cTableIds = _dirRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 16).ToList();
  442. if (cTableIds.Count < 1)
  443. {
  444. result.Msg = $@"未查询到操作模块信息!";
  445. return result;
  446. }
  447. List<Grp_TeamRate> grp_TeamRates = new List<Grp_TeamRate>();
  448. foreach (var item in cTableIds)
  449. {
  450. grp_TeamRates.Add(
  451. new Grp_TeamRate() { DiId = diId, CTable = item.Id, Remark = rateInit, CreateUserId = userId }
  452. );
  453. }
  454. if (grp_TeamRates.Count > 0)
  455. {
  456. var addId = _teamRateRep._sqlSugar.Insertable(grp_TeamRates).ExecuteCommand();
  457. if (addId < 1)
  458. {
  459. result.Msg = string.Format(@"添加失败!");
  460. return result;
  461. }
  462. }
  463. result.Code = 0;
  464. result.Msg = string.Format(@"操作成功!");
  465. return result;
  466. }
  467. /// <summary>
  468. /// 团组任务分配
  469. /// 建团时 默认按照岗位分配权限
  470. /// </summary>
  471. /// <param name="userId"></param>
  472. /// <param name="diId"></param>
  473. /// <param name="companyId"></param>
  474. /// <returns></returns>
  475. public static async Task<Result> PostGroupAuthAddInit(int userId, int diId, int companyId = 2)
  476. {
  477. Result result = new() { Code = -2 };
  478. if (userId < 0)
  479. {
  480. result.Msg = string.Format(@"请传入正确的userId");
  481. return result;
  482. }
  483. if (companyId < 0)
  484. {
  485. result.Msg = string.Format(@"请传入正确的companyId");
  486. return result;
  487. }
  488. if (diId < 0)
  489. {
  490. result.Msg = string.Format(@"请传入正确的DiId");
  491. return result;
  492. }
  493. var userDatas = await _teamRateRep._sqlSugar
  494. .Queryable<Sys_Users>()
  495. .LeftJoin<Sys_Department>((su,sd) => su.DepId == sd.Id && sd.IsDel == 0)
  496. .LeftJoin<Sys_JobPost>((su,sd,sjp) => su.JobPostId == sjp.Id && sjp.IsDel == 0)
  497. .Where(su => su.IsDel == 0)
  498. .Select((su,sd,sjp) => new {
  499. su.DepId,
  500. sd.DepName,
  501. su.JobPostId,
  502. sjp.JobName,
  503. su.Id,
  504. su.CnName
  505. })
  506. .ToListAsync();
  507. /*
  508. * 76 酒店预订 --> 国交部门 酒店 岗位
  509. * 77 行程 --> 国交部门 经理,主管 岗位
  510. * 79 车/导游地接 --> 国交部门 OP 岗位
  511. * 80 签证 --> 国交部门 签证 岗位
  512. * 81 邀请/公务活动 --> 国交部门 商邀 岗位
  513. * 82 团组客户保险 --> 国交部 经理,主管 岗位
  514. * 85 机票预订 --> 国交部门 机票 岗位
  515. * 98 其他款项 --> 总经办部门 总经理 岗位/国交部门(ALL) 岗位/财务部门(ALL) 岗位/策划部门(ALL) 岗位/人事部门 采购 岗位
  516. * 1015 超支费用,69 收款退还 --> 财务部门(ALL)岗位
  517. * 1015 超支费用 --> 国交部(ALL)岗位
  518. */
  519. List<Grp_GroupsTaskAssignment> _GroupsTaskAssignments = new List<Grp_GroupsTaskAssignment>();
  520. // 76 酒店预订 --> 国交部门(7) 酒店(25) 岗位
  521. _GroupsTaskAssignments.AddRange(
  522. userDatas
  523. .Where(it => it.DepId == 7 && it.JobPostId == 25)
  524. .Select(it => new Grp_GroupsTaskAssignment()
  525. {
  526. DIId = diId,
  527. CTId = 76,
  528. UId = it.Id,
  529. CreateUserId = userId
  530. }).ToList()
  531. );
  532. // 77 行程 --> 国交部门(7) 经理(32),主管(22) 岗位
  533. _GroupsTaskAssignments.AddRange(
  534. userDatas
  535. .Where(it => it.DepId == 7 && (it.JobPostId == 22 || it.JobPostId == 32))
  536. .Select(it => new Grp_GroupsTaskAssignment()
  537. {
  538. DIId = diId,
  539. CTId = 77,
  540. UId = it.Id,
  541. CreateUserId = userId
  542. }).ToList()
  543. );
  544. //79 车/导游地接 --> 国交部门(7) OP(28) 岗位
  545. _GroupsTaskAssignments.AddRange(
  546. userDatas.Where(it => it.DepId == 7 && it.JobPostId == 28)
  547. .Select(it => new Grp_GroupsTaskAssignment()
  548. {
  549. DIId = diId,
  550. CTId = 79,
  551. UId = it.Id,
  552. CreateUserId = userId
  553. }).ToList()
  554. );
  555. //81 邀请/公务活动 --> 国交部门(7) 商邀(27) 岗位
  556. _GroupsTaskAssignments.AddRange(
  557. userDatas
  558. .Where(it => it.DepId == 7 && it.JobPostId == 27)
  559. .Select(it => new Grp_GroupsTaskAssignment()
  560. {
  561. DIId = diId,
  562. CTId = 81,
  563. UId = it.Id,
  564. CreateUserId = userId
  565. }).ToList()
  566. );
  567. //80 签证 --> 国交部门(7) 签证(26) 岗位
  568. _GroupsTaskAssignments.AddRange(
  569. userDatas
  570. .Where(it => it.DepId == 7 && it.JobPostId == 26)
  571. .Select(it => new Grp_GroupsTaskAssignment()
  572. {
  573. DIId = diId,
  574. CTId = 80,
  575. UId = it.Id,
  576. CreateUserId = userId
  577. }).ToList()
  578. );
  579. //82 团组客户保险 --> 国交部(7) 经理(32),主管(22) 岗位
  580. _GroupsTaskAssignments.AddRange(
  581. userDatas
  582. .Where(it => it.DepId == 7 && (it.JobPostId == 22 || it.JobPostId == 32))
  583. .Select(it => new Grp_GroupsTaskAssignment()
  584. {
  585. DIId = diId,
  586. CTId = 82,
  587. UId = it.Id,
  588. CreateUserId = userId
  589. }).ToList()
  590. );
  591. //85 机票预订 --> 国交部门(7) 机票(24) 岗位
  592. _GroupsTaskAssignments.AddRange(
  593. userDatas
  594. .Where(it => it.DepId == 7 && it.JobPostId == 24)
  595. .Select(it => new Grp_GroupsTaskAssignment()
  596. {
  597. DIId = diId,
  598. CTId = 85,
  599. UId = it.Id,
  600. CreateUserId = userId
  601. }).ToList()
  602. );
  603. //98 其他款项 --> 总经办部门(1) 总经理(1) 岗位/国交部门(7)(ALL) 岗位/财务部门(3)(ALL) 岗位/策划部门(5)(ALL) 岗位/人事部门(4) 采购(74) 岗位
  604. List<int> depIds = new List<int>() { 7,3,5 };
  605. List<int> jobIds = new List<int>() { 1,74};
  606. _GroupsTaskAssignments.AddRange(
  607. userDatas
  608. .Where(it => depIds.Contains(it.DepId) || jobIds.Contains(it.JobPostId))
  609. .Select(it => new Grp_GroupsTaskAssignment()
  610. {
  611. DIId = diId,
  612. CTId = 98,
  613. UId = it.Id,
  614. CreateUserId = userId
  615. }).ToList()
  616. );
  617. //1015 超支费用,285 收款退还 --> 财务部门(ALL)岗位
  618. _GroupsTaskAssignments.AddRange(
  619. userDatas
  620. .Where(it => it.DepId == 3)
  621. .Select(it => new Grp_GroupsTaskAssignment()
  622. {
  623. DIId = diId,
  624. CTId = 1015,
  625. UId = it.Id,
  626. CreateUserId = userId
  627. }).ToList()
  628. );
  629. _GroupsTaskAssignments.AddRange(
  630. userDatas
  631. .Where(it => it.DepId == 3)
  632. .Select(it => new Grp_GroupsTaskAssignment()
  633. {
  634. DIId = diId,
  635. CTId = 285,
  636. UId = it.Id,
  637. CreateUserId = userId
  638. }).ToList()
  639. );
  640. //1015 超支费用 --> 国交部(ALL)岗位
  641. _GroupsTaskAssignments.AddRange(
  642. userDatas
  643. .Where(it => it.DepId == 7)
  644. .Select(it => new Grp_GroupsTaskAssignment()
  645. {
  646. DIId = diId,
  647. CTId = 1015,
  648. UId = it.Id,
  649. CreateUserId = userId
  650. }).ToList()
  651. );
  652. if (_GroupsTaskAssignments.Count > 0)
  653. {
  654. var addId =_teamRateRep._sqlSugar.Insertable(_GroupsTaskAssignments).ExecuteCommand();
  655. }
  656. result.Code = 0;
  657. result.Msg = string.Format(@"操作成功!");
  658. return result;
  659. }
  660. #endregion
  661. #endregion
  662. #region 团组汇率
  663. /// <summary>
  664. /// 团组汇率
  665. /// 获取板块 币种 及 汇率
  666. /// 76 酒店预订 77 行程 79 车/导游地接
  667. /// 80 签证 82 团组客户保险 85 机票预订
  668. /// 98 其他款项 285 收款退还
  669. /// </summary>
  670. /// <param name="teamRateModels"></param>
  671. /// <param name="cTable"></param>
  672. /// <param name="currencyCode"></param>
  673. /// <returns>
  674. /// string
  675. /// eg: CNY 1.0000
  676. /// </returns>
  677. public static async Task<string> PostGroupRateByCTableAndCurrency(List<TeamRateModelView> teamRateModels, int cTable, List<string> currencyCodes)
  678. {
  679. string str = "";
  680. List<string> currencyRates = new List<string>();
  681. TeamRateModelView hotelRateData = teamRateModels.Where(it => it.CTableId == cTable).FirstOrDefault();
  682. if (hotelRateData != null)
  683. {
  684. var hotelRates = hotelRateData.TeamRates;
  685. foreach (var item in currencyCodes)
  686. {
  687. if (!string.IsNullOrEmpty(item))
  688. {
  689. var hotelRateInfo = hotelRates.Where(it => it.CurrencyCode.Equals(item)).FirstOrDefault();
  690. if (hotelRateInfo != null)
  691. {
  692. string str1 = string.Format("{0} {1}\r\n", hotelRateInfo.CurrencyCode, hotelRateInfo.Rate.ToString("#0.0000"));
  693. currencyRates.Add(str1);
  694. }
  695. }
  696. }
  697. if (currencyRates != null || currencyRates.Count > 0)
  698. {
  699. currencyRates = currencyRates.Distinct().ToList();
  700. foreach (var item in currencyRates)
  701. {
  702. str += item;
  703. }
  704. }
  705. }
  706. return str;
  707. }
  708. /// <summary>
  709. /// 团组汇率 币种 Item (来源:团组汇率)
  710. /// 根据 团组Id And 业务类型(CTable)Id
  711. /// api处理CTable = 285,默认返回CNY
  712. /// </summary>
  713. /// <param name="portType"></param>
  714. /// <param name="diId"></param>
  715. /// <param name="cTable"></param>
  716. /// <returns></returns>
  717. public static async Task<TeamRateModelGeneralView> PostGroupTeamRateByDiIdAndCTableId(int portType, int diId, int cTable)
  718. {
  719. TeamRateModelGeneralView _view = new TeamRateModelGeneralView();
  720. _view = await _teamRateRep.PostGroupTeamRateByDiIdAndCTableId(portType, diId, cTable);
  721. return _view;
  722. }
  723. /// <summary>
  724. /// 汇率备注拆分
  725. /// (美元(USD):7.2370|日元(JPY):0.0499|欧元(EUR):8.3000|英镑(GBP):9.1996|港币(HKD):0.9291)
  726. /// </summary>
  727. /// <param name="rateRemark"></param>
  728. /// <returns></returns>
  729. public static async Task<List<TeamRateDescAddCurrencyIdView>> SplitExchangeRate(this string rateRemark)
  730. {
  731. List<TeamRateDescAddCurrencyIdView> _view = new List<TeamRateDescAddCurrencyIdView>();
  732. List<SetDataInfoView> currencyDatas = new List<SetDataInfoView>();
  733. #region 获取所有币种
  734. string sql = string.Format(@"select * from Sys_SetData where STid = {0} and isdel = 0", 66);
  735. var DBdata = _setDataRep.GetListBySqlWithNolock(sql);
  736. if (DBdata == null || DBdata.Count == 0)
  737. {
  738. return _view;
  739. }
  740. currencyDatas = DBdata.Select(x => new SetDataInfoView
  741. {
  742. Name = x.Name,
  743. Id = x.Id,
  744. Remark = x.Remark,
  745. }).ToList();
  746. #endregion
  747. #region 拆分remark里的汇率
  748. if (string.IsNullOrEmpty(rateRemark))
  749. {
  750. return _view;
  751. }
  752. if (rateRemark.Contains("|"))
  753. {
  754. string[] currencyArr = rateRemark.Split("|");
  755. foreach (string currency in currencyArr)
  756. {
  757. string[] currency1 = currency.Split(":");
  758. string[] currency2 = currency1[0].Split("(");
  759. string currencyCode = currency2[1].Replace(")", "").TrimEnd();
  760. TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
  761. {
  762. CurrencyId = currencyDatas.Find(it => it.Name == currencyCode).Id,
  763. CurrencyCode = currencyCode,
  764. CurrencyName = currency2[0],
  765. Rate = decimal.Parse(currency1[1]),
  766. };
  767. _view.Add(rateDescView);
  768. }
  769. }
  770. else
  771. {
  772. try
  773. {
  774. string[] currency1 = rateRemark.Split(":");
  775. string[] currency2 = currency1[0].Split("(");
  776. string currencyCode = currency2[1].Replace(")", "").TrimEnd();
  777. TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
  778. {
  779. CurrencyId = currencyDatas.Find(it => it.Name == currencyCode).Id,
  780. CurrencyCode = currencyCode,
  781. CurrencyName = currency2[0],
  782. Rate = decimal.Parse(currency1[1]),
  783. };
  784. _view.Add(rateDescView);
  785. }
  786. catch (Exception)
  787. {
  788. return _view;
  789. }
  790. }
  791. #endregion
  792. return _view;
  793. }
  794. #endregion
  795. #region 汉字转换拼音
  796. private static Dictionary<int, List<string>> GetTotalPingYinDictionary(string text)
  797. {
  798. var chs = text.ToCharArray();
  799. //记录每个汉字的全拼
  800. Dictionary<int, List<string>> totalPingYinList = new Dictionary<int, List<string>>();
  801. for (int i = 0; i < chs.Length; i++)
  802. {
  803. var pinyinList = new List<string>();
  804. //是否是有效的汉字
  805. if (ChineseChar.IsValidChar(chs[i]))
  806. {
  807. ChineseChar cc = new ChineseChar(chs[i]);
  808. pinyinList = cc.Pinyins.Where(p => !string.IsNullOrWhiteSpace(p)).ToList();
  809. }
  810. else
  811. {
  812. pinyinList.Add(chs[i].ToString());
  813. }
  814. //去除声调,转小写
  815. pinyinList = pinyinList.ConvertAll(p => Regex.Replace(p, @"\d", "").ToLower());
  816. //去重
  817. pinyinList = pinyinList.Where(p => !string.IsNullOrWhiteSpace(p)).Distinct().ToList();
  818. if (pinyinList.Any())
  819. {
  820. totalPingYinList[i] = pinyinList;
  821. }
  822. }
  823. return totalPingYinList;
  824. }
  825. /// <summary>
  826. /// 获取汉语拼音全拼
  827. /// </summary>
  828. /// <param name="text">The string.</param>
  829. /// <returns></returns>
  830. public static List<string> GetTotalPingYin(this string text)
  831. {
  832. var result = new List<string>();
  833. foreach (var pys in GetTotalPingYinDictionary(text))
  834. {
  835. var items = pys.Value;
  836. if (result.Count <= 0)
  837. {
  838. result = items;
  839. }
  840. else
  841. {
  842. //全拼循环匹配
  843. var newTotalPingYinList = new List<string>();
  844. foreach (var totalPingYin in result)
  845. {
  846. newTotalPingYinList.AddRange(items.Select(item => totalPingYin + item));
  847. }
  848. newTotalPingYinList = newTotalPingYinList.Distinct().ToList();
  849. result = newTotalPingYinList;
  850. }
  851. }
  852. return result;
  853. }
  854. /// <summary>
  855. /// 获取汉语拼音首字母
  856. /// </summary>
  857. /// <param name="text"></param>
  858. /// <returns></returns>
  859. public static List<string> GetFirstPingYin(this string text)
  860. {
  861. var result = new List<string>();
  862. foreach (var pys in GetTotalPingYinDictionary(text))
  863. {
  864. var items = pys.Value;
  865. if (result.Count <= 0)
  866. {
  867. result = items.ConvertAll(p => p.Substring(0, 1)).Distinct().ToList();
  868. }
  869. else
  870. {
  871. //首字母循环匹配
  872. var newFirstPingYinList = new List<string>();
  873. foreach (var firstPingYin in result)
  874. {
  875. newFirstPingYinList.AddRange(items.Select(item => firstPingYin + item.Substring(0, 1)));
  876. }
  877. newFirstPingYinList = newFirstPingYinList.Distinct().ToList();
  878. result = newFirstPingYinList;
  879. }
  880. }
  881. return result;
  882. }
  883. #endregion
  884. #region 新客户资料表 操作记录
  885. /// <summary>
  886. /// 新客户资料表
  887. /// 操作记录添加
  888. /// </summary>
  889. /// <param name="portType"></param>
  890. /// <param name="operationEnum"></param>
  891. /// <param name="userId"></param>
  892. /// <param name="dataId"></param>
  893. /// <param name="remark"></param>
  894. /// <returns></returns>
  895. public static async Task<bool> NewClientOperationRecord(int portType, OperationEnum operationEnum, int userId, int dataId, string remark)
  896. {
  897. Crm_TableOperationRecord _TableOperationRecord = new Crm_TableOperationRecord()
  898. {
  899. TableName = "Crm_NewClientData",
  900. PortType = portType,
  901. OperationItem = operationEnum,
  902. DataId = dataId,
  903. CreateUserId = userId,
  904. CreateTime = DateTime.Now,
  905. Remark = remark
  906. };
  907. bool add = await _tableOperationRecordRep._Add(_TableOperationRecord);
  908. if (add) return false;
  909. return false;
  910. }
  911. #endregion
  912. #region 金额转大写
  913. /// <summary>
  914. /// 金额转换为大写数字
  915. /// <para>1、支持的最大数字:999999999999.99(玖仟玖佰玖拾玖亿玖仟玖佰玖拾玖万玖仟玖佰玖拾玖元玖角玖分)</para>
  916. /// <para>2、小数点后最多支持两位</para>
  917. /// </summary>
  918. /// <param name="num">数值</param>
  919. /// <returns></returns>
  920. public static string ConvertCNYUpper(this decimal num)
  921. {
  922. if (num == 0)
  923. {
  924. return "零元";
  925. }
  926. // 解决327000000转换后缺少单位万的问题
  927. return ConvertToChinese(num);
  928. }
  929. #region 实例
  930. /// <summary>
  931. /// 要转换的数字
  932. /// </summary>
  933. private static decimal j;
  934. /// <summary>
  935. ///
  936. /// </summary>
  937. private static string[] NumChineseCharacter = new string[] { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
  938. /// <summary>
  939. /// 判断输入的数字是否大于double类型
  940. /// </summary>
  941. private static bool IsNumber
  942. {
  943. get
  944. {
  945. if (j > decimal.MaxValue || j <= 0)
  946. return false;
  947. else
  948. return true;
  949. }
  950. }
  951. /// <summary>
  952. /// 数字转换成大写汉字主函数
  953. /// </summary>
  954. /// <returns>返回转换后的大写汉字</returns>
  955. public static string ConvertToChinese(decimal m)
  956. {
  957. j = m;
  958. string bb = "";
  959. if (IsNumber)
  960. {
  961. string str = j.ToString();
  962. string[] Num = str.Split('.');
  963. if (Num.Length == 1)
  964. {
  965. bb = NumberString(Num[0]) + "元整";
  966. bb = bb.Replace("零零", "零");
  967. }
  968. else
  969. {
  970. bb = NumberString(Num[0]) + "元";
  971. bb += FloatString(Num[1]);
  972. bb = bb.Replace("零零", "零");
  973. }
  974. }
  975. else
  976. {
  977. throw new FormatException("你输入的数字格式不正确或不是数字!");
  978. }
  979. return bb;
  980. }
  981. /// <summary>
  982. /// 小数位转换只支持两位的小数
  983. /// </summary>
  984. /// <param name="Num">转换的小数</param>
  985. /// <returns>小数转换成汉字</returns>
  986. private static string FloatString(string Num)
  987. {
  988. string cc = "";
  989. if (Num.Length > 2)
  990. {
  991. throw new FormatException("小数位数过多.");
  992. }
  993. else
  994. {
  995. string bb = ConvertString(Num);
  996. int len = bb.IndexOf("零");
  997. if (len != 0)
  998. {
  999. bb = bb.Replace("零", "");
  1000. if (bb.Length == 1)
  1001. {
  1002. cc = bb.Substring(0, 1) + "角";
  1003. }
  1004. else
  1005. {
  1006. cc = bb.Substring(0, 1) + "角";
  1007. cc += bb.Substring(1, 1) + "分";
  1008. }
  1009. }
  1010. else
  1011. cc = bb + "分";
  1012. }
  1013. return cc;
  1014. }
  1015. /// <summary>
  1016. /// 判断数字位数以进行拆分转换
  1017. /// </summary>
  1018. /// <param name="Num">要进行拆分的数字</param>
  1019. /// <returns>转换成的汉字</returns>
  1020. private static string NumberString(string Num)
  1021. {
  1022. string bb = "";
  1023. if (Num.Length <= 4)
  1024. {
  1025. bb = Convert4(Num);
  1026. }
  1027. else if (Num.Length > 4 && Num.Length <= 8)
  1028. {
  1029. bb = Convert4(Num.Substring(0, Num.Length - 4)) + "万";
  1030. bb += Convert4(Num.Substring(Num.Length - 4, 4));
  1031. }
  1032. else if (Num.Length > 8 && Num.Length <= 12)
  1033. {
  1034. bb = Convert4(Num.Substring(0, Num.Length - 8)) + "亿";
  1035. if (Convert4(Num.Substring(Num.Length - 8, 4)) == "")
  1036. if (Convert4(Num.Substring(Num.Length - 4, 4)) != "")
  1037. bb += "零";
  1038. else
  1039. bb += "";
  1040. else
  1041. bb += Convert4(Num.Substring(Num.Length - 8, 4)) + "万";
  1042. bb += Convert4(Num.Substring(Num.Length - 4, 4));
  1043. }
  1044. else
  1045. {
  1046. throw new Exception("整数部分最多支持12位");
  1047. }
  1048. return bb;
  1049. }
  1050. /// <summary>
  1051. /// 四位数字的转换
  1052. /// </summary>
  1053. /// <param name="Num">准备转换的四位数字</param>
  1054. /// <returns>转换以后的汉字</returns>
  1055. private static string Convert4(string Num)
  1056. {
  1057. string bb = "";
  1058. if (Num.Length == 1)
  1059. {
  1060. bb = ConvertString(Num);
  1061. }
  1062. else if (Num.Length == 2)
  1063. {
  1064. bb = ConvertString(Num);
  1065. bb = Convert2(bb);
  1066. }
  1067. else if (Num.Length == 3)
  1068. {
  1069. bb = ConvertString(Num);
  1070. bb = Convert3(bb);
  1071. }
  1072. else
  1073. {
  1074. bb = ConvertString(Num);
  1075. string cc = "";
  1076. string len = bb.Substring(0, 4);
  1077. if (len != "零零零零")
  1078. {
  1079. len = bb.Substring(0, 3);
  1080. if (len != "零零零")
  1081. {
  1082. bb = bb.Replace("零零零", "");
  1083. if (bb.Length == 1)
  1084. {
  1085. bb = bb.Substring(0, 1) + "仟";
  1086. }
  1087. else
  1088. {
  1089. if (bb.Substring(0, 1) != "零" && bb.Substring(0, 2) != "零")
  1090. cc = bb.Substring(0, 1) + "仟";
  1091. else
  1092. cc = bb.Substring(0, 1);
  1093. bb = cc + Convert3(bb.Substring(1, 3));
  1094. }
  1095. }
  1096. else
  1097. {
  1098. bb = bb.Replace("零零零", "零");
  1099. }
  1100. }
  1101. else
  1102. {
  1103. bb = bb.Replace("零零零零", "");
  1104. }
  1105. }
  1106. return bb;
  1107. }
  1108. /// <summary>
  1109. /// 将数字转换成汉字
  1110. /// </summary>
  1111. /// <param name="Num">需要转换的数字</param>
  1112. /// <returns>转换后的汉字</returns>
  1113. private static string ConvertString(string Num)
  1114. {
  1115. string bb = "";
  1116. for (int i = 0; i < Num.Length; i++)
  1117. {
  1118. bb += NumChineseCharacter[int.Parse(Num.Substring(i, 1))];
  1119. }
  1120. return bb;
  1121. }
  1122. /// <summary>
  1123. /// 两位数字的转换
  1124. /// </summary>
  1125. /// <param name="Num">两位数字</param>
  1126. /// <returns>转换后的汉字</returns>
  1127. private static string Convert2(string Num)
  1128. {
  1129. string bb = ""; string cc = "";
  1130. string len = Num.Substring(0, 1);
  1131. if (len != "零")
  1132. {
  1133. bb = Num.Replace("零", "");
  1134. if (bb.Length == 1)
  1135. {
  1136. cc = bb.Substring(0, 1) + "拾";
  1137. }
  1138. else
  1139. {
  1140. cc = bb.Substring(0, 1) + "拾";
  1141. cc += bb.Substring(1, 1);
  1142. }
  1143. }
  1144. else
  1145. cc = Num;
  1146. return cc;
  1147. }
  1148. /// <summary>
  1149. /// 三位数字的转换
  1150. /// </summary>
  1151. /// <param name="Num">三位数字</param>
  1152. /// <returns>转换后的汉字</returns>
  1153. private static string Convert3(string Num)
  1154. {
  1155. string bb = ""; string cc = "";
  1156. string len = Num.Substring(0, 2);
  1157. if (len != "零零")
  1158. {
  1159. bb = Num.Replace("零零", "");
  1160. if (bb.Length == 1)
  1161. {
  1162. bb = bb.Substring(0, 1) + "佰";
  1163. }
  1164. else
  1165. {
  1166. if (bb.Substring(0, 1) != "零")
  1167. cc = bb.Substring(0, 1) + "佰";
  1168. else
  1169. cc = bb.Substring(0, 1);
  1170. bb = cc + Convert2(bb.Substring(1, 2));
  1171. }
  1172. }
  1173. else
  1174. {
  1175. bb = Num.Replace("零零", "零");
  1176. }
  1177. return bb;
  1178. }
  1179. #endregion
  1180. #endregion
  1181. #region 数字验证
  1182. /// <summary>
  1183. /// 验证数字字符串
  1184. /// </summary>
  1185. /// <param name="num"></param>
  1186. /// <returns></returns>
  1187. public static bool IsNumeric(this string numStr)
  1188. {
  1189. bool isNumeric = Regex.IsMatch(numStr, @"^\d+$");
  1190. if (isNumeric)
  1191. {
  1192. return true;
  1193. }
  1194. return false;
  1195. }
  1196. #endregion
  1197. #region 日期 格式转换
  1198. /// <summary>
  1199. /// 验证数字字符串
  1200. /// </summary>
  1201. /// <param name="str"></param>
  1202. /// <returns></returns>
  1203. public static string ConvertToDatetime(this string str)
  1204. {
  1205. if (!string.IsNullOrEmpty(str))
  1206. {
  1207. DateTime currentDate = Convert.ToDateTime(str);
  1208. return $"{currentDate.Year}年{currentDate.Month}月{currentDate.Day}日";
  1209. }
  1210. return "";
  1211. }
  1212. #endregion
  1213. #region 月份/季度
  1214. /// <summary>
  1215. /// 获取月份对应的起始天数
  1216. /// </summary>
  1217. /// <param name="year"></param>
  1218. /// <returns></returns>
  1219. public static List<MonthInfo> GetMonthInfos(int year)
  1220. {
  1221. List<MonthInfo> months = new List<MonthInfo>();
  1222. if (year > 1)
  1223. {
  1224. for (int i = 1; i < 13; i++)
  1225. {
  1226. months.Add(new MonthInfo()
  1227. {
  1228. Month = i,
  1229. Days = new DaysInfo() { BeginDays = 1, EndDays = DateTime.DaysInMonth(year, i) }
  1230. });
  1231. }
  1232. }
  1233. return months;
  1234. }
  1235. /// <summary>
  1236. /// 获取季度对应的起始天数
  1237. /// </summary>
  1238. /// <param name="year"></param>
  1239. /// <returns></returns>
  1240. public static List<MonthInfo> GetQuarter(int year)
  1241. {
  1242. List<MonthInfo> months = new List<MonthInfo>();
  1243. months.Add(new MonthInfo() { Month = 1, Days = new DaysInfo() { BeginDays = 1, EndDays = 31 }}); //1.1 - 3.31
  1244. months.Add(new MonthInfo() { Month = 2, Days = new DaysInfo() { BeginDays = 1, EndDays = 31 } }); //4.1 - 6.30
  1245. months.Add(new MonthInfo() { Month = 3, Days = new DaysInfo() { BeginDays = 1, EndDays = 31 } }); //7.1 - 9.31
  1246. months.Add(new MonthInfo() { Month = 4, Days = new DaysInfo() { BeginDays = 1, EndDays = 31 } }); //10.1 - 12.31
  1247. return months;
  1248. }
  1249. public class MonthInfo
  1250. {
  1251. public int Month { get; set; }
  1252. public DaysInfo Days { get; set; }
  1253. }
  1254. public class DaysInfo
  1255. {
  1256. public int BeginDays { get; set; }
  1257. public int EndDays { get; set; }
  1258. }
  1259. #endregion
  1260. #region op行程单,黑屏幕代码
  1261. public static string GetCountryStandingTime(int diId)
  1262. {
  1263. DataTable datas = GetTableByBlackCode(diId);
  1264. string countryStr = "";
  1265. if (datas.Rows.Count > 0 )
  1266. {
  1267. var airDatas = from row in datas.AsEnumerable()
  1268. select new
  1269. {
  1270. Three = row.Field<string>("Three"),
  1271. Day = row.Field<string>("Day"),
  1272. ArrivedDate = row.Field<string>("ArrivedDate"),
  1273. };
  1274. //三字码信息
  1275. List<Res_ThreeCode> listcode = _dirRep._sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.IsDel == 0).ToList();
  1276. //string countryStr = "";
  1277. int index = 0;
  1278. List<string> cityCodes = new List<string>();
  1279. //去掉开始和结束城市
  1280. foreach (var row in airDatas)
  1281. {
  1282. if (index == 0) cityCodes.Add(row.Three.Substring(3, 3)); //到达国家
  1283. else if (airDatas.Count()-1 == index) cityCodes.Add(row.Three.Substring(0, 3)); //到达国家
  1284. else cityCodes.Add(row.Three.Substring(0, 3)); //到达国家
  1285. index++;
  1286. }
  1287. cityCodes = cityCodes.Distinct().ToList();
  1288. foreach (var item in cityCodes)
  1289. {
  1290. var airData = airDatas.Where(it => it.Three.Contains(item)).ToList();
  1291. string country = listcode.Find(it => it.Three.Equals(item))?.Country ?? "Unknown";
  1292. if (country.Equals("中国"))
  1293. {
  1294. country = listcode.Find(it => it.Three.Equals(item))?.City ?? "Unknown";
  1295. }
  1296. int days = 0;
  1297. if (airData.Count == 2)
  1298. {
  1299. DateTime arr_dt = Convert.ToDateTime(airData[0].ArrivedDate); //抵达时间
  1300. DateTime dep_dt = Convert.ToDateTime(airData[1].Day); //离开时间
  1301. days = (dep_dt - arr_dt).Days;
  1302. countryStr += $@"{country}停留{days}日、";
  1303. }
  1304. }
  1305. if (countryStr.Length > 0) countryStr = countryStr.Substring(0, countryStr.Length - 1);
  1306. }
  1307. return countryStr;
  1308. }
  1309. /// <summary>
  1310. ///根据机票黑屏代码整理DataTable
  1311. /// </summary>
  1312. /// <param name="diid"></param>
  1313. /// <returns></returns>
  1314. public static DataTable GetTableByBlackCode(int diid)
  1315. {
  1316. //黑屏代码信息
  1317. List<Air_TicketBlackCode> listcode = _dirRep._sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.DiId == diid && x.IsDel == 0).ToList();
  1318. //测试数据为序号,航班号,起飞日期,三字码,起飞时刻,到达时刻,出发航站楼,到达航站楼,机型,飞行时间
  1319. //1.3U8391 TU17NOV CTUCAI 0220 0715 T1 T2 330 10H55M
  1320. DataTable dt = new DataTable();
  1321. dt.Columns.Add("Fliagtcode", typeof(string)); //航班号
  1322. dt.Columns.Add("Date", typeof(string));//起飞日期
  1323. dt.Columns.Add("Three", typeof(string));//三字码
  1324. dt.Columns.Add("StartTime", typeof(string));//起飞时刻
  1325. dt.Columns.Add("EndTime", typeof(string));//到达时刻
  1326. dt.Columns.Add("StartBuilding", typeof(string));//出发航站楼
  1327. dt.Columns.Add("EndBuilding", typeof(string));//到达航站楼
  1328. dt.Columns.Add("AirModel", typeof(string)); //机型
  1329. dt.Columns.Add("FlightTime", typeof(string));//飞行时间
  1330. dt.Columns.Add("Day", typeof(string));//整理的起飞日期;作为排序依据
  1331. dt.Columns.Add("ArrivedDate", typeof(string));//整理的到达日期
  1332. dt.Columns.Add("Error", typeof(string));//整理的到达日期
  1333. dt.Columns.Add("Sign", typeof(string));//标识:0表示为原生黑屏代码、1表示“+1”新增的黑屏代码
  1334. //判断是否录入黑屏代码
  1335. if (listcode.Count() == 0 || listcode == null)
  1336. {
  1337. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "黑屏代码未录入!", null);
  1338. }
  1339. else
  1340. {
  1341. //读取单段黑屏代码
  1342. for (int i = 0; i < listcode.Count; i++)
  1343. {
  1344. //去除序号
  1345. string[] CodeList = Regex.Split(listcode[i].BlackCode, "\\d+\\.", RegexOptions.IgnoreCase);
  1346. //去除多余空格,方法一Linq扩展方法
  1347. CodeList = CodeList.Where(str => str != "").ToArray();
  1348. CodeList = CodeList.Where(str => str != " ").ToArray();
  1349. //年
  1350. int year = Convert.ToInt32(DateTime.Now.Year.ToString());
  1351. //读取单条黑屏代码
  1352. for (int j = 0; j < CodeList.Count(); j++)
  1353. {
  1354. //去除多余空格,方法二使用Split()方法进行分割,分割有一个选项是RemoveEmptyEntries
  1355. CodeList[j] = CodeList[j].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty).TrimStart().TrimEnd();
  1356. string[] Info = CodeList[j].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  1357. //string[] Info = CodeList[j].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty)
  1358. // .TrimStart().TrimEnd().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  1359. //去除多余空格
  1360. Info = Info.Where(str => str != "").ToArray();
  1361. Info = Info.Where(str => str != " ").ToArray();
  1362. //判断黑屏代码是否正确拆分; 理应拆成9段
  1363. if (Info.Count() < 9)
  1364. {
  1365. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "本团组第" + (i + 1) + "段黑屏代码中第" + (j + 1) + " 条有误,请联系机票同事核对", null);
  1366. }
  1367. else
  1368. {
  1369. try
  1370. {
  1371. //月
  1372. int month = Convert.ToInt32(GetLonger(Info[1].Substring(4, 3)));
  1373. //日
  1374. int day = Convert.ToInt32(Info[1].Substring(2, 2));
  1375. #region 逐一比较月份,判断是否翻年;逐一比较三字码顶真,判断是否跑错机场
  1376. if (j > 0)
  1377. {
  1378. string[] Temp = CodeList[j - 1].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty)
  1379. .TrimStart().TrimEnd().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  1380. Temp = Temp.Where(str => str != "").ToArray();
  1381. Temp = Temp.Where(str => str != " ").ToArray();
  1382. int monthTemp = Convert.ToInt32(GetLonger(Temp[1].Substring(4, 3)));
  1383. // 如果相邻月份之差小于0,则证明次一条年份需+1
  1384. if (month - monthTemp < 0)
  1385. {
  1386. year = year + 1;
  1387. }
  1388. //如果相邻代码三字码不顶真,提醒
  1389. string FootThree = Temp[2].Substring(3, 3);
  1390. string HeadThree = Info[2].Substring(0, 3);
  1391. if (FootThree != HeadThree)
  1392. {
  1393. //DelegationInfoService s = new DelegationInfoService();
  1394. //UsersService us = new UsersService();
  1395. //GroupsTaskAssignmentService gts = new GroupsTaskAssignmentService();
  1396. //77 行程
  1397. List<Grp_GroupsTaskAssignment> list2 = _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(x => x.CTId == 77 && x.DIId == diid && x.IsDel == 0).ToList();
  1398. foreach (var temp in list2)
  1399. {
  1400. //if (temp.UId != 21)
  1401. //SendAndReturn(us.GetUsersByID(temp.UId).Email,
  1402. // "黑屏代码提醒",
  1403. // s.GetDelegationInfoByID(diid).TeamName + "的机票黑屏代码中,相邻航段的三字码不连续,请查看!");
  1404. }
  1405. //85 机票预订
  1406. List<Grp_GroupsTaskAssignment> list6 = _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(x => x.CTId == 85 && x.DIId == diid && x.IsDel == 0).ToList();
  1407. foreach (var temp in list6)
  1408. {
  1409. //if (temp.UId != 21)
  1410. //SendAndReturn(us.GetUsersByID(temp.UId).Email,
  1411. // "黑屏代码提醒",
  1412. // s.GetDelegationInfoByID(diid).TeamName + "的机票黑屏代码中,相邻航段的三字码不连续,请查看!");
  1413. }
  1414. }
  1415. }
  1416. #endregion
  1417. #region 判断到达日期是否需要加1
  1418. if (Info[4].Contains("+"))
  1419. {
  1420. //日期+1
  1421. day = day + 1;
  1422. //判断是否进入下一月
  1423. if (day > Convert.ToInt32(GetDaysByMonth(Info[1].Substring(4, 3), year)))
  1424. {
  1425. day = day - Convert.ToInt32(GetDaysByMonth(Info[1].Substring(4, 3), year));
  1426. month = month + 1;
  1427. //判断是否进入下一年
  1428. if (month > 12)
  1429. {
  1430. month = month - 12;
  1431. year = year + 1;
  1432. }
  1433. }
  1434. //月份整理格式
  1435. string monthTemp = month.ToString();
  1436. if (month < 10)
  1437. {
  1438. monthTemp = "0" + monthTemp;
  1439. }
  1440. //日期整理格式
  1441. string daytemp = day.ToString();
  1442. if (day < 10)
  1443. {
  1444. daytemp = "0" + daytemp;
  1445. }
  1446. string temp = Info[4].Split('+')[0];
  1447. //添加起飞数据
  1448. dt.Rows.Add(Info[0],
  1449. Info[1],
  1450. Info[2],
  1451. Info[3],
  1452. temp,
  1453. Info[5],
  1454. Info[6],
  1455. Info[7],
  1456. Info[8],
  1457. year + "-" + GetLonger(Info[1].Substring(4, 3)) + "-" + Info[1].Substring(2, 2),
  1458. year + "-" + monthTemp + "-" + daytemp,
  1459. "",
  1460. "0");
  1461. //加1天,添加到达数据
  1462. dt.Rows.Add(Info[0],
  1463. Info[1].Replace(Info[1].Substring(2, 2), daytemp),
  1464. Info[2],
  1465. Info[3],
  1466. temp,
  1467. Info[5],
  1468. Info[6],
  1469. Info[7],
  1470. Info[8],
  1471. year + "-" + monthTemp + "-" + daytemp,
  1472. year + "-" + monthTemp + "-" + daytemp,
  1473. "",
  1474. "1");
  1475. }
  1476. else
  1477. {
  1478. //月份整理格式
  1479. string monthTemp = month.ToString();
  1480. if (month < 10)
  1481. {
  1482. monthTemp = "0" + monthTemp;
  1483. }
  1484. //日期整理格式
  1485. string daytemp = day.ToString();
  1486. if (day < 10)
  1487. {
  1488. daytemp = "0" + daytemp;
  1489. }
  1490. dt.Rows.Add(Info[0],
  1491. Info[1],
  1492. Info[2],
  1493. Info[3],
  1494. Info[4],
  1495. Info[5],
  1496. Info[6],
  1497. Info[7],
  1498. Info[8],
  1499. year + "-" + monthTemp + "-" + daytemp,
  1500. year + "-" + monthTemp + "-" + daytemp,
  1501. "",
  1502. "0");
  1503. }
  1504. #endregion
  1505. }
  1506. catch (Exception ex)
  1507. {
  1508. string exstr = ex.Message.ToString();
  1509. }
  1510. }
  1511. }
  1512. //排序
  1513. dt.DefaultView.Sort = "Day asc";
  1514. dt = dt.DefaultView.ToTable();
  1515. }
  1516. }
  1517. return dt;
  1518. }
  1519. /// <summary>
  1520. /// 根据星期,月份的缩写,转换成数字或者全称
  1521. /// 根据币种中文名称返回币种代码
  1522. /// 根据数字返回机型型号【2、3开头的就是空客,比如空客320,7开头的就是波音,比如波音777】
  1523. /// 20210903贾文滔
  1524. /// </summary>
  1525. /// <param name="startDate"></param>
  1526. /// <param name="endDate"></param>
  1527. /// <returns></returns>
  1528. public static string GetLonger(string temp)
  1529. {
  1530. string str = "";
  1531. switch (temp.ToUpper())
  1532. {
  1533. case "美元":
  1534. str = "USD";
  1535. break;
  1536. case "日元":
  1537. str = "JPY";
  1538. break;
  1539. case "英镑":
  1540. str = "GBP";
  1541. break;
  1542. case "欧元":
  1543. str = "EUR";
  1544. break;
  1545. case "港币":
  1546. str = "HKD";
  1547. break;
  1548. case "MO":
  1549. str = "星期一";
  1550. break;
  1551. case "TU":
  1552. str = "星期二";
  1553. break;
  1554. case "WE":
  1555. str = "星期三";
  1556. break;
  1557. case "TH":
  1558. str = "星期四";
  1559. break;
  1560. case "FR":
  1561. str = "星期五";
  1562. break;
  1563. case "SA":
  1564. str = "星期六";
  1565. break;
  1566. case "SU":
  1567. str = "星期天";
  1568. break;
  1569. case "JAN":
  1570. str = "01";
  1571. break;
  1572. case "FEB":
  1573. str = "02";
  1574. break;
  1575. case "MAR":
  1576. str = "03";
  1577. break;
  1578. case "APR":
  1579. str = "04";
  1580. break;
  1581. case "MAY":
  1582. str = "05";
  1583. break;
  1584. case "JUN":
  1585. str = "06";
  1586. break;
  1587. case "JUL":
  1588. str = "07";
  1589. break;
  1590. case "AUG":
  1591. str = "08";
  1592. break;
  1593. case "SEP":
  1594. str = "09";
  1595. break;
  1596. case "OCT":
  1597. str = "10";
  1598. break;
  1599. case "NOV":
  1600. str = "11";
  1601. break;
  1602. case "DEC":
  1603. str = "12";
  1604. break;
  1605. case "MONDAY":
  1606. str = "星期一";
  1607. break;
  1608. case "TUESDAY":
  1609. str = "星期二";
  1610. break;
  1611. case "WEDNESDAY":
  1612. str = "星期三";
  1613. break;
  1614. case "THURSDAY":
  1615. str = "星期四";
  1616. break;
  1617. case "FRIDAY":
  1618. str = "星期五";
  1619. break;
  1620. case "SATURDAY":
  1621. str = "星期六";
  1622. break;
  1623. case "SUNDAY":
  1624. str = "星期日";
  1625. break;
  1626. case "01":
  1627. str = "JAN";
  1628. break;
  1629. case "02":
  1630. str = "FEB";
  1631. break;
  1632. case "03":
  1633. str = "MAR";
  1634. break;
  1635. case "04":
  1636. str = "APR";
  1637. break;
  1638. case "05":
  1639. str = "MAY";
  1640. break;
  1641. case "06":
  1642. str = "JUN";
  1643. break;
  1644. case "07":
  1645. str = "JUL";
  1646. break;
  1647. case "08":
  1648. str = "AUG";
  1649. break;
  1650. case "09":
  1651. str = "SEP";
  1652. break;
  1653. case "10":
  1654. str = "OCT";
  1655. break;
  1656. case "11":
  1657. str = "NOV";
  1658. break;
  1659. case "12":
  1660. str = "DEC";
  1661. break;
  1662. case "2":
  1663. str = "空客A";
  1664. break;
  1665. case "3":
  1666. str = "空客A";
  1667. break;
  1668. case "7":
  1669. str = "波音";
  1670. break;
  1671. }
  1672. return str;
  1673. }
  1674. /// <summary>
  1675. /// 根据月份返回天数
  1676. /// </summary>
  1677. /// <param name="temp"></param>
  1678. /// <returns></returns>
  1679. public static string GetDaysByMonth(string Month, int year)
  1680. {
  1681. string str = "";
  1682. //判断是否是闰年
  1683. if (DateTime.IsLeapYear(year) == false)
  1684. {
  1685. switch (Month.ToUpper())
  1686. {
  1687. case "JAN":
  1688. str = "31";
  1689. break;
  1690. case "FEB":
  1691. str = "28";
  1692. break;
  1693. case "MAR":
  1694. str = "31";
  1695. break;
  1696. case "APR":
  1697. str = "30";
  1698. break;
  1699. case "MAY":
  1700. str = "31";
  1701. break;
  1702. case "JUN":
  1703. str = "30";
  1704. break;
  1705. case "JUL":
  1706. str = "31";
  1707. break;
  1708. case "AUG":
  1709. str = "31";
  1710. break;
  1711. case "SEP":
  1712. str = "30";
  1713. break;
  1714. case "OCT":
  1715. str = "31";
  1716. break;
  1717. case "NOV":
  1718. str = "30";
  1719. break;
  1720. case "DEC":
  1721. str = "31";
  1722. break;
  1723. case "01":
  1724. str = "31";
  1725. break;
  1726. case "02":
  1727. str = "28";
  1728. break;
  1729. case "03":
  1730. str = "31";
  1731. break;
  1732. case "04":
  1733. str = "30";
  1734. break;
  1735. case "05":
  1736. str = "31";
  1737. break;
  1738. case "06":
  1739. str = "30";
  1740. break;
  1741. case "07":
  1742. str = "31";
  1743. break;
  1744. case "08":
  1745. str = "31";
  1746. break;
  1747. case "09":
  1748. str = "30";
  1749. break;
  1750. case "10":
  1751. str = "31";
  1752. break;
  1753. case "11":
  1754. str = "30";
  1755. break;
  1756. case "12":
  1757. str = "31";
  1758. break;
  1759. }
  1760. }
  1761. else
  1762. {
  1763. switch (Month.ToUpper())
  1764. {
  1765. case "JAN":
  1766. str = "31";
  1767. break;
  1768. case "FEB":
  1769. str = "29";
  1770. break;
  1771. case "MAR":
  1772. str = "31";
  1773. break;
  1774. case "APR":
  1775. str = "30";
  1776. break;
  1777. case "MAY":
  1778. str = "31";
  1779. break;
  1780. case "JUN":
  1781. str = "30";
  1782. break;
  1783. case "JUL":
  1784. str = "31";
  1785. break;
  1786. case "AUG":
  1787. str = "31";
  1788. break;
  1789. case "SEP":
  1790. str = "30";
  1791. break;
  1792. case "OCT":
  1793. str = "31";
  1794. break;
  1795. case "NOV":
  1796. str = "30";
  1797. break;
  1798. case "DEC":
  1799. str = "31";
  1800. break;
  1801. case "01":
  1802. str = "31";
  1803. break;
  1804. case "02":
  1805. str = "29";
  1806. break;
  1807. case "03":
  1808. str = "31";
  1809. break;
  1810. case "04":
  1811. str = "30";
  1812. break;
  1813. case "05":
  1814. str = "31";
  1815. break;
  1816. case "06":
  1817. str = "30";
  1818. break;
  1819. case "07":
  1820. str = "31";
  1821. break;
  1822. case "08":
  1823. str = "31";
  1824. break;
  1825. case "09":
  1826. str = "30";
  1827. break;
  1828. case "10":
  1829. str = "31";
  1830. break;
  1831. case "11":
  1832. str = "30";
  1833. break;
  1834. case "12":
  1835. str = "31";
  1836. break;
  1837. }
  1838. }
  1839. return str;
  1840. }
  1841. /// <summary>
  1842. /// op行程单 团组 城市路径
  1843. /// </summary>
  1844. /// <param name="diid">团组Id</param>
  1845. /// <param name="separator">分隔符</param>
  1846. /// <returns></returns>
  1847. public static string GetGroupCityLine(int diid,string separator)
  1848. {
  1849. string city = string.Empty;
  1850. var blackCode = _dirRep._sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.IsDel == 0 && x.DiId == diid).ToList();
  1851. if (blackCode.Count > 0)
  1852. {
  1853. var black = blackCode.First();
  1854. black.BlackCode = black.BlackCode == null ? "" : black.BlackCode;
  1855. var blackSp = Regex.Split(black.BlackCode, "\\d+\\.", RegexOptions.IgnoreCase).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
  1856. if (blackSp.Length > 0)
  1857. {
  1858. try
  1859. {
  1860. var cityArrCode = new List<string>(20);
  1861. foreach (var item in blackSp)
  1862. {
  1863. var itemSp = item.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
  1864. var IndexSelect = itemSp[2];
  1865. var cityArrCodeLength = cityArrCode.Count - 1;
  1866. var startCity = IndexSelect.Substring(0, 3);
  1867. if (cityArrCodeLength > 0)
  1868. {
  1869. var arrEndCity = cityArrCode[cityArrCodeLength];
  1870. if (arrEndCity != startCity)
  1871. {
  1872. cityArrCode.Add(startCity.ToUpper());
  1873. }
  1874. }
  1875. else
  1876. {
  1877. cityArrCode.Add(startCity.ToUpper());
  1878. }
  1879. var endCity = IndexSelect.Substring(3, 3);
  1880. cityArrCode.Add(endCity.ToUpper());
  1881. }
  1882. var cityThree = string.Empty;
  1883. cityArrCode.ForEach(x => cityThree += "'" + x + "',");
  1884. cityThree = cityThree.TrimEnd(',');
  1885. if (string.IsNullOrWhiteSpace(cityThree))
  1886. {
  1887. throw new Exception("error");
  1888. }
  1889. string sql = $"SELECT * FROM Res_ThreeCode rtc WHERE UPPER(rtc.Three) in ({cityThree}) ";
  1890. var cityArr = _dirRep._sqlSugar.SqlQueryable<Res_ThreeCode>(sql).ToList();
  1891. foreach (var item in cityArrCode)
  1892. {
  1893. var find = cityArr.Find(x => x.Three.ToUpper() == item.ToUpper());
  1894. if (find != null)
  1895. {
  1896. city += find.City + separator;
  1897. }
  1898. else
  1899. {
  1900. city += item + "[三字码未收录]" + separator;
  1901. }
  1902. }
  1903. city = city.TrimEnd(char.Parse(separator));
  1904. }
  1905. catch (Exception e)
  1906. {
  1907. city = "[黑屏代码格式不正确!]";
  1908. }
  1909. }
  1910. }
  1911. else city = "[未录入黑屏代码]";
  1912. return city;
  1913. }
  1914. #endregion
  1915. }
  1916. }