|
@@ -0,0 +1,136 @@
|
|
|
+package cn.com.qmth.stmms.biz.exam.service.impl;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import javax.persistence.EntityManager;
|
|
|
+import javax.persistence.PersistenceContext;
|
|
|
+import javax.persistence.Query;
|
|
|
+
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import cn.com.qmth.stmms.biz.common.BaseQueryService;
|
|
|
+import cn.com.qmth.stmms.biz.exam.model.ExamStudent;
|
|
|
+import cn.com.qmth.stmms.biz.exam.query.ExamStudentSearchQuery;
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.ExamStudentService;
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.InspectedService;
|
|
|
+import cn.com.qmth.stmms.common.enums.SubjectiveStatus;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class InspectedServiceImpl extends BaseQueryService<ExamStudent> implements InspectedService {
|
|
|
+
|
|
|
+ @PersistenceContext
|
|
|
+ private EntityManager entityManager;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamStudentService studentService;
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ @Override
|
|
|
+ public List<ExamStudent> findByQuery(ExamStudentSearchQuery query, SubjectiveStatus status, Integer mainNumber,
|
|
|
+ Double mainStartScore, Double mainEndScore, Double questionScore) {
|
|
|
+ StringBuilder dataSql = new StringBuilder("select distinct s.id "
|
|
|
+ + " from eb_exam_student s left join eb_subjective_score e on e.student_id = s.id ");
|
|
|
+ StringBuilder limitSql = new StringBuilder(" limit :offset,:pageSize");
|
|
|
+ Query dataQuery = getQuery(query, status, mainNumber, mainStartScore, mainEndScore, questionScore, dataSql,
|
|
|
+ limitSql);
|
|
|
+ dataQuery.setParameter("offset", (query.getPageNumber() - 1) * query.getPageSize());
|
|
|
+ dataQuery.setParameter("pageSize", query.getPageSize());
|
|
|
+ List<Integer> list = dataQuery.getResultList();
|
|
|
+ List<ExamStudent> resultList = new ArrayList<ExamStudent>();
|
|
|
+ if (list != null && !list.isEmpty()) {
|
|
|
+ for (Integer id : list) {
|
|
|
+ ExamStudent e = studentService.findById(id);
|
|
|
+ resultList.add(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resultList;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private Query getQuery(ExamStudentSearchQuery query, SubjectiveStatus status, Integer mainNumber,
|
|
|
+ Double mainStartScore, Double mainEndScore, Double questionScore, StringBuilder dataSql,
|
|
|
+ StringBuilder limitSql) {
|
|
|
+ StringBuilder whereSql = new StringBuilder(" WHERE s.is_upload = 1 and s.is_absent = 0 and s.is_breach = 0 ");
|
|
|
+ if (query.getExamId() != null) {
|
|
|
+ whereSql.append(" and s.exam_id = :examId");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(query.getSubjectCode())) {
|
|
|
+ whereSql.append(" and s.subject_code = :subjectCode");
|
|
|
+ }
|
|
|
+ if (status != null) {
|
|
|
+ whereSql.append(" and s.subjective_status = :status");
|
|
|
+ } else {
|
|
|
+ whereSql.append(" and s.subjective_status IN ('MARKED','INSPECTED')");
|
|
|
+ }
|
|
|
+ if (query.getStartScore() != null) {
|
|
|
+ whereSql.append(" and (s.objective_score+s.subjective_score) >= :startScore");
|
|
|
+ }
|
|
|
+ if (query.getEndScore() != null) {
|
|
|
+ whereSql.append(" and (s.objective_score+s.subjective_score) <= :endScore");
|
|
|
+ }
|
|
|
+ if (mainNumber != null) {
|
|
|
+ whereSql.append(" and e.main_number = :mainNumber");
|
|
|
+ }
|
|
|
+ if (mainStartScore != null) {
|
|
|
+ whereSql.append(" and e.main_score >= :mainStartScore");
|
|
|
+ }
|
|
|
+ if (mainEndScore != null) {
|
|
|
+ whereSql.append(" and e.main_score <= :mainEndScore");
|
|
|
+ }
|
|
|
+ if (questionScore != null) {
|
|
|
+ whereSql.append(" and e.score = :questionScore");
|
|
|
+ }
|
|
|
+ dataSql.append(whereSql);
|
|
|
+ // StringBuilder orderSql = new StringBuilder("order by s.id desc ");
|
|
|
+ // dataSql.append(orderSql);
|
|
|
+ if (limitSql != null) {
|
|
|
+ dataSql.append(limitSql);
|
|
|
+ }
|
|
|
+ Query dataQuery = entityManager.createNativeQuery(dataSql.toString());
|
|
|
+
|
|
|
+ if (query.getExamId() != null) {
|
|
|
+ dataQuery.setParameter("examId", query.getExamId());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(query.getSubjectCode())) {
|
|
|
+ dataQuery.setParameter("subjectCode", query.getSubjectCode());
|
|
|
+ }
|
|
|
+ if (status != null) {
|
|
|
+ dataQuery.setParameter("status", status);
|
|
|
+ }
|
|
|
+ if (query.getStartScore() != null) {
|
|
|
+ dataQuery.setParameter("startScore", query.getStartScore());
|
|
|
+ }
|
|
|
+ if (query.getEndScore() != null) {
|
|
|
+ dataQuery.setParameter("endScore", query.getEndScore());
|
|
|
+ }
|
|
|
+ if (mainNumber != null) {
|
|
|
+ dataQuery.setParameter("mainNumber", mainNumber);
|
|
|
+ }
|
|
|
+ if (mainStartScore != null) {
|
|
|
+ dataQuery.setParameter("mainStartScore", mainStartScore);
|
|
|
+ }
|
|
|
+ if (mainEndScore != null) {
|
|
|
+ dataQuery.setParameter("mainEndScore", mainEndScore);
|
|
|
+ }
|
|
|
+ if (questionScore != null) {
|
|
|
+ dataQuery.setParameter("questionScore", questionScore);
|
|
|
+ }
|
|
|
+ return dataQuery;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer countByQuery(ExamStudentSearchQuery query, SubjectiveStatus status, Integer mainNumber,
|
|
|
+ Double mainStartScore, Double mainEndScore, Double questionScore) {
|
|
|
+ StringBuilder countSql = new StringBuilder("select count(distinct s.id) "
|
|
|
+ + "from eb_exam_student s left join eb_subjective_score e on e.student_id = s.id ");
|
|
|
+ Query countQuery = getQuery(query, status, mainNumber, mainStartScore, mainEndScore, questionScore, countSql,
|
|
|
+ null);
|
|
|
+ Object singleResult = countQuery.getResultList().get(0);
|
|
|
+ Integer count = singleResult == null ? 0 : Integer.valueOf(singleResult.toString());
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|