|
@@ -1,28 +1,39 @@
|
|
|
package cn.com.qmth.stmms.biz.exam.service.impl;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+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 org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
import cn.com.qmth.stmms.biz.common.BaseQueryService;
|
|
|
import cn.com.qmth.stmms.biz.exam.model.ExamStudent;
|
|
|
+import cn.com.qmth.stmms.biz.exam.model.ExamSubject;
|
|
|
import cn.com.qmth.stmms.biz.exam.model.InspectHistory;
|
|
|
import cn.com.qmth.stmms.biz.exam.model.MarkGroup;
|
|
|
import cn.com.qmth.stmms.biz.exam.model.SelectiveGroup;
|
|
|
import cn.com.qmth.stmms.biz.exam.query.ExamStudentSearchQuery;
|
|
|
-import cn.com.qmth.stmms.biz.exam.service.*;
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.ExamStudentService;
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.ExamSubjectService;
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.InspectHistoryService;
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.InspectedService;
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.MarkGroupService;
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.SelectiveGroupService;
|
|
|
import cn.com.qmth.stmms.biz.user.service.UserService;
|
|
|
import cn.com.qmth.stmms.biz.utils.TaskLock;
|
|
|
import cn.com.qmth.stmms.biz.utils.TaskLockUtil;
|
|
|
import cn.com.qmth.stmms.common.enums.SelectiveStatus;
|
|
|
import cn.com.qmth.stmms.common.enums.SubjectiveStatus;
|
|
|
-import org.apache.commons.lang.StringUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
-import javax.persistence.EntityManager;
|
|
|
-import javax.persistence.PersistenceContext;
|
|
|
-import javax.persistence.Query;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
|
|
|
@Service
|
|
|
public class InspectedServiceImpl extends BaseQueryService<ExamStudent> implements InspectedService {
|
|
@@ -32,6 +43,9 @@ public class InspectedServiceImpl extends BaseQueryService<ExamStudent> implemen
|
|
|
|
|
|
@Autowired
|
|
|
private ExamStudentService studentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamSubjectService examSubjectService;
|
|
|
|
|
|
@Autowired
|
|
|
private UserService userService;
|
|
@@ -49,12 +63,12 @@ public class InspectedServiceImpl extends BaseQueryService<ExamStudent> implemen
|
|
|
@Override
|
|
|
public List<ExamStudent> findByQuery(ExamStudentSearchQuery query, SubjectiveStatus status, Integer mainNumber,
|
|
|
Double mainStartScore, Double mainEndScore, Double questionScore, SelectiveStatus selectiveStatus) {
|
|
|
+ int offset=(query.getPageNumber() - 1) * query.getPageSize();
|
|
|
StringBuilder dataSql = new StringBuilder("select s.id from eb_exam_student s ");
|
|
|
- StringBuilder limitSql = new StringBuilder(" limit :offset,:pageSize");
|
|
|
- Query dataQuery = getQuery(query, status, mainNumber, mainStartScore, mainEndScore, questionScore,
|
|
|
- selectiveStatus, dataSql, limitSql);
|
|
|
- dataQuery.setParameter("offset", (query.getPageNumber() - 1) * query.getPageSize());
|
|
|
- dataQuery.setParameter("pageSize", query.getPageSize());
|
|
|
+ String whereSql = getWhereSql(query, status, mainNumber, mainStartScore, mainEndScore, questionScore,
|
|
|
+ selectiveStatus);
|
|
|
+ dataSql.append(whereSql).append(" order by s.inspect_time desc ").append(" limit "+offset+","+query.getPageSize());
|
|
|
+ Query dataQuery = entityManager.createNativeQuery(dataSql.toString());
|
|
|
List<Integer> list = dataQuery.getResultList();
|
|
|
List<ExamStudent> resultList = new ArrayList<ExamStudent>();
|
|
|
if (list != null && !list.isEmpty()) {
|
|
@@ -70,48 +84,60 @@ public class InspectedServiceImpl extends BaseQueryService<ExamStudent> implemen
|
|
|
|
|
|
}
|
|
|
|
|
|
- private Query getQuery(ExamStudentSearchQuery query, SubjectiveStatus status, Integer mainNumber,
|
|
|
- Double mainStartScore, Double mainEndScore, Double questionScore, SelectiveStatus selectiveStatus,
|
|
|
- StringBuilder dataSql, StringBuilder limitSql) {
|
|
|
+ private String getWhereSql(ExamStudentSearchQuery query, SubjectiveStatus status, Integer mainNumber,
|
|
|
+ Double mainStartScore, Double mainEndScore, Double questionScore, SelectiveStatus selectiveStatus) {
|
|
|
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");
|
|
|
+ whereSql.append(" and s.exam_id ="+query.getExamId());
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(query.getSubjectCode())) {
|
|
|
- whereSql.append(" and s.subject_code = :subjectCode ");
|
|
|
+ whereSql.append(" and s.subject_code ='"+query.getSubjectCode()+"'");
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(query.getSubjectCodeIn())) {
|
|
|
- whereSql.append(" and s.subject_code in (:subjectCodeIn) ");
|
|
|
+ String[] subjectCodeIn = query.getSubjectCodeIn().split(",");
|
|
|
+ List<String> in = new ArrayList<String>();
|
|
|
+ for (String code : subjectCodeIn) {
|
|
|
+ in.add(code);
|
|
|
+ }
|
|
|
+ whereSql.append(" and s.subject_code in ('"+StringUtils.join(in, "','")+"') ");
|
|
|
}
|
|
|
+ whereSql.append(" and s.subjective_status IN ('MARKED','INSPECTED')");
|
|
|
if (status != null) {
|
|
|
- whereSql.append(" and s.subjective_status = :status");
|
|
|
- } else {
|
|
|
- whereSql.append(" and s.subjective_status IN ('MARKED','INSPECTED')");
|
|
|
+ if(SubjectiveStatus.MARKED.equals(status)) {
|
|
|
+ whereSql.append(" and not exists(select 1 from eb_inspect_history h "
|
|
|
+ +"left join eb_exam_subject sub on h.exam_id=sub.exam_id and h.subject_code=sub.code "
|
|
|
+ +"where s.id=h.student_id and h.inspect_round=sub.inspect_round) ");
|
|
|
+ }
|
|
|
+ if(SubjectiveStatus.INSPECTED.equals(status)) {
|
|
|
+ whereSql.append(" and exists(select 1 from eb_inspect_history h "
|
|
|
+ +"left join eb_exam_subject sub on h.exam_id=sub.exam_id and h.subject_code=sub.code "
|
|
|
+ +"where s.id=h.student_id and h.inspect_round=sub.inspect_round) ");
|
|
|
+ }
|
|
|
}
|
|
|
if (query.getStartScore() != null) {
|
|
|
whereSql.append(
|
|
|
- " and (cast(s.objective_score as decimal(10,3))+cast(s.subjective_score as decimal(10,3))) >= :startScore");
|
|
|
+ " and (cast(s.objective_score as decimal(10,3))+cast(s.subjective_score as decimal(10,3))) >="+query.getStartScore());
|
|
|
}
|
|
|
if (query.getEndScore() != null) {
|
|
|
whereSql.append(
|
|
|
- " and (cast(s.objective_score as decimal(10,3))+cast(s.subjective_score as decimal(10,3))) <= :endScore");
|
|
|
+ " and (cast(s.objective_score as decimal(10,3))+cast(s.subjective_score as decimal(10,3))) <="+query.getEndScore());
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(query.getSecretNumber())) {
|
|
|
- whereSql.append(" and s.secret_number = :secretNumber");
|
|
|
+ whereSql.append(" and s.secret_number ='"+query.getSecretNumber()+"'");
|
|
|
}
|
|
|
if (mainNumber != null || mainStartScore != null || mainEndScore != null || questionScore != null) {
|
|
|
whereSql.append(" and exists (select e.student_id from eb_subjective_score e where e.student_id = s.id ");
|
|
|
if (mainNumber != null) {
|
|
|
- whereSql.append(" and e.main_number = :mainNumber");
|
|
|
+ whereSql.append(" and e.main_number ="+mainNumber);
|
|
|
}
|
|
|
if (mainStartScore != null) {
|
|
|
- whereSql.append(" and e.main_score >= :mainStartScore");
|
|
|
+ whereSql.append(" and e.main_score >="+mainStartScore);
|
|
|
}
|
|
|
if (mainEndScore != null) {
|
|
|
- whereSql.append(" and e.main_score <= :mainEndScore");
|
|
|
+ whereSql.append(" and e.main_score <="+mainEndScore);
|
|
|
}
|
|
|
if (questionScore != null) {
|
|
|
- whereSql.append(" and e.score = :questionScore");
|
|
|
+ whereSql.append(" and e.score ="+questionScore);
|
|
|
}
|
|
|
whereSql.append(" ) ");
|
|
|
}
|
|
@@ -122,8 +148,13 @@ public class InspectedServiceImpl extends BaseQueryService<ExamStudent> implemen
|
|
|
.findByExamIdAndSubjectCode(query.getExamId(), query.getSubjectCode());
|
|
|
if (selectiveStatus != null && SelectiveStatus.UN_SELECTIVE.equals(selectiveStatus) && !groups.isEmpty()
|
|
|
&& !selectiveGroups.isEmpty()) {
|
|
|
+ List<Integer> groupNumbers = new ArrayList<Integer>();
|
|
|
+ for (int i = 0; i < groups.size(); i++) {
|
|
|
+ groupNumbers.add(groups.get(i).getNumber());
|
|
|
+ }
|
|
|
whereSql.append(
|
|
|
- " and not exists (select e.student_id from eb_subjective_score e where e.student_id = s.id and e.group_number in (:groupNumbers) and e.group_score != -1 )");
|
|
|
+ " and not exists (select e.student_id from eb_subjective_score e where e.student_id = s.id and e.group_number in ("
|
|
|
+ +StringUtils.join(groupNumbers,",")+") and e.group_score != -1 )");
|
|
|
}
|
|
|
// 选做题多选做
|
|
|
if (selectiveStatus != null && SelectiveStatus.MUTI_SELECTIVE.equals(selectiveStatus) && !groups.isEmpty()
|
|
@@ -137,70 +168,31 @@ public class InspectedServiceImpl extends BaseQueryService<ExamStudent> implemen
|
|
|
whereSql.append(
|
|
|
" and exists (select ss.student_id from eb_selective_student ss where ss.student_id = s.id and ss.less_selective=1) ");
|
|
|
}
|
|
|
- dataSql.append(whereSql);
|
|
|
- StringBuilder orderSql = new StringBuilder(" order by s.inspect_time 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 (StringUtils.isNotBlank(query.getSubjectCodeIn())) {
|
|
|
- String[] subjectCodeIn = query.getSubjectCodeIn().split(",");
|
|
|
- List<String> in = new ArrayList<String>();
|
|
|
- for (String code : subjectCodeIn) {
|
|
|
- in.add(code);
|
|
|
- }
|
|
|
- dataQuery.setParameter("subjectCodeIn", in);
|
|
|
- }
|
|
|
- if (status != null) {
|
|
|
- dataQuery.setParameter("status", status.toString());
|
|
|
- }
|
|
|
- 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);
|
|
|
- }
|
|
|
- if (StringUtils.isNotBlank(query.getSecretNumber())) {
|
|
|
- dataQuery.setParameter("secretNumber", query.getSecretNumber());
|
|
|
- }
|
|
|
- if (selectiveStatus != null && !groups.isEmpty() && !selectiveGroups.isEmpty()) {
|
|
|
- if (selectiveStatus == SelectiveStatus.UN_SELECTIVE) {
|
|
|
- List<Integer> groupNumbers = new ArrayList<Integer>();
|
|
|
- for (int i = 0; i < groups.size(); i++) {
|
|
|
- groupNumbers.add(groups.get(i).getNumber());
|
|
|
- }
|
|
|
- dataQuery.setParameter("groupNumbers", groupNumbers);
|
|
|
- }
|
|
|
- }
|
|
|
- return dataQuery;
|
|
|
+ return whereSql.toString();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Integer countByQuery(ExamStudentSearchQuery query, SubjectiveStatus status, Integer mainNumber,
|
|
|
Double mainStartScore, Double mainEndScore, Double questionScore, SelectiveStatus selectiveStatus) {
|
|
|
StringBuilder countSql = new StringBuilder("select count(s.id) from eb_exam_student s ");
|
|
|
- Query countQuery = getQuery(query, status, mainNumber, mainStartScore, mainEndScore, questionScore,
|
|
|
- selectiveStatus, countSql, null);
|
|
|
+ String whereSql = getWhereSql(query, status, mainNumber, mainStartScore, mainEndScore, questionScore,
|
|
|
+ selectiveStatus);
|
|
|
+ countSql.append(whereSql);
|
|
|
+ Query countQuery = entityManager.createNativeQuery(countSql.toString());
|
|
|
+ Object singleResult = countQuery.getResultList().get(0);
|
|
|
+ Integer count = singleResult == null ? 0 : Integer.valueOf(singleResult.toString());
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer needInspectCount(ExamStudentSearchQuery query, Integer mainNumber,
|
|
|
+ Double mainStartScore, Double mainEndScore, Double questionScore,
|
|
|
+ SelectiveStatus selectiveStatus) {
|
|
|
+ StringBuilder countSql = new StringBuilder("select count(s.id) from eb_exam_student s ");
|
|
|
+ String whereSql = getWhereSql(query, SubjectiveStatus.MARKED, mainNumber, mainStartScore, mainEndScore, questionScore,
|
|
|
+ selectiveStatus);
|
|
|
+ countSql.append(whereSql);
|
|
|
+ Query countQuery = entityManager.createNativeQuery(countSql.toString());
|
|
|
Object singleResult = countQuery.getResultList().get(0);
|
|
|
Integer count = singleResult == null ? 0 : Integer.valueOf(singleResult.toString());
|
|
|
return count;
|
|
@@ -250,6 +242,15 @@ public class InspectedServiceImpl extends BaseQueryService<ExamStudent> implemen
|
|
|
@Override
|
|
|
public boolean inspect(ExamStudent student, Integer userId) {
|
|
|
if (this.hasApplied(student, userId) && SubjectiveStatus.MARKED.equals(student.getSubjectiveStatus())) {
|
|
|
+ if (!SubjectiveStatus.MARKED.equals(student.getSubjectiveStatus())
|
|
|
+ &&!SubjectiveStatus.INSPECTED.equals(student.getSubjectiveStatus())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ ExamSubject subject=examSubjectService.find(student.getExamId(), student.getSubjectCode());
|
|
|
+ InspectHistory old=inspectHistoryService.findByStudentIdAndInspectRound(student.getId(),subject.getInspectRound());
|
|
|
+ if(old!=null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
Date now = new Date();
|
|
|
studentService.updateSubjectiveStatusAndTimeAndInspectorId(student.getId(), SubjectiveStatus.INSPECTED, now,
|
|
|
userId);
|
|
@@ -259,6 +260,7 @@ public class InspectedServiceImpl extends BaseQueryService<ExamStudent> implemen
|
|
|
i.setSubjectCode(student.getSubjectCode());
|
|
|
i.setInspectorId(userId);
|
|
|
i.setInspectTime(now);
|
|
|
+ i.setInspectRound(subject.getInspectRound());
|
|
|
inspectHistoryService.save(i);
|
|
|
studentService.updateInspectCount(student.getId(), inspectHistoryService.countByStudentId(student.getId()));
|
|
|
//this.releaseByStudent(student);
|
|
@@ -277,4 +279,46 @@ public class InspectedServiceImpl extends BaseQueryService<ExamStudent> implemen
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void fillInspectHistoryMap(List<ExamStudent> list, int maxInspectRound) {
|
|
|
+ List<Integer> sids=list.stream().map(e->e.getId()).collect(Collectors.toList());
|
|
|
+ List<InspectHistory> ihs=inspectHistoryService.findByStudentIdIn(sids);
|
|
|
+ if(ihs==null||ihs.size()==0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<Integer,Map<String,InspectHistory>> map=new HashMap<>();
|
|
|
+ for(InspectHistory ih:ihs) {
|
|
|
+ Map<String,InspectHistory> tem=map.get(ih.getStudentId());
|
|
|
+ if(tem==null) {
|
|
|
+ tem=new HashMap<>();
|
|
|
+ map.put(ih.getStudentId(),tem);
|
|
|
+ }
|
|
|
+ tem.put(ih.getInspectRound().toString(),ih);
|
|
|
+ }
|
|
|
+ for(ExamStudent es:list) {
|
|
|
+ es.setInspectHistoryMap(map.get(es.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean inspectFinish(Integer examId, String subjectCode, Integer inspectRound) {
|
|
|
+ ExamStudentSearchQuery sQuery = new ExamStudentSearchQuery();
|
|
|
+ sQuery.setExamId(examId);
|
|
|
+ sQuery.setUpload(true);
|
|
|
+ sQuery.setAbsent(false);
|
|
|
+ sQuery.setBreach(false);
|
|
|
+ sQuery.setSubjectCode(subjectCode);
|
|
|
+ long totalPaperCount = studentService.countByQuery(sQuery);
|
|
|
+ StringBuilder countSql = new StringBuilder("select count(s.id) from eb_exam_student s where s.exam_id ="
|
|
|
+ +examId+" and s.subject_code ='"+subjectCode+"'");
|
|
|
+ countSql.append(" and s.subjective_status IN ('MARKED','INSPECTED')");
|
|
|
+ countSql.append(" and exists(select 1 from eb_inspect_history h "
|
|
|
+ +" left join eb_exam_subject sub on h.exam_id=sub.exam_id and h.subject_code=sub.code "
|
|
|
+ +" where s.id=h.student_id and h.inspect_round="+inspectRound+") ");
|
|
|
+ Query countQuery = entityManager.createNativeQuery(countSql.toString());
|
|
|
+ Object singleResult = countQuery.getResultList().get(0);
|
|
|
+ Integer count = singleResult == null ? 0 : Integer.valueOf(singleResult.toString());
|
|
|
+ return totalPaperCount==count;
|
|
|
+ }
|
|
|
}
|