TicketBlackCodeRepository.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. using AutoMapper;
  2. using EyeSoft.Collections.Generic;
  3. using EyeSoft.Extensions;
  4. using OASystem.Domain;
  5. using OASystem.Domain.Dtos.Groups;
  6. using OASystem.Domain.Dtos.Resource;
  7. using OASystem.Domain.Entities.Groups;
  8. using OASystem.Domain.Entities.Resource;
  9. using OASystem.Domain.ViewModels.Groups;
  10. using OASystem.Domain.ViewModels.Resource;
  11. using SqlSugar.Extensions;
  12. using System;
  13. using System.Collections;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. namespace OASystem.Infrastructure.Repositories.Resource
  19. {
  20. public class TicketBlackCodeRepository : BaseRepository<Air_TicketBlackCode, TicketBlackCodeView>
  21. {
  22. private readonly IMapper _mapper;
  23. public TicketBlackCodeRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  24. {
  25. _mapper = mapper;
  26. }
  27. /// <summary>
  28. /// 黑屏代码操作(Status:1.新增,2.修改)
  29. /// </summary>
  30. /// <param name="dto"></param>
  31. /// <returns></returns>
  32. /// <exception cref="NotImplementedException"></exception>
  33. public async Task<Result> OpTicketBlackCode(OpTicketBlackCodeDto dto)
  34. {
  35. Result result = new Result() { Code = -2, Msg = "未知错误" };
  36. try
  37. {
  38. if (dto.Status == 1)//添加
  39. {
  40. Air_TicketBlackCode _TicketBlackCode = await _sqlSugar.Queryable<Air_TicketBlackCode>().FirstAsync(a=>a.IsDel==0 && a.BlackCode==dto.BlackCode && a.DiId==dto.DiId);//查询是否存在
  41. if (_TicketBlackCode != null)
  42. {
  43. return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
  44. }
  45. else//不存在,可添加
  46. {
  47. Air_TicketBlackCode air_TicketBlack = _mapper.Map<Air_TicketBlackCode>(dto);
  48. int id = await _sqlSugar.Insertable(air_TicketBlack).ExecuteReturnIdentityAsync();
  49. if (id == 0)
  50. {
  51. return result = new Result() { Code = -1, Msg = "添加失败!" };
  52. }
  53. return result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
  54. }
  55. }
  56. else if (dto.Status == 2)//修改
  57. {
  58. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Air_TicketBlackCode
  59. {
  60. DiId=dto.DiId,
  61. BlackCode=dto.BlackCode,
  62. Price=dto.Price,
  63. NowPrice=dto.NowPrice,
  64. BCPrice=dto.BCPrice,
  65. ECPrice=dto.ECPrice,
  66. CreateUserId = dto.CreateUserId,
  67. Remark = dto.Remark,
  68. });
  69. if (!res)
  70. {
  71. return result = new Result() { Code = -1, Msg = "修改失败!" };
  72. }
  73. return result = new Result() { Code = 0, Msg = "修改成功!", Data = new { Id = dto.Id } };
  74. }
  75. else
  76. {
  77. return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  78. }
  79. }
  80. catch (Exception ex)
  81. {
  82. return result = new Result() { Code = -2, Msg = "程序错误!" };
  83. }
  84. }
  85. public async Task<Result> QueryTicketBlackCodeByDiId(QueryTicketBlackCodeByDiIdDto dto)
  86. {
  87. Result result = new Result() { Code = -2, Msg = "未知错误" };
  88. try
  89. {
  90. string sqlWhere = string.Empty;
  91. sqlWhere += string.Format(@" And a.IsDel={0} And a.DiId={1}", 0, dto.DiId);
  92. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  93. {
  94. Regex r = new Regex("And");
  95. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  96. }
  97. string sql = string.Format(@"select *,(select CnName from Sys_Users where id=a.CreateUserId) as CreateName from Air_TicketBlackCode a {0}", sqlWhere);
  98. List<TicketBlackCodeView> _TicketBlackCodes = await _sqlSugar.SqlQueryable<TicketBlackCodeView>(sql).ToListAsync();
  99. Grp_DelegationInfo _DelegationInfo=await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(a=>a.IsDel==0 && a.Id==dto.DiId);
  100. if (_TicketBlackCodes.Count!=0)
  101. {
  102. return result = new Result()
  103. {
  104. Code = 0,
  105. Msg = "查询成功",
  106. Data = new
  107. {
  108. TicketBlackCodes= _TicketBlackCodes,
  109. DelegationInfo= _DelegationInfo
  110. },
  111. };
  112. }
  113. else
  114. {
  115. return result = new Result()
  116. {
  117. Code = 0,
  118. Msg = "暂无数据",
  119. Data = new
  120. {
  121. TicketBlackCodes = _TicketBlackCodes,
  122. DelegationInfo = _DelegationInfo
  123. },
  124. };
  125. }
  126. }
  127. catch (Exception)
  128. {
  129. return result;
  130. throw;
  131. }
  132. }
  133. public async Task<Result> QueryTicketBlackCodeById(QueryTicketBlackCodeByIdDto dto)
  134. {
  135. Result result = new Result() { Code = -2, Msg = "未知错误" };
  136. try
  137. {
  138. //查询成本和团组信息
  139. Grp_GroupCostParameter _GroupCostParameter = _sqlSugar.Queryable<Grp_GroupCostParameter>().First(a => a.DiId == dto.DiId && a.IsDel==0);//团组成本
  140. AirGroupCostParameterView _AirgroupCostParameter = _mapper.Map<AirGroupCostParameterView>(_GroupCostParameter);
  141. Grp_DelegationInfo _DelegationInfo=_sqlSugar.Queryable<Grp_DelegationInfo>().First(a=>a.Id == dto.DiId && a.IsDel==0);//团组信息
  142. Air_TicketBlackCode _TicketBlackCode=new Air_TicketBlackCode();
  143. if (dto.Id!=0 && !string.IsNullOrWhiteSpace(dto.Id.ToString()))
  144. {
  145. _TicketBlackCode = _sqlSugar.Queryable<Air_TicketBlackCode>().First(a => a.IsDel==0 && a.Id==dto.Id);
  146. return result = new Result()
  147. {
  148. Code = 0,
  149. Msg = "查询成功!",
  150. Data = new
  151. {
  152. GroupCostParameter = _AirgroupCostParameter,
  153. DelegationInfo = _DelegationInfo,
  154. TicketBlackCode = _TicketBlackCode
  155. },
  156. };
  157. }
  158. else
  159. {
  160. return result = new Result()
  161. {
  162. Code = 0,
  163. Msg = "查询成功!",
  164. Data = new
  165. {
  166. GroupCostParameter = _AirgroupCostParameter,
  167. DelegationInfo = _DelegationInfo,
  168. },
  169. };
  170. }
  171. }
  172. catch (Exception)
  173. {
  174. return result;
  175. throw;
  176. }
  177. }
  178. /// <summary>
  179. /// 三公费用提示
  180. /// 使用
  181. /// </summary>
  182. /// <param name="diId"></param>
  183. /// <returns></returns>
  184. public async Task<Result> EntryAndExitTips(int diId)
  185. {
  186. if (diId < 1) return new Result() { Code = -1, Msg = "请输入有效的DiId参数!" };
  187. Air_TicketBlackCode _TicketBlackCode = await _sqlSugar.Queryable<Air_TicketBlackCode>().FirstAsync(a => a.IsDel == 0 && a.DiId == diId);
  188. if (_TicketBlackCode != null)
  189. {
  190. return new Result()
  191. {
  192. Code = 0,
  193. Msg = "操作成功!",
  194. Data = new
  195. {
  196. jjcCurrentRate = _TicketBlackCode.ECPrice,
  197. gwcCurrentRate = _TicketBlackCode.BCPrice,
  198. Remark = $"经济舱现价:{_TicketBlackCode.ECPrice.ToString("#0.00")} 元/人 公务舱:{_TicketBlackCode.BCPrice.ToString("#0.00")} 元/人"
  199. }
  200. };
  201. }
  202. return new Result() { Code = -1,Msg="操作失败" };
  203. }
  204. public Result DescBlackToVisa(int diid)
  205. {
  206. Result rt = new Result();
  207. rt.Data = Array.Empty<string>();
  208. var group = _sqlSugar.Queryable<Grp_DelegationInfo>()
  209. .First(x => x.Id == diid && x.IsDel == 0);
  210. Func<string,string> RemoveSpecialCharacters = ( string input ) => {
  211. string pattern = @"[^\u4e00-\u9fa5]+";
  212. // 用空字符串替换所有匹配到的字符
  213. return Regex.Replace(input, pattern, "|");
  214. };
  215. if (group != null)
  216. {
  217. var country = RemoveSpecialCharacters(group.VisitCountry);
  218. if (!country.IsNullOrWhiteSpace())
  219. {
  220. var countryArr = country.Split('|');
  221. var blackCode = _sqlSugar.Queryable<Air_TicketBlackCode>().First(x => x.IsDel == 0 && x.DiId == diid);
  222. //去除序号
  223. string[] CodeList = Regex.Split(blackCode.BlackCode, "\\d+\\.", RegexOptions.IgnoreCase)
  224. .Where(str => !string.IsNullOrWhiteSpace(str)).ToArray();
  225. var threeCodeList = new List<CountryDataTime>();
  226. //读取单条黑屏代码
  227. for (int j = 0; j < CodeList.Count(); j++)
  228. {
  229. //去除多余空格,方法二使用Split()方法进行分割,分割有一个选项是RemoveEmptyEntries
  230. CodeList[j] = CodeList[j].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty).TrimStart().TrimEnd();
  231. string[] Info = CodeList[j].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  232. var threeCode = Info[2];
  233. var startTimeStr = Info[3];
  234. var endTimeStr = Info[4];
  235. var monthEn = Info[1].Substring(4, 3);
  236. //月
  237. int month = Convert.ToInt32(GetLonger(monthEn));
  238. //日
  239. int day = Convert.ToInt32(Info[1].Substring(2, 2));
  240. var startTime = new DateTime(DateTime.Now.Year, month, day, startTimeStr.Substring(0,2).ObjToInt(), startTimeStr.Substring(2, 2).ObjToInt(), 00); //
  241. var endTime = new DateTime(DateTime.Now.Year, month, day, endTimeStr.Substring(0, 2).ObjToInt(), endTimeStr.Substring(2, 2).ObjToInt(), 00); //
  242. if (!threeCode.IsNullOrWhiteSpace() && threeCode.Length > 5)
  243. {
  244. var start = threeCode.Substring(0, 3).ToLower();
  245. var end = threeCode.Substring(3, 3).ToLower();
  246. if (!threeCodeList.Select(x => x.Code).Contains(end)) {
  247. var temp = new CountryDataTime
  248. {
  249. Code = end,
  250. StartTime = startTime,
  251. EndTime = endTime,
  252. Country = ""
  253. };
  254. threeCodeList.Add(temp);
  255. }
  256. }
  257. }
  258. var dbThreeCode = _sqlSugar.Queryable<Res_ThreeCode>()
  259. .Where(x => x.IsDel == 0 && threeCodeList.Select(x => x.Code).Contains(x.Three.ToLower()))
  260. .ToList();
  261. var data = new List<CountryDataTime>();
  262. var info = new List<string>();
  263. foreach (var code in dbThreeCode)
  264. {
  265. for (int i = 0; i < threeCodeList.Count; i++)
  266. {
  267. if (threeCodeList[i].Code == code.Three.ToLower()) {
  268. threeCodeList[i].Country = code.Country;
  269. if (countryArr.Contains(code.Country))
  270. {
  271. var copy = new CountryDataTime
  272. {
  273. Code = threeCodeList[i].Code,
  274. EndTime = threeCodeList[i].EndTime,
  275. StartTime = threeCodeList[i].StartTime,
  276. Country = threeCodeList[i].Country,
  277. };
  278. try
  279. {
  280. threeCodeList[i].StartTime = threeCodeList[i].EndTime;
  281. threeCodeList[i].EndTime = threeCodeList[i + 1].StartTime;
  282. info.Add($@"{code.Country} 抵达:{threeCodeList[i].EndTime.ToString("yyyy-MM-dd HH:mm")} 离开:{threeCodeList[i + 1].StartTime.ToString("yyyy-MM-dd HH:mm")} ");
  283. }
  284. catch (Exception)
  285. {
  286. threeCodeList[i] = copy;
  287. info.Add($@"{code.Country} 抵达:{threeCodeList[i].EndTime.ToString("yyyy-MM-dd HH:mm")} 离开: 未知 ");
  288. }
  289. data.Add(threeCodeList[i]);
  290. }
  291. break;
  292. }
  293. }
  294. }
  295. rt.Msg = "SUCCESS!";
  296. rt.Code = 0;
  297. rt.Data = new
  298. {
  299. data = data,
  300. info = info
  301. };
  302. }
  303. }
  304. return rt;
  305. }
  306. public string GetLonger(string temp)
  307. {
  308. string str = "";
  309. switch (temp.ToUpper())
  310. {
  311. case "美元":
  312. str = "USD";
  313. break;
  314. case "日元":
  315. str = "JPY";
  316. break;
  317. case "英镑":
  318. str = "GBP";
  319. break;
  320. case "欧元":
  321. str = "EUR";
  322. break;
  323. case "港币":
  324. str = "HKD";
  325. break;
  326. case "MO":
  327. str = "星期一";
  328. break;
  329. case "TU":
  330. str = "星期二";
  331. break;
  332. case "WE":
  333. str = "星期三";
  334. break;
  335. case "TH":
  336. str = "星期四";
  337. break;
  338. case "FR":
  339. str = "星期五";
  340. break;
  341. case "SA":
  342. str = "星期六";
  343. break;
  344. case "SU":
  345. str = "星期天";
  346. break;
  347. case "JAN":
  348. str = "01";
  349. break;
  350. case "FEB":
  351. str = "02";
  352. break;
  353. case "MAR":
  354. str = "03";
  355. break;
  356. case "APR":
  357. str = "04";
  358. break;
  359. case "MAY":
  360. str = "05";
  361. break;
  362. case "JUN":
  363. str = "06";
  364. break;
  365. case "JUL":
  366. str = "07";
  367. break;
  368. case "AUG":
  369. str = "08";
  370. break;
  371. case "SEP":
  372. str = "09";
  373. break;
  374. case "OCT":
  375. str = "10";
  376. break;
  377. case "NOV":
  378. str = "11";
  379. break;
  380. case "DEC":
  381. str = "12";
  382. break;
  383. case "MONDAY":
  384. str = "星期一";
  385. break;
  386. case "TUESDAY":
  387. str = "星期二";
  388. break;
  389. case "WEDNESDAY":
  390. str = "星期三";
  391. break;
  392. case "THURSDAY":
  393. str = "星期四";
  394. break;
  395. case "FRIDAY":
  396. str = "星期五";
  397. break;
  398. case "SATURDAY":
  399. str = "星期六";
  400. break;
  401. case "SUNDAY":
  402. str = "星期日";
  403. break;
  404. case "01":
  405. str = "JAN";
  406. break;
  407. case "02":
  408. str = "FEB";
  409. break;
  410. case "03":
  411. str = "MAR";
  412. break;
  413. case "04":
  414. str = "APR";
  415. break;
  416. case "05":
  417. str = "MAY";
  418. break;
  419. case "06":
  420. str = "JUN";
  421. break;
  422. case "07":
  423. str = "JUL";
  424. break;
  425. case "08":
  426. str = "AUG";
  427. break;
  428. case "09":
  429. str = "SEP";
  430. break;
  431. case "10":
  432. str = "OCT";
  433. break;
  434. case "11":
  435. str = "NOV";
  436. break;
  437. case "12":
  438. str = "DEC";
  439. break;
  440. case "2":
  441. str = "空客A";
  442. break;
  443. case "3":
  444. str = "空客A";
  445. break;
  446. case "7":
  447. str = "波音";
  448. break;
  449. }
  450. return str;
  451. }
  452. }
  453. }