|
@@ -1,32 +1,39 @@
|
|
package cn.com.qmth.stmms.api.controller.admin;
|
|
package cn.com.qmth.stmms.api.controller.admin;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
|
-
|
|
|
|
|
|
+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;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import com.qmth.boot.core.collection.PageResult;
|
|
import com.qmth.boot.core.collection.PageResult;
|
|
|
|
|
|
import cn.com.qmth.stmms.api.controller.BaseApiController;
|
|
import cn.com.qmth.stmms.api.controller.BaseApiController;
|
|
-import cn.com.qmth.stmms.api.exception.ApiException;
|
|
|
|
|
|
+import cn.com.qmth.stmms.biz.exam.bean.ExamVo;
|
|
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.query.ExamSearchQuery;
|
|
import cn.com.qmth.stmms.biz.exam.query.ExamSearchQuery;
|
|
import cn.com.qmth.stmms.biz.exam.service.ExamService;
|
|
import cn.com.qmth.stmms.biz.exam.service.ExamService;
|
|
-import cn.com.qmth.stmms.biz.school.service.SchoolService;
|
|
|
|
|
|
+import cn.com.qmth.stmms.biz.mark.model.PictureConfigItem;
|
|
|
|
+import cn.com.qmth.stmms.biz.user.model.User;
|
|
import cn.com.qmth.stmms.biz.utils.PageUtil;
|
|
import cn.com.qmth.stmms.biz.utils.PageUtil;
|
|
|
|
+import cn.com.qmth.stmms.common.annotation.Logging;
|
|
import cn.com.qmth.stmms.common.domain.ApiUser;
|
|
import cn.com.qmth.stmms.common.domain.ApiUser;
|
|
import cn.com.qmth.stmms.common.enums.ExamStatus;
|
|
import cn.com.qmth.stmms.common.enums.ExamStatus;
|
|
import cn.com.qmth.stmms.common.enums.ExamType;
|
|
import cn.com.qmth.stmms.common.enums.ExamType;
|
|
-import cn.com.qmth.stmms.common.utils.RequestUtils;
|
|
|
|
|
|
+import cn.com.qmth.stmms.common.enums.LogType;
|
|
|
|
+import cn.com.qmth.stmms.common.enums.ObjectiveStatus;
|
|
|
|
+import cn.com.qmth.stmms.common.enums.TrackCountPolicy;
|
|
|
|
+import net.sf.json.JSONArray;
|
|
|
|
+import net.sf.json.JSONObject;
|
|
|
|
+import net.sf.json.JsonConfig;
|
|
|
|
|
|
@Controller("adminExamController")
|
|
@Controller("adminExamController")
|
|
@RequestMapping("/api/admin/exam")
|
|
@RequestMapping("/api/admin/exam")
|
|
@@ -38,40 +45,115 @@ public class ExamController extends BaseApiController {
|
|
private ExamService examService;
|
|
private ExamService examService;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- private SchoolService schoolService;
|
|
|
|
|
|
+ // private SchoolService schoolService;
|
|
|
|
|
|
- private Exam validateExam(ApiUser au, Integer examId, ExamType... types) {
|
|
|
|
- Exam exam = examService.findById(examId);
|
|
|
|
- if (exam == null || !validateSchool(au.getSchoolId(), exam.getSchoolId())
|
|
|
|
- || exam.getStatus() != ExamStatus.START) {
|
|
|
|
- throw ApiException.EXAM_NOT_ACCESSIBLED;
|
|
|
|
- }
|
|
|
|
- if (types != null && types.length > 0 && !Arrays.asList(types).contains(exam.getType())) {
|
|
|
|
- throw ApiException.QUERY_PARAM_ERROR.replaceMessage("exam type invalid");
|
|
|
|
- }
|
|
|
|
- return exam;
|
|
|
|
- }
|
|
|
|
|
|
+ // private Exam validateExam(ApiUser au, Integer examId, ExamType... types)
|
|
|
|
+ // {
|
|
|
|
+ // Exam exam = examService.findById(examId);
|
|
|
|
+ // if (exam == null || !validateSchool(au.getSchoolId(), exam.getSchoolId())
|
|
|
|
+ // || exam.getStatus() != ExamStatus.START) {
|
|
|
|
+ // throw ApiException.EXAM_NOT_ACCESSIBLED;
|
|
|
|
+ // }
|
|
|
|
+ // if (types != null && types.length > 0 &&
|
|
|
|
+ // !Arrays.asList(types).contains(exam.getType())) {
|
|
|
|
+ // throw ApiException.QUERY_PARAM_ERROR.replaceMessage("exam type invalid");
|
|
|
|
+ // }
|
|
|
|
+ // return exam;
|
|
|
|
+ // }
|
|
|
|
|
|
- @RequestMapping(value = "/list", method = RequestMethod.POST)
|
|
|
|
|
|
+ @RequestMapping(value = "list", method = RequestMethod.POST)
|
|
@ResponseBody
|
|
@ResponseBody
|
|
- public PageResult<Exam> list(HttpServletRequest request, ExamSearchQuery query) {
|
|
|
|
- ApiUser user = RequestUtils.getApiUser(request);
|
|
|
|
|
|
+ public PageResult<Exam> list(ExamSearchQuery query) {
|
|
|
|
+ ApiUser user = getApiUser();
|
|
query.setSchoolId(user.getSchoolId());
|
|
query.setSchoolId(user.getSchoolId());
|
|
query.orderByIdDesc();
|
|
query.orderByIdDesc();
|
|
query = examService.findByQuery(query);
|
|
query = examService.findByQuery(query);
|
|
return PageUtil.of(query);
|
|
return PageUtil.of(query);
|
|
}
|
|
}
|
|
|
|
|
|
- @RequestMapping(value = "/types", method = RequestMethod.POST)
|
|
|
|
|
|
+ @RequestMapping(value = "types", method = RequestMethod.POST)
|
|
@ResponseBody
|
|
@ResponseBody
|
|
public List<ExamType> examTypeList() {
|
|
public List<ExamType> examTypeList() {
|
|
return Arrays.asList(ExamType.values());
|
|
return Arrays.asList(ExamType.values());
|
|
}
|
|
}
|
|
|
|
|
|
- @RequestMapping(value = "/status", method = RequestMethod.POST)
|
|
|
|
|
|
+ @RequestMapping(value = "status", method = RequestMethod.POST)
|
|
@ResponseBody
|
|
@ResponseBody
|
|
public List<ExamStatus> statusLlist() {
|
|
public List<ExamStatus> statusLlist() {
|
|
return Arrays.asList(ExamStatus.values());
|
|
return Arrays.asList(ExamStatus.values());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @ResponseBody
|
|
|
|
+ @RequestMapping(value = "find", method = RequestMethod.POST)
|
|
|
|
+ public ExamVo find(@RequestParam Integer examId) {
|
|
|
|
+ Exam exam = examService.findById(examId);
|
|
|
|
+ return ExamVo.of(exam);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ResponseBody
|
|
|
|
+ @Logging(menu = "创建考试", type = LogType.ADD)
|
|
|
|
+ @RequestMapping(value = "save", method = RequestMethod.POST)
|
|
|
|
+ public void save(@RequestBody ExamVo vo) {
|
|
|
|
+ User user = getApiUser().getUser();
|
|
|
|
+ Exam exam = ExamVo.of(vo);
|
|
|
|
+ exam.setSchoolId(user.getSchoolId());
|
|
|
|
+ exam.setCreatorId(user.getId());
|
|
|
|
+ exam.setStatus(ExamStatus.START);
|
|
|
|
+ exam.setTrackCountPolicy(TrackCountPolicy.LE);
|
|
|
|
+ exam.setObjectiveStatus(ObjectiveStatus.WAITING);
|
|
|
|
+ if (exam.getType().equals(ExamType.MULTI_MEDIA)) {
|
|
|
|
+ exam.setForceSpecialTag(false);
|
|
|
|
+ }
|
|
|
|
+ JSONObject sasConfig = new JSONObject();
|
|
|
|
+ sasConfig.accumulate("passScore", vo.getPassScore());
|
|
|
|
+ sasConfig.accumulate("excellentScore", vo.getExcellentScore());
|
|
|
|
+ exam.setSasConfig(sasConfig.toString());
|
|
|
|
+ exam = examService.save(exam);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ResponseBody
|
|
|
|
+ @Logging(menu = "编辑考试", type = LogType.UPDATE)
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
+ @RequestMapping(value = "edit", method = RequestMethod.POST)
|
|
|
|
+ public void edit(@RequestBody ExamVo exam) {
|
|
|
|
+ User user = getApiUser().getUser();
|
|
|
|
+ Exam oldExam = examService.findById(exam.getId());
|
|
|
|
+ if (oldExam != null && oldExam.getSchoolId().equals(user.getSchoolId())) {
|
|
|
|
+ oldExam.setName(exam.getName());
|
|
|
|
+ oldExam.setExamTime(exam.getExamTime());
|
|
|
|
+ oldExam.setDescription(exam.getDescription());
|
|
|
|
+ oldExam.setStatus(exam.getStatus());
|
|
|
|
+ oldExam.setForceSpecialTag(exam.getForceSpecialTag());
|
|
|
|
+ oldExam.setForbiddenInfo(exam.getForbiddenInfo());
|
|
|
|
+ if (exam.getForbiddenInfo()) {
|
|
|
|
+ oldExam.setForbiddenScore(exam.getForbiddenScore());
|
|
|
|
+ } else {
|
|
|
|
+ oldExam.setForbiddenScore(false);
|
|
|
|
+ }
|
|
|
|
+ oldExam.setEnableSplit(exam.getEnableSplit());
|
|
|
|
+ oldExam.setAutoScroll(exam.getAutoScroll());
|
|
|
|
+ oldExam.setShowReject(exam.getShowReject());
|
|
|
|
+ JSONObject sasConfig = new JSONObject();
|
|
|
|
+ sasConfig.accumulate("passScore", exam.getPassScore());
|
|
|
|
+ sasConfig.accumulate("excellentScore", exam.getExcellentScore());
|
|
|
|
+ oldExam.setSasConfig(sasConfig.toString());
|
|
|
|
+ if (StringUtils.isNotBlank(exam.getSheetConfig())) {
|
|
|
|
+ String sheetConfig = exam.getSheetConfig();
|
|
|
|
+ JSONArray array = JSONArray.fromObject(sheetConfig);
|
|
|
|
+ List<PictureConfigItem> list = JSONArray.toList(array, new PictureConfigItem(), new JsonConfig());
|
|
|
|
+ oldExam.setSheetConfig(list == null ? null : StringUtils.join(list, PictureConfigItem.DB_ITEM_JOINER));
|
|
|
|
+ }
|
|
|
|
+ oldExam.setStartTime(exam.getStartTime());
|
|
|
|
+ oldExam.setEndTime(exam.getEndTime());
|
|
|
|
+ oldExam.setMarkMode(exam.getMarkMode());
|
|
|
|
+ oldExam.setSheetView(exam.getSheetView());
|
|
|
|
+ oldExam.setInspectScrollBottom(exam.getInspectScrollBottom());
|
|
|
|
+ oldExam.setInspectUnrepeated(exam.getInspectUnrepeated());
|
|
|
|
+ oldExam.setShowObjectiveScore(exam.getShowObjectiveScore());
|
|
|
|
+ oldExam.setRemarkCount(exam.getRemarkCount());
|
|
|
|
+ oldExam.setInspectRoundLimit(exam.getInspectRoundLimit());
|
|
|
|
+ oldExam.setTrackCountPolicy(exam.getTrackCountPolicy());
|
|
|
|
+ examService.save(oldExam);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|