QuestionKnowladgeService.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using Exam.Infrastructure.Data.Entity;
  2. using Exam.Insfrastructure.Service.Service;
  3. using Exam.Questions;
  4. using Exam.Share;
  5. using Hotline.Application.Exam.QueryExtensions.Questions;
  6. using Hotline.Repository.SqlSugar;
  7. using Hotline.Repository.SqlSugar.Exam.Interfaces.Questions;
  8. using Hotline.Share.Dtos.Questions;
  9. using Hotline.Share.Requests.Question;
  10. using Mapster;
  11. using System.ComponentModel;
  12. using XF.Domain.Dependency;
  13. namespace Exam.Application
  14. {
  15. /// <summary>
  16. /// 关联知识服务
  17. /// </summary>
  18. [Description("关联知识服务")]
  19. public class QuestionKnowladgeService : ApiService<QuestionKnowladge, QuestionKnowladgeDto,HotlineDbContext>,IQuestionKnowladgeService, IScopeDependency
  20. {
  21. private readonly IQuestionKnowladgeRepository _repository;
  22. public QuestionKnowladgeService(IQuestionKnowladgeRepository repository) : base(repository)
  23. {
  24. _repository = repository;
  25. }
  26. public async Task<QuestionKnowladgeDto> GetAsync(EntityQueryRequest entityQueryRequest)
  27. {
  28. var entity = await _repository.GetAsync(entityQueryRequest.Id);
  29. return entity.Adapt<QuestionKnowladgeDto>();
  30. }
  31. public async Task<(int, List<QuestionKnowladgeViewResponse>)> GetListAsync(QuestionKnowladgePagedRequest queryRequest)
  32. {
  33. var query = _repository.Queryable();
  34. var result = await query.Select(m => new QuestionKnowladgeViewResponse {
  35. QuestionId = m.QuestionId,
  36. KnowladgeId = m.KnowladgeId,
  37. Id = m.Id,
  38. }).ToListAsync();
  39. var total = await query.CountAsync();
  40. return (total,result);
  41. }
  42. public async Task<PageViewResponse<QuestionKnowladgeViewResponse>> GetPagedListAsync(QuestionKnowladgePagedRequest queryRequest)
  43. {
  44. var expression = queryRequest.GetExpression();
  45. var questionKnowladgeTable = _repository.Queryable().Where(expression);
  46. var queryable = questionKnowladgeTable.Select((m) => new QuestionKnowladgeViewResponse
  47. {
  48. QuestionId = m.QuestionId,
  49. KnowladgeId = m.KnowladgeId,
  50. Id = m.Id,
  51. });
  52. var list = await queryable.ToPageListAsync(queryRequest.PageIndex, queryRequest.PageSize);
  53. var total = await queryable.CountAsync();
  54. var result = new PageViewResponse<QuestionKnowladgeViewResponse>
  55. {
  56. Items = list,
  57. Pagination = new Pagination(queryRequest.PageIndex, queryRequest.PageSize, total)
  58. };
  59. return result;
  60. }
  61. }
  62. }