|
@@ -0,0 +1,592 @@
|
|
|
+package cn.com.qmth.stmms.api.controller.admin;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
+import org.apache.commons.lang.StringEscapeUtils;
|
|
|
+import org.apache.commons.lang.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.beans.factory.annotation.Value;
|
|
|
+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.thread.MarkGroupDeleteThread;
|
|
|
+import cn.com.qmth.stmms.api.controller.BaseApiController;
|
|
|
+import cn.com.qmth.stmms.biz.config.service.impl.SystemCache;
|
|
|
+import cn.com.qmth.stmms.biz.exam.bean.ResultMessage;
|
|
|
+import cn.com.qmth.stmms.biz.exam.dao.SelectiveStudentDao;
|
|
|
+import cn.com.qmth.stmms.biz.exam.model.*;
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.*;
|
|
|
+import cn.com.qmth.stmms.biz.file.service.FileService;
|
|
|
+import cn.com.qmth.stmms.biz.lock.LockService;
|
|
|
+import cn.com.qmth.stmms.biz.mark.model.MarkConfigItem;
|
|
|
+import cn.com.qmth.stmms.biz.mark.service.MarkService;
|
|
|
+import cn.com.qmth.stmms.biz.school.model.School;
|
|
|
+import cn.com.qmth.stmms.biz.school.service.SchoolService;
|
|
|
+import cn.com.qmth.stmms.common.annotation.Logging;
|
|
|
+import cn.com.qmth.stmms.common.domain.ApiUser;
|
|
|
+import cn.com.qmth.stmms.common.enums.*;
|
|
|
+import cn.com.qmth.stmms.common.utils.RequestUtils;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import net.sf.json.JSONArray;
|
|
|
+import net.sf.json.JSONObject;
|
|
|
+import net.sf.json.JsonConfig;
|
|
|
+
|
|
|
+@Api(tags = "分组管理")
|
|
|
+@Controller("adminExamGroupController")
|
|
|
+@RequestMapping("/api/admin/exam/group")
|
|
|
+public class MarkGroupController extends BaseApiController {
|
|
|
+
|
|
|
+ protected static Logger log = LoggerFactory.getLogger(MarkGroupController.class);
|
|
|
+
|
|
|
+ public static final String SPLIT = ",";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamSubjectService subjectService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamQuestionService questionService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MarkGroupService groupService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MarkerService markerService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamStudentService studentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MarkService markService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LockService lockService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamService examService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FileService fileService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SelectiveGroupService selectiveGroupService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InspectHistoryService inspectHistoryService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SchoolService schoolService;
|
|
|
+
|
|
|
+ @Qualifier("task-executor")
|
|
|
+ @Autowired
|
|
|
+ private AsyncTaskExecutor taskExecutor;
|
|
|
+
|
|
|
+ @Value("${mark.group.delete}")
|
|
|
+ private String markDeleteCode;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SystemCache systemCache;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SelectiveStudentDao selectiveStudentDao;
|
|
|
+
|
|
|
+ @ApiOperation(value = "分组查询")
|
|
|
+ @Logging(menu = "大题查询", type = LogType.QUERY)
|
|
|
+ @RequestMapping(value = "query", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public List<MarkGroup> query(@RequestParam String subjectCode) {
|
|
|
+ ApiUser wu = getApiUser();
|
|
|
+ int examId = getSessionExamId();
|
|
|
+ ExamSubject subject = subjectService.find(examId, subjectCode);
|
|
|
+ if (subject == null) {
|
|
|
+ throw new StatusException("科目不能为空");
|
|
|
+ }
|
|
|
+ List<MarkGroup> list = groupService.findByExamAndSubject(examId, subject.getCode());
|
|
|
+ for (MarkGroup group : list) {
|
|
|
+ List<ExamQuestion> qList = questionService.findByExamAndSubjectAndObjectiveAndGroupNumber(examId,
|
|
|
+ subject.getCode(), false, group.getNumber());
|
|
|
+ group.setQuestionList(qList);
|
|
|
+ group.setMarkerCount(
|
|
|
+ markerService.countByExamAndSubjectAndGroup(examId, subject.getCode(), group.getNumber()));
|
|
|
+ group.setCurrentCount(markService.applyCount(group));
|
|
|
+ int percent = group.getLibraryCount() > 0
|
|
|
+ ? (int) (group.getMarkedCount() * 100.00 / group.getLibraryCount())
|
|
|
+ : 0;
|
|
|
+ if (group.getMarkedCount() > 0 && percent == 0) {
|
|
|
+ percent = 1;
|
|
|
+ } else if (group.getLeftCount() > 0 && percent == 100) {
|
|
|
+ percent = 99;
|
|
|
+ }
|
|
|
+ group.setPercent(percent);
|
|
|
+ group.setDeleting(lockService.isLocked(LockType.GROUP_DELETE, group.getExamId(), group.getSubjectCode(),
|
|
|
+ group.getNumber()));
|
|
|
+ if (!qList.isEmpty() && group.isSelective()) {
|
|
|
+ SelectiveGroup selectiveGroup = selectiveGroupService.findOne(examId, group.getSubjectCode(),
|
|
|
+ qList.get(0).getMainNumber());
|
|
|
+ if (selectiveGroup != null) {
|
|
|
+ group.setSelectiveIndex(selectiveGroup.getSelectiveIndex());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "分组下拉查询")
|
|
|
+ @RequestMapping(value = "/list", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public List<MarkGroup> list(@RequestParam String subjectCode, @RequestParam(required = false) Boolean withDouble,
|
|
|
+ @RequestParam(required = false) MarkStatus status) {
|
|
|
+ int examId = getSessionExamId();
|
|
|
+ List<MarkGroup> list = withDouble != null && withDouble
|
|
|
+ ? groupService.findByExamAndSubjectWithDouble(examId, subjectCode)
|
|
|
+ : (status != null ? groupService.findByExamAndSubjectAndStatus(examId, subjectCode, status)
|
|
|
+ : groupService.findByExamAndSubject(examId, subjectCode));
|
|
|
+ for (MarkGroup group : list) {
|
|
|
+ group.setQuestionList(questionService.findByExamAndSubjectAndObjectiveAndGroupNumber(examId, subjectCode,
|
|
|
+ false, group.getNumber()));
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "新增分组")
|
|
|
+ @Logging(menu = "新增大题", type = LogType.ADD)
|
|
|
+ @RequestMapping(value = "/insert", method = RequestMethod.POST)
|
|
|
+ @Transactional
|
|
|
+ @ResponseBody
|
|
|
+ public ResultMessage insert(@RequestParam String subjectCode, @RequestParam Integer number,
|
|
|
+ @RequestParam Integer[] questionIds, @RequestParam String picList,
|
|
|
+ @RequestParam(required = false) Double doubleRate,
|
|
|
+ @RequestParam(required = false) Double arbitrateThreshold,
|
|
|
+ @RequestParam(required = false) Integer thirdPolicy, @RequestParam(required = false) Integer scorePolicy,
|
|
|
+ @RequestParam(required = false) String arbitrateThresholdList,
|
|
|
+ @RequestParam(required = false) Integer arbitrateType, @RequestParam(required = false) String markMode,
|
|
|
+ @RequestParam(required = false) Integer trialCount,
|
|
|
+ @RequestParam(required = false, defaultValue = "false") boolean sheetView,
|
|
|
+ @RequestParam(defaultValue = "false") boolean enableAllZero) {
|
|
|
+ int examId = getSessionExamId();
|
|
|
+ Exam exam = examService.findById(examId);
|
|
|
+ MarkGroup group = groupService.findOne(examId, subjectCode, number);
|
|
|
+ if (group != null) {
|
|
|
+ throw new StatusException("评卷分组序号不能重复");
|
|
|
+ } else if (questionIds == null || questionIds.length <= 0) {
|
|
|
+ throw new StatusException("题目不能为空");
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ // create group
|
|
|
+ // build picList
|
|
|
+ List<MarkConfigItem> picConfigList = null;
|
|
|
+ if (!exam.getType().equals(ExamType.MULTI_MEDIA)) {
|
|
|
+ picList = StringEscapeUtils.unescapeHtml(StringUtils.trimToNull(picList));
|
|
|
+ JSONArray array = JSONArray.fromObject(picList);
|
|
|
+ picConfigList = JSONArray.toList(array, new MarkConfigItem(), new JsonConfig());
|
|
|
+ }
|
|
|
+ List<ExamQuestion> list = new ArrayList<ExamQuestion>();
|
|
|
+ BigDecimal totalScore = BigDecimal.ZERO;
|
|
|
+ boolean selective = false;
|
|
|
+ List<Double> arbitrateThresholds = buildDoubleList(arbitrateThresholdList);
|
|
|
+ for (int i = 0; i < questionIds.length; i++) {
|
|
|
+ Integer questionId = questionIds[i];
|
|
|
+ ExamQuestion question = questionService.findById(questionId);
|
|
|
+ question.setGroupNumber(number);
|
|
|
+ if (doubleRate != null && doubleRate > 0
|
|
|
+ && ArbitrateType.QUESTION.equals(ArbitrateType.findByValue(arbitrateType))) {
|
|
|
+ question.setArbitrateThreshold(arbitrateThresholds.get(i));
|
|
|
+ } else {
|
|
|
+ question.setArbitrateThreshold(null);
|
|
|
+ }
|
|
|
+ list.add(question);
|
|
|
+ totalScore = totalScore.add(BigDecimal.valueOf(question.getTotalScore()));
|
|
|
+ if (selective == false
|
|
|
+ && selectiveGroupService.findOne(examId, subjectCode, question.getMainNumber()) != null) {
|
|
|
+ selective = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (trialCount != null && trialCount > 0) {
|
|
|
+ subjectService.updateTrialCount(examId, subjectCode, trialCount);
|
|
|
+ }
|
|
|
+ if (this.groupService.countByExamAndSubjectAndStatus(examId, subjectCode, MarkStatus.TRIAL) > 0) {
|
|
|
+ ExamSubject subject = subjectService.find(examId, subjectCode);
|
|
|
+ trialCount = subject.getTrialCount();
|
|
|
+ }
|
|
|
+ group = new MarkGroup(examId, subjectCode, number, picConfigList, totalScore.doubleValue(), doubleRate,
|
|
|
+ arbitrateThreshold, scorePolicy, arbitrateType, markMode, trialCount, sheetView, enableAllZero,
|
|
|
+ thirdPolicy, selective);
|
|
|
+ // clear and replace exam_question
|
|
|
+ questionService.save(list);
|
|
|
+ groupService.save(group);
|
|
|
+
|
|
|
+ studentService.updateSubjectiveStatusAndScore(examId, subjectCode, SubjectiveStatus.UNMARK, 0, null);
|
|
|
+ inspectHistoryService.deleteByExamIdAndSubjectCode(examId, subjectCode);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("add markgroup error", e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new StatusException("新增失败!失败信息:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resultOk();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "分组修改")
|
|
|
+ @Logging(menu = "分组修改", type = LogType.UPDATE)
|
|
|
+ @RequestMapping(value = "/update", method = RequestMethod.POST)
|
|
|
+ @Transactional
|
|
|
+ @ResponseBody
|
|
|
+ public ResultMessage update(HttpServletRequest request, @RequestParam String subjectCode,
|
|
|
+ @RequestParam Integer number, @RequestParam Boolean reset, @RequestParam(required = false) String picList,
|
|
|
+ @RequestParam(required = false) Double doubleRate,
|
|
|
+ @RequestParam(required = false) Double arbitrateThreshold,
|
|
|
+ @RequestParam(required = false) Integer thirdPolicy, @RequestParam(required = false) Integer scorePolicy,
|
|
|
+ @RequestParam(required = false) Integer arbitrateType, @RequestParam(required = false) MarkMode markMode,
|
|
|
+ @RequestParam(required = false) Integer trialCount,
|
|
|
+ @RequestParam(required = false, defaultValue = "false") Boolean sheetView,
|
|
|
+ @RequestParam(required = false, defaultValue = "false") Boolean enableAllZero,
|
|
|
+ @RequestParam(required = false) Integer[] questionIds,
|
|
|
+ @RequestParam(required = false) String intervalScoreList,
|
|
|
+ @RequestParam(required = false) String arbitrateThresholdList,
|
|
|
+ @RequestParam(required = false) String deleteCode) {
|
|
|
+ int examId = getSessionExamId();
|
|
|
+ Exam exam = examService.findById(examId);
|
|
|
+ MarkGroup group = groupService.findOne(examId, subjectCode, number);
|
|
|
+ if (group != null) {
|
|
|
+ try {
|
|
|
+ if (questionIds != null && reset.booleanValue()) {
|
|
|
+ // advance update
|
|
|
+ School school = schoolService.findById(exam.getSchoolId());
|
|
|
+ boolean warn = systemCache.isGroupDeleteWarn() ? true : school.isGroupDeleteCheck();
|
|
|
+ if (warn && group.getLibraryCount() != 0 && group.getLeftCount() == 0
|
|
|
+ && !markDeleteCode.equals(deleteCode)) {
|
|
|
+ throw new StatusException("分组授权码不正确");
|
|
|
+ }
|
|
|
+ List<ExamQuestion> questionList = new ArrayList<ExamQuestion>();
|
|
|
+ ArbitrateType at = arbitrateType != null ? ArbitrateType.findByValue(arbitrateType)
|
|
|
+ : ArbitrateType.GROUP;
|
|
|
+ if (ArbitrateType.QUESTION.equals(at)) {
|
|
|
+ arbitrateThreshold = null;
|
|
|
+ }
|
|
|
+ List<Double> arbitrateThresholds = buildDoubleList(arbitrateThresholdList);
|
|
|
+ boolean selective = false;
|
|
|
+ for (int i = 0; i < questionIds.length; i++) {
|
|
|
+ ExamQuestion question = questionService.findById(questionIds[i]);
|
|
|
+ if (doubleRate != null && doubleRate > 0 && ArbitrateType.QUESTION.equals(at)) {
|
|
|
+ question.setArbitrateThreshold(arbitrateThresholds.get(i));
|
|
|
+ } else {
|
|
|
+ question.setArbitrateThreshold(null);
|
|
|
+ }
|
|
|
+ questionList.add(question);
|
|
|
+ if (selective == false && selectiveGroupService.findOne(examId, subjectCode,
|
|
|
+ question.getMainNumber()) != null) {
|
|
|
+ selective = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!questionList.isEmpty()) {
|
|
|
+ ScorePolicy policy = scorePolicy != null ? ScorePolicy.findByValue(scorePolicy) : null;
|
|
|
+ ThirdPolicy third = thirdPolicy != null ? ThirdPolicy.findByValue(thirdPolicy)
|
|
|
+ : ThirdPolicy.DISABLE;
|
|
|
+ try {
|
|
|
+ lockService.waitlock(LockType.GROUP, true, group.getExamId(), group.getSubjectCode(),
|
|
|
+ group.getNumber());
|
|
|
+ markService.updateGroup(group, questionList, policy, at, third, selective);
|
|
|
+ RequestUtils.setLog(request, "重置分组,科目代码:" + subjectCode + " 分组号:" + number);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("update group error", e);
|
|
|
+ throw new StatusException("重置更新大题失败" + e.getMessage());
|
|
|
+ } finally {
|
|
|
+ lockService.unlock(LockType.GROUP, true, group.getExamId(), group.getSubjectCode(),
|
|
|
+ group.getNumber());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // simple update
|
|
|
+ List<Double> intervalScores = buildDoubleList(intervalScoreList);
|
|
|
+ List<Double> arbitrateThresholds = buildDoubleList(arbitrateThresholdList);
|
|
|
+ List<ExamQuestion> questionList = questionService
|
|
|
+ .findByExamAndSubjectAndObjectiveAndGroupNumber(examId, subjectCode, false, number);
|
|
|
+ if (intervalScores.size() == questionList.size()) {
|
|
|
+ for (int i = 0; i < questionList.size(); i++) {
|
|
|
+ ExamQuestion q = questionList.get(i);
|
|
|
+ q.setIntervalScore(intervalScores.get(i));
|
|
|
+ if (doubleRate != null && doubleRate > 0
|
|
|
+ && ArbitrateType.QUESTION.equals(group.getArbitrateType())) {
|
|
|
+ q.setArbitrateThreshold(arbitrateThresholds.get(i));
|
|
|
+ } else {
|
|
|
+ q.setArbitrateThreshold(null);
|
|
|
+ }
|
|
|
+ questionService.save(q);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // quick update
|
|
|
+ picList = StringEscapeUtils.unescapeHtml(picList);
|
|
|
+ JSONArray array = JSONArray.fromObject(picList);
|
|
|
+ List<MarkConfigItem> list = JSONArray.toList(array, new MarkConfigItem(), new JsonConfig());
|
|
|
+ if (list != null && !list.isEmpty()) {
|
|
|
+ groupService.updatePicList(examId, subjectCode, number, list);
|
|
|
+ }
|
|
|
+ groupService.updateDoubleRate(examId, subjectCode, number, doubleRate);
|
|
|
+ groupService.updateArbitrateThreshold(examId, subjectCode, number, arbitrateThreshold);
|
|
|
+ groupService.updateMarkMode(examId, subjectCode, number, markMode);
|
|
|
+ if (sheetView != null) {
|
|
|
+ groupService.updateSheetView(examId, subjectCode, number, sheetView);
|
|
|
+ }
|
|
|
+ if (enableAllZero != null) {
|
|
|
+ groupService.updateEnableAllZero(examId, subjectCode, number, enableAllZero);
|
|
|
+ }
|
|
|
+ return resultOk();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("edit markgroup error", e);
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new StatusException("更新分组!失败信息:" + e.getMessage());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new StatusException("找不到对应大题");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Double> buildDoubleList(String content) {
|
|
|
+ List<Double> list = new ArrayList<Double>();
|
|
|
+ content = StringUtils.trimToNull(content);
|
|
|
+ if (content != null) {
|
|
|
+ String[] values = StringUtils.split(content, ",");
|
|
|
+ if (values != null) {
|
|
|
+ for (String value : values) {
|
|
|
+ try {
|
|
|
+ Double number = Double.valueOf(value);
|
|
|
+ if (number != null) {
|
|
|
+ list.add(number);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "分组状态修改")
|
|
|
+ @Logging(menu = "大题状态修改", type = LogType.QUERY)
|
|
|
+ @RequestMapping(value = "/changeStatus", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public ResultMessage changeStatus(HttpServletRequest request, @RequestParam String subjectCode,
|
|
|
+ @RequestParam Integer number, @RequestParam MarkStatus status) {
|
|
|
+ int examId = getSessionExamId(request);
|
|
|
+ MarkGroup markGroup = groupService.findOne(examId, subjectCode, number);
|
|
|
+ if (markGroup == null) {
|
|
|
+ throw new StatusException("找不到对应大题");
|
|
|
+ }
|
|
|
+ boolean allow = false;
|
|
|
+ if (markGroup.getStatus() == MarkStatus.TRIAL && status == MarkStatus.FORMAL) {
|
|
|
+ allow = true;
|
|
|
+ } else if (markGroup.getStatus() == MarkStatus.FORMAL && status == MarkStatus.FINISH
|
|
|
+ && markGroup.getLeftCount() == 0
|
|
|
+ && selectiveStudentDao.countByExamIdAndSubjectCodeAndLessSelectiveOrNotSelective(markGroup.getExamId(),
|
|
|
+ markGroup.getSubjectCode(), true, true) == 0) {
|
|
|
+ allow = true;
|
|
|
+ } else if (markGroup.getStatus() == MarkStatus.FINISH && status == MarkStatus.FORMAL) {
|
|
|
+ allow = true;
|
|
|
+ }
|
|
|
+ if (!allow) {
|
|
|
+ throw new StatusException("不能切换到指定的评卷状态,评卷未完成或存在选做异常");
|
|
|
+ }
|
|
|
+ if (markGroup.getStatus() == MarkStatus.TRIAL && status == MarkStatus.FORMAL) {
|
|
|
+ List<MarkGroup> list = groupService.findByExamAndSubjectAndStatus(examId, subjectCode, MarkStatus.TRIAL);
|
|
|
+ for (MarkGroup group : list) {
|
|
|
+ updateStatus(group, status);
|
|
|
+ }
|
|
|
+ markService.groupTrialToFormal(examId, subjectCode);
|
|
|
+ } else {
|
|
|
+ updateStatus(markGroup, status);
|
|
|
+ }
|
|
|
+ return resultOk();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateStatus(MarkGroup group, MarkStatus status) {
|
|
|
+ try {
|
|
|
+ lockService.waitlock(LockType.GROUP, group.getExamId(), group.getSubjectCode(), group.getNumber());
|
|
|
+ if (groupService.updateStatus(group.getExamId(), group.getSubjectCode(), group.getNumber(), status,
|
|
|
+ group.getStatus())) {
|
|
|
+ if (status == MarkStatus.FORMAL) {
|
|
|
+ // 切换到正评成功后刷新任务数量
|
|
|
+ group.setStatus(status);
|
|
|
+ markService.updateLibraryCount(group);
|
|
|
+ markService.updateMarkedCount(group);
|
|
|
+ markerService.logoutByExamIdAndSubjectCodeAndGroupNumber(group.getExamId(), group.getSubjectCode(),
|
|
|
+ group.getNumber());
|
|
|
+ } else if (status == MarkStatus.FINISH) {
|
|
|
+ // 结束时判断是否全部完成统分
|
|
|
+ long unGroupQuestionCount = questionService.countByExamIdAndSubjectAndObjectiveAndGroupNumberIsNull(
|
|
|
+ group.getExamId(), group.getSubjectCode(), false);
|
|
|
+ // 考生整体状态与总分更新
|
|
|
+ long groupCount = groupService.countByExamAndSubjectAndStatus(group.getExamId(),
|
|
|
+ group.getSubjectCode(), MarkStatus.TRIAL, MarkStatus.FORMAL);
|
|
|
+ if (unGroupQuestionCount > 0 || groupCount > 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ groupCount = groupService.countByExamAndSubject(group.getExamId(), group.getSubjectCode());
|
|
|
+ List<Integer> studentList = studentService
|
|
|
+ .findIdByExamIdAndSubjectCodeAndSubjectiveStatusAndUploadAndAbsentAndBreach(
|
|
|
+ group.getExamId(), group.getSubjectCode(), SubjectiveStatus.UNMARK, true, false,
|
|
|
+ false);
|
|
|
+ for (Integer studentId : studentList) {
|
|
|
+ lockService.waitlock(LockType.STUDENT, studentId);
|
|
|
+ markService.checkStudentSubjective(studentId, groupCount, unGroupQuestionCount);
|
|
|
+ lockService.unlock(LockType.STUDENT, studentId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } finally {
|
|
|
+ lockService.unlock(LockType.GROUP, group.getExamId(), group.getSubjectCode(), group.getNumber());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "分组数量校对")
|
|
|
+ @Logging(menu = "大题数量校对", type = LogType.UPDATE)
|
|
|
+ @RequestMapping(value = "/checkCount", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public ResultMessage ckeckCount(@RequestParam String subjectCode) {
|
|
|
+ int examId = getSessionExamId();
|
|
|
+ ExamSubject subject = subjectService.find(examId, subjectCode);
|
|
|
+ if (subject == null) {
|
|
|
+ throw new StatusException("找不到对应科目");
|
|
|
+ }
|
|
|
+ markService.updateAllCount(examId, subjectCode);
|
|
|
+ return resultOk();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "分组任务回收")
|
|
|
+ @Logging(menu = "大题任务回收", type = LogType.UPDATE)
|
|
|
+ @RequestMapping(value = "/release", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public ResultMessage release(@RequestParam String subjectCode, @RequestParam Integer number) {
|
|
|
+ int examId = getSessionExamId();
|
|
|
+ MarkGroup group = groupService.findOne(examId, subjectCode, number);
|
|
|
+ if (group == null) {
|
|
|
+ throw new StatusException("找不到大题");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ lockService.waitlock(LockType.GROUP, group.getExamId(), group.getSubjectCode(), group.getNumber());
|
|
|
+ markService.releaseByGroup(group);
|
|
|
+ } finally {
|
|
|
+ lockService.unlock(LockType.GROUP, group.getExamId(), group.getSubjectCode(), group.getNumber());
|
|
|
+ }
|
|
|
+ return resultOk();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "分组重置")
|
|
|
+ @Logging(menu = "分组重置", type = LogType.UPDATE)
|
|
|
+ @RequestMapping(value = "/reset", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public ResultMessage reset(@RequestParam String subjectCode, @RequestParam Integer number) {
|
|
|
+ int examId = getSessionExamId();
|
|
|
+ MarkGroup group = groupService.findOne(examId, subjectCode, number);
|
|
|
+ if (group == null) {
|
|
|
+ throw new StatusException("找不到大题");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ lockService.waitlock(LockType.EXAM_SUBJECT, group.getExamId(), group.getSubjectCode());
|
|
|
+ lockService.waitlock(LockType.GROUP, group.getExamId(), group.getSubjectCode(), group.getNumber());
|
|
|
+ markService.resetByGroup(group);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("reset group error", e);
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new StatusException("重置大题失败", e);
|
|
|
+ } finally {
|
|
|
+ lockService.unlock(LockType.GROUP, group.getExamId(), group.getSubjectCode(), group.getNumber());
|
|
|
+ lockService.unlock(LockType.EXAM_SUBJECT, group.getExamId(), group.getSubjectCode());
|
|
|
+ }
|
|
|
+ return resultOk();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "分组删除")
|
|
|
+ @Logging(menu = "分组重置-删除", type = LogType.DELETE)
|
|
|
+ @RequestMapping(value = "/delete", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public ResultMessage delete(HttpServletRequest request, @RequestParam String subjectCode,
|
|
|
+ @RequestParam Integer number, @RequestParam(required = false) String deleteCode) {
|
|
|
+ int examId = getSessionExamId();
|
|
|
+ MarkGroup group = groupService.findOne(examId, subjectCode, number);
|
|
|
+ if (group == null) {
|
|
|
+ throw new StatusException("找不到大题");
|
|
|
+ }
|
|
|
+ Exam exam = examService.findById(examId);
|
|
|
+ School school = schoolService.findById(exam.getSchoolId());
|
|
|
+ boolean warn = systemCache.isGroupDeleteWarn() ? true : school.isGroupDeleteCheck();
|
|
|
+ if (warn && group.getLibraryCount() != 0 && group.getLeftCount() == 0 && !markDeleteCode.equals(deleteCode)) {
|
|
|
+ throw new StatusException("删除分组授权码不正确");
|
|
|
+ }
|
|
|
+ if (lockService.trylock(LockType.GROUP_DELETE, group.getExamId(), group.getSubjectCode(), group.getNumber())) {
|
|
|
+ taskExecutor.submit(new MarkGroupDeleteThread(group, markService, lockService));
|
|
|
+ RequestUtils.setLog(request, "删除分组,科目代码:" + subjectCode + " 分组号:" + number);
|
|
|
+ }
|
|
|
+ return resultOk();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "分组关闭")
|
|
|
+ @Logging(menu = "大题关闭", type = LogType.QUERY)
|
|
|
+ @RequestMapping(value = "/finish", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public ResultMessage finish(@RequestParam String subjectCode, @RequestParam Integer[] groupNumbers) {
|
|
|
+ int examId = getSessionExamId();
|
|
|
+ String messages = "";
|
|
|
+ for (Integer number : groupNumbers) {
|
|
|
+ MarkGroup group = groupService.findOne(examId, subjectCode, number);
|
|
|
+ if (group == null || group.getStatus() == MarkStatus.FINISH) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ lockService.waitlock(LockType.GROUP, group.getExamId(), group.getSubjectCode(), group.getNumber());
|
|
|
+ if (group.getStatus() == MarkStatus.FORMAL && group.getLeftCount() == 0
|
|
|
+ && selectiveStudentDao.countByExamIdAndSubjectCodeAndLessSelectiveOrNotSelective(
|
|
|
+ group.getExamId(), group.getSubjectCode(), true, true) == 0) {
|
|
|
+ groupService.updateStatus(examId, subjectCode, number, MarkStatus.FINISH, group.getStatus());
|
|
|
+ } else {
|
|
|
+ messages = "评卷未完成或选做题异常,无法关闭分组";
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ lockService.unlock(LockType.GROUP, group.getExamId(), group.getSubjectCode(), group.getNumber());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(messages)) {
|
|
|
+ throw new StatusException(messages);
|
|
|
+ }
|
|
|
+ return resultOk();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "设置试评数量")
|
|
|
+ @Logging(menu = "设置试评数量", type = LogType.UPDATE)
|
|
|
+ @RequestMapping(value = "/updateTrialCount", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public ResultMessage updateTrialCount(@RequestParam String subjectCode, @RequestParam Integer trialCount) {
|
|
|
+ int examId = getSessionExamId();
|
|
|
+ ExamSubject subject = subjectService.find(examId, subjectCode);
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
+ if (subject == null) {
|
|
|
+ throw new StatusException("科目不能为空");
|
|
|
+ }
|
|
|
+ long groupCount = groupService.countByExamAndSubjectAndStatus(examId, subjectCode, MarkStatus.TRIAL);
|
|
|
+ if (groupCount == 0) {
|
|
|
+ throw new StatusException("试评分组不能为空");
|
|
|
+ }
|
|
|
+ if (subject.getTrialCount() > trialCount) {
|
|
|
+ throw new StatusException("设置数量请大于" + subject.getTrialCount());
|
|
|
+ } else {
|
|
|
+ subjectService.updateTrialCount(examId, subjectCode, trialCount);
|
|
|
+ }
|
|
|
+ return resultOk();
|
|
|
+ }
|
|
|
+}
|