InvitationOfficialActivitiesRepository.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 InvitationOfficialActivitiesRepository : BaseRepository<Grp_InvitationOfficialActivities, InvitationOfficialActivitiesListDto>
  14. {
  15. private readonly IMapper _mapper;
  16. public InvitationOfficialActivitiesRepository(SqlSugarClient sqlSugar, IMapper mapper) :
  17. base(sqlSugar)
  18. {
  19. this._mapper = mapper;
  20. }
  21. public async Task<Result> InvitationOfficialActivitiesById(InvitationOfficialActivitiesByIdDto dto)
  22. {
  23. Result result = new Result() { Code = -2, Msg = "程序错误" };
  24. try
  25. {
  26. Grp_InvitationOfficialActivities grp_Invitation = _sqlSugar.Queryable<Grp_InvitationOfficialActivities>().First(a => a.Id == dto.Id && a.IsDel == 0);
  27. Grp_CreditCardPayment grp_CreditCard = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0);
  28. var data = new
  29. {
  30. _Invitation = grp_Invitation,
  31. _CreditCard = grp_CreditCard,
  32. };
  33. result = new Result() { Code = 0, Msg = "查询成功!", Data = data };
  34. }
  35. catch (Exception)
  36. {
  37. result = new Result() { Code = -2, Msg = "程序错误" };
  38. throw;
  39. }
  40. return result;
  41. }
  42. public async Task<Result> InvitationOfficialActivitiesList(InvitationOfficialActivitiesListDto dto)
  43. {
  44. Result result = new Result() { Code = -2, Msg = "未知错误" };
  45. try
  46. {
  47. string sqlWhere = string.Empty;
  48. if (!string.IsNullOrWhiteSpace(dto.Inviter))
  49. {
  50. sqlWhere += string.Format(@" And Inviter={0}", dto.Inviter);
  51. }
  52. if (!string.IsNullOrWhiteSpace(dto.StartInviteTime) && !string.IsNullOrWhiteSpace(dto.EndInviteTime))
  53. {
  54. sqlWhere += string.Format(@" And i.InviteTime between '{0}' and '{1}'", dto.StartInviteTime,dto.EndInviteTime);
  55. }
  56. sqlWhere += string.Format(@" And i.DiId={0} And i.IsDel={1}",dto.DiId,0);
  57. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  58. {
  59. Regex r = new Regex("And");
  60. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  61. }
  62. string sql = string.Format(@"select Id,DiId,InviterArea,Inviter,InviteTime,InviteCosts,(select name from Sys_SetData where id=i.Currency and IsDel={0})
  63. as Currency,IsGoOfficaiaBussiness,(select IsAuditGM from Grp_CreditCardPayment where CTable=81 and CId=i.Id
  64. and IsDel={0}) as 'isAudit',Attachment from Grp_InvitationOfficialActivities i {1}", 0, sqlWhere);
  65. List<InvitationOfficialActivitiesView> _DecreasePayments = await _sqlSugar.SqlQueryable<InvitationOfficialActivitiesView>(sql).ToListAsync();
  66. if (_DecreasePayments.Count != 0)
  67. {
  68. result = new Result() { Code = 0, Msg = "查询成功!", Data = _DecreasePayments };
  69. }
  70. else
  71. {
  72. result = new Result() { Code = 0, Msg = "暂无数据!", Data = _DecreasePayments };
  73. }
  74. }
  75. catch (Exception ex)
  76. {
  77. result = new Result() { Code = -2, Msg = "未知错误" };
  78. }
  79. return result;
  80. }
  81. }
  82. }