|
|
@@ -1,7 +1,6 @@
|
|
|
package cn.iselab.mooctest.site.service.impl;
|
|
|
|
|
|
import cn.iselab.mooctest.site.dao.*;
|
|
|
-import cn.iselab.mooctest.site.data.CaseBlock;
|
|
|
import cn.iselab.mooctest.site.models.*;
|
|
|
import cn.iselab.mooctest.site.service.BaseService;
|
|
|
import cn.iselab.mooctest.site.service.ExamService;
|
|
|
@@ -10,7 +9,7 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.shiro.authz.UnauthorizedException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
-
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.data.jpa.domain.Specifications;
|
|
|
@@ -33,13 +32,15 @@ public class ExamServiceImpl extends BaseService implements ExamService {
|
|
|
@Autowired
|
|
|
GroupDao groupDao;
|
|
|
@Autowired
|
|
|
- ExamGroupUserDao examGroupUserDao;
|
|
|
+ ParticipantExamDao participantExamDao;
|
|
|
@Autowired
|
|
|
Task2GroupDao task2GroupDao;
|
|
|
@Autowired
|
|
|
Exam2PaperDao exam2PaperDao;
|
|
|
@Autowired
|
|
|
- Exam2CaseDao exam2CaseDao;
|
|
|
+ AssistManagerExamDao assistManagerExamDao;
|
|
|
+ @Autowired
|
|
|
+ ContestMentorExamDao contestMentorExamDao;
|
|
|
|
|
|
@Override
|
|
|
public Page<Task> getExams(Long organizerId, Byte type, Integer status, String keyword, Pageable pageable) {
|
|
|
@@ -49,18 +50,33 @@ public class ExamServiceImpl extends BaseService implements ExamService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Page<ExamGroupUser> getExamsByParticipantId(Long participantId, Byte type, Integer status, String keyword, Pageable pageable) {
|
|
|
- Specifications<ExamGroupUser> where = Specifications.where(getExamUserWhereClause(participantId,status, type, keyword));
|
|
|
- return examGroupUserDao.findAll(where, pageable);
|
|
|
+ public Page<ParticipantExam> getExamsByParticipantId(Long participantId, Byte type, Integer status, String keyword, Pageable pageable) {
|
|
|
+ Specifications<ParticipantExam> where = Specifications.where(
|
|
|
+ getExamListQuery(ParticipantExam.class,"participantId",participantId,status, type, keyword));
|
|
|
+ return participantExamDao.findAll(where, pageable);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<AssistManagerExam> getExamsByAssistManagerId(Long assistManagerId, Byte type, Integer status, String keyword, PageRequest pageable) {
|
|
|
+ Specifications<AssistManagerExam> where = Specifications.where(
|
|
|
+ getExamListQuery(AssistManagerExam.class,"assistManagerId",assistManagerId,status, type, keyword));
|
|
|
+ return assistManagerExamDao.findAll(where, pageable);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<ContestMentorExam> getExamsByContestMentorId(Long contestMentorId, Byte type, Integer status, String keyword, PageRequest pageable) {
|
|
|
+ Specifications<ContestMentorExam> where = Specifications.where(
|
|
|
+ getExamListQuery(ContestMentorExam.class,"ContestMentorId",contestMentorId,status, type, keyword));
|
|
|
+ return contestMentorExamDao.findAll(where, pageable);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Task getExamByIdAndParticipantIdIfPermited(Long examId, Long participantId) {
|
|
|
- ExamGroupUser examGroupUser = examGroupUserDao.findByIdAndParticipantId(examId, participantId);
|
|
|
- if(examGroupUser == null){
|
|
|
+ ParticipantExam participantExam = participantExamDao.findByIdAndParticipantId(examId, participantId);
|
|
|
+ if(participantExam == null){
|
|
|
throw new UnauthorizedException("unauthorized");
|
|
|
}
|
|
|
- return Converter.convert(Task.class, examGroupUser);
|
|
|
+ return Converter.convert(Task.class, participantExam);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -141,14 +157,15 @@ public class ExamServiceImpl extends BaseService implements ExamService {
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
- private Specification<ExamGroupUser> getExamUserWhereClause(Long participantId, Integer status, Byte type, String keyword) {
|
|
|
- return new Specification<ExamGroupUser>() {
|
|
|
+ private <T> Specification<T> getExamListQuery(Class<T> model,String JoinedUserColumn,Long userId, Integer status, Byte type, String keyword) {
|
|
|
+ return new Specification<T>(){
|
|
|
+
|
|
|
@Override
|
|
|
- public Predicate toPredicate(Root<ExamGroupUser> a, CriteriaQuery<?> q, CriteriaBuilder cb) {
|
|
|
+ public Predicate toPredicate(Root a, CriteriaQuery q, CriteriaBuilder cb) {
|
|
|
Predicate predicate = cb.conjunction();
|
|
|
- if(participantId!=null) {
|
|
|
+ if(userId!=null) {
|
|
|
predicate.getExpressions().add(
|
|
|
- cb.equal(a.<Long>get("participantId"), participantId)
|
|
|
+ cb.equal(a.<Long>get(JoinedUserColumn), userId)
|
|
|
);
|
|
|
}
|
|
|
if(status!=null) {
|