|
|
@@ -1,5 +1,6 @@
|
|
|
package cn.reghao.tnb.content.app.exam.service;
|
|
|
|
|
|
+import cn.reghao.jutil.jdk.converter.DateTimeConverter;
|
|
|
import cn.reghao.jutil.jdk.db.Page;
|
|
|
import cn.reghao.jutil.jdk.db.PageList;
|
|
|
import cn.reghao.jutil.jdk.result.Result;
|
|
|
@@ -15,6 +16,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -25,22 +27,22 @@ import java.util.stream.Collectors;
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class PaperService {
|
|
|
+ private final SubjectMapper subjectMapper;
|
|
|
private final PaperMapper paperMapper;
|
|
|
private final PaperQuestionMapper paperQuestionMapper;
|
|
|
private final QuestionMapper questionMapper;
|
|
|
private final QuestionOptionMapper questionOptionMapper;
|
|
|
private final PaperResultMapper paperResultMapper;
|
|
|
- private final ExamUserMapper examUserMapper;
|
|
|
|
|
|
- public PaperService(PaperMapper paperMapper, PaperQuestionMapper paperQuestionMapper,
|
|
|
+ public PaperService(SubjectMapper subjectMapper, PaperMapper paperMapper, PaperQuestionMapper paperQuestionMapper,
|
|
|
QuestionMapper questionMapper, QuestionOptionMapper questionOptionMapper,
|
|
|
- PaperResultMapper paperResultMapper, ExamUserMapper examUserMapper) {
|
|
|
+ PaperResultMapper paperResultMapper) {
|
|
|
+ this.subjectMapper = subjectMapper;
|
|
|
this.paperMapper = paperMapper;
|
|
|
this.paperQuestionMapper = paperQuestionMapper;
|
|
|
this.questionMapper = questionMapper;
|
|
|
this.questionOptionMapper = questionOptionMapper;
|
|
|
this.paperResultMapper = paperResultMapper;
|
|
|
- this.examUserMapper = examUserMapper;
|
|
|
}
|
|
|
|
|
|
public Result createExamPaper(PaperAddDto paperAddDto) {
|
|
|
@@ -57,8 +59,6 @@ public class PaperService {
|
|
|
list.forEach(paperQuestion -> {
|
|
|
paperQuestion.setPaperId(paperId);
|
|
|
});
|
|
|
-
|
|
|
- examUserMapper.saveAll(getExamUsers(paperId));
|
|
|
/*List<PaperQuestion> list1 = list.stream()
|
|
|
.map(paperQuestion -> {
|
|
|
if (paperQuestion.getChildren().isEmpty()) {
|
|
|
@@ -81,29 +81,17 @@ public class PaperService {
|
|
|
}*/
|
|
|
}
|
|
|
|
|
|
- private List<ExamUser> getExamUsers(int paperId) {
|
|
|
- List<ExamUser> list = new ArrayList<>();
|
|
|
- long start = 10001L;
|
|
|
- long total = 100;
|
|
|
- while (start < start + total) {
|
|
|
- ExamUser examUser = new ExamUser(paperId, start, 1);
|
|
|
- list.add(examUser);
|
|
|
- start++;
|
|
|
- }
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
public Result deleteExamPaper(int paperId) {
|
|
|
paperMapper.deleteById(paperId);
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
- public PageList<PaperView> getExamPapers(PaperQuery paperQuery) {
|
|
|
+ public PageList<EvalPaper> getEvalPapers(PaperQuery paperQuery) {
|
|
|
long loginUser = UserContext.getUser();
|
|
|
int total = paperMapper.countByCriteria(paperQuery);
|
|
|
Page page = paperQuery.getPage();
|
|
|
List<Paper> list = paperMapper.findPaperByPage(page, paperQuery);
|
|
|
- List<PaperView> list1 = list.stream()
|
|
|
+ List<EvalPaper> list1 = list.stream()
|
|
|
.map(paper -> {
|
|
|
int paperId = paper.getId();
|
|
|
int markType = paper.getMarkType();
|
|
|
@@ -113,17 +101,41 @@ public class PaperService {
|
|
|
// 2. 试卷已完成, 自己批改
|
|
|
// 3. 试卷已完成, 他人批改
|
|
|
// 4. 试卷已完成, 已批改
|
|
|
+ int userScore = 0;
|
|
|
if (paperResult == null) {
|
|
|
status = 1;
|
|
|
} else if (paperResult.getMarked()) {
|
|
|
status = 4;
|
|
|
+ userScore = paperResult.getUserScore();
|
|
|
} else if (markType == 2) {
|
|
|
status = 2;
|
|
|
} else {
|
|
|
status = 3;
|
|
|
}
|
|
|
|
|
|
- return new PaperView(paper, status);
|
|
|
+ return new EvalPaper(paper, status, userScore);
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ return PageList.pageList(page, total, list1);
|
|
|
+ }
|
|
|
+
|
|
|
+ public PageList<PaperView> getExamPapers(PaperQuery paperQuery) {
|
|
|
+ int total = paperMapper.countByCriteria(paperQuery);
|
|
|
+ Page page = paperQuery.getPage();
|
|
|
+ List<Paper> list = paperMapper.findPaperByPage(page, paperQuery);
|
|
|
+ List<PaperView> list1 = list.stream()
|
|
|
+ .map(paper -> {
|
|
|
+ int subjectId = paper.getSubjectId();
|
|
|
+ String subject = subjectMapper.findById(subjectId).getName();
|
|
|
+
|
|
|
+ boolean expired = false;
|
|
|
+ LocalDateTime startTime = paper.getStartTime();
|
|
|
+ if (startTime != null) {
|
|
|
+ long expireAt = DateTimeConverter.msTimestamp(startTime) + paper.getDuration()*60*1000L;
|
|
|
+ expired = expireAt < System.currentTimeMillis();
|
|
|
+ }
|
|
|
+ return new PaperView(subject, paper, expired);
|
|
|
})
|
|
|
.collect(Collectors.toList());
|
|
|
|