|
@@ -1,26 +1,5 @@
|
|
|
package cn.com.qmth.stmms.biz.exam.service.impl;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.Comparator;
|
|
|
-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;
|
|
|
-import org.springframework.data.domain.Sort.Direction;
|
|
|
-import org.springframework.data.jpa.domain.Specification;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
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;
|
|
@@ -29,7 +8,20 @@ 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;
|
|
|
-import cn.com.qmth.stmms.common.utils.BigDecimalUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.data.domain.Sort.Direction;
|
|
|
+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.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
public class ExamQuestionServiceImpl extends BaseQueryService<ExamQuestion> implements ExamQuestionService {
|
|
@@ -96,8 +88,8 @@ public class ExamQuestionServiceImpl extends BaseQueryService<ExamQuestion> impl
|
|
|
return j;
|
|
|
}
|
|
|
} else {
|
|
|
- return Integer.parseUnsignedInt(o1.getSubNumber())
|
|
|
- - Integer.parseUnsignedInt(o2.getSubNumber());
|
|
|
+ return Integer.parseUnsignedInt(o1.getSubNumber()) - Integer
|
|
|
+ .parseUnsignedInt(o2.getSubNumber());
|
|
|
}
|
|
|
}
|
|
|
return i;
|
|
@@ -109,8 +101,8 @@ public class ExamQuestionServiceImpl extends BaseQueryService<ExamQuestion> impl
|
|
|
@Override
|
|
|
public List<ExamQuestion> findByExamAndSubjectAndObjectiveGroupByNumber(Integer examId, String subjectCode,
|
|
|
boolean objective) {
|
|
|
- List<ExamQuestion> list = questionDao.findByExamIdAndSubjectCodeAndObjectiveGroupByNumber(examId, subjectCode,
|
|
|
- objective);
|
|
|
+ List<ExamQuestion> list = questionDao
|
|
|
+ .findByExamIdAndSubjectCodeAndObjectiveGroupByNumber(examId, subjectCode, objective);
|
|
|
questionSort(list);
|
|
|
return list;
|
|
|
}
|
|
@@ -118,8 +110,9 @@ public class ExamQuestionServiceImpl extends BaseQueryService<ExamQuestion> impl
|
|
|
@Override
|
|
|
public List<ExamQuestion> findByExamAndSubjectAndObjectiveAndPaperType(Integer examId, String subjectCode,
|
|
|
boolean objective, String paperType) {
|
|
|
- List<ExamQuestion> list = questionDao.findByExamIdAndSubjectCodeAndObjectiveAndPaperType(examId, subjectCode,
|
|
|
- objective, paperType, new Sort(Direction.ASC, "mainNumber", "subNumber"));
|
|
|
+ List<ExamQuestion> list = questionDao
|
|
|
+ .findByExamIdAndSubjectCodeAndObjectiveAndPaperType(examId, subjectCode, objective, paperType,
|
|
|
+ new Sort(Direction.ASC, "mainNumber", "subNumber"));
|
|
|
if (objective) {
|
|
|
list = questionSort(list);
|
|
|
}
|
|
@@ -129,13 +122,13 @@ public class ExamQuestionServiceImpl extends BaseQueryService<ExamQuestion> impl
|
|
|
@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);
|
|
|
}
|
|
@@ -143,8 +136,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
|
|
@@ -169,8 +162,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) {
|
|
@@ -205,8 +198,9 @@ 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()]));
|
|
|
}
|
|
|
};
|
|
|
}
|
|
@@ -225,15 +219,17 @@ 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, String subNumber) {
|
|
|
- return questionDao.countByExamIdAndSubjectCodeAndObjectiveAndMainNumberAndSubNumber(examId, subjectCode,
|
|
|
- objective, mainNumber, subNumber);
|
|
|
+ return questionDao
|
|
|
+ .countByExamIdAndSubjectCodeAndObjectiveAndMainNumberAndSubNumber(examId, subjectCode, objective,
|
|
|
+ mainNumber, subNumber);
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
@@ -254,25 +250,28 @@ public class ExamQuestionServiceImpl extends BaseQueryService<ExamQuestion> impl
|
|
|
@Override
|
|
|
public ExamQuestion findByExamAndSubjectAndObjectiveAndMainNumberAndSubNumber(Integer examId, String subjectCode,
|
|
|
boolean objective, Integer mainNumber, String subNumber) {
|
|
|
- return questionDao.findByExamIdAndSubjectCodeAndObjectiveAndMainNumberAndSubNumber(examId, subjectCode,
|
|
|
- objective, mainNumber, subNumber);
|
|
|
+ return questionDao
|
|
|
+ .findByExamIdAndSubjectCodeAndObjectiveAndMainNumberAndSubNumber(examId, subjectCode, objective,
|
|
|
+ mainNumber, subNumber);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<ExamQuestion> findMainByExamAndSubjectAndObjective(Integer examId, String subjectCode, boolean objective) {
|
|
|
+ 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<ExamQuestion> questions = questionDao.findByExamIdAndSubjectCodeAndObjectiveAndMainNumber(examId,
|
|
|
- subjectCode, objective, q.getMainNumber());
|
|
|
- double totalScore = 0;
|
|
|
+ List<ExamQuestion> questions = questionDao
|
|
|
+ .findByExamIdAndSubjectCodeAndObjectiveAndMainNumber(examId, subjectCode, objective,
|
|
|
+ q.getMainNumber());
|
|
|
+ BigDecimal totalScore = BigDecimal.ZERO;
|
|
|
for (ExamQuestion examQuestion : questions) {
|
|
|
- totalScore = BigDecimalUtils.add(totalScore, examQuestion.getTotalScore());
|
|
|
+ totalScore = totalScore.add(BigDecimal.valueOf(examQuestion.getTotalScore()));
|
|
|
}
|
|
|
- q.setTotalScore(totalScore);
|
|
|
+ q.setTotalScore(totalScore.doubleValue());
|
|
|
list.add(q);
|
|
|
}
|
|
|
}
|