HotelPriceRepository.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Dtos.Groups;
  4. using OASystem.Domain.Entities.Groups;
  5. using OASystem.Domain.ViewModels.Groups;
  6. using SqlSugar;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace OASystem.Infrastructure.Repositories.Groups
  13. {
  14. public class HotelPriceRepository : BaseRepository<Grp_HotelReservations, Grp_HotelReservations>
  15. {
  16. private readonly IMapper _mapper;
  17. public HotelPriceRepository(SqlSugarClient sqlSugar, IMapper mapper) :
  18. base(sqlSugar)
  19. {
  20. this._mapper = mapper;
  21. }
  22. public async Task<Result> HotelReservationsByDiId(HotelReservationsByDiIdDto dto)
  23. {
  24. Result result = new Result() { Code = -2, Msg = "未知错误" };
  25. try
  26. {
  27. string UserId = "";
  28. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 76).ToList();
  29. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  30. UserId += gta.UId + ",";
  31. if (!string.IsNullOrWhiteSpace(UserId))
  32. {
  33. UserId = UserId.Substring(0, UserId.Length - 1);
  34. }
  35. else
  36. {
  37. UserId = "0";
  38. }
  39. string sqlWhere = string.Format(@"Where h.DiId={0} and h.IsDel={1} And h.CreateUserId in ({2})", dto.DiId, 0,UserId);
  40. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  41. int endIndex = startIndex + dto.PageSize - 1;
  42. if (dto.PortType == 1)
  43. {
  44. string sql = string.Format(@"select h.Id,s1.Name as GuestType,h.ReservationsNo,h.HotelName,h.CheckInDate,
  45. h.CheckOutDate,c.PayMoney,s.Name as PaymentCurrency,u.CnName as CreateUserName,c.IsAuditGM,h.CreateTime,h.Attachment
  46. From Grp_HotelReservations h
  47. Join Grp_CreditCardPayment c on h.Id=c.CId and c.CTable=76 and c.IsDel=0
  48. left Join Sys_SetData s on c.PaymentCurrency=s.Id and s.IsDel=0
  49. left Join Sys_SetData s1 on h.GTId=s1.Id and s1.IsDel=0
  50. left Join Sys_Users u on u.Id=h.CreateUserId and u.isdel=0 {0}", sqlWhere);
  51. List<HotelReservationsByDiIdView> hotelDataList = _sqlSugar.SqlQueryable<HotelReservationsByDiIdView>(sql).ToList();
  52. foreach (var item in hotelDataList)
  53. {
  54. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  55. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  56. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  57. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  58. }
  59. return result = new Result() { Code = 0, Msg = "查询成功!", Data = hotelDataList };
  60. }
  61. else if (dto.PortType == 2 || dto.PortType == 3)
  62. {
  63. string sql = string.Format(@"Select * From (
  64. Select row_number() over (order by h.Id Desc) as RowNumber,h.Id,s1.Name as GuestType,h.ReservationsNo,h.HotelName,h.CheckInDate,
  65. h.CheckOutDate,c.PayMoney,s.Name as PaymentCurrency,u.CnName as CreateUserName,c.IsAuditGM,h.CreateTime,h.Attachment
  66. From Grp_HotelReservations h
  67. Join Grp_CreditCardPayment c on h.Id=c.CId and c.CTable=76 and c.IsDel=0
  68. left Join Sys_SetData s on c.PaymentCurrency=s.Id and s.IsDel=0
  69. left Join Sys_SetData s1 on h.GTId=s1.Id and s1.IsDel=0
  70. left Join Sys_Users u on u.Id=h.CreateUserId and u.isdel=0 {0}
  71. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  72. List<HotelReservationsByDiIdView> hotelDataList = _sqlSugar.SqlQueryable<HotelReservationsByDiIdView>(sql).ToList();
  73. foreach (var item in hotelDataList)
  74. {
  75. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  76. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  77. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  78. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  79. }
  80. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  81. Select h.Id,s1.Name as GuestType,h.ReservationsNo,h.HotelName,h.CheckInDate,
  82. h.CheckOutDate,c.PayMoney,s.Name as PaymentCurrency,u.CnName as CreateUserName,c.IsAuditGM,h.CreateTime,h.Attachment
  83. From Grp_HotelReservations h
  84. Join Grp_CreditCardPayment c on h.Id=c.CId and c.CTable=76 and c.IsDel=0
  85. left Join Sys_SetData s on c.PaymentCurrency=s.Id and s.IsDel=0
  86. left Join Sys_SetData s1 on h.GTId=s1.Id and s1.IsDel=0
  87. left Join Sys_Users u on u.Id=h.CreateUserId and u.isdel=0 {0}
  88. ) temp", sqlWhere);
  89. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  90. int count = dataCount.Count;
  91. float totalPage = (float)count / dto.PageSize;//总页数
  92. if (totalPage == 0) totalPage = 1;
  93. else totalPage = (int)Math.Ceiling((double)totalPage);
  94. ListViewBase<HotelReservationsByDiIdView> rst = new ListViewBase<HotelReservationsByDiIdView>();
  95. rst.DataList = hotelDataList;
  96. rst.DataCount = count;
  97. rst.CurrPageIndex = dto.PageIndex;
  98. rst.CurrPageSize = dto.PageSize;
  99. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  100. }
  101. else
  102. {
  103. return result = new Result() { Code = -2, Msg = "请传入PortType参数,1 Web 2 Android 3 IOS" };
  104. }
  105. }
  106. catch (Exception ex)
  107. {
  108. return result = new Result() { Code = -2, Msg = "未知错误" };
  109. throw;
  110. }
  111. }
  112. public async Task<Result> HotelReservationsById(HotelReservationsByIdDto dto)
  113. {
  114. Result result = new Result() { Code = -2, Msg = "未知错误" };
  115. try
  116. {
  117. Grp_HotelReservations hotelReservationsById = _sqlSugar.Queryable<Grp_HotelReservations>().First(a => a.IsDel == 0 && a.Id == dto.Id);
  118. HotelReservationsByIdView _hotelReservations = _mapper.Map<HotelReservationsByIdView>(hotelReservationsById);
  119. Grp_CreditCardPayment _CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 76);
  120. var data = new
  121. {
  122. hotelReservations = _hotelReservations,
  123. creditCardPayment = _CreditCardPayment,
  124. };
  125. return result = new Result() { Code = 0, Msg = "查询成功",Data= data };
  126. }
  127. catch (Exception ex)
  128. {
  129. return result = new Result() { Code = -2, Msg = "未知错误" };
  130. throw;
  131. }
  132. }
  133. public async Task<Result> HotelReservationsInitialize(HotelReservationsDto dto)
  134. {
  135. Result result = new Result() { Code = -2, Msg = "未知错误" };
  136. try
  137. {
  138. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == 76).ToList();
  139. string DiId = "0";
  140. foreach (var item in grp_GroupsTaskAssignment)
  141. {
  142. DiId += item.DIId + ",";
  143. }
  144. if (DiId != "0")
  145. {
  146. DiId = DiId.Substring(0, DiId.Length - 1);
  147. }
  148. string sql = string.Format(@"select * from Grp_DelegationInfo where Id in({0}) and IsDel={1}", DiId, 0);
  149. //团组下拉框
  150. List<Grp_DelegationInfo> Delegations = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
  151. List<ShareGroupInfoIIView> grp_Delegations = _mapper.Map<List<ShareGroupInfoIIView>>(Delegations);
  152. for (int i = 0;i< grp_Delegations.Count; i++)
  153. {
  154. grp_Delegations[i].VisitDate = Delegations[i].VisitStartDate.ToString("yyyy-MM-dd")+"至"+ Delegations[i].VisitEndDate.ToString("yyyy-MM-dd");
  155. }
  156. //客人类型
  157. List<Sys_SetData> GuestType = _sqlSugar.Queryable<Sys_SetData>().Where(a=>a.IsDel==0 && a.STid==11).ToList();
  158. List<SetDataInfoView> _GuestType = _mapper.Map<List<SetDataInfoView>>(GuestType);
  159. //支付方式
  160. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  161. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  162. //币种
  163. List<Sys_SetData> CurrencyList = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 66 && a.IsDel == 0).ToList();
  164. List<SetDataInfoView> _CurrencyList = _mapper.Map<List<SetDataInfoView>>(CurrencyList);
  165. //卡类型
  166. List<Sys_SetData> BankCard = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 15 && a.IsDel == 0).ToList();
  167. List<SetDataInfoView> _BankCard = _mapper.Map<List<SetDataInfoView>>(BankCard);
  168. //预订网站
  169. List<Sys_SetData> BookingWebsite = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 12 && a.IsDel == 0).ToList();
  170. List<SetDataInfoView> _BookingWebsite = _mapper.Map<List<SetDataInfoView>>(BookingWebsite);
  171. var data = new
  172. {
  173. Delegations = grp_Delegations,
  174. GuestType = _GuestType,
  175. Payment = _Payment,
  176. CurrencyList = _CurrencyList,
  177. BankCard = _BankCard,
  178. BookingWebsite = _BookingWebsite,
  179. };
  180. return result = new Result() { Code = 0, Msg = "查询成功",Data=data };
  181. }
  182. catch (Exception ex)
  183. {
  184. return result = new Result() { Code = -2, Msg = "未知错误" };
  185. throw;
  186. }
  187. }
  188. public Task<Result> OpHotelReservations(OpHotelReservationsData dto)
  189. {
  190. throw new NotImplementedException();
  191. }
  192. }
  193. }