CarTouristGuideGroundRepository.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. using AutoMapper;
  2. using NPOI.OpenXmlFormats.Shared;
  3. using OASystem.Domain;
  4. using OASystem.Domain.Dtos.Groups;
  5. using OASystem.Domain.Entities.Financial;
  6. using OASystem.Domain.Entities.Groups;
  7. using OASystem.Domain.Entities.Resource;
  8. using OASystem.Domain.ViewModels.Groups;
  9. using OASystem.Infrastructure.Tools;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. namespace OASystem.Infrastructure.Repositories.Groups
  16. {
  17. public class CarTouristGuideGroundRepository:BaseRepository<Grp_CarTouristGuideGroundReservations, Grp_CarTouristGuideGroundReservationsContent>
  18. {
  19. private readonly IMapper _mapper;
  20. public CarTouristGuideGroundRepository(SqlSugarClient sqlSugar, IMapper mapper)
  21. : base(sqlSugar)
  22. {
  23. _mapper = mapper;
  24. }
  25. public async Task<Result> OpCarTouristGuideGround(OpCarTouristGuideGroundDto dto)
  26. {
  27. Result result = new Result() { Code = -2, Msg = "未知错误" };
  28. BeginTran();
  29. try
  30. {
  31. int id = 0;
  32. Grp_CarTouristGuideGroundReservations grp_CarTouristGuide = _mapper.Map<Grp_CarTouristGuideGroundReservations>(dto);
  33. if (dto.Status == 1)//添加
  34. {
  35. Grp_CarTouristGuideGroundReservations grp_CarTouristGuideGround = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().First(a => a.IsDel == 0 && a.Area == dto.Area && a.BusName == dto.BusName && a.ServiceGuide == dto.ServiceGuide && a.DiId==dto.DiId && a.BusTel==dto.BusTel && a.ServiceTel==dto.ServiceTel);
  36. if (grp_CarTouristGuideGround != null)
  37. {
  38. return result = new Result() { Code = -1, Msg = "该笔费用已存在,请勿重复添加!" };
  39. }
  40. else
  41. {
  42. id = await AddAsyncReturnId(grp_CarTouristGuide);
  43. if (id == 0)
  44. {
  45. RollbackTran();
  46. result = new Result() { Code = -1, Msg = "添加失败,请稍后重试!" };
  47. }
  48. else
  49. {
  50. result = new Result() { Code = 0, Msg = "添加成功!" };
  51. }
  52. }
  53. }
  54. else if (dto.Status == 2)//修改
  55. {
  56. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_CarTouristGuideGroundReservations
  57. {
  58. Area = grp_CarTouristGuide.Area,
  59. ServiceCompany = grp_CarTouristGuide.ServiceCompany,
  60. ServiceGuide = grp_CarTouristGuide.ServiceGuide,
  61. ServiceTel = grp_CarTouristGuide.ServiceTel,
  62. BusName = grp_CarTouristGuide.BusName,
  63. BusDescription = grp_CarTouristGuide.BusDescription,
  64. BusTel = grp_CarTouristGuide.BusTel,
  65. ServiceStartTime = grp_CarTouristGuide.ServiceStartTime,
  66. ServiceEndTime = grp_CarTouristGuide.ServiceEndTime,
  67. ServiceDescription = grp_CarTouristGuide.ServiceDescription,
  68. QuotedPriceExplanation = grp_CarTouristGuide.QuotedPriceExplanation,
  69. OrbitalPrivateTransfer = grp_CarTouristGuide.OrbitalPrivateTransfer,
  70. Remark = grp_CarTouristGuide.Remark,
  71. });
  72. if (res)
  73. {
  74. id = dto.Id;
  75. result = new Result() { Code = 0, Msg = "修改成功!" };
  76. }
  77. else
  78. {
  79. RollbackTran();
  80. result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  81. }
  82. }
  83. if (id!=0)
  84. {
  85. Res_LocalGuideData _LocalGuideDataCar = _sqlSugar.Queryable<Res_LocalGuideData>().First(a => a.UnitName == dto.BusName && a.ContactTel == dto.BusTel && a.IsDel == 0);
  86. if (_LocalGuideDataCar == null)
  87. {
  88. Res_LocalGuideData res_LocalGuideCar = new Res_LocalGuideData();
  89. res_LocalGuideCar.UnitName = dto.BusName;
  90. res_LocalGuideCar.ContactTel = dto.BusTel;
  91. res_LocalGuideCar.CreateUserId = dto.CreateUserId;
  92. int cId = await _sqlSugar.Insertable(res_LocalGuideCar).ExecuteReturnIdentityAsync();
  93. }
  94. Res_LocalGuideData _LocalGuideDataService = _sqlSugar.Queryable<Res_LocalGuideData>().First(a => a.UnitName == dto.ServiceCompany && a.ContactTel == dto.ServiceTel && a.IsDel == 0);
  95. if (_LocalGuideDataService == null)
  96. {
  97. Res_LocalGuideData res_LocalGuideService = new Res_LocalGuideData();
  98. res_LocalGuideService.UnitName = dto.ServiceCompany;
  99. res_LocalGuideService.ContactTel = dto.ServiceTel;
  100. res_LocalGuideService.Contact = dto.ServiceTel;
  101. res_LocalGuideService.CreateUserId = dto.CreateUserId;
  102. int cId = await _sqlSugar.Insertable(res_LocalGuideService).ExecuteReturnIdentityAsync();
  103. }
  104. }
  105. CommitTran();
  106. }
  107. catch (Exception ex)
  108. {
  109. result = new Result() { Code = -2, Msg = "未知错误" };
  110. }
  111. return result;
  112. }
  113. public async Task<Result> CarTouristGuideGroundConten(CarTouristGuideGroundContenDto dto)
  114. {
  115. Result result = new Result() { Code = -2, Msg = "未知错误" };
  116. try
  117. {
  118. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == 79).ToList();
  119. string DiId = "0";
  120. foreach (var item in grp_GroupsTaskAssignment)
  121. {
  122. DiId += item.DIId + ",";
  123. }
  124. if (DiId != "0")
  125. {
  126. DiId = DiId.Substring(0, DiId.Length - 1);
  127. }
  128. string sql = string.Format(@"select * from Grp_DelegationInfo where Id in({0}) and IsDel={1}", DiId, 0);
  129. //团组下拉框
  130. List<Grp_DelegationInfo> grp_Delegations = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
  131. //支付方式
  132. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  133. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  134. //币种
  135. List<Sys_SetData> CurrencyList = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 66 && a.IsDel == 0).ToList();
  136. List<SetDataInfoView> _CurrencyList = _mapper.Map<List<SetDataInfoView>>(CurrencyList);
  137. //列表初始化
  138. List<Sys_SetData> TableInitialization = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 17 && a.IsDel == 0).ToList();
  139. List<SetDataInfoView> _TableInitialization = _mapper.Map<List<SetDataInfoView>>(TableInitialization);
  140. _TableInitialization= _TableInitialization.OrderBy(a=>a.Name).ToList();
  141. var data = new
  142. {
  143. Payment = _Payment,
  144. CurrencyList = _CurrencyList,
  145. Delegations = grp_Delegations,
  146. TableInitialization = _TableInitialization
  147. };
  148. return result = new Result() { Code = 0, Msg = "查询成功",Data=data };
  149. }
  150. catch (Exception)
  151. {
  152. return result = new Result() { Code = -2, Msg = "未知错误" };
  153. throw;
  154. }
  155. }
  156. public async Task<Result> OpCarTouristGuideGroundContenById(CarTouristGuideGroundIdDto dto)
  157. {
  158. Result result = new Result() { Code = -2, Msg = "未知错误" };
  159. try
  160. {
  161. List<Grp_CarTouristGuideGroundReservationsContent> grp_CarTouristsConten = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.IsDel==0 && a.CTGGRId==dto.Id).ToList();
  162. Grp_CreditCardPayment _CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 79);
  163. Grp_CarTouristGuideGroundReservations grp_CarTouristGuideGround= _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().First(a => a.Id == dto.Id && a.IsDel == 0);
  164. var data = new
  165. {
  166. CarTouristsConten = grp_CarTouristsConten,
  167. CarTourists = grp_CarTouristGuideGround,
  168. CreditCardPayment = _CreditCardPayment,
  169. };
  170. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  171. }
  172. catch (Exception)
  173. {
  174. return result = new Result() { Code = -2, Msg = "未知错误" };
  175. throw;
  176. }
  177. }
  178. /// <summary>
  179. /// 根据diid查询op费用列表
  180. /// </summary>
  181. /// <param name="dto"></param>
  182. /// <returns></returns>
  183. public async Task<Result> QueryCarTouristGuideGroundByDiId(CarTouristGuideGroundDto dto)
  184. {
  185. Result result = new Result() { Code = -2, Msg = "未知错误" };
  186. if (dto.PortType == 0 || string.IsNullOrWhiteSpace(dto.PortType.ToString()))
  187. {
  188. return result = new Result() { Code = -1, Msg = "请传入PortType参数,请求端口分类 1 Web 2 Android 3 IOS" };
  189. }
  190. try
  191. {
  192. #region SQL条件拼接
  193. string sqlWhere = string.Empty;
  194. sqlWhere += string.Format(@"And t.DIId={0} and t.isdel={1}", dto.DiId, 0);
  195. string UserId = "";
  196. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 79).ToList();
  197. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  198. UserId += gta.UId + ",";
  199. if (!string.IsNullOrWhiteSpace(UserId))
  200. {
  201. UserId = UserId.Substring(0, UserId.Length - 1);
  202. }
  203. else
  204. {
  205. UserId = "0";
  206. }
  207. sqlWhere += string.Format(@" And t.CreateUserId in ({0})", UserId);
  208. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  209. {
  210. Regex r = new Regex("And");
  211. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  212. }
  213. #endregion
  214. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  215. int endIndex = startIndex + dto.PageSize - 1;
  216. if (dto.PortType == 1)
  217. {
  218. string sql = string.Format(@"select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage,c.PayMoney from
  219. Grp_CarTouristGuideGroundReservations t
  220. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id
  221. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  222. order by CreateTime desc", sqlWhere);
  223. List<Grp_CarTouristGuideGroundView> infoViews = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  224. foreach (var item in infoViews)
  225. {
  226. item.ServiceQuotedPrice = item.PayMoney;
  227. item.PayThenMoney = Math.Round(item.PayPercentage/100 * item.ServiceQuotedPrice, 2);
  228. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice- item.PayPercentage / 100 * item.ServiceQuotedPrice);
  229. }
  230. return result = new Result() { Code = 0, Msg = "查询成功!", Data = infoViews };
  231. }
  232. else if (dto.PortType == 2 || dto.PortType == 3)
  233. {
  234. string sql = string.Format(@"Select * From (
  235. Select row_number() over (order by t.Id Desc) as RowNumber,t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage
  236. from
  237. Grp_CarTouristGuideGroundReservations t
  238. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id
  239. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  240. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  241. List<Grp_CarTouristGuideGroundView> grp_CarTourists = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  242. foreach (var item in grp_CarTourists)
  243. {
  244. item.PayThenMoney = Math.Round(item.PayPercentage / 100 * item.ServiceQuotedPrice, 2);
  245. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice - item.PayPercentage / 100 * item.ServiceQuotedPrice);
  246. }
  247. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  248. select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage from
  249. Grp_CarTouristGuideGroundReservations t
  250. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id
  251. left Join Sys_SetData s on s.Id=t.CId {0}
  252. ) temp ", sqlWhere);
  253. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  254. if (dataCount != null)
  255. {
  256. int count = dataCount.Count;
  257. float totalPage = (float)count / dto.PageSize;//总页数
  258. if (totalPage == 0) totalPage = 1;
  259. else totalPage = (int)Math.Ceiling((double)totalPage);
  260. ListViewBase<Grp_CarTouristGuideGroundView> rst = new ListViewBase<Grp_CarTouristGuideGroundView>();
  261. rst.DataList = grp_CarTourists;
  262. rst.DataCount = count;
  263. rst.CurrPageIndex = dto.PageIndex;
  264. rst.CurrPageSize = dto.PageSize;
  265. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  266. }
  267. }
  268. }
  269. catch (Exception)
  270. {
  271. return result = new Result() { Code = -2, Msg = "未知错误" };
  272. throw;
  273. }
  274. return result;
  275. }
  276. /// <summary>
  277. /// OP费用录入填写详情
  278. /// </summary>
  279. /// <param name="dto"></param>
  280. /// <returns></returns>
  281. public async Task<Result> OpCarTouristGuideGroundConten(OpCarTouristGuideGroundContenDto dto)
  282. {
  283. Result result = new Result() { Code = -2, Msg = "未知错误" };
  284. try
  285. {
  286. BeginTran();
  287. List<Grp_CarTouristGuideGroundReservationsContent> carTouristList = new List<Grp_CarTouristGuideGroundReservationsContent>();
  288. foreach (var item in dto.OPContenList)
  289. {
  290. Grp_CarTouristGuideGroundReservationsContent s = new Grp_CarTouristGuideGroundReservationsContent();
  291. s.Id= item.Id;
  292. s.DiId = dto.DiId;
  293. s.CTGGRId = dto.CTGGRId;
  294. s.SId = item.SId;
  295. s.Price=item.Price;
  296. s.PriceContent = item.priceContent;
  297. s.Currency = dto.Currency;
  298. s.Remark=item.Remark;
  299. s.CreateUserId = dto.CreateUserId;
  300. carTouristList.Add(s);
  301. }
  302. foreach (var item in carTouristList)
  303. {
  304. Grp_CarTouristGuideGroundReservationsContent QueryData = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().First(a => a.SId == item.SId && a.Id == item.Id && a.DiId == item.DiId && a.IsDel==0);
  305. if (QueryData==null)
  306. {
  307. if (item.Price!=0)
  308. {
  309. int id = await _sqlSugar.Insertable(item).ExecuteReturnIdentityAsync();
  310. if (id == 0)
  311. {
  312. RollbackTran();
  313. return result = new Result() { Code = -2, Msg = "添加失败" };
  314. }
  315. }
  316. }
  317. else
  318. {
  319. int CTable = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.Id == item.Id).SetColumns(a => new Grp_CarTouristGuideGroundReservationsContent
  320. {
  321. Price = item.Price,
  322. PriceContent = item.PriceContent,
  323. Currency = dto.Currency,
  324. Remark = item.Remark,
  325. }).ExecuteCommandAsync();
  326. if (CTable==0)
  327. {
  328. RollbackTran();
  329. return result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  330. }
  331. }
  332. }
  333. //修改C表数据
  334. List<Grp_CarTouristGuideGroundReservationsContent> carTouristListEnd = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.DiId==dto.DiId && a.CTGGRId==dto.CTGGRId && a.IsDel==0).ToList();
  335. Grp_CreditCardPayment c=new Grp_CreditCardPayment();
  336. c.PaymentCurrency = dto.Currency;
  337. foreach (var item in carTouristListEnd)
  338. {
  339. c.PayMoney += item.Price;
  340. }
  341. c.PayPercentage = dto.PayPercentage;
  342. c.ConsumptionDate= DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  343. c.CTable = 79;
  344. c.CId = dto.CTGGRId;
  345. c.IsAuditGM = 0;
  346. c.PayDId=dto.PayDId;
  347. c.DIId = dto.DiId;
  348. c.OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer;
  349. c.Payee=dto.Payee;
  350. c.CreateUserId=dto.CreateUserId;
  351. if (c.PayDId == 72)
  352. {
  353. c.IsPay = 1;
  354. }
  355. c.RMBPrice = c.PayMoney;
  356. c.DayRate = 1;
  357. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 79);
  358. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  359. if (_TeamRate != null)
  360. {
  361. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  362. if (_SetData != null)
  363. {
  364. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  365. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  366. if (CurrencyRate != null)
  367. {
  368. c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  369. c.DayRate = CurrencyRate.Rate;
  370. }
  371. }
  372. }
  373. Grp_CreditCardPayment grp_CreditCard = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a=>a.CId==dto.CTGGRId && a.IsDel==0 && a.CTable==79 && a.DIId==dto.DiId);
  374. if (grp_CreditCard!=null)//修改
  375. {
  376. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == dto.CTGGRId && a.CTable == 79 && a.DIId==dto.DiId).SetColumns(a => new Grp_CreditCardPayment
  377. {
  378. PaymentCurrency = c.PaymentCurrency,
  379. PayMoney = c.PayMoney,
  380. PayPercentage = c.PayPercentage,
  381. CTable = c.CTable,
  382. PayDId = c.PayDId,
  383. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  384. Payee = c.Payee,
  385. IsPay = c.IsPay,
  386. RMBPrice = c.RMBPrice,
  387. DayRate = c.DayRate,
  388. }).ExecuteCommandAsync();
  389. if (CTable == 0)
  390. {
  391. RollbackTran();
  392. return result = new Result() { Code = -2, Msg = "修改失败" };
  393. }
  394. }
  395. else//添加
  396. {
  397. int id = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  398. if (id == 0)
  399. {
  400. RollbackTran();
  401. return result = new Result() { Code = -2, Msg = "添加失败" };
  402. }
  403. }
  404. int CarTouristGuideCTable = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservations>().Where(a => a.Id == dto.CTGGRId && a.DiId == dto.DiId).SetColumns(a => new Grp_CarTouristGuideGroundReservations
  405. {
  406. CId=dto.Currency,
  407. ServiceQuotedPrice=c.PayMoney,
  408. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  409. }).ExecuteCommandAsync();
  410. if (CarTouristGuideCTable == 0)
  411. {
  412. RollbackTran();
  413. return result = new Result() { Code = -2, Msg = "修改失败" };
  414. }
  415. result = new Result() { Code =0, Msg = "保存成功" };
  416. CommitTran();
  417. }
  418. catch (Exception)
  419. {
  420. return result = new Result() { Code = -2, Msg = "未知错误" };
  421. throw;
  422. }
  423. return result;
  424. }
  425. }
  426. }