ソースを参照

修改成绩导出功能,在没有可导出科目的情况下,误导出所有考生的bug

luoshi 4 年 前
コミット
b2e390fa9f

+ 46 - 59
stmms-web/src/main/java/cn/com/qmth/stmms/admin/exam/ScoreController.java

@@ -1,42 +1,11 @@
 package cn.com.qmth.stmms.admin.exam;
 
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import net.sf.json.JSONObject;
-
-import org.apache.commons.lang.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.servlet.ModelAndView;
-import org.springframework.web.servlet.mvc.support.RedirectAttributes;
-
 import cn.com.qmth.stmms.admin.dto.ExamStudentDTO;
 import cn.com.qmth.stmms.admin.dto.ScoreEditDTO;
 import cn.com.qmth.stmms.admin.utils.ExportStudentExcel;
-import cn.com.qmth.stmms.biz.exam.model.Exam;
-import cn.com.qmth.stmms.biz.exam.model.ExamPackage;
-import cn.com.qmth.stmms.biz.exam.model.ExamQuestion;
-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.MarkGroup;
+import cn.com.qmth.stmms.biz.exam.model.*;
 import cn.com.qmth.stmms.biz.exam.query.ExamStudentSearchQuery;
-import cn.com.qmth.stmms.biz.exam.service.CheckStudentService;
-import cn.com.qmth.stmms.biz.exam.service.ExamPackageService;
-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.ExamStudentService;
-import cn.com.qmth.stmms.biz.exam.service.ExamSubjectService;
-import cn.com.qmth.stmms.biz.exam.service.MarkGroupService;
+import cn.com.qmth.stmms.biz.exam.service.*;
 import cn.com.qmth.stmms.biz.file.service.FileService;
 import cn.com.qmth.stmms.biz.utils.ScoreItem;
 import cn.com.qmth.stmms.common.annotation.Logging;
@@ -47,6 +16,19 @@ import cn.com.qmth.stmms.common.enums.MarkStatus;
 import cn.com.qmth.stmms.common.enums.Role;
 import cn.com.qmth.stmms.common.utils.ExportExcel;
 import cn.com.qmth.stmms.common.utils.RequestUtils;
+import net.sf.json.JSONObject;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.servlet.ModelAndView;
+import org.springframework.web.servlet.mvc.support.RedirectAttributes;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.*;
 
 @Controller
 @RequestMapping("/admin/exam/score")
@@ -102,8 +84,9 @@ public class ScoreController extends BaseExamController {
             buildPackageUrl(student);
             buildAnswerUrl(student);
         }
