AskDataRepository.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Dtos.Resource;
  4. using OASystem.Domain.Entities.Groups;
  5. using OASystem.Domain.Entities.Resource;
  6. using OASystem.Domain.ViewModels.Resource;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace OASystem.Infrastructure.Repositories.Resource
  13. {
  14. public class AskDataRepository : BaseRepository<Res_AskData, QueryAskDataDto>
  15. {
  16. private readonly IMapper _mapper;
  17. public AskDataRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  18. {
  19. _mapper = mapper;
  20. }
  21. public async Task<Result> QueryAskData(QueryAskDataDto dto)
  22. {
  23. Result result = new Result() { Code = -2, Msg = "未知错误" };
  24. try
  25. {
  26. string sqlWhere = string.Empty;
  27. if (!string.IsNullOrWhiteSpace(dto.Country))
  28. {
  29. sqlWhere += string.Format(@"And Country like '%{0}%'", dto.Country);
  30. }
  31. if (!string.IsNullOrWhiteSpace(dto.Area))
  32. {
  33. sqlWhere += string.Format(@"And Area like '%{0}%'", dto.Area);
  34. }
  35. if (!string.IsNullOrWhiteSpace(dto.Field))
  36. {
  37. sqlWhere += string.Format(@"And Field like '%{0}%'", dto.Field);
  38. }
  39. sqlWhere += string.Format(@"And IsDel={0}", 0);
  40. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  41. {
  42. Regex r = new Regex("And");
  43. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  44. }
  45. string sql = string.Format(@"select * from Res_AskData {0}", sqlWhere);
  46. List<Res_AskData> askDatd = await _sqlSugar.SqlQueryable<Res_AskData>(sql).ToListAsync();
  47. List<Grp_DelegationInfo> delegationInfo=await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(a=>a.IsDel==0).ToListAsync();
  48. if (askDatd.Count != 0 && delegationInfo.Count!=0)
  49. {
  50. result = new Result() { Code = 0, Msg = "查询成功!", Data = new { askDatd= askDatd, delegationInfo= delegationInfo } };
  51. }
  52. else
  53. {
  54. result = new Result() { Code = 0, Msg = "暂无数据!", Data = new { askDatd = askDatd, delegationInfo = delegationInfo } };
  55. }
  56. }
  57. catch (Exception ex)
  58. {
  59. result = new Result() { Code = -2, Msg = "未知错误" };
  60. }
  61. return result;
  62. }
  63. }
  64. }