CarTouristGuideGroundRepository.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Dtos.Groups;
  4. using OASystem.Domain.Entities.Financial;
  5. using OASystem.Domain.Entities.Groups;
  6. using OASystem.Domain.ViewModels.Groups;
  7. using OASystem.Infrastructure.Tools;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace OASystem.Infrastructure.Repositories.Groups
  14. {
  15. public class CarTouristGuideGroundRepository:BaseRepository<Grp_CarTouristGuideGroundReservations, Grp_CarTouristGuideGroundReservationsContent>
  16. {
  17. private readonly IMapper _mapper;
  18. public CarTouristGuideGroundRepository(SqlSugarClient sqlSugar, IMapper mapper)
  19. : base(sqlSugar)
  20. {
  21. _mapper = mapper;
  22. }
  23. public async Task<Result> OpCarTouristGuideGround(OpCarTouristGuideGroundDto dto)
  24. {
  25. Result result = new Result() { Code = -2, Msg = "未知错误" };
  26. BeginTran();
  27. try
  28. {
  29. //int id = 0;
  30. //Grp_CarTouristGuideGroundReservations grp_CarTouristGuide = _mapper.Map<Grp_CarTouristGuideGroundReservations>(dto);
  31. //if (dto.Status == 1)//添加
  32. //{
  33. // 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);
  34. // if (grp_CarTouristGuideGround != null)
  35. // {
  36. // return result = new Result() { Code = -1, Msg = "该笔费用已存在,请勿重复添加!" };
  37. // }
  38. // else
  39. // {
  40. // id = await AddAsyncReturnId(grp_CarTouristGuide);
  41. // if (id != 0)
  42. // {
  43. // //int cId = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  44. // if (true)
  45. // {
  46. // result = new Result() { Code = 0, Msg = "添加成功!" };
  47. // }
  48. // else
  49. // {
  50. // RollbackTran();
  51. // result = new Result() { Code = -1, Msg = "添加失败!" };
  52. // }
  53. // }
  54. // else
  55. // {
  56. // RollbackTran();
  57. // result = new Result() { Code = -1, Msg = "添加失败,请稍后重试!" };
  58. // }
  59. // }
  60. //}
  61. //else if (dto.Status == 2)//修改
  62. //{
  63. // bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_VisaInfo
  64. // {
  65. // VisaClient = grp_Visa1.VisaClient,
  66. // VisaPrice = grp_Visa1.VisaPrice,
  67. // VisaCurrency = grp_Visa1.VisaCurrency,
  68. // IsThird = grp_Visa1.IsThird,
  69. // PassengerType = grp_Visa1.PassengerType,
  70. // VisaNumber = grp_Visa1.VisaNumber,
  71. // VisaFreeNumber = grp_Visa1.VisaFreeNumber,
  72. // Remark = dto.Remark,
  73. // });
  74. // if (res)
  75. // {
  76. // int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == grp_Visa1.Id && a.CTable == 80).SetColumns(a => new Grp_CreditCardPayment
  77. // {
  78. // PayDId = dto.PayDId,
  79. // PayMoney = c.PayMoney,
  80. // PaymentCurrency = c.PaymentCurrency,
  81. // Payee = c.Payee,
  82. // OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  83. // DayRate = c.DayRate,
  84. // RMBPrice = c.RMBPrice,
  85. // ConsumptionPatterns = c.ConsumptionPatterns,
  86. // ConsumptionDate = c.ConsumptionDate,
  87. // CTDId = c.CTDId,
  88. // CompanyBankNo = c.CompanyBankNo,
  89. // OtherBankName = c.OtherBankName,
  90. // OtherSideNo = c.OtherSideNo,
  91. // OtherSideName = c.OtherSideName,
  92. // BankNo = c.BankNo,
  93. // CardholderName = c.CardholderName,
  94. // Remark = c.Remark,
  95. // }).ExecuteCommandAsync();
  96. // result = new Result() { Code = 0, Msg = "修改成功!" };
  97. // }
  98. // else
  99. // {
  100. // RollbackTran();
  101. // result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  102. // }
  103. //}
  104. //CommitTran();
  105. }
  106. catch (Exception ex)
  107. {
  108. result = new Result() { Code = -2, Msg = "未知错误" };
  109. }
  110. return result;
  111. }
  112. public async Task<Result> QueryCarTouristGuideGroundByDiId(CarTouristGuideGroundDto dto)
  113. {
  114. Result result = new Result() { Code = -2, Msg = "未知错误" };
  115. if (dto.PortType == 0 || string.IsNullOrWhiteSpace(dto.PortType.ToString()))
  116. {
  117. return result = new Result() { Code = -1, Msg = "请传入PortType参数,请求端口分类 1 Web 2 Android 3 IOS" };
  118. }
  119. try
  120. {
  121. #region SQL条件拼接
  122. string sqlWhere = string.Empty;
  123. sqlWhere += string.Format(@"And t.DIId={0} and t.isdel={1}", dto.DiId, 0);
  124. string UserId = "";
  125. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 79).ToList();
  126. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  127. UserId += gta.UId + ",";
  128. if (!string.IsNullOrWhiteSpace(UserId))
  129. {
  130. UserId = UserId.Substring(0, UserId.Length - 1);
  131. }
  132. else
  133. {
  134. UserId = "0";
  135. }
  136. sqlWhere += string.Format(@" And t.CreateUserId in ({0})", UserId);
  137. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  138. {
  139. Regex r = new Regex("And");
  140. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  141. }
  142. #endregion
  143. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  144. int endIndex = startIndex + dto.PageSize - 1;
  145. if (dto.PortType == 1)
  146. {
  147. string sql = string.Format(@"select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage,c.PayMoney from
  148. Grp_CarTouristGuideGroundReservations t
  149. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id
  150. left Join Sys_SetData s on s.Id=t.CId {0}
  151. order by CreateTime desc", sqlWhere);
  152. List<Grp_CarTouristGuideGroundView> infoViews = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  153. foreach (var item in infoViews)
  154. {
  155. item.PayThenMoney = Math.Round(item.PayPercentage/100 * item.ServiceQuotedPrice, 2);
  156. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice- item.PayPercentage / 100 * item.ServiceQuotedPrice);
  157. }
  158. return result = new Result() { Code = 0, Msg = "查询成功!", Data = infoViews };
  159. }
  160. else if (dto.PortType == 2 || dto.PortType == 3)
  161. {
  162. string sql = string.Format(@"Select * From (
  163. Select row_number() over (order by t.Id Desc) as RowNumber,t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage
  164. from
  165. Grp_CarTouristGuideGroundReservations t
  166. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id
  167. left Join Sys_SetData s on s.Id=t.CId {0}
  168. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  169. List<Grp_CarTouristGuideGroundView> grp_CarTourists = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  170. foreach (var item in grp_CarTourists)
  171. {
  172. item.PayThenMoney = Math.Round(item.PayPercentage / 100 * item.ServiceQuotedPrice, 2);
  173. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice - item.PayPercentage / 100 * item.ServiceQuotedPrice);
  174. }
  175. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  176. select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage from
  177. Grp_CarTouristGuideGroundReservations t
  178. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id
  179. left Join Sys_SetData s on s.Id=t.CId {0}
  180. ) temp ", sqlWhere);
  181. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  182. if (dataCount != null)
  183. {
  184. int count = dataCount.Count;
  185. float totalPage = (float)count / dto.PageSize;//总页数
  186. if (totalPage == 0) totalPage = 1;
  187. else totalPage = (int)Math.Ceiling((double)totalPage);
  188. ListViewBase<Grp_CarTouristGuideGroundView> rst = new ListViewBase<Grp_CarTouristGuideGroundView>();
  189. rst.DataList = grp_CarTourists;
  190. rst.DataCount = count;
  191. rst.CurrPageIndex = dto.PageIndex;
  192. rst.CurrPageSize = dto.PageSize;
  193. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  194. }
  195. }
  196. }
  197. catch (Exception)
  198. {
  199. return result = new Result() { Code = -2, Msg = "未知错误" };
  200. throw;
  201. }
  202. return result;
  203. }
  204. }
  205. }