| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- package com.ruoyi.learn.service.impl;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import java.util.stream.Collectors;
- import com.ruoyi.common.utils.DateUtils;
- import org.apache.commons.collections4.CollectionUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import com.ruoyi.learn.mapper.LearnQuestionsMapper;
- import com.ruoyi.learn.domain.LearnQuestions;
- import com.ruoyi.learn.service.ILearnQuestionsService;
- /**
- * 试题Service业务层处理
- *
- * @author ruoyi
- * @date 2025-09-18
- */
- @Service
- public class LearnQuestionsServiceImpl implements ILearnQuestionsService
- {
- @Autowired
- private LearnQuestionsMapper learnQuestionsMapper;
- /**
- * 查询试题
- *
- * @param id 试题主键
- * @return 试题
- */
- @Override
- public LearnQuestions selectLearnQuestionsById(Long id)
- {
- return learnQuestionsMapper.selectLearnQuestionsById(id);
- }
- /**
- * 查询试题列表
- *
- * @param learnQuestions 试题
- * @return 试题
- */
- @Override
- public List<LearnQuestions> selectLearnQuestionsList(LearnQuestions learnQuestions)
- {
- return learnQuestionsMapper.selectLearnQuestionsList(learnQuestions);
- }
- /**
- * 新增试题
- *
- * @param learnQuestions 试题
- * @return 结果
- */
- @Override
- public int insertLearnQuestions(LearnQuestions learnQuestions)
- {
- learnQuestions.setCreateTime(DateUtils.getNowDate());
- return learnQuestionsMapper.insertLearnQuestions(learnQuestions);
- }
- /**
- * 修改试题
- *
- * @param learnQuestions 试题
- * @return 结果
- */
- @Override
- public int updateLearnQuestions(LearnQuestions learnQuestions)
- {
- return learnQuestionsMapper.updateLearnQuestions(learnQuestions);
- }
- /**
- * 批量删除试题
- *
- * @param ids 需要删除的试题主键
- * @return 结果
- */
- @Override
- public int deleteLearnQuestionsByIds(Long[] ids)
- {
- return learnQuestionsMapper.deleteLearnQuestionsByIds(ids);
- }
- /**
- * 删除试题信息
- *
- * @param id 试题主键
- * @return 结果
- */
- @Override
- public int deleteLearnQuestionsById(Long id)
- {
- return learnQuestionsMapper.deleteLearnQuestionsById(id);
- }
- @Override
- public List<LearnQuestions> selectCollectedList(LearnQuestions questions) {
- return learnQuestionsMapper.selectCollectedList(questions);
- }
- @Override
- public void fillCollectInfo(Long userId, List<LearnQuestions> questions) {
- if (null == userId || CollectionUtils.isEmpty(questions)) {
- return;
- }
- List<Long> ids = questions.stream().map(LearnQuestions::getId).collect(Collectors.toList());
- if (CollectionUtils.isNotEmpty(ids)){
- Map<String, Object> map = new HashMap<String, Object>();
- map.put("userId", userId);
- map.put("ids", ids);
- List<LearnQuestions> collectInfos = learnQuestionsMapper.selectCollectInfo(map);
- // Set<Long> collected = collectInfos.stream().map(LearnQuestions::getId).collect(Collectors.toSet());
- questions.forEach(e -> {
- e.setCollect(true);
- });
- }
- }
- }
|