-        String exportMessage = StringUtils.isNotBlank(query.getSubjectCode()) ? enableExport(examId,
-                query.getSubjectCode()) : null;
+        String exportMessage = StringUtils.isNotBlank(query.getSubjectCode()) ?
+                enableExport(examId, query.getSubjectCode()) :
+                null;
         if (exportMessage != null) {
             view.addObject("exportMessage", exportMessage);
             view.addObject("enableExport", false);
@@ -210,19 +193,22 @@ public class ScoreController extends BaseExamController {
         String paperType = null;
         try {
             List<ExamStudentDTO> list = new LinkedList<>();
-            String subjectCodeIn = StringUtils.join(subjectSet, ",");
-            query.setSubjectCodeIn(subjectCodeIn);
-            query.setPageNumber(1);
-            query.setPageSize(Integer.MAX_VALUE);
-            query = studentService.findByQuery(query);
-            for (ExamStudent student : query.getResult()) {
-                if (student.isBreach() || student.isAbsent()) {
-                    student.setObjectiveScore(0d);
-                    student.setSubjectiveScore(0d);
-                } else if (paperType == null) {
-                    paperType = student.getPaperType();
+            // 可导出科目不为空时,才能执行查询操作
+            if (!subjectSet.isEmpty()) {
+                String subjectCodeIn = StringUtils.join(subjectSet, ",");
+                query.setSubjectCodeIn(subjectCodeIn);
+                query.setPageNumber(1);
+                query.setPageSize(Integer.MAX_VALUE);
+                query = studentService.findByQuery(query);
+                for (ExamStudent student : query.getResult()) {
+                    if (student.isBreach() || student.isAbsent()) {
+                        student.setObjectiveScore(0d);
+                        student.setSubjectiveScore(0d);
+                    } else if (paperType == null) {
+                        paperType = student.getPaperType();
+                    }
+                    list.add(new ExamStudentDTO(student));
                 }
-                list.add(new ExamStudentDTO(student));
             }
             if (StringUtils.isNotBlank(query.getSubjectCode())) {
                 List<String> headerList = getOptionHeader(exam.getId(), query.getSubjectCode(), paperType);
@@ -242,8 +228,8 @@ public class ScoreController extends BaseExamController {
 
     private List<String> getOptionHeader(int examId, String subjectCode, String paperType) {
         List<String> headerList = new ArrayList<String>();
-        List<ExamQuestion> oQuestions = questionService.findByExamAndSubjectAndObjectiveAndPaperType(examId,
-                subjectCode, true, paperType);
+        List<ExamQuestion> oQuestions = questionService
+                .findByExamAndSubjectAndObjectiveAndPaperType(examId, subjectCode, true, paperType);
         List<ExamQuestion> sQestions = questionService.findByExamAndSubjectAndObjective(examId, subjectCode, false);
         for (ExamQuestion examQuestion : oQuestions) {
             headerList.add(getTitle(examQuestion) + "选项");
@@ -277,8 +263,9 @@ public class ScoreController extends BaseExamController {
     private List<ScoreItem> buildScoreList(ExamStudent student) {
         List<ScoreItem> scoreList = new LinkedList<ScoreItem>();
 
-        List<ExamQuestion> oList = questionService.findByExamAndSubjectAndObjectiveAndPaperType(student.getExamId(),
-                student.getSubjectCode(), true, student.getPaperType());
+        List<ExamQuestion> oList = questionService
+                .findByExamAndSubjectAndObjectiveAndPaperType(student.getExamId(), student.getSubjectCode(), true,
+                        student.getPaperType());
         List<ScoreItem> list1 = student.getScoreList(true);
         int index = 0;
         for (ExamQuestion question : oList) {
@@ -293,8 +280,8 @@ public class ScoreController extends BaseExamController {
         }
         scoreList.addAll(list1);
 
-        List<ExamQuestion> sList = questionService.findByExamAndSubjectAndObjective(student.getExamId(),
-                student.getSubjectCode(), false);
+        List<ExamQuestion> sList = questionService
+                .findByExamAndSubjectAndObjective(student.getExamId(), student.getSubjectCode(), false);
         List<ScoreItem> list2 = student.getScoreList(false);
         index = 0;
         for (ExamQuestion question : sList) {
@@ -317,8 +304,8 @@ public class ScoreController extends BaseExamController {
         // student.setSheetUrls(PictureUrlBuilder
         // .getInnerSheetUrls(student.getExamId(), student.getExamNumber(),
         // student.getSheetCount()));
-        student.setSheetUrls(fileService.getSheetUris(student.getExamId(), student.getExamNumber(), 1,
-                student.getSheetCount()));
+        student.setSheetUrls(
+                fileService.getSheetUris(student.getExamId(), student.getExamNumber(), 1, student.getSheetCount()));
     }
 
     private void buildPackageUrl(ExamStudent student) {
@@ -333,8 +320,8 @@ public class ScoreController extends BaseExamController {
     private void buildAnswerUrl(ExamStudent student) {
         ExamSubject subject = subjectService.find(student.getExamId(), student.getSubjectCode());
         if (subject != null && subject.getAnswerFileType() != null) {
-            student.setAnswerUrl(fileService.getAnswerUri(subject.getExamId(), subject.getCode(),
-                    subject.getAnswerFileType()));
+            student.setAnswerUrl(
+                    fileService.getAnswerUri(subject.getExamId(), subject.getCode(), subject.getAnswerFileType()));
         }
         if (subject != null) {
             student.setSubjectRemark(StringUtils.trimToEmpty(subject.getRemark()));
@@ -347,8 +334,8 @@ public class ScoreController extends BaseExamController {
             return "该科目不存在";
         }
 
-        List<MarkGroup> groups = groupService.findByExamAndSubjectAndStatus(examId, subjectCode, MarkStatus.FORMAL,
-                MarkStatus.TRIAL);
+        List<MarkGroup> groups = groupService
+                .findByExamAndSubjectAndStatus(examId, subjectCode, MarkStatus.FORMAL, MarkStatus.TRIAL);
         if (groups != null && !groups.isEmpty()) {
             return subjectCode + "评卷未完成";
         }