CarTouristGuideGroundRepository.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 CarTouristGuideGroundRepository:BaseRepository<Grp_CarTouristGuideGroundReservations, Grp_CarTouristGuideGroundReservationsContent>
  14. {
  15. private readonly IMapper _mapper;
  16. public CarTouristGuideGroundRepository(SqlSugarClient sqlSugar, IMapper mapper)
  17. : base(sqlSugar)
  18. {
  19. _mapper = mapper;
  20. }
  21. public Task<Result> OpCarTouristGuideGround(OpCarTouristGuideGroundDto dto)
  22. {
  23. throw new NotImplementedException();
  24. }
  25. public async Task<Result> QueryCarTouristGuideGroundByDiId(CarTouristGuideGroundDto dto)
  26. {
  27. Result result = new Result() { Code = -2, Msg = "未知错误" };
  28. if (dto.PortType == 0 || string.IsNullOrWhiteSpace(dto.PortType.ToString()))
  29. {
  30. return result = new Result() { Code = -1, Msg = "请传入PortType参数,请求端口分类 1 Web 2 Android 3 IOS" };
  31. }
  32. try
  33. {
  34. #region SQL条件拼接
  35. string sqlWhere = string.Empty;
  36. sqlWhere += string.Format(@"And t.DIId={0} and t.isdel={1}", dto.DiId, 0);
  37. string UserId = "";
  38. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 79).ToList();
  39. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  40. UserId += gta.UId + ",";
  41. if (!string.IsNullOrWhiteSpace(UserId))
  42. {
  43. UserId = UserId.Substring(0, UserId.Length - 1);
  44. }
  45. else
  46. {
  47. UserId = "0";
  48. }
  49. sqlWhere += string.Format(@" And t.CreateUserId in ({0})", UserId);
  50. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  51. {
  52. Regex r = new Regex("And");
  53. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  54. }
  55. #endregion
  56. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  57. int endIndex = startIndex + dto.PageSize - 1;
  58. if (dto.PortType == 1)
  59. {
  60. string sql = string.Format(@"select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage,c.PayMoney from
  61. Grp_CarTouristGuideGroundReservations t
  62. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id
  63. left Join Sys_SetData s on s.Id=t.CId {0}
  64. order by CreateTime desc", sqlWhere);
  65. List<Grp_CarTouristGuideGroundView> infoViews = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  66. foreach (var item in infoViews)
  67. {
  68. item.PayThenMoney = Math.Round(item.PayPercentage/100 * item.ServiceQuotedPrice, 2);
  69. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice- item.PayPercentage / 100 * item.ServiceQuotedPrice);
  70. }
  71. return result = new Result() { Code = 0, Msg = "查询成功!", Data = infoViews };
  72. }
  73. else if (dto.PortType == 2 || dto.PortType == 3)
  74. {
  75. string sql = string.Format(@"Select * From (
  76. Select row_number() over (order by t.Id Desc) as RowNumber,t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage
  77. from
  78. Grp_CarTouristGuideGroundReservations t
  79. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id
  80. left Join Sys_SetData s on s.Id=t.CId {0}
  81. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  82. List<Grp_CarTouristGuideGroundView> grp_CarTourists = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  83. foreach (var item in grp_CarTourists)
  84. {
  85. item.PayThenMoney = Math.Round(item.PayPercentage / 100 * item.ServiceQuotedPrice, 2);
  86. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice - item.PayPercentage / 100 * item.ServiceQuotedPrice);
  87. }
  88. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  89. select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage from
  90. Grp_CarTouristGuideGroundReservations t
  91. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id
  92. left Join Sys_SetData s on s.Id=t.CId {0}
  93. ) temp ", sqlWhere);
  94. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  95. if (dataCount != null)
  96. {
  97. int count = dataCount.Count;
  98. float totalPage = (float)count / dto.PageSize;//总页数
  99. if (totalPage == 0) totalPage = 1;
  100. else totalPage = (int)Math.Ceiling((double)totalPage);
  101. ListViewBase<Grp_CarTouristGuideGroundView> rst = new ListViewBase<Grp_CarTouristGuideGroundView>();
  102. rst.DataList = grp_CarTourists;
  103. rst.DataCount = count;
  104. rst.CurrPageIndex = dto.PageIndex;
  105. rst.CurrPageSize = dto.PageSize;
  106. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  107. }
  108. }
  109. }
  110. catch (Exception)
  111. {
  112. return result = new Result() { Code = -2, Msg = "未知错误" };
  113. throw;
  114. }
  115. return result;
  116. }
  117. }
  118. }