GroupCostRepository.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. using OASystem.Domain;
  2. using OASystem.Domain.Entities.Groups;
  3. using OASystem.Domain.Entities.Resource;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace OASystem.Infrastructure.Repositories.Groups
  10. {
  11. public class GroupCostRepository:BaseRepository<Grp_GroupCost, GroupCostView>
  12. {
  13. public GroupCostRepository(SqlSugarClient sqlSugar) : base(sqlSugar)
  14. {}
  15. public List<Grp_GroupCost> GetAllByDiid(int diid)
  16. {
  17. return Query(x => x.Diid == diid).ToList();
  18. }
  19. public List<Grp_GroupCost> GetAll()
  20. {
  21. return Query(x=> x.IsDel < 1).ToList();
  22. }
  23. public async Task<bool> SaveGroupCostList(List<Grp_GroupCost> costList,int diid, int userid)
  24. {
  25. BeginTran();
  26. //注释删除
  27. //bool isTrue = await DeleteGroupCostList(diid);
  28. bool isTrue = await UpdateAsync(x => x.Diid == diid && x.IsDel == 0, x => new Grp_GroupCost
  29. {
  30. IsDel = 1,
  31. DeleteUserId = userid,
  32. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  33. }) ;
  34. if (costList.Count > 0)
  35. {
  36. isTrue = Adds(costList) > 0;
  37. }
  38. if (isTrue)
  39. {
  40. CommitTran();
  41. }
  42. else
  43. {
  44. RollbackTran();
  45. }
  46. return isTrue;
  47. }
  48. public Task<bool> DeleteGroupCostList(int diid)
  49. {
  50. return DeleteAsync(x => x.Diid == diid);
  51. }
  52. public Result CreateGroupCostByBlackCode(int diid)
  53. {
  54. Result rt = new Result();
  55. List<Grp_GroupCost> returnArr = new List<Grp_GroupCost>();
  56. DataTable resultTable = null;
  57. try
  58. {
  59. resultTable = GetTableByBlackCode(diid);
  60. if (resultTable.Rows.Count == 0 || string.IsNullOrWhiteSpace(resultTable.Rows[0][1].ToString()))
  61. {
  62. string msg = string.Empty;
  63. if (resultTable.Rows.Count > 0)
  64. {
  65. msg = resultTable.Rows[0]["Error"].ToString();
  66. }
  67. rt.Msg = "黑屏代码有误! " + msg;
  68. rt.Data = returnArr;
  69. rt.Code = -1;
  70. }
  71. else
  72. {
  73. var timeArr = GetTimeListByDataTable(resultTable);
  74. var dayIndex = 1;
  75. var stopCity = string.Empty;
  76. foreach (var item in timeArr)
  77. {
  78. var tabSelect = resultTable.Select(string.Format("Day = '{0}'", item));
  79. var itin = string.Empty;
  80. if (tabSelect.Length > 0)
  81. {
  82. var threeCodeValue = new List<string>(4);
  83. foreach (var tabRow in tabSelect)
  84. {
  85. var threeCode = tabRow["Three"].ToString();
  86. var start = threeCode.Substring(0, 3);
  87. var end = threeCode.Substring(3, 3);
  88. stopCity = end;
  89. if (start == stopCity)
  90. {
  91. threeCodeValue.Add(end);
  92. }
  93. else
  94. {
  95. threeCodeValue.Add(start);
  96. threeCodeValue.Add(end);
  97. }
  98. itin = $@"{threeCodeValue[0]}/{threeCodeValue[threeCodeValue.Count - 1]}
  99. {tabRow["Fliagtcode"].ToString()}
  100. {tabRow["StartTime"].ToString()}/{tabRow["EndTime"].ToString()}";
  101. }
  102. }
  103. else
  104. {
  105. itin = stopCity;
  106. }
  107. Grp_GroupCost ggc = new Grp_GroupCost();
  108. ggc.DAY = dayIndex.ToString();
  109. ggc.Date = item;
  110. ggc.ITIN = itin;
  111. ggc.Diid = diid;
  112. returnArr.Add(ggc);
  113. dayIndex++;
  114. }
  115. rt.Data = returnArr;
  116. if (returnArr.Count > 0)
  117. {
  118. rt.Code = 0;
  119. rt.Msg = "生成成功!";
  120. }
  121. else
  122. {
  123. rt.Code = -1;
  124. rt.Msg = "生成失败!" + "请检查机票黑屏代码!";
  125. }
  126. }
  127. }
  128. catch (Exception ex)
  129. {
  130. rt.Code = -1;
  131. rt.Msg = ex.Message;
  132. rt.Data = ex.StackTrace;
  133. }
  134. return rt;
  135. }
  136. /// <summary>
  137. ///根据机票黑屏代码整理DataTable
  138. /// </summary>
  139. /// <param name="diid"></param>
  140. /// <returns></returns>
  141. public DataTable GetTableByBlackCode(int diid)
  142. {
  143. string[] excludeArr = new string[] { "[中转]", "[转机]" };
  144. //黑屏代码信息
  145. List<Air_TicketBlackCode> listcode = _sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.DiId == diid && x.IsDel == 0).ToList();
  146. //测试数据为序号,航班号,起飞日期,三字码,起飞时刻,到达时刻,出发航站楼,到达航站楼,机型,飞行时间
  147. //1.3U8391 TU17NOV CTUCAI 0220 0715 T1 T2 330 10H55M
  148. DataTable dt = new DataTable();
  149. dt.Columns.Add("Fliagtcode", typeof(string)); //航班号
  150. dt.Columns.Add("Date", typeof(string));//起飞日期
  151. dt.Columns.Add("Three", typeof(string));//三字码
  152. dt.Columns.Add("StartTime", typeof(string));//起飞时刻
  153. dt.Columns.Add("EndTime", typeof(string));//到达时刻
  154. dt.Columns.Add("StartBuilding", typeof(string));//出发航站楼
  155. dt.Columns.Add("EndBuilding", typeof(string));//到达航站楼
  156. dt.Columns.Add("AirModel", typeof(string)); //机型
  157. dt.Columns.Add("FlightTime", typeof(string));//飞行时间
  158. dt.Columns.Add("Day", typeof(string));//整理的起飞日期;作为排序依据
  159. dt.Columns.Add("ArrivedDate", typeof(string));//整理的到达日期
  160. dt.Columns.Add("Error", typeof(string));//整理的到达日期
  161. dt.Columns.Add("Sign", typeof(string));//标识:0表示为原生黑屏代码、1表示“+1”新增的黑屏代码
  162. //添加转机标识
  163. dt.Columns.Add("isTransitShipment", typeof(bool));
  164. //判断是否录入黑屏代码
  165. if (listcode.Count() == 0 || listcode == null)
  166. {
  167. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "黑屏代码未录入!", null, false);
  168. }
  169. else
  170. {
  171. //读取单段黑屏代码
  172. for (int i = 0; i < listcode.Count; i++)
  173. {
  174. //去除序号
  175. string[] CodeList = Regex.Split(listcode[i].BlackCode, "\\d+\\.", RegexOptions.IgnoreCase);
  176. //去除多余空格,方法一Linq扩展方法
  177. CodeList = CodeList.Where(str => !string.IsNullOrWhiteSpace(str)).ToArray();
  178. //读取单条黑屏代码
  179. for (int j = 0; j < CodeList.Count(); j++)
  180. {
  181. //去除多余空格,方法二使用Split()方法进行分割,分割有一个选项是RemoveEmptyEntries
  182. CodeList[j] = CodeList[j].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty).TrimStart().TrimEnd();
  183. string[] Info = CodeList[j].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  184. //去除多余空格
  185. Info = Info.Where(str => !string.IsNullOrWhiteSpace(str)).ToArray();
  186. //判断黑屏代码是否正确拆分; 理应拆成9段
  187. if (Info.TakeWhile((x) =>
  188. {
  189. return !excludeArr.Contains(x);
  190. }).Count() != 9)
  191. {
  192. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "本团组第" + (i + 1) + "段黑屏代码中第" + (j + 1) + " 条有误,请联系机票同事核对", null, false);
  193. //MessageBoxEx.Show("第" + (i + 1) + "段黑屏代码中第" + (j + 1) + " 条有误, 请联系机票同事核对");
  194. return dt;
  195. }
  196. else
  197. {
  198. try
  199. {
  200. var monthEn = Info[1].Substring(4, 3);
  201. //月
  202. int month = Convert.ToInt32(GetLonger(monthEn));
  203. //日
  204. int day = Convert.ToInt32(Info[1].Substring(2, 2));
  205. var time = new DateTime(DateTime.Now.Year, month, day); //
  206. var isExist = Info.Contains("[中转]");
  207. if (!isExist)
  208. {
  209. isExist = Info.Contains("[转机]");
  210. }
  211. //dt.Columns.Add("Fliagtcode", typeof(string)); //航班号
  212. //dt.Columns.Add("Date", typeof(string));//起飞日期
  213. //dt.Columns.Add("Three", typeof(string));//三字码
  214. //dt.Columns.Add("StartTime", typeof(string));//起飞时刻
  215. //dt.Columns.Add("EndTime", typeof(string));//到达时刻
  216. //dt.Columns.Add("StartBuilding", typeof(string));//出发航站楼
  217. //dt.Columns.Add("EndBuilding", typeof(string));//到达航站楼
  218. //dt.Columns.Add("AirModel", typeof(string)); //机型
  219. //dt.Columns.Add("FlightTime", typeof(string));//飞行时间
  220. //dt.Columns.Add("Day", typeof(string));//整理的起飞日期;作为排序依据
  221. //dt.Columns.Add("ArrivedDate", typeof(string));//整理的到达日期
  222. //dt.Columns.Add("Error", typeof(string));//整理的到达日期
  223. //dt.Columns.Add("Sign", typeof(string));//标识:0表示为原生黑屏代码、1表示“+1”新增的黑屏代码
  224. dt.Rows.Add(Info[0],
  225. Info[1],
  226. Info[2],
  227. Info[3],
  228. Info[4],
  229. Info[5],
  230. Info[6],
  231. Info[7],
  232. Info[8],
  233. time.ToString("yyyy-MM-dd"),
  234. time.ToString("yyyy-MM-dd"),
  235. "",
  236. "0",
  237. isExist
  238. );
  239. }
  240. catch (Exception ex)
  241. {
  242. string exstr = ex.Message.ToString();
  243. }
  244. }
  245. }
  246. //排序
  247. dt.DefaultView.Sort = "Day asc";
  248. dt = dt.DefaultView.ToTable();
  249. }
  250. }
  251. return dt;
  252. }
  253. public string GetLonger(string temp)
  254. {
  255. string str = "";
  256. switch (temp.ToUpper())
  257. {
  258. case "美元":
  259. str = "USD";
  260. break;
  261. case "日元":
  262. str = "JPY";
  263. break;
  264. case "英镑":
  265. str = "GBP";
  266. break;
  267. case "欧元":
  268. str = "EUR";
  269. break;
  270. case "港币":
  271. str = "HKD";
  272. break;
  273. case "MO":
  274. str = "星期一";
  275. break;
  276. case "TU":
  277. str = "星期二";
  278. break;
  279. case "WE":
  280. str = "星期三";
  281. break;
  282. case "TH":
  283. str = "星期四";
  284. break;
  285. case "FR":
  286. str = "星期五";
  287. break;
  288. case "SA":
  289. str = "星期六";
  290. break;
  291. case "SU":
  292. str = "星期天";
  293. break;
  294. case "JAN":
  295. str = "01";
  296. break;
  297. case "FEB":
  298. str = "02";
  299. break;
  300. case "MAR":
  301. str = "03";
  302. break;
  303. case "APR":
  304. str = "04";
  305. break;
  306. case "MAY":
  307. str = "05";
  308. break;
  309. case "JUN":
  310. str = "06";
  311. break;
  312. case "JUL":
  313. str = "07";
  314. break;
  315. case "AUG":
  316. str = "08";
  317. break;
  318. case "SEP":
  319. str = "09";
  320. break;
  321. case "OCT":
  322. str = "10";
  323. break;
  324. case "NOV":
  325. str = "11";
  326. break;
  327. case "DEC":
  328. str = "12";
  329. break;
  330. case "MONDAY":
  331. str = "星期一";
  332. break;
  333. case "TUESDAY":
  334. str = "星期二";
  335. break;
  336. case "WEDNESDAY":
  337. str = "星期三";
  338. break;
  339. case "THURSDAY":
  340. str = "星期四";
  341. break;
  342. case "FRIDAY":
  343. str = "星期五";
  344. break;
  345. case "SATURDAY":
  346. str = "星期六";
  347. break;
  348. case "SUNDAY":
  349. str = "星期日";
  350. break;
  351. case "01":
  352. str = "JAN";
  353. break;
  354. case "02":
  355. str = "FEB";
  356. break;
  357. case "03":
  358. str = "MAR";
  359. break;
  360. case "04":
  361. str = "APR";
  362. break;
  363. case "05":
  364. str = "MAY";
  365. break;
  366. case "06":
  367. str = "JUN";
  368. break;
  369. case "07":
  370. str = "JUL";
  371. break;
  372. case "08":
  373. str = "AUG";
  374. break;
  375. case "09":
  376. str = "SEP";
  377. break;
  378. case "10":
  379. str = "OCT";
  380. break;
  381. case "11":
  382. str = "NOV";
  383. break;
  384. case "12":
  385. str = "DEC";
  386. break;
  387. case "2":
  388. str = "空客A";
  389. break;
  390. case "3":
  391. str = "空客A";
  392. break;
  393. case "7":
  394. str = "波音";
  395. break;
  396. }
  397. return str;
  398. }
  399. public List<string> GetTimeListByDataTable(DataTable dt)
  400. {
  401. DateTime datestart = Convert.ToDateTime(dt.Rows[0]["Day"].ToString());
  402. DateTime dateend = Convert.ToDateTime(dt.Rows[dt.Rows.Count - 1]["ArrivedDate"].ToString());
  403. List<string> timeList = new List<string>();
  404. while (datestart <= dateend)
  405. {
  406. timeList.Add(datestart.ToString("yyyy-MM-dd"));
  407. datestart = datestart.AddDays(1);
  408. }
  409. return timeList;
  410. }
  411. }
  412. }