|
@@ -0,0 +1,238 @@
|
|
|
+package cn.com.qmth.stmms.api.controller.admin;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.LinkedHashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+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.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.qmth.boot.core.collection.PageResult;
|
|
|
+
|
|
|
+import cn.com.qmth.stmms.admin.vo.InspectedStudentVO;
|
|
|
+import cn.com.qmth.stmms.admin.vo.TagStudentVO;
|
|
|
+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.ExamStudent;
|
|
|
+import cn.com.qmth.stmms.biz.exam.model.ImportQuery;
|
|
|
+import cn.com.qmth.stmms.biz.exam.query.ExamStudentSearchQuery;
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.ExamStudentService;
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.ImportQueryService;
|
|
|
+import cn.com.qmth.stmms.biz.exception.StatusException;
|
|
|
+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.ImportType;
|
|
|
+import cn.com.qmth.stmms.common.enums.LogType;
|
|
|
+import cn.com.qmth.stmms.common.enums.SubjectiveStatus;
|
|
|
+import cn.com.qmth.stmms.common.utils.ExportExcel;
|
|
|
+import cn.com.qmth.stmms.common.utils.ImportExcel;
|
|
|
+import cn.com.qmth.stmms.common.utils.RequestUtils;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+
|
|
|
+@Api(tags = "导入复核")
|
|
|
+@Controller("adminImportQueryController")
|
|
|
+@RequestMapping("/api/admin/exam/inspected/import")
|
|
|
+public class ImportQueryController extends BaseApiController {
|
|
|
+
|
|
|
+ protected static Logger log = LoggerFactory.getLogger(ImportQueryController.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamStudentService studentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ImportQueryService queryService;
|
|
|
+
|
|
|
+ public static final String DB_ITEM_JOINER = ":";
|
|
|
+
|
|
|
+ public static final String UN_SELECTIVE_SCORE = "-1";
|
|
|
+
|
|
|
+ @ApiOperation(value = "待复核数")
|
|
|
+ @RequestMapping(value = "todo-count", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public Integer subjectStatus(ExamStudentSearchQuery query) {
|
|
|
+ int examId = getSessionExamId();
|
|
|
+ ApiUser wu = getApiUser();
|
|
|
+ ImportQuery importQuery = queryService.findByExamIdAndUserIdAndType(examId, wu.getUser().getId(),
|
|
|
+ ImportType.INSPECTED);
|
|
|
+ int inspectCount = 0;
|
|
|
+ if (importQuery != null) {
|
|
|
+ inspectCount = importQuery.getStudentCodeList().size() > 0 ? 0 : importQuery.getStudentIdList().size();
|
|
|
+ }
|
|
|
+ return inspectCount;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "分页查询")
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping(value = "list", method = RequestMethod.POST)
|
|
|
+ public PageResult<ExamStudent> list(ExamStudentSearchQuery query) {
|
|
|
+ int examId = getSessionExamId();
|
|
|
+ ApiUser wu = getApiUser();
|
|
|
+ ImportQuery importQuery = queryService.findByExamIdAndUserIdAndType(examId, wu.getUser().getId(),
|
|
|
+ ImportType.INSPECTED);
|
|
|
+ int inspectCount = 0;
|
|
|
+ if (importQuery != null) {
|
|
|
+ inspectCount = importQuery.getStudentCodeList().size() > 0 ? 0 : importQuery.getStudentIdList().size();
|
|
|
+ }
|
|
|
+ if (inspectCount > 0) {
|
|
|
+ List<?> ids = PageUtil.startPage(importQuery.getStudentIdList(), query.getPageNumber(),
|
|
|
+ query.getPageSize());
|
|
|
+ List<ExamStudent> list = new ArrayList<ExamStudent>();
|
|
|
+ if (ids != null) {
|
|
|
+ for (Object id : ids) {
|
|
|
+ ExamStudent student = studentService.findById((int) id);
|
|
|
+ if (importQuery.getTagIdList().contains(id)) {
|
|
|
+ student.setTagValue("1");
|
|
|
+ }
|
|
|
+ if (student.getSubjectiveScoreList() != null) {
|
|
|
+ student.setSubjectiveScoreList(
|
|
|
+ student.getSubjectiveScoreList().replace(UN_SELECTIVE_SCORE, "/"));
|
|
|
+ }
|
|
|
+ list.add(student);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ query.setTotalCount(inspectCount);
|
|
|
+ query.setResult(list);
|
|
|
+ return PageUtil.of(list, query);
|
|
|
+ }
|
|
|
+ return PageUtil.emptyPage();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "导入模版下载")
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping(value = "template", method = RequestMethod.POST)
|
|
|
+ public void template(HttpServletResponse response) {
|
|
|
+ try {
|
|
|
+ String fileName = "复核名单导入模板.xlsx";
|
|
|
+ List<InspectedStudentVO> list = Lists.newArrayList();
|
|
|
+ list.add(new InspectedStudentVO());
|
|
|
+ new ExportExcel("复核名单", InspectedStudentVO.class, 2).setDataList(list).write(response, fileName).dispose();
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new StatusException("导入模板下载失败!失败信息:" + e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Logging(menu = "导入复核名单", type = LogType.IMPORT_FILE)
|
|
|
+ @ApiOperation(value = "导入复核名单")
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping(method = RequestMethod.POST)
|
|
|
+ public ResultMessage importFile(MultipartFile file) {
|
|
|
+ int examId = getSessionExamId();
|
|
|
+ ApiUser wu = getApiUser();
|
|
|
+ queryService.deleteByExamIdAndUserIdAndType(examId, wu.getUser().getId(), ImportType.INSPECTED);
|
|
|
+ try {
|
|
|
+ int successNum = 0;
|
|
|
+ int failureNum = 0;
|
|
|
+ Set<Integer> successStudent = new LinkedHashSet<Integer>();
|
|
|
+ Set<String> failureStudent = new HashSet<String>();
|
|
|
+ ImportExcel ei = new ImportExcel(file, 1, 0);
|
|
|
+ List<InspectedStudentVO> list = ei.getDataList(InspectedStudentVO.class);
|
|
|
+ if (list.size() > 1000) {
|
|
|
+ throw new StatusException("导入考生失败!数据超过1000行");
|
|
|
+ }
|
|
|
+ for (InspectedStudentVO studentVO : list) {
|
|
|
+ if (StringUtils.isBlank(studentVO.getStudentCode())
|
|
|
+ || StringUtils.isBlank(studentVO.getSubjectCode())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<ExamStudent> studentList = studentService.findByExamIdAndStudentCodeAndSubjectCode(examId,
|
|
|
+ studentVO.getStudentCode(), studentVO.getSubjectCode());
|
|
|
+ if (!studentList.isEmpty()) {
|
|
|
+ for (ExamStudent examStudent : studentList) {
|
|
|
+ if (SubjectiveStatus.MARKED.equals(examStudent.getSubjectiveStatus())) {
|
|
|
+ successStudent.add(examStudent.getId());
|
|
|
+ successNum++;
|
|
|
+ } else {
|
|
|
+ failureStudent
|
|
|
+ .add(studentVO.getSubjectCode() + DB_ITEM_JOINER + studentVO.getStudentCode());
|
|
|
+ failureNum++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ failureStudent.add(studentVO.getSubjectCode() + DB_ITEM_JOINER + studentVO.getStudentCode());
|
|
|
+ failureNum++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ImportQuery importQuery = new ImportQuery(examId, wu.getUser().getId(), ImportType.INSPECTED,
|
|
|
+ successStudent, failureStudent);
|
|
|
+ queryService.save(importQuery);
|
|
|
+ String message = "已成功导入 " + successNum + " 条,关联考生记录 " + successStudent.size() + " 条";
|
|
|
+ if (failureNum > 0) {
|
|
|
+ message = "失败 " + failureNum + " 条";
|
|
|
+ }
|
|
|
+ RequestUtils.setLog(message);
|
|
|
+ ResultMessage ret = new ResultMessage();
|
|
|
+ ret.setSuccess(true);
|
|
|
+ ret.setMessage(message);
|
|
|
+ return ret;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("Batch import inpectedStudent error!", e);
|
|
|
+ throw new StatusException("导入考生失败!失败信息:" + e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Logging(menu = "复核名单重置", type = LogType.UPDATE)
|
|
|
+ @ApiOperation(value = "复核名单重置")
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping(value = "reset", method = RequestMethod.POST)
|
|
|
+ public ResultMessage reset() {
|
|
|
+ int examId = getSessionExamId();
|
|
|
+ ApiUser wu = getApiUser();
|
|
|
+ queryService.deleteByExamIdAndUserIdAndType(examId, wu.getUser().getId(), ImportType.INSPECTED);
|
|
|
+ return resultOk();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "导出错误日志")
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping(value = "export", method = RequestMethod.POST)
|
|
|
+ public void export(HttpServletResponse response) {
|
|
|
+ int examId = getSessionExamId();
|
|
|
+ ApiUser wu = getApiUser();
|
|
|
+ try {
|
|
|
+ String fileName = "错误信息.xlsx";
|
|
|
+ List<InspectedStudentVO> list = Lists.newArrayList();
|
|
|
+ ImportQuery importQuery = queryService.findByExamIdAndUserIdAndType(examId, wu.getUser().getId(),
|
|
|
+ ImportType.INSPECTED);
|
|
|
+ for (String studentCode : importQuery.getStudentCodeList()) {
|
|
|
+ String[] s = studentCode.split(DB_ITEM_JOINER);
|
|
|
+ list.add(new InspectedStudentVO(s[0], s[1]));
|
|
|
+ }
|
|
|
+ new ExportExcel("错误信息", InspectedStudentVO.class, 2).setDataList(list).write(response, fileName).dispose();
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new StatusException("错误信息下载失败!失败信息:" + e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "导出标记卷")
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping(value = "export-tag", method = RequestMethod.POST)
|
|
|
+ public void exportTag(HttpServletResponse response) {
|
|
|
+ int examId = getSessionExamId();
|
|
|
+ ApiUser wu = getApiUser();
|
|
|
+ try {
|
|
|
+ String fileName = "标记卷.xlsx";
|
|
|
+ List<TagStudentVO> list = Lists.newArrayList();
|
|
|
+ ImportQuery importQuery = queryService.findByExamIdAndUserIdAndType(examId, wu.getId(),
|
|
|
+ ImportType.INSPECTED);
|
|
|
+ for (Integer studentId : importQuery.getTagIdList()) {
|
|
|
+ list.add(new TagStudentVO(studentService.findById(studentId)));
|
|
|
+ }
|
|
|
+ new ExportExcel("标记卷信息", TagStudentVO.class, 2).setDataList(list).write(response, fileName).dispose();
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new StatusException("标记卷下载失败!失败信息:" + e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|