|
@@ -0,0 +1,232 @@
|
|
|
+package cn.com.qmth.stmms.api.controller.admin;
|
|
|
+
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+import cn.com.qmth.stmms.admin.dto.MarkInfoDTO;
|
|
|
+import cn.com.qmth.stmms.admin.dto.MarkerInfoDTO;
|
|
|
+import cn.com.qmth.stmms.biz.exam.dao.SelectiveStudentDao;
|
|
|
+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.Marker;
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.*;
|
|
|
+import cn.com.qmth.stmms.biz.lock.LockService;
|
|
|
+import cn.com.qmth.stmms.biz.mark.query.MarkLibrarySearchQuery;
|
|
|
+import cn.com.qmth.stmms.biz.mark.service.MarkLibraryService;
|
|
|
+import cn.com.qmth.stmms.biz.user.service.UserService;
|
|
|
+import cn.com.qmth.stmms.common.annotation.Logging;
|
|
|
+import cn.com.qmth.stmms.common.annotation.RoleRequire;
|
|
|
+import cn.com.qmth.stmms.common.domain.WebUser;
|
|
|
+import cn.com.qmth.stmms.common.enums.*;
|
|
|
+import cn.com.qmth.stmms.common.utils.ExportExcel;
|
|
|
+import cn.com.qmth.stmms.common.utils.RequestUtils;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.ui.Model;
|
|
|
+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.collection.PageResult;
|
|
|
+
|
|
|
+import cn.com.qmth.stmms.api.controller.BaseApiController;
|
|
|
+import cn.com.qmth.stmms.biz.exam.model.OperationLog;
|
|
|
+import cn.com.qmth.stmms.biz.exam.query.OperationLogSearchQuery;
|
|
|
+import cn.com.qmth.stmms.biz.utils.PageUtil;
|
|
|
+import cn.com.qmth.stmms.common.domain.ApiUser;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+@Api(tags = "评卷管理")
|
|
|
+@Controller("adminMarkInfoController")
|
|
|
+@RequestMapping("/api/admin/mark/info")
|
|
|
+public class MarkInfoController extends BaseApiController {
|
|
|
+
|
|
|
+ protected static Logger log = LoggerFactory.getLogger(MarkInfoController.class);
|
|
|
+
|
|
|
+ public static final String SPLIT = ",";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamSubjectService subjectService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MarkerService markerService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MarkGroupService groupService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamQuestionService questionService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MarkLibraryService libraryService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LockService lockService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamStudentService studentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SelectiveStudentDao selectiveStudentDao;
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "评卷进度列表")
|
|
|
+ @RequestMapping(value = "query", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public PageResult<OperationLog> query(OperationLogSearchQuery query) {
|
|
|
+ ApiUser user = getApiUser();
|
|
|
+ int examId = getSessionExamId();
|
|
|
+ query.setExamId(examId);
|
|
|
+ query.setSchoolId(user.getUser().getSchoolId());
|
|
|
+ query.orderByCreateTime();
|
|
|
+ query = logService.findByQuery(query);
|
|
|
+ return PageUtil.of(query);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "评卷进度统计")
|
|
|
+ @RequestMapping(value = "types", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public List<LogType> examTypeList() {
|
|
|
+ return Arrays.asList(LogType.values());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Logging(menu = "整体评卷进度导出", type = LogType.EXPORT)
|
|
|
+ @RequestMapping(value = "/export-progress", method = RequestMethod.POST)
|
|
|
+ public String exportProgress(HttpServletRequest request, HttpServletResponse response,
|
|
|
+ RedirectAttributes redirectAttributes) {
|
|
|
+ WebUser wu = RequestUtils.getWebUser(request);
|
|
|
+ int examId = getSessionExamId(request);
|
|
|
+ List<MarkInfoDTO> result = new LinkedList<MarkInfoDTO>();
|
|
|
+ List<ExamSubject> list = subjectService.list(examId);
|
|
|
+ if (wu.isSubjectHeader()) {
|
|
|
+ list = getExamSubject(examId, wu);
|
|
|
+ }
|
|
|
+ for (ExamSubject subject : list) {
|
|
|
+ MarkInfoDTO dto = new MarkInfoDTO(subject);
|
|
|
+ MarkLibrarySearchQuery mQuery = new MarkLibrarySearchQuery();
|
|
|
+ mQuery.setExamId(examId);
|
|
|
+ mQuery.setSubjectCode(subject.getCode());
|
|
|
+ long libraryCount = libraryService.countByQuery(mQuery);
|
|
|
+ mQuery.addStatus(LibraryStatus.MARKED);
|
|
|
+ long inspectedCount = libraryService.countByQuery(mQuery);
|
|
|
+ dto.setInspectedCount(inspectedCount);
|
|
|
+ mQuery.addStatus(LibraryStatus.ARBITRATED);
|
|
|
+ mQuery.addStatus(LibraryStatus.INSPECTED);
|
|
|
+ long totalMarkedCount = libraryService.countByQuery(mQuery);
|
|
|
+ String percent = libraryCount > 0
|
|
|
+ ? (new DecimalFormat("####.###").format(totalMarkedCount * 100.0 / libraryCount) + "%")
|
|
|
+ : "0%";
|
|
|
+ dto.setPercent(percent);
|
|
|
+ dto.setGroupCount(groupService.countByExamAndSubject(examId, subject.getCode()));
|
|
|
+ result.add(dto);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ String fileName = "整体评卷进度.xlsx";
|
|
|
+ new ExportExcel("整体评卷进度", MarkInfoDTO.class).setDataList(result).write(response, fileName).dispose();
|
|
|
+ return null;
|
|
|
+ } catch (Exception e) {
|
|
|
+ addMessage(redirectAttributes, "导出整体评卷进度失败!" + e.getMessage());
|
|
|
+ return "redirect:/admin/exam/mark";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Logging(menu = "评卷员工作量导出", type = LogType.EXPORT)
|
|
|
+ @RequestMapping(value = "/export-marker", method = RequestMethod.POST)
|
|
|
+ public String exportMarker(HttpServletRequest request, HttpServletResponse response,
|
|
|
+ RedirectAttributes redirectAttributes) {
|
|
|
+ WebUser wu = RequestUtils.getWebUser(request);
|
|
|
+ int examId = getSessionExamId(request);
|
|
|
+ List<MarkerInfoDTO> result = new LinkedList<MarkerInfoDTO>();
|
|
|
+ List<Marker> list = markerService.getMarkCount(examId);
|
|
|
+ if (wu.isSubjectHeader()) {
|
|
|
+ list = markerService.getMarkCount(examId, wu.getSubjectCodeSet());
|
|
|
+ }
|
|
|
+ Map<String, ExamSubject> subjectMap = new HashMap<String, ExamSubject>();
|
|
|
+ Map<String, String> collegeMap = new HashMap<String, String>();
|
|
|
+ for (Marker marker : list) {
|
|
|
+ ExamSubject subject = subjectMap.get(marker.getSubjectCode());
|
|
|
+ if (subject == null) {
|
|
|
+ subject = subjectService.find(marker.getExamId(), marker.getSubjectCode());
|
|
|
+ subjectMap.put(marker.getSubjectCode(), subject);
|
|
|
+ collegeMap.put(marker.getSubjectCode(), StringUtils
|
|
|
+ .join(studentService.findDistinctCollegeBySubjectCode(examId, marker.getSubjectCode()), SPLIT));
|
|
|
+ }
|
|
|
+ MarkGroup group = groupService.findOne(examId, marker.getSubjectCode(), marker.getGroupNumber());
|
|
|
+ group.setQuestionList(questionService.findByExamAndSubjectAndObjectiveAndGroupNumber(examId,
|
|
|
+ group.getSubjectCode(), false, group.getNumber()));
|
|
|
+ marker.setUser(userService.findById(marker.getUserId()));
|
|
|
+ MarkerInfoDTO dto = new MarkerInfoDTO(marker, subject, group);
|
|
|
+ dto.setTotalScore(questionService.sumTotalScoreByGroupNumber(examId, marker.getSubjectCode(), false,
|
|
|
+ marker.getGroupNumber()));
|
|
|
+ dto.setCollege(collegeMap.get(marker.getSubjectCode()));
|
|
|
+ result.add(dto);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ String fileName = "评卷员工作量.xlsx";
|
|
|
+ new ExportExcel("评卷员工作量", MarkerInfoDTO.class).setDataList(result).write(response, fileName).dispose();
|
|
|
+ return null;
|
|
|
+ } catch (Exception e) {
|
|
|
+ addMessage(redirectAttributes, "导出评卷员工作量失败!" + e.getMessage());
|
|
|
+ return "redirect:/admin/exam/mark";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Logging(menu = "大题关闭", type = LogType.QUERY)
|
|
|
+ @RequestMapping("/finish")
|
|
|
+ @RoleRequire({ Role.SCHOOL_ADMIN, Role.SUBJECT_HEADER, Role.COLLEGE_ADMIN })
|
|
|
+ public String finish(HttpServletRequest request, Model model, RedirectAttributes redirectAttributes,
|
|
|
+ @RequestParam String[] codes) {
|
|
|
+ int examId = getSessionExamId(request);
|
|
|
+ String messages = "";
|
|
|
+ for (String code : codes) {
|
|
|
+ MarkLibrarySearchQuery mQuery = new MarkLibrarySearchQuery();
|
|
|
+ mQuery.setExamId(examId);
|
|
|
+ mQuery.setSubjectCode(code);
|
|
|
+ long libraryCount = libraryService.countByQuery(mQuery);
|
|
|
+ mQuery.addStatus(LibraryStatus.MARKED);
|
|
|
+ mQuery.addStatus(LibraryStatus.ARBITRATED);
|
|
|
+ mQuery.addStatus(LibraryStatus.INSPECTED);
|
|
|
+ long markedCount = libraryService.countByQuery(mQuery);
|
|
|
+ if (markedCount != libraryCount) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<MarkGroup> groups = groupService.findByExamAndSubject(examId, code);
|
|
|
+ for (MarkGroup group : groups) {
|
|
|
+ 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, code, group.getNumber(), MarkStatus.FINISH,
|
|
|
+ group.getStatus());
|
|
|
+ } else {
|
|
|
+ messages = " " + code;
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ lockService.unlock(LockType.GROUP, group.getExamId(), group.getSubjectCode(), group.getNumber());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(messages)) {
|
|
|
+ addMessage(redirectAttributes, messages + " 评卷未完成或选做题异常,无法关闭分组");
|
|
|
+ }
|
|
|
+ return "redirect:/admin/exam/mark";
|
|
|
+ }
|
|
|
+}
|