CustomersRepository.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace OASystem.Infrastructure.Repositories.Groups
  12. {
  13. public class CustomersRepository:BaseRepository<Grp_Customers, Grp_Ommission>
  14. {
  15. private readonly IMapper _mapper;
  16. public CustomersRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  17. {
  18. _mapper = mapper;
  19. }
  20. public async Task<Result> CustomersByDiId(CustomersByDiIdDto dto)
  21. {
  22. Result result = new Result() { Code = -2, Msg = "未知错误" };
  23. try
  24. {
  25. string UserId = "";
  26. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 76).ToList();
  27. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  28. UserId += gta.UId + ",";
  29. if (!string.IsNullOrWhiteSpace(UserId))
  30. {
  31. UserId = UserId.Substring(0, UserId.Length - 1);
  32. }
  33. else
  34. {
  35. UserId = "0";
  36. }
  37. string sqlWhere = string.Format(@"Where h.DiId={0} and h.IsDel={1} And h.CreateUserId in ({2})", dto.DiId, 0, UserId);
  38. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  39. int endIndex = startIndex + dto.PageSize - 1;
  40. if (dto.PortType == 1)
  41. {
  42. string sql = string.Format(@"select h.Id,s1.Name as GuestType,h.ReservationsNo,h.HotelName,h.CheckInDate,
  43. h.CheckOutDate,c.PayMoney,s.Name as PaymentCurrency,u.CnName as CreateUserName,c.IsAuditGM,h.CreateTime,h.Attachment
  44. From Grp_HotelReservations h
  45. Join Grp_CreditCardPayment c on h.Id=c.CId and c.CTable=76 and c.isdel=0
  46. left Join Sys_SetData s on c.PaymentCurrency=s.Id
  47. left Join Sys_SetData s1 on h.GTId=s1.Id
  48. left Join Sys_Users u on u.Id=h.CreateUserId {0} order by c.IsAuditGM,c.PayPercentage desc", sqlWhere);
  49. List<HotelReservationsByDiIdView> hotelDataList = _sqlSugar.SqlQueryable<HotelReservationsByDiIdView>(sql).ToList();
  50. foreach (var item in hotelDataList)
  51. {
  52. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  53. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  54. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  55. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  56. if (!string.IsNullOrWhiteSpace(item.CheckInDate))
  57. {
  58. item.CheckInDate = DateTime.Parse(item.CheckInDate).ToString("yyyy-MM-dd");
  59. }
  60. if (!string.IsNullOrWhiteSpace(item.CheckOutDate))
  61. {
  62. item.CheckOutDate = DateTime.Parse(item.CheckOutDate).ToString("yyyy-MM-dd");
  63. }
  64. }
  65. return result = new Result() { Code = 0, Msg = "查询成功!", Data = hotelDataList };
  66. }
  67. else if (dto.PortType == 2 || dto.PortType == 3)
  68. {
  69. string sql = string.Format(@"Select * From (
  70. Select row_number() over (order by c.IsAuditGM,c.PayPercentage desc) as RowNumber,h.Id,s1.Name as GuestType,h.ReservationsNo,h.HotelName,h.CheckInDate,
  71. h.CheckOutDate,c.PayMoney,s.Name as PaymentCurrency,u.CnName as CreateUserName,c.IsAuditGM,h.CreateTime,h.Attachment
  72. From Grp_HotelReservations h
  73. Join Grp_CreditCardPayment c on h.Id=c.CId and c.CTable=76 and c.isdel=0
  74. left Join Sys_SetData s on c.PaymentCurrency=s.Id
  75. left Join Sys_SetData s1 on h.GTId=s1.Id
  76. left Join Sys_Users u on u.Id=h.CreateUserId {0}
  77. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  78. List<HotelReservationsByDiIdView> hotelDataList = _sqlSugar.SqlQueryable<HotelReservationsByDiIdView>(sql).ToList();
  79. foreach (var item in hotelDataList)
  80. {
  81. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  82. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  83. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  84. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  85. if (!string.IsNullOrWhiteSpace(item.CheckInDate))
  86. {
  87. item.CheckInDate = DateTime.Parse(item.CheckInDate).ToString("yyyy-MM-dd");
  88. }
  89. if (!string.IsNullOrWhiteSpace(item.CheckOutDate))
  90. {
  91. item.CheckOutDate = DateTime.Parse(item.CheckOutDate).ToString("yyyy-MM-dd");
  92. }
  93. }
  94. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  95. Select h.Id,s1.Name as GuestType,h.ReservationsNo,h.HotelName,h.CheckInDate,
  96. h.CheckOutDate,c.PayMoney,s.Name as PaymentCurrency,u.CnName as CreateUserName,c.IsAuditGM,h.CreateTime,h.Attachment
  97. From Grp_HotelReservations h
  98. Join Grp_CreditCardPayment c on h.Id=c.CId and c.CTable=76 and c.isdel=0
  99. left Join Sys_SetData s on c.PaymentCurrency=s.Id
  100. left Join Sys_SetData s1 on h.GTId=s1.Id
  101. left Join Sys_Users u on u.Id=h.CreateUserId {0}
  102. ) temp", sqlWhere);
  103. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  104. int count = dataCount.Count;
  105. float totalPage = (float)count / dto.PageSize;//总页数
  106. if (totalPage == 0) totalPage = 1;
  107. else totalPage = (int)Math.Ceiling((double)totalPage);
  108. ListViewBase<HotelReservationsByDiIdView> rst = new ListViewBase<HotelReservationsByDiIdView>();
  109. rst.DataList = hotelDataList;
  110. rst.DataCount = count;
  111. rst.CurrPageIndex = dto.PageIndex;
  112. rst.CurrPageSize = dto.PageSize;
  113. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  114. }
  115. else
  116. {
  117. return result = new Result() { Code = -2, Msg = "请传入PortType参数,1 Web 2 Android 3 IOS" };
  118. }
  119. }
  120. catch (Exception ex)
  121. {
  122. return result = new Result() { Code = -2, Msg = "未知错误" };
  123. throw;
  124. }
  125. }
  126. }
  127. }