|
@@ -1,11 +1,16 @@
|
|
|
package cn.com.qmth.stmms.biz.exam.service.impl;
|
|
|
|
|
|
-import cn.com.qmth.stmms.biz.common.BaseQueryService;
|
|
|
-import cn.com.qmth.stmms.biz.exam.dao.ExamQuestionDao;
|
|
|
-import cn.com.qmth.stmms.biz.exam.model.ExamQuestion;
|
|
|
-import cn.com.qmth.stmms.biz.exam.service.ExamQuestionService;
|
|
|
-import cn.com.qmth.stmms.biz.exam.service.query.ExamQuestionSearchQuery;
|
|
|
-import cn.com.qmth.stmms.common.enums.ObjectivePolicy;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.LinkedHashSet;
|
|
|
+import java.util.LinkedList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+import javax.persistence.criteria.CriteriaBuilder;
|
|
|
+import javax.persistence.criteria.CriteriaQuery;
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
+import javax.persistence.criteria.Root;
|
|
|
+
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Sort;
|
|
@@ -14,12 +19,14 @@ import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import javax.persistence.criteria.CriteriaBuilder;
|
|
|
-import javax.persistence.criteria.CriteriaQuery;
|
|
|
-import javax.persistence.criteria.Predicate;
|
|
|
-import javax.persistence.criteria.Root;
|
|
|
-import java.util.LinkedList;
|
|
|
-import java.util.List;
|
|
|
+import cn.com.qmth.stmms.biz.common.BaseQueryService;
|
|
|
+import cn.com.qmth.stmms.biz.exam.dao.ExamQuestionDao;
|
|
|
+import cn.com.qmth.stmms.biz.exam.model.ExamQuestion;
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.ExamQuestionService;
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.ExamService;
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.query.ExamQuestionSearchQuery;
|
|
|
+import cn.com.qmth.stmms.common.enums.ObjectivePolicy;
|
|
|
+import cn.com.qmth.stmms.common.enums.ObjectiveStatus;
|
|
|
|
|
|
@Service
|
|
|
public class ExamQuestionServiceImpl extends BaseQueryService<ExamQuestion> implements ExamQuestionService {
|
|
@@ -27,6 +34,9 @@ public class ExamQuestionServiceImpl extends BaseQueryService<ExamQuestion> impl
|
|
|
@Autowired
|
|
|
private ExamQuestionDao questionDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ExamService examService;
|
|
|
+
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public ExamQuestion save(ExamQuestion question) {
|
|
@@ -67,20 +77,20 @@ public class ExamQuestionServiceImpl extends BaseQueryService<ExamQuestion> impl
|
|
|
@Override
|
|
|
public List<ExamQuestion> findByExamAndSubjectAndObjectiveAndPaperType(Integer examId, String subjectCode,
|
|
|
boolean objective, String paperType) {
|
|
|
- return questionDao.findByExamIdAndSubjectCodeAndObjectiveAndPaperType(examId, subjectCode, objective, paperType,
|
|
|
- new Sort(Direction.ASC, "mainNumber", "subNumber"));
|
|
|
+ return questionDao.findByExamIdAndSubjectCodeAndObjectiveAndPaperType(examId, subjectCode, objective,
|
|
|
+ paperType, new Sort(Direction.ASC, "mainNumber", "subNumber"));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<ExamQuestion> findByExamAndSubjectAndObjectiveAndGroupNumber(Integer examId, String subjectCode,
|
|
|
boolean objective, Integer groupNumber) {
|
|
|
- return questionDao
|
|
|
- .findByExamIdAndSubjectCodeAndObjectiveAndGroupNumber(examId, subjectCode, objective, groupNumber);
|
|
|
+ return questionDao.findByExamIdAndSubjectCodeAndObjectiveAndGroupNumber(examId, subjectCode, objective,
|
|
|
+ groupNumber);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<ExamQuestion> findByExamAndSubjectAndObjectiveAndGroupNumberNotEqual(Integer examId, String subjectCode,
|
|
|
- boolean objective, Integer groupNumber) {
|
|
|
+ public List<ExamQuestion> findByExamAndSubjectAndObjectiveAndGroupNumberNotEqual(Integer examId,
|
|
|
+ String subjectCode, boolean objective, Integer groupNumber) {
|
|
|
return questionDao.findByExamIdAndSubjectCodeAndObjectiveAndGroupNumberNotEqual(examId, subjectCode, objective,
|
|
|
groupNumber);
|
|
|
}
|
|
@@ -88,8 +98,8 @@ public class ExamQuestionServiceImpl extends BaseQueryService<ExamQuestion> impl
|
|
|
@Override
|
|
|
public List<ExamQuestion> findByExamAndSubjectAndObjectiveAndMainNumber(Integer examId, String subjectCode,
|
|
|
boolean objective, Integer mainNumber) {
|
|
|
- return questionDao
|
|
|
- .findByExamIdAndSubjectCodeAndObjectiveAndMainNumber(examId, subjectCode, objective, mainNumber);
|
|
|
+ return questionDao.findByExamIdAndSubjectCodeAndObjectiveAndMainNumber(examId, subjectCode, objective,
|
|
|
+ mainNumber);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -108,8 +118,8 @@ public class ExamQuestionServiceImpl extends BaseQueryService<ExamQuestion> impl
|
|
|
@Override
|
|
|
public long countByExamAndSubjectAndObjectiveAndMainNumber(Integer examId, String subjectCode, boolean objective,
|
|
|
Integer mainNumber) {
|
|
|
- return questionDao
|
|
|
- .countByExamIdAndSubjectCodeAndObjectiveAndMainNumber(examId, subjectCode, objective, mainNumber);
|
|
|
+ return questionDao.countByExamIdAndSubjectCodeAndObjectiveAndMainNumber(examId, subjectCode, objective,
|
|
|
+ mainNumber);
|
|
|
}
|
|
|
|
|
|
private Specification<ExamQuestion> buildSpecification(final ExamQuestionSearchQuery query) {
|
|
@@ -127,8 +137,6 @@ public class ExamQuestionServiceImpl extends BaseQueryService<ExamQuestion> impl
|
|
|
}
|
|
|
if (query.getPaperType() != null) {
|
|
|
predicates.add(cb.equal(root.get("paperType"), query.getPaperType()));
|
|
|
- } else if (query.getNullPaperType() != null && query.getNullPaperType().booleanValue()) {
|
|
|
- predicates.add(cb.isNull(root.get("paperType")));
|
|
|
}
|
|
|
if (query.getObjective() != null) {
|
|
|
predicates.add(cb.equal(root.get("objective"), query.getObjective()));
|
|
@@ -146,9 +154,8 @@ public class ExamQuestionServiceImpl extends BaseQueryService<ExamQuestion> impl
|
|
|
if (query.getMainNumber() != null) {
|
|
|
predicates.add(cb.equal(root.get("mainNumber"), query.getMainNumber()));
|
|
|
}
|
|
|
- return predicates.isEmpty() ?
|
|
|
- cb.conjunction() :
|
|
|
- cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ return predicates.isEmpty() ? cb.conjunction() : cb.and(predicates.toArray(new Predicate[predicates
|
|
|
+ .size()]));
|
|
|
}
|
|
|
};
|
|
|
}
|
|
@@ -167,22 +174,15 @@ public class ExamQuestionServiceImpl extends BaseQueryService<ExamQuestion> impl
|
|
|
@Override
|
|
|
public long countByExamAndSubjectAndObjectiveAndMainNumberAndPaperType(Integer examId, String subjectCode,
|
|
|
boolean objective, Integer mainNumber, String paperType) {
|
|
|
- return questionDao
|
|
|
- .countByExamIdAndSubjectCodeAndObjectiveAndMainNumber(examId, subjectCode, objective, mainNumber,
|
|
|
- paperType);
|
|
|
+ return questionDao.countByExamIdAndSubjectCodeAndObjectiveAndMainNumber(examId, subjectCode, objective,
|
|
|
+ mainNumber, paperType);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public long countByExamAndSubjectAndObjectiveAndMainNumberAndSubNumber(Integer examId, String subjectCode,
|
|
|
boolean objective, Integer mainNumber, Integer subNumber) {
|
|
|
- return questionDao
|
|
|
- .countByExamIdAndSubjectCodeAndObjectiveAndMainNumberAndSubNumber(examId, subjectCode, objective,
|
|
|
- mainNumber, subNumber);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<String> getPaperTypeWitnNull(Integer examId, String subjectCode) {
|
|
|
- return questionDao.getPaperTypeWitnNull(examId, subjectCode, true);
|
|
|
+ return questionDao.countByExamIdAndSubjectCodeAndObjectiveAndMainNumberAndSubNumber(examId, subjectCode,
|
|
|
+ objective, mainNumber, subNumber);
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
@@ -191,7 +191,7 @@ public class ExamQuestionServiceImpl extends BaseQueryService<ExamQuestion> impl
|
|
|
ExamQuestion question = questionDao.findOne(questionId);
|
|
|
question.setObjectivePolicy(objectivePolicy);
|
|
|
questionDao.save(question);
|
|
|
- // TODO - 修改后需要重新统分
|
|
|
+ examService.updateObjectiveStatus(question.getExamId(), ObjectiveStatus.WAITING);
|
|
|
return question;
|
|
|
}
|
|
|
|
|
@@ -200,4 +200,25 @@ public class ExamQuestionServiceImpl extends BaseQueryService<ExamQuestion> impl
|
|
|
return questionDao.findOne(questionId);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ExamQuestion findByExamAndSubjectAndObjectiveAndMainNumberAndSubNumber(Integer examId, String subjectCode,
|
|
|
+ boolean objective, Integer mainNumber, Integer subNumber) {
|
|
|
+ return questionDao.findByExamIdAndSubjectCodeAndObjectiveAndMainNumberAndSubNumber(examId, subjectCode,
|
|
|
+ objective, mainNumber, subNumber);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ExamQuestion> findMainByExamAndSubjectAndObjective(Integer examId, String subjectCode, boolean objective) {
|
|
|
+ List<ExamQuestion> list = new ArrayList<ExamQuestion>();
|
|
|
+ Set<Integer> mainNumbers = new LinkedHashSet<>();
|
|
|
+ List<ExamQuestion> all = questionDao.findByExamIdAndSubjectCodeAndObjective(examId, subjectCode, objective);
|
|
|
+ for (ExamQuestion q : all) {
|
|
|
+ if (!mainNumbers.contains(q.getMainNumber())) {
|
|
|
+ mainNumbers.add(q.getMainNumber());
|
|
|
+ list.add(q);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
}
|