GroupCostParameterRepository.cs 13 KB

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