LearnQuestionsServiceImpl.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package com.ruoyi.learn.service.impl;
  2. import java.util.HashMap;
  3. import java.util.List;
  4. import java.util.Map;
  5. import java.util.Set;
  6. import java.util.stream.Collectors;
  7. import com.ruoyi.common.utils.DateUtils;
  8. import org.apache.commons.collections4.CollectionUtils;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Service;
  11. import com.ruoyi.learn.mapper.LearnQuestionsMapper;
  12. import com.ruoyi.learn.domain.LearnQuestions;
  13. import com.ruoyi.learn.service.ILearnQuestionsService;
  14. /**
  15. * 试题Service业务层处理
  16. *
  17. * @author ruoyi
  18. * @date 2025-09-18
  19. */
  20. @Service
  21. public class LearnQuestionsServiceImpl implements ILearnQuestionsService
  22. {
  23. @Autowired
  24. private LearnQuestionsMapper learnQuestionsMapper;
  25. /**
  26. * 查询试题
  27. *
  28. * @param id 试题主键
  29. * @return 试题
  30. */
  31. @Override
  32. public LearnQuestions selectLearnQuestionsById(Long id)
  33. {
  34. return learnQuestionsMapper.selectLearnQuestionsById(id);
  35. }
  36. /**
  37. * 查询试题列表
  38. *
  39. * @param learnQuestions 试题
  40. * @return 试题
  41. */
  42. @Override
  43. public List<LearnQuestions> selectLearnQuestionsList(LearnQuestions learnQuestions)
  44. {
  45. return learnQuestionsMapper.selectLearnQuestionsList(learnQuestions);
  46. }
  47. /**
  48. * 新增试题
  49. *
  50. * @param learnQuestions 试题
  51. * @return 结果
  52. */
  53. @Override
  54. public int insertLearnQuestions(LearnQuestions learnQuestions)
  55. {
  56. learnQuestions.setCreateTime(DateUtils.getNowDate());
  57. return learnQuestionsMapper.insertLearnQuestions(learnQuestions);
  58. }
  59. /**
  60. * 修改试题
  61. *
  62. * @param learnQuestions 试题
  63. * @return 结果
  64. */
  65. @Override
  66. public int updateLearnQuestions(LearnQuestions learnQuestions)
  67. {
  68. return learnQuestionsMapper.updateLearnQuestions(learnQuestions);
  69. }
  70. /**
  71. * 批量删除试题
  72. *
  73. * @param ids 需要删除的试题主键
  74. * @return 结果
  75. */
  76. @Override
  77. public int deleteLearnQuestionsByIds(Long[] ids)
  78. {
  79. return learnQuestionsMapper.deleteLearnQuestionsByIds(ids);
  80. }
  81. /**
  82. * 删除试题信息
  83. *
  84. * @param id 试题主键
  85. * @return 结果
  86. */
  87. @Override
  88. public int deleteLearnQuestionsById(Long id)
  89. {
  90. return learnQuestionsMapper.deleteLearnQuestionsById(id);
  91. }
  92. @Override
  93. public List<LearnQuestions> selectCollectedList(LearnQuestions questions) {
  94. return learnQuestionsMapper.selectCollectedList(questions);
  95. }
  96. @Override
  97. public void fillCollectInfo(Long userId, List<LearnQuestions> questions) {
  98. if (null == userId || CollectionUtils.isEmpty(questions)) {
  99. return;
  100. }
  101. List<Long> ids = questions.stream().map(LearnQuestions::getId).collect(Collectors.toList());
  102. if (CollectionUtils.isNotEmpty(ids)){
  103. Map<String, Object> map = new HashMap<String, Object>();
  104. map.put("userId", userId);
  105. map.put("ids", ids);
  106. List<LearnQuestions> collectInfos = learnQuestionsMapper.selectCollectInfo(map);
  107. // Set<Long> collected = collectInfos.stream().map(LearnQuestions::getId).collect(Collectors.toSet());
  108. questions.forEach(e -> {
  109. e.setCollect(true);
  110. });
  111. }
  112. }
  113. }