GroupCostParameterRepository.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. using AutoMapper;
  2. using OASystem.Domain.Entities.Groups;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace OASystem.Infrastructure.Repositories.Groups
  9. {
  10. public class GroupCostParameterRepository : BaseRepository<Grp_GroupCostParameter, Grp_GroupCostParameterView>
  11. {
  12. public GroupCostParameterRepository(SqlSugarClient sqlSugar) :
  13. base(sqlSugar)
  14. {
  15. }
  16. public List<Grp_GroupCostParameter> GetGroupCostParameterListByDiid(int diid)
  17. {
  18. return Query(x=>x.DiId == diid).ToList();
  19. }
  20. public Grp_GroupCostParameter GetGroupCostParameterMainByDiid(int diid)
  21. {
  22. return Query(x => x.DiId == diid).First(x => x.CostType == "A");
  23. }
  24. public async Task<bool> UpdateIsShareById(int id,int IsShare)
  25. {
  26. return await UpdateAsync(x => x.Id == id, x=>new Grp_GroupCostParameter { IsShare = IsShare });
  27. }
  28. public async Task<bool> DeleteGroupCostParameterListByDiid(int diid)
  29. {
  30. return await SoftDeleteAsync(x=>x.DiId == diid);
  31. }
  32. public async Task<bool> SaveAsync(List<Grp_GroupCostParameter> List,int Userid, int diid)
  33. {
  34. bool isTrue = false;
  35. try
  36. {
  37. BeginTran();
  38. isTrue = await DeleteGroupCostParameterListByDiid(diid);
  39. if (List.Count > 0)
  40. {
  41. List.ForEach(x => { x.CreateUserId = Userid; x.CreateTime = DateTime.Now; });
  42. isTrue = Adds(List) > 0;
  43. }
  44. CommitTran();
  45. }
  46. catch (Exception ex)
  47. {
  48. RollbackTran();
  49. isTrue = false;
  50. }
  51. return isTrue;
  52. }
  53. public object GetBaoPi(int diid)
  54. {
  55. List<dynamic> dynamics = new List<dynamic>();
  56. try
  57. {
  58. Grp_EnterExitCost eec = _sqlSugar.Queryable<Grp_EnterExitCost>().First(x => x.DiId == diid && x.IsDel == 0);
  59. if (eec != null)
  60. {
  61. var AirJJ = new
  62. {
  63. Type = "JJC",
  64. Price = eec.AirJJ
  65. };
  66. dynamics.Add(AirJJ);
  67. var AirGW = new
  68. {
  69. Type = "GWC",
  70. Price = eec.AirGW
  71. };
  72. dynamics.Add(AirGW);
  73. List<Grp_DayAndCost> dac1 = _sqlSugar.Queryable<Grp_DayAndCost>().Where(x => x.DiId == diid && x.Type == 1 && x.NationalTravelFeeId > 0 && x.IsDel == 0).ToList(); //酒店费用
  74. List<Grp_DayAndCost> dac2 = _sqlSugar.Queryable<Grp_DayAndCost>().Where(x => x.DiId == diid && x.Type == 2 && x.NationalTravelFeeId > 0 && x.IsDel == 0).ToList(); //餐费用
  75. List<Grp_DayAndCost> dac3 = (from item in _sqlSugar.Queryable<Grp_DayAndCost>() //公杂费用
  76. where item.DiId == diid && item.Type == 3 && item.NationalTravelFeeId > 0 && item.IsDel == 0
  77. select item).ToList();
  78. if (dac1.Count == 0)
  79. {
  80. dac1 = _sqlSugar.Queryable<Grp_DayAndCost>().Where(x => x.DiId == diid && x.Type == 1 && x.IsDel == 0).ToList(); //酒店费用
  81. }
  82. if (dac2.Count == 0)
  83. {
  84. dac2 = _sqlSugar.Queryable<Grp_DayAndCost>().Where(x => x.DiId == diid && x.Type == 2 && x.IsDel == 0).ToList(); //酒店费用
  85. }
  86. if (dac2.Count == 0)
  87. {
  88. dac3 = _sqlSugar.Queryable<Grp_DayAndCost>().Where(x => x.DiId == diid && x.Type == 3 && x.IsDel == 0).ToList(); //酒店费用
  89. }
  90. decimal SumHotel = 0;
  91. decimal SumMeals = 0;
  92. decimal SumGongZa = 0;
  93. List<dynamic> hotelList = new List<dynamic>();
  94. List<string> checkString = new List<string>();
  95. if (dac1.Count != 0)//酒店费用
  96. {
  97. for (int i = 0; i < dac1.Count; i++)
  98. {
  99. if (!string.IsNullOrWhiteSpace(dac1[i].Place))
  100. {
  101. if (!checkString.Contains(dac1[i].Place))
  102. {
  103. var hotelData = new
  104. {
  105. CountryOrCity = dac1[i].Place,
  106. Price = dac1[i].SubTotal
  107. };
  108. hotelList.Add(hotelData);
  109. checkString.Add(dac1[i].Place);
  110. }
  111. }
  112. SumHotel += dac1[i].SubTotal;
  113. }
  114. if (hotelList.Count == 0)
  115. {
  116. var group = dac1.GroupBy(x => x.NationalTravelFeeId).ToList();
  117. foreach (var hotel in group)
  118. {
  119. var city = _sqlSugar.Queryable<Grp_NationalTravelFee>().First(it => it.IsDel == 0 && it.Id == hotel.Key);
  120. var hotelData = new
  121. {
  122. CountryOrCity = city?.Country + city?.City,
  123. Price = hotel.ToList()[0].SubTotal,
  124. };
  125. hotelList.Add(hotelData);
  126. checkString.Add(city?.City ?? "");
  127. }
  128. }
  129. }
  130. hotelList = hotelList.Distinct().ToList();
  131. List<dynamic> MealsList = new List<dynamic>();
  132. if (dac2.Count != 0) //餐费用
  133. {
  134. for (int i = 0; i < dac2.Count; i++)
  135. {
  136. if (checkString.Contains(dac2[i].Place))
  137. {
  138. var mealsData = new
  139. {
  140. CountryOrCity = dac2[i].Place,
  141. Price = dac2[i].SubTotal
  142. };
  143. MealsList.Add(mealsData);
  144. }
  145. SumMeals += dac2[i].SubTotal;
  146. }
  147. if (MealsList.Count == 0)
  148. {
  149. var group = dac3.GroupBy(x => x.NationalTravelFeeId).ToList();
  150. foreach (var hotel in group)
  151. {
  152. var city = _sqlSugar.Queryable<Grp_NationalTravelFee>().First(it => it.IsDel == 0 && it.Id == hotel.Key);
  153. var mealsData = new
  154. {
  155. CountryOrCity = city?.Country + city?.City,
  156. Price = hotel.ToList()[0].SubTotal,
  157. };
  158. MealsList.Add(mealsData);
  159. }
  160. }
  161. }
  162. MealsList = MealsList.Distinct().ToList();
  163. List<dynamic> GongZaList = new List<dynamic>();
  164. if (dac3.Count != 0) //公杂费用
  165. {
  166. for (int i = 0; i < dac3.Count; i++)
  167. {
  168. if (checkString.Contains(dac3[i].Place))
  169. {
  170. var gongZaData = new
  171. {
  172. CountryOrCity = dac3[i].Place,
  173. Price = dac3[i].SubTotal
  174. };
  175. GongZaList.Add(gongZaData);
  176. }
  177. SumGongZa += dac3[i].SubTotal;
  178. }
  179. if (GongZaList.Count == 0)
  180. {
  181. var group = dac3.GroupBy(x => x.NationalTravelFeeId).ToList();
  182. foreach (var hotel in group)
  183. {
  184. var city = _sqlSugar.Queryable<Grp_NationalTravelFee>().First(it => it.IsDel == 0 && it.Id == hotel.Key);
  185. var gongZaData = new
  186. {
  187. CountryOrCity = city?.Country + city?.City,
  188. Price = hotel.ToList()[0].SubTotal,
  189. };
  190. GongZaList.Add(gongZaData);
  191. }
  192. }
  193. }
  194. GongZaList = GongZaList.Distinct().ToList();
  195. //签证
  196. var Visa = new
  197. {
  198. Type = "Visa",
  199. Price = eec.Visa,
  200. Desc = eec.VisaRemark
  201. };
  202. dynamics.Add(Visa);
  203. //核酸检测费
  204. var HeSuan = new
  205. {
  206. Type = "HeSuan",
  207. Price = eec.HeSuan //元/人
  208. };
  209. dynamics.Add(HeSuan);
  210. //保险费
  211. var Insurance = new
  212. {
  213. Type = "Insurance",
  214. Price = eec.Safe //元/人
  215. };
  216. dynamics.Add(Insurance);
  217. // 伙食费
  218. var Meals = new
  219. {
  220. Type = "Meals",
  221. Content = MealsList
  222. };
  223. dynamics.Add(Meals);
  224. // 酒店费用
  225. var Hotel = new
  226. {
  227. Type = "Hotel",
  228. Content = hotelList
  229. };
  230. dynamics.Add(Hotel);
  231. // 公杂费用
  232. var GongZa = new
  233. {
  234. Type = "GongZa",
  235. Content = GongZaList
  236. };
  237. dynamics.Add(GongZa);
  238. decimal AirJJCTotal = 0;
  239. decimal AirGWCTotal = 0;
  240. //境内费用(其他费用)选择框
  241. if (eec.ChoiceOne == 1)
  242. {
  243. AirJJCTotal += Math.Round((eec.InsidePay), 2);
  244. AirGWCTotal += Math.Round((eec.InsidePay), 2);
  245. }
  246. //国际旅费合计选择框
  247. if (eec.SumJJC == 1)
  248. {
  249. AirJJCTotal += Math.Round((eec.OutsideJJPay), 2);
  250. }
  251. if (eec.SumGWC == 1)
  252. {
  253. AirGWCTotal += Math.Round((eec.OutsaideGWPay), 2);
  254. }
  255. //住宿费合计选择框
  256. if (eec.ChoiceThree == 1)
  257. {
  258. AirJJCTotal += Math.Round(SumHotel, 2);
  259. AirGWCTotal += Math.Round(SumHotel, 2);
  260. }
  261. //伙食费合计选择框
  262. if (eec.ChoiceFour == 1)
  263. {
  264. AirJJCTotal += Math.Round(SumMeals, 2);
  265. AirGWCTotal += Math.Round(SumMeals, 2);
  266. }
  267. //公杂费合计选择框
  268. if (eec.ChoiceFour == 1)
  269. {
  270. AirJJCTotal += Math.Round(SumGongZa, 2);
  271. AirGWCTotal += Math.Round(SumGongZa, 2);
  272. }
  273. // 报批总报价 - 经济舱
  274. var SumAirJJC = new
  275. {
  276. Type = "SumAirJJC",
  277. Price = AirJJCTotal
  278. };
  279. dynamics.Add(SumAirJJC);
  280. //报批总报价 - 公务舱
  281. var SumAirGWC = new
  282. {
  283. Type = "SumAirGWC",
  284. Price = AirGWCTotal
  285. };
  286. dynamics.Add(SumAirGWC);
  287. }
  288. }
  289. catch (Exception)
  290. {
  291. dynamics = new List<dynamic>();
  292. }
  293. return dynamics;
  294. }
  295. }
  296. }