|
@@ -0,0 +1,130 @@
|
|
|
+package cn.com.qmth.stmms.api.controller.admin;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.LinkedList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+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.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+
|
|
|
+import com.qmth.boot.core.collection.PageResult;
|
|
|
+
|
|
|
+import cn.com.qmth.stmms.admin.dto.ExceptionStudentDTO;
|
|
|
+import cn.com.qmth.stmms.admin.thread.ImageCheckThread;
|
|
|
+import cn.com.qmth.stmms.api.controller.BaseApiController;
|
|
|
+import cn.com.qmth.stmms.biz.exam.bean.ImageCheckVo;
|
|
|
+import cn.com.qmth.stmms.biz.exam.bean.ResultMessage;
|
|
|
+import cn.com.qmth.stmms.biz.exam.model.Exam;
|
|
|
+import cn.com.qmth.stmms.biz.exam.model.ExamStudent;
|
|
|
+import cn.com.qmth.stmms.biz.exam.model.ExamSubject;
|
|
|
+import cn.com.qmth.stmms.biz.exam.query.ExamStudentSearchQuery;
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.ExamService;
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.ExamStudentService;
|
|
|
+import cn.com.qmth.stmms.biz.exception.StatusException;
|
|
|
+import cn.com.qmth.stmms.biz.file.service.FileService;
|
|
|
+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.enums.LogType;
|
|
|
+import cn.com.qmth.stmms.common.utils.ExportExcel;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+
|
|
|
+@Api(tags = "图片检查")
|
|
|
+@Controller("adminImageCheckController")
|
|
|
+@RequestMapping("/api/admin/exam/check/image")
|
|
|
+public class ImageCheckController extends BaseApiController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamStudentService studentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FileService fileService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamService examService;
|
|
|
+
|
|
|
+ @Qualifier("task-executor")
|
|
|
+ @Autowired
|
|
|
+ private AsyncTaskExecutor taskExecutor;
|
|
|
+
|
|
|
+ private AtomicBoolean running = new AtomicBoolean(false);
|
|
|
+
|
|
|
+ @ApiOperation(value = "检查状态")
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping(value = "status", method = RequestMethod.POST)
|
|
|
+ public Boolean status() {
|
|
|
+ return running.get();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Logging(menu = "图片检查", type = LogType.QUERY)
|
|
|
+ @ApiOperation(value = "图片检查")
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping(value = "list", method = RequestMethod.POST)
|
|
|
+ public PageResult<ImageCheckVo> list(ExamStudentSearchQuery query) {
|
|
|
+ ApiUser wu = getApiUser();
|
|
|
+ int examId = getSessionExamId();
|
|
|
+ List<ExamSubject> subjectList = getExamSubject(examId, wu);
|
|
|
+ query.setExamId(examId);
|
|
|
+ query.setUpload(true);
|
|
|
+ query.setAbsent(false);
|
|
|
+ query.setException(true);
|
|
|
+ query.orderByExamNumber();
|
|
|
+ if (StringUtils.isBlank(query.getSubjectCode()) && !subjectList.isEmpty()) {
|
|
|
+ query.setSubjectCode(subjectList.get(0).getCode());
|
|
|
+ }
|
|
|
+ query = studentService.findByQuery(query);
|
|
|
+ List<ImageCheckVo> ret = new ArrayList<>();
|
|
|
+ for (ExamStudent student : query.getResult()) {
|
|
|
+ ret.add(ImageCheckVo.of(student));
|
|
|
+ }
|
|
|
+
|
|
|
+ return PageUtil.of(ret, query);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "开始检查")
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping(value = "run", method = RequestMethod.POST)
|
|
|
+ public ResultMessage checkImage() {
|
|
|
+ Exam exam = examService.findById(getSessionExamId());
|
|
|
+ if (running.compareAndSet(false, true)) {
|
|
|
+ ImageCheckThread thread = new ImageCheckThread(exam, studentService, fileService, running);
|
|
|
+ taskExecutor.submit(thread);
|
|
|
+ }
|
|
|
+ return resultOk();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Logging(menu = "图片检查导出", type = LogType.EXPORT)
|
|
|
+ @ApiOperation(value = "导出")
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping(value = "export", method = RequestMethod.POST)
|
|
|
+ public void export(ExamStudentSearchQuery query, HttpServletResponse response) {
|
|
|
+ List<ExceptionStudentDTO> list = new LinkedList<ExceptionStudentDTO>();
|
|
|
+ query.setExamId(getSessionExamId());
|
|
|
+ query.setUpload(true);
|
|
|
+ query.setAbsent(false);
|
|
|
+ query.setException(true);
|
|
|
+ query.setPageNumber(1);
|
|
|
+ query.setPageSize(Integer.MAX_VALUE);
|
|
|
+ query = studentService.findByQuery(query);
|
|
|
+ for (ExamStudent student : query.getResult()) {
|
|
|
+ ExceptionStudentDTO dto = new ExceptionStudentDTO(student);
|
|
|
+ list.add(dto);
|
|
|
+ }
|
|
|
+ String fileName = "异常名单.xlsx";
|
|
|
+ try {
|
|
|
+ new ExportExcel("异常名单", ExceptionStudentDTO.class).setDataList(list).write(response, fileName).dispose();
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new StatusException("导出失败!" + e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|