|
@@ -98,7 +98,7 @@ public class PaperService {
|
|
public Paper getOnePaper(Long id) {
|
|
public Paper getOnePaper(Long id) {
|
|
AuthUser user = SecurityUtil.getCurrentUser();
|
|
AuthUser user = SecurityUtil.getCurrentUser();
|
|
boolean student = Constants.USER_TYPE_STUDENT.equals(user.getUser().getUserType());
|
|
boolean student = Constants.USER_TYPE_STUDENT.equals(user.getUser().getUserType());
|
|
- Paper paper = paperRepo.getOne(id);
|
|
|
|
|
|
+ Paper paper = paperRepo.findById(id).orElse(null);
|
|
if (paper == null || paper.getStatus() == Constants.NOTREADY) {
|
|
if (paper == null || paper.getStatus() == Constants.NOTREADY) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
@@ -113,12 +113,23 @@ public class PaperService {
|
|
Map<Long, List<QuestionOption>> group = options.stream().collect(Collectors.groupingBy(QuestionOption::getQid));
|
|
Map<Long, List<QuestionOption>> group = options.stream().collect(Collectors.groupingBy(QuestionOption::getQid));
|
|
for (Question question : questions) {
|
|
for (Question question : questions) {
|
|
List<QuestionOption> optionList = group.get(question.getId());
|
|
List<QuestionOption> optionList = group.get(question.getId());
|
|
|
|
+ List<QuestionOption> os = new ArrayList<>();
|
|
//学生要去掉答案
|
|
//学生要去掉答案
|
|
if (student) {
|
|
if (student) {
|
|
question.setCorrectNum(0);
|
|
question.setCorrectNum(0);
|
|
- optionList.forEach(o -> o.setCorrect(null));
|
|
|
|
|
|
+ //避免自动持久化
|
|
|
|
+ for (QuestionOption o : optionList) {
|
|
|
|
+ QuestionOption option = new QuestionOption();
|
|
|
|
+ option.setId(o.getId());
|
|
|
|
+ option.setContent(o.getContent());
|
|
|
|
+ option.setOindex(o.getOindex());
|
|
|
|
+ option.setQid(o.getQid());
|
|
|
|
+ os.add(option);
|
|
|
|
+ }
|
|
|
|
+ question.setOptions(os);
|
|
|
|
+ } else {
|
|
|
|
+ question.setOptions(optionList);
|
|
}
|
|
}
|
|
- question.setOptions(optionList);
|
|
|
|
}
|
|
}
|
|
return paper;
|
|
return paper;
|
|
}
|
|
}
|