Commit e38057d2 by yangyang

选择、判断随机答题以及图片提交

parent 04591073
...@@ -33,11 +33,15 @@ public class PaperController { ...@@ -33,11 +33,15 @@ public class PaperController {
@GetMapping("/paper/{paperId}") @GetMapping("/paper/{paperId}")
public Map<Integer, List<?>> findById(@PathVariable("paperId") Integer paperId) { public Map<Integer, List<?>> findById(@PathVariable("paperId") Integer paperId) {
List<MultiQuestion> multiQuestionRes = multiQuestionService.findByIdAndType(paperId); //选择题题库 1 int number = new Random().nextInt(9) + 1;
//List<FillQuestion> fillQuestionsRes = fillQuestionService.findByIdAndType(paperId); //填空题题库 2 List<MultiQuestion> multiQuestionRes = new ArrayList<>();//选择题题库 1
//List<JudgeQuestion> judgeQuestionRes = judgeQuestionService.findByIdAndType(paperId); //判断题题库 3 List<JudgeQuestion> judgeQuestionRes = new ArrayList<>();//判断题题库 3
List<FillQuestion> fillQuestionsRes = new ArrayList<>(); //填空题题库 2 List<FillQuestion> fillQuestionsRes = new ArrayList<>(); //填空题题库 2(暂定)
List<JudgeQuestion> judgeQuestionRes = new ArrayList<>(); //判断题题库 3 if(number>=4){
multiQuestionRes = multiQuestionService.findByIdAndType(paperId);
}else{
judgeQuestionRes = judgeQuestionService.findByIdAndType(paperId);
}
Map<Integer, List<?>> map = new HashMap<>(); Map<Integer, List<?>> map = new HashMap<>();
map.put(1,multiQuestionRes); map.put(1,multiQuestionRes);
map.put(2,fillQuestionsRes); map.put(2,fillQuestionsRes);
......
...@@ -2,6 +2,8 @@ package com.exam.entity; ...@@ -2,6 +2,8 @@ package com.exam.entity;
import lombok.Data; import lombok.Data;
import java.util.List;
//判断题实体类 //判断题实体类
@Data @Data
public class JudgeQuestion { public class JudgeQuestion {
...@@ -20,4 +22,6 @@ public class JudgeQuestion { ...@@ -20,4 +22,6 @@ public class JudgeQuestion {
private Integer score; private Integer score;
private String analysis; //题目解析 private String analysis; //题目解析
private List<String> img; // 照片
} }
\ No newline at end of file
...@@ -2,6 +2,8 @@ package com.exam.entity; ...@@ -2,6 +2,8 @@ package com.exam.entity;
import lombok.Data; import lombok.Data;
import java.util.List;
// 选择题实体 // 选择题实体
@Data @Data
public class MultiQuestion { public class MultiQuestion {
...@@ -31,4 +33,5 @@ public class MultiQuestion { ...@@ -31,4 +33,5 @@ public class MultiQuestion {
private String oneOrMore; //单选还是多选 1是单选 2是多选 private String oneOrMore; //单选还是多选 1是单选 2是多选
private List<String> img; // 照片
} }
\ No newline at end of file
...@@ -15,7 +15,7 @@ import java.util.List; ...@@ -15,7 +15,7 @@ import java.util.List;
@Mapper @Mapper
public interface JudgeQuestionMapper { public interface JudgeQuestionMapper {
@Select("select * from judge_question where questionId in (select questionId from paper_manage where questionType = 3 and paperId = #{paperId})") @Select("select * from judge_question where questionId in (select questionId from paper_manage where questionType = 3 and paperId = #{paperId}) order by rand() limit 1")
List<JudgeQuestion> findByIdAndType(Integer paperId); List<JudgeQuestion> findByIdAndType(Integer paperId);
@Select("select * from judge_question") @Select("select * from judge_question")
......
...@@ -3,22 +3,35 @@ package com.exam.serviceimpl; ...@@ -3,22 +3,35 @@ package com.exam.serviceimpl;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.JudgeQuestion; import com.exam.entity.JudgeQuestion;
import com.exam.entity.PaperPhoto;
import com.exam.mapper.AnswerMapper;
import com.exam.mapper.JudgeQuestionMapper; import com.exam.mapper.JudgeQuestionMapper;
import com.exam.service.JudgeQuestionService; import com.exam.service.JudgeQuestionService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
@Service @Service
public class JudgeQuestionServiceImpl implements JudgeQuestionService { public class JudgeQuestionServiceImpl implements JudgeQuestionService {
@Autowired @Autowired
private JudgeQuestionMapper judgeQuestionMapper; private JudgeQuestionMapper judgeQuestionMapper;
@Autowired
AnswerMapper answerMapper;
@Override @Override
public List<JudgeQuestion> findByIdAndType(Integer paperId) { public List<JudgeQuestion> findByIdAndType(Integer paperId) {
return judgeQuestionMapper.findByIdAndType(paperId); List<JudgeQuestion> list = judgeQuestionMapper.findByIdAndType(paperId);
list.stream().forEach(p->{
List<PaperPhoto> listPhoto = answerMapper.answersPhoto(String.valueOf(p.getQuestionId()),"3",p.getSubject());
p.setImg(listPhoto.stream()
.map(PaperPhoto::getImg)
.distinct()
.collect(Collectors.toList()));
});
return list;
} }
@Override @Override
......
...@@ -3,21 +3,35 @@ package com.exam.serviceimpl; ...@@ -3,21 +3,35 @@ package com.exam.serviceimpl;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.MultiQuestion; import com.exam.entity.MultiQuestion;
import com.exam.entity.PaperPhoto;
import com.exam.mapper.AnswerMapper;
import com.exam.mapper.MultiQuestionMapper; import com.exam.mapper.MultiQuestionMapper;
import com.exam.service.MultiQuestionService; import com.exam.service.MultiQuestionService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
@Service @Service
public class MultiQuestionServiceImpl implements MultiQuestionService { public class MultiQuestionServiceImpl implements MultiQuestionService {
@Autowired @Autowired
private MultiQuestionMapper multiQuestionMapper; private MultiQuestionMapper multiQuestionMapper;
@Autowired
AnswerMapper answerMapper;
@Override @Override
public List<MultiQuestion> findByIdAndType(Integer PaperId) { public List<MultiQuestion> findByIdAndType(Integer PaperId) {
return multiQuestionMapper.findByIdAndType(PaperId); List<MultiQuestion> list = multiQuestionMapper.findByIdAndType(PaperId);
list.stream().forEach(p->{
List<PaperPhoto> listPhoto = answerMapper.answersPhoto(String.valueOf(p.getQuestionId()),"1",p.getSubject());
p.setImg(listPhoto.stream()
.map(PaperPhoto::getImg)
.distinct()
.collect(Collectors.toList()));
});
return list;
} }
@Override @Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment