CarTouristGuideGroundRepository.cs 6.4 KB

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