|
@@ -6,6 +6,10 @@ import java.util.List;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
+import net.sf.json.JSONArray;
|
|
|
|
+import net.sf.json.JSONObject;
|
|
|
|
+
|
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -17,25 +21,27 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
-import com.google.common.base.Strings;
|
|
|
|
-
|
|
|
|
import cn.com.qmth.stmms.api.utils.AESUtil;
|
|
import cn.com.qmth.stmms.api.utils.AESUtil;
|
|
import cn.com.qmth.stmms.biz.api.auth.annotation.AuthValidate;
|
|
import cn.com.qmth.stmms.biz.api.auth.annotation.AuthValidate;
|
|
import cn.com.qmth.stmms.biz.campus.model.Campus;
|
|
import cn.com.qmth.stmms.biz.campus.model.Campus;
|
|
import cn.com.qmth.stmms.biz.campus.service.CampusService;
|
|
import cn.com.qmth.stmms.biz.campus.service.CampusService;
|
|
import cn.com.qmth.stmms.biz.exam.model.Exam;
|
|
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.ExamStudent;
|
|
import cn.com.qmth.stmms.biz.exam.query.ExamStudentSearchQuery;
|
|
import cn.com.qmth.stmms.biz.exam.query.ExamStudentSearchQuery;
|
|
import cn.com.qmth.stmms.biz.exam.service.ExamPackageService;
|
|
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.ExamService;
|
|
import cn.com.qmth.stmms.biz.exam.service.ExamStudentService;
|
|
import cn.com.qmth.stmms.biz.exam.service.ExamStudentService;
|
|
-import net.sf.json.JSONArray;
|
|
|
|
-import net.sf.json.JSONObject;
|
|
|
|
|
|
+import cn.com.qmth.stmms.biz.user.model.User;
|
|
|
|
+import cn.com.qmth.stmms.biz.utils.ScoreItem;
|
|
|
|
+import cn.com.qmth.stmms.common.utils.RequestUtils;
|
|
|
|
+
|
|
|
|
+import com.google.common.base.Strings;
|
|
|
|
|
|
@Controller("examStudentApiController")
|
|
@Controller("examStudentApiController")
|
|
@RequestMapping("/api")
|
|
@RequestMapping("/api")
|
|
-public class ExamStudentController {
|
|
|
|
|
|
+public class ExamStudentController extends BaseApiController {
|
|
|
|
|
|
protected static Logger logger = LoggerFactory.getLogger(ExamStudentController.class);
|
|
protected static Logger logger = LoggerFactory.getLogger(ExamStudentController.class);
|
|
|
|
|
|
@@ -50,41 +56,9 @@ public class ExamStudentController {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private ExamPackageService packageService;
|
|
private ExamPackageService packageService;
|
|
-
|
|
|
|
- @RequestMapping(value = "/package/{examId}", method = RequestMethod.GET)
|
|
|
|
- @ResponseBody
|
|
|
|
- public JSONArray getPackageCode(HttpServletRequest request, @PathVariable Integer examId) {
|
|
|
|
- JSONArray array = new JSONArray();
|
|
|
|
- Exam exam = examService.findById(examId);
|
|
|
|
- if (exam == null) {
|
|
|
|
- return array;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- List<String> list = examStudentService.findDistinctPackageCode(examId);
|
|
|
|
- if (list != null) {
|
|
|
|
- for (String code : list) {
|
|
|
|
- array.add(code);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return array;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @AuthValidate({ "adminUser", "scanner" })
|
|
|
|
- @RequestMapping(value = "/package/{examId}", method = RequestMethod.POST)
|
|
|
|
- @ResponseBody
|
|
|
|
- public int updatePackage(HttpServletRequest request, @PathVariable Integer examId,
|
|
|
|
- @RequestBody ExamPackage examPackage) {
|
|
|
|
- Exam exam = examService.findById(examId);
|
|
|
|
- if (exam != null) {
|
|
|
|
- ExamPackage obj = packageService.find(examId, examPackage.getCode());
|
|
|
|
- if (obj != null && examPackage.getPicCount() != null) {
|
|
|
|
- obj.setPicCount(examPackage.getPicCount());
|
|
|
|
- obj = packageService.save(obj);
|
|
|
|
- return obj.getPicCount();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return -1;
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ExamQuestionService questionService;
|
|
|
|
|
|
@AuthValidate({ "adminUser", "scanner" })
|
|
@AuthValidate({ "adminUser", "scanner" })
|
|
@RequestMapping(value = "/exam/students/{examId}", method = RequestMethod.GET)
|
|
@RequestMapping(value = "/exam/students/{examId}", method = RequestMethod.GET)
|
|
@@ -185,6 +159,124 @@ public class ExamStudentController {
|
|
}
|
|
}
|
|
return obj;
|
|
return obj;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @AuthValidate("adminUser")
|
|
|
|
+ @RequestMapping("/students/count/{examId}")
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public long getStudentCount(HttpServletRequest request, @PathVariable Integer examId,
|
|
|
|
+ @RequestParam(required = false) Boolean upload, @RequestParam(required = false) Boolean absent) {
|
|
|
|
+ User user = RequestUtils.getApiUser(request);
|
|
|
|
+ Exam exam = examService.findById(examId);
|
|
|
|
+ if (exam != null && exam.getSchoolId().equals(user.getSchoolId())) {
|
|
|
|
+ ExamStudentSearchQuery query = new ExamStudentSearchQuery();
|
|
|
|
+ query.setExamId(examId);
|
|
|
|
+ query.setUpload(upload);
|
|
|
|
+ query.setAbsent(absent);
|
|
|
|
+ return examStudentService.countByQuery(query);
|
|
|
|
+ }
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @AuthValidate("adminUser")
|
|
|
|
+ @RequestMapping("/exam/students")
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public JSONArray getStudent(HttpServletRequest request, ExamStudentSearchQuery query,
|
|
|
|
+ @RequestParam(required = false) Boolean withScoreDetail) {
|
|
|
|
+ User user = RequestUtils.getApiUser(request);
|
|
|
|
+ JSONArray array = new JSONArray();
|
|
|
|
+ if (query.getExamId() == null) {
|
|
|
|
+ return array;
|
|
|
|
+ }
|
|
|
|
+ Exam exam = examService.findById(query.getExamId());
|
|
|
|
+ if (exam != null && exam.getSchoolId().equals(user.getSchoolId())) {
|
|
|
|
+ DecimalFormat format = new DecimalFormat("####.##");
|
|
|
|
+ examStudentService.findByQuery(query);
|
|
|
|
+ for (ExamStudent student : query.getResult()) {
|
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
|
+ obj.accumulate("id", student.getId());
|
|
|
|
+ obj.accumulate("schoolId", student.getSchoolId());
|
|
|
|
+ obj.accumulate("examNumber", student.getExamNumber());
|
|
|
|
+ obj.accumulate("campusName", student.getCampusName());
|
|
|
|
+ obj.accumulate("subjectCode", student.getSubjectCode());
|
|
|
|
+ obj.accumulate("subjectName", student.getSubjectName());
|
|
|
|
+ obj.accumulate("name", student.getName());
|
|
|
|
+ obj.accumulate("studentCode", student.getStudentCode());
|
|
|
|
+ obj.accumulate("packageCode", student.getPackageCode());
|
|
|
|
+ obj.accumulate("batchCode", student.getBatchCode() == null ? "" : student.getBatchCode());
|
|
|
|
+ obj.accumulate("sheetCount", student.getSheetCount() != null ? student.getSheetCount() : 0);
|
|
|
|
+ obj.accumulate("sliceCount", student.getSliceCount() != null ? student.getSliceCount() : 0);
|
|
|
|
+ obj.accumulate("answers", StringUtils.trimToEmpty(student.getAnswers()));
|
|
|
|
+ obj.accumulate("upload", student.isUpload());
|
|
|
|
+ obj.accumulate("absent", student.isAbsent());
|
|
|
|
+ obj.accumulate("manualAbsent", student.isManualAbsent());
|
|
|
|
+ obj.accumulate("breach", student.isBreach());
|
|
|
|
+ obj.accumulate("objectiveScore",
|
|
|
|
+ student.getObjectiveScore() == null ? "" : format.format(student.getObjectiveScore()));
|
|
|
|
+ obj.accumulate("subjectiveScore",
|
|
|
|
+ student.getSubjectiveScore() == null ? "" : format.format(student.getSubjectiveScore()));
|
|
|
|
+ obj.accumulate("examSite", StringUtils.trimToEmpty(student.getExamSite()));
|
|
|
|
+ obj.accumulate("examRoom", StringUtils.trimToEmpty(student.getExamRoom()));
|
|
|
|
+ obj.accumulate("remark", StringUtils.trimToEmpty(student.getRemark()));
|
|
|
|
+ Campus campus = campusService.findBySchoolAndName(student.getSchoolId(), student.getCampusName());
|
|
|
|
+ obj.accumulate("campusCode", campus != null ? campus.getId().toString() : "");
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ if (withScoreDetail != null && withScoreDetail.booleanValue()) {
|
|
|
|
+ // 构造客观题得分明细
|
|
|
|
+ JSONArray objective = new JSONArray();
|
|
|
|
+ List<ScoreItem> scoreList = student.getScoreList(true);
|
|
|
|
+ List<ExamQuestion> questionList = questionService
|
|
|
|
+ .findByExamAndSubjectAndObjective(student.getExamId(), student.getSubjectCode(), true);
|
|
|
|
+ int i = 0;
|
|
|
|
+ for (ScoreItem item : scoreList) {
|
|
|
|
+ i++;
|
|
|
|
+ if (questionList.size() < i) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ ExamQuestion question = questionList.get(i - 1);
|
|
|
|
+ if (question.getTotalScore() == null || question.getTotalScore() == 0) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ JSONObject detail = new JSONObject();
|
|
|
|
+ detail.accumulate("mainNumber", question.getMainNumber());
|
|
|
|
+ detail.accumulate("subNumber", question.getSubNumber());
|
|
|
|
+ detail.accumulate("score", item.getScore());
|
|
|
|
+ detail.accumulate("answer", item.getAnswer());
|
|
|
|
+ objective.add(detail);
|
|
|
|
+ }
|
|
|
|
+ obj.accumulate("objectiveScoreDetail", objective);
|
|
|
|
+
|
|
|
|
+ // 构造主观题得分明细
|
|
|
|
+ JSONArray subjective = new JSONArray();
|
|
|
|
+ scoreList = student.getScoreList(false);
|
|
|
|
+ questionList = questionService.findByExamAndSubjectAndObjective(student.getExamId(),
|
|
|
|
+ student.getSubjectCode(), false);
|
|
|
|
+ i = 0;
|
|
|
|
+ for (ScoreItem item : scoreList) {
|
|
|
|
+ i++;
|
|
|
|
+ if (questionList.size() < i) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ ExamQuestion question = questionList.get(i - 1);
|
|
|
|
+ if (question.getTotalScore() == null || question.getTotalScore() == 0) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ JSONObject detail = new JSONObject();
|
|
|
|
+ detail.accumulate("mainNumber", question.getMainNumber());
|
|
|
|
+ detail.accumulate("subNumber", question.getSubNumber());
|
|
|
|
+ detail.accumulate("score", item.getScore());
|
|
|
|
+ subjective.add(detail);
|
|
|
|
+ }
|
|
|
|
+ obj.accumulate("subjectiveScoreDetail", subjective);
|
|
|
|
+ }
|
|
|
|
+ array.add(obj);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ logger.error("student api error", e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return array;
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
@@ -279,4 +371,6 @@ public class ExamStudentController {
|
|
String result = obj.toString();
|
|
String result = obj.toString();
|
|
return encrypt ? AESUtil.encrypt(result) : result;
|
|
return encrypt ? AESUtil.encrypt(result) : result;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|