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 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 selectCollectedList(LearnQuestions questions) { return learnQuestionsMapper.selectCollectedList(questions); } @Override public void fillCollectInfo(Long userId, List questions) { if (null == userId || CollectionUtils.isEmpty(questions)) { return; } List ids = questions.stream().map(LearnQuestions::getId).collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(ids)){ Map map = new HashMap(); map.put("userId", userId); map.put("ids", ids); List collectInfos = learnQuestionsMapper.selectCollectInfo(map); // Set collected = collectInfos.stream().map(LearnQuestions::getId).collect(Collectors.toSet()); questions.forEach(e -> { e.setCollect(true); }); } } }