|
@@ -0,0 +1,238 @@
|
|
|
+package cn.com.qmth.stmms.api.controller.admin;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+import org.apache.commons.lang.StringEscapeUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.core.task.AsyncTaskExecutor;
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+
|
|
|
+import com.qmth.boot.core.exception.StatusException;
|
|
|
+
|
|
|
+import cn.com.qmth.stmms.admin.dto.SelectivePartDTO;
|
|
|
+import cn.com.qmth.stmms.admin.thread.SubjectiveCalculateThread;
|
|
|
+import cn.com.qmth.stmms.api.controller.BaseApiController;
|
|
|
+import cn.com.qmth.stmms.biz.exam.bean.ResultMessage;
|
|
|
+import cn.com.qmth.stmms.biz.exam.model.ExamQuestion;
|
|
|
+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.SelectiveGroup;
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.*;
|
|
|
+import cn.com.qmth.stmms.biz.lock.LockService;
|
|
|
+import cn.com.qmth.stmms.biz.mark.service.MarkService;
|
|
|
+import cn.com.qmth.stmms.common.annotation.Logging;
|
|
|
+import cn.com.qmth.stmms.common.domain.ApiUser;
|
|
|
+import cn.com.qmth.stmms.common.enums.LockType;
|
|
|
+import cn.com.qmth.stmms.common.enums.LogType;
|
|
|
+import cn.com.qmth.stmms.common.enums.ScorePolicy;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import net.sf.json.JSONArray;
|
|
|
+import net.sf.json.JSONObject;
|
|
|
+
|
|
|
+@Api(tags = "选做题管理")
|
|
|
+@Controller("adminSelectiveGroupController")
|
|
|
+@RequestMapping("/api/admin/selective")
|
|
|
+public class SelectiveGroupController extends BaseApiController {
|
|
|
+
|
|
|
+ protected static Logger log = LoggerFactory.getLogger(SelectiveGroupController.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamQuestionService questionService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MarkGroupService groupService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamSubjectService subjectService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SelectiveGroupService selectiveGroupService;
|
|
|
+
|
|
|
+ @Qualifier("task-executor")
|
|
|
+ @Autowired
|
|
|
+ private AsyncTaskExecutor taskExecutor;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LockService lockService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MarkService markService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamStudentService studentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MarkerService markerService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InspectedService inspectedService;
|
|
|
+
|
|
|
+ @ApiOperation(value = "选做题分组列表")
|
|
|
+ @RequestMapping(value = "/group", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public List<SelectiveGroup> query(@RequestParam String subjectCode) {
|
|
|
+ int examId = getSessionExamId();
|
|
|
+ return selectiveGroupService.findIndexByExamIdAndSubjectCode(examId, subjectCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "选做题列表")
|
|
|
+ @RequestMapping(value = "/question", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public List<ExamQuestion> question(@RequestParam String subjectCode) {
|
|
|
+ int examId = getSessionExamId();
|
|
|
+ List<SelectiveGroup> list = selectiveGroupService.findByExamIdAndSubjectCode(examId, subjectCode);
|
|
|
+ Map<Integer, SelectiveGroup> map = new HashMap<Integer, SelectiveGroup>();
|
|
|
+ for (SelectiveGroup selectiveGroup : list) {
|
|
|
+ map.put(selectiveGroup.getMainNumber(), selectiveGroup);
|
|
|
+ }
|
|
|
+ List<ExamQuestion> questions = questionService.findByExamAndSubjectAndObjective(examId, subjectCode, false);
|
|
|
+ for (ExamQuestion examQuestion : questions) {
|
|
|
+ if (map.containsKey(examQuestion.getMainNumber())) {
|
|
|
+ examQuestion.setSelective(true);
|
|
|
+ examQuestion.setSelectiveIndex(map.get(examQuestion.getMainNumber()).getSelectiveIndex());
|
|
|
+ examQuestion.setSelectivePart(map.get(examQuestion.getMainNumber()).getSelectivePart());
|
|
|
+ examQuestion.setScorePolicy(map.get(examQuestion.getMainNumber()).getScorePolicy().getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return questions;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "取分规则")
|
|
|
+ @RequestMapping(value = "scorePolicys", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public List<ScorePolicy> scorePolicyList() {
|
|
|
+ ScorePolicy[] scorePolicyList = { ScorePolicy.MAX, ScorePolicy.MIN, ScorePolicy.MIN_WITHOUT_ZERO };
|
|
|
+ return Arrays.asList(scorePolicyList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "选做题组新增")
|
|
|
+ @Logging(menu = "选做题新增", type = LogType.ADD)
|
|
|
+ @RequestMapping(value = "/group/save", method = RequestMethod.POST)
|
|
|
+ @Transactional
|
|
|
+ public ResultMessage save(@RequestParam String subjectCode, @RequestParam Integer selectiveCount,
|
|
|
+ @RequestParam Integer scorePolicy, @RequestParam Integer selectivePart,
|
|
|
+ @RequestParam(required = true, defaultValue = "false") Boolean enableAllSelectiveAdd,
|
|
|
+ @RequestParam String parts) {
|
|
|
+ int examId = getSessionExamId();
|
|
|
+ if (selectiveCount >= selectivePart) {
|
|
|
+ throw new StatusException("选做题数量不能大于已选择题目数量");
|
|
|
+ }
|
|
|
+ List<MarkGroup> groups = groupService.findByExamAndSubject(examId, subjectCode);
|
|
|
+ if (groups != null && groups.size() > 0) {
|
|
|
+ throw new StatusException("该科目已经存在分组,无法设置");
|
|
|
+ }
|
|
|
+ List<SelectivePartDTO> partList = getPartList(parts);
|
|
|
+ if (checkTotalScore(examId, subjectCode, partList)) {
|
|
|
+ throw new StatusException("选做题区分数必须一样");
|
|
|
+ }
|
|
|
+ int index = selectiveGroupService.findMaxIndexByExamIdAndSubjectCode(examId, subjectCode);
|
|
|
+ List<SelectiveGroup> list = new ArrayList<SelectiveGroup>();
|
|
|
+ for (SelectivePartDTO part : partList) {
|
|
|
+ for (Integer mainNumber : part.getMainNumbers()) {
|
|
|
+ list.add(new SelectiveGroup(examId, subjectCode, mainNumber, index + 1, selectiveCount,
|
|
|
+ part.getSelectivePart(), ScorePolicy.findByValue(scorePolicy)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ selectiveGroupService.save(list);
|
|
|
+ subjectService.updateSelective(examId, subjectCode, true);
|
|
|
+ subjectService.updateScore(examId, subjectCode, false,
|
|
|
+ questionService.sumTotalScore(examId, subjectCode, false));
|
|
|
+ ExamSubject subject = subjectService.find(examId, subjectCode);
|
|
|
+ if (subject.isEnableAllSelective() != enableAllSelectiveAdd) {
|
|
|
+ subjectService.updateEnableAllSelective(examId, subjectCode, enableAllSelectiveAdd);
|
|
|
+ }
|
|
|
+ return resultOk();
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean checkTotalScore(int examId, String subjectCode, List<SelectivePartDTO> parts) {
|
|
|
+ List<ExamQuestion> questions = questionService.findMainByExamAndSubjectAndObjective(examId, subjectCode, false);
|
|
|
+ Map<Integer, ExamQuestion> map = new HashMap<Integer, ExamQuestion>();
|
|
|
+ for (ExamQuestion examQuestion : questions) {
|
|
|
+ map.put(examQuestion.getMainNumber(), examQuestion);
|
|
|
+ }
|
|
|
+ Set<Double> scores = new HashSet<Double>();
|
|
|
+ for (SelectivePartDTO part : parts) {
|
|
|
+ double totalScore = 0;
|
|
|
+ for (Integer mainNumber : part.getMainNumbers()) {
|
|
|
+ totalScore = totalScore + map.get(mainNumber).getTotalScore();
|
|
|
+ }
|
|
|
+ scores.add(totalScore);
|
|
|
+ }
|
|
|
+ return scores.size() > 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<SelectivePartDTO> getPartList(String parts) {
|
|
|
+ List<SelectivePartDTO> list = new ArrayList<SelectivePartDTO>();
|
|
|
+ if (StringUtils.isNotBlank(parts)) {
|
|
|
+ parts = StringEscapeUtils.unescapeHtml(parts);
|
|
|
+ JSONArray array = JSONArray.fromObject(parts);
|
|
|
+ for (int i = 0; i < array.size(); i++) {
|
|
|
+ JSONObject part = array.getJSONObject(i);
|
|
|
+ SelectivePartDTO dto = new SelectivePartDTO();
|
|
|
+ dto.setSelectivePart(part.getInt("selectivePart"));
|
|
|
+ List<Integer> mainNumbers = new ArrayList<Integer>();
|
|
|
+ JSONArray mainNumberArr = part.getJSONArray("mainNumbers");
|
|
|
+ for (Object object : mainNumberArr) {
|
|
|
+ mainNumbers.add(Integer.parseInt(object.toString()));
|
|
|
+ }
|
|
|
+ dto.setMainNumbers(mainNumbers);
|
|
|
+ list.add(dto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "选做题组删除")
|
|
|
+ @Logging(menu = "删除选做题", type = LogType.DELETE)
|
|
|
+ @RequestMapping(value = "/group/delete", method = RequestMethod.POST)
|
|
|
+ @Transactional
|
|
|
+ public ResultMessage delete(@RequestParam String subjectCode, @RequestParam Integer selectiveIndex) {
|
|
|
+ int examId = getSessionExamId();
|
|
|
+ List<MarkGroup> groups = groupService.findByExamAndSubject(examId, subjectCode);
|
|
|
+ if (groups != null && groups.size() > 0) {
|
|
|
+ throw new StatusException("该科目已经存在分组,无法设置");
|
|
|
+ }
|
|
|
+ selectiveGroupService.deleteByExamIdAndSubjectCodeAndSelectiveIndex(examId, subjectCode, selectiveIndex);
|
|
|
+ return resultOk();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "选做题区分规则修改")
|
|
|
+ @Logging(menu = "修改选做题取分规则", type = LogType.UPDATE)
|
|
|
+ @RequestMapping(value = "/group/edit", method = RequestMethod.POST)
|
|
|
+ @Transactional
|
|
|
+ public ResultMessage edit(@RequestParam String subjectCode, @RequestParam Integer selectiveIndex,
|
|
|
+ @RequestParam Integer policy,
|
|
|
+ @RequestParam(required = true, defaultValue = "false") Boolean enableAllSelective) {
|
|
|
+ int examId = getSessionExamId();
|
|
|
+ if (lockService.isLocked(LockType.SCORE_CALCULATE, examId, subjectCode)) {
|
|
|
+ throw new StatusException("正在统分中,请稍后再试");
|
|
|
+ }
|
|
|
+ ExamSubject subject = subjectService.find(examId, subjectCode);
|
|
|
+ if (subject.isEnableAllSelective() != enableAllSelective) {
|
|
|
+ subjectService.updateEnableAllSelective(examId, subjectCode, enableAllSelective);
|
|
|
+ }
|
|
|
+ List<SelectiveGroup> list = selectiveGroupService.findByExamIdAndSubjectCodeAndSelectiveIndex(examId,
|
|
|
+ subjectCode, selectiveIndex);
|
|
|
+ if (!list.isEmpty() && list.get(0).getScorePolicy().equals(ScorePolicy.findByValue(policy))) {
|
|
|
+ return resultOk();
|
|
|
+ } else {
|
|
|
+ selectiveGroupService.updateScorePolicy(examId, subjectCode, selectiveIndex,
|
|
|
+ ScorePolicy.findByValue(policy));
|
|
|
+ SubjectiveCalculateThread thread = new SubjectiveCalculateThread(examId, subjectCode, markService,
|
|
|
+ lockService, questionService, groupService, markerService, inspectedService, studentService);
|
|
|
+ taskExecutor.submit(thread);
|
|
|
+ }
|
|
|
+ return resultOk();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|