|
@@ -1,10 +1,14 @@
|
|
package cn.com.qmth.stmms.ms.marking.api;
|
|
package cn.com.qmth.stmms.ms.marking.api;
|
|
|
|
|
|
|
|
+import cn.com.qmth.stmms.ms.commons.config.SystemConfig;
|
|
import cn.com.qmth.stmms.ms.commons.web.PageableDTO;
|
|
import cn.com.qmth.stmms.ms.commons.web.PageableDTO;
|
|
|
|
+import cn.com.qmth.stmms.ms.core.domain.ExamQuestion;
|
|
import cn.com.qmth.stmms.ms.core.domain.MarkStage;
|
|
import cn.com.qmth.stmms.ms.core.domain.MarkStage;
|
|
|
|
+import cn.com.qmth.stmms.ms.core.domain.MarkSubject;
|
|
import cn.com.qmth.stmms.ms.core.domain.Paper;
|
|
import cn.com.qmth.stmms.ms.core.domain.Paper;
|
|
import cn.com.qmth.stmms.ms.core.domain.task.MarkTask;
|
|
import cn.com.qmth.stmms.ms.core.domain.task.MarkTask;
|
|
import cn.com.qmth.stmms.ms.core.repository.ExamQuestionRepo;
|
|
import cn.com.qmth.stmms.ms.core.repository.ExamQuestionRepo;
|
|
|
|
+import cn.com.qmth.stmms.ms.core.repository.MarkSubjectRepo;
|
|
import cn.com.qmth.stmms.ms.core.repository.MarkTaskRepo;
|
|
import cn.com.qmth.stmms.ms.core.repository.MarkTaskRepo;
|
|
import cn.com.qmth.stmms.ms.core.repository.PaperRepo;
|
|
import cn.com.qmth.stmms.ms.core.repository.PaperRepo;
|
|
import cn.com.qmth.stmms.ms.core.vo.Subject;
|
|
import cn.com.qmth.stmms.ms.core.vo.Subject;
|
|
@@ -13,6 +17,7 @@ import cn.com.qmth.stmms.ms.marking.assembler.PaperAssembler;
|
|
import cn.com.qmth.stmms.ms.marking.dto.MarkTaskDTO;
|
|
import cn.com.qmth.stmms.ms.marking.dto.MarkTaskDTO;
|
|
import cn.com.qmth.stmms.ms.marking.dto.PaperDTO;
|
|
import cn.com.qmth.stmms.ms.marking.dto.PaperDTO;
|
|
import cn.com.qmth.stmms.ms.marking.service.MarkingService;
|
|
import cn.com.qmth.stmms.ms.marking.service.MarkingService;
|
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.PageRequest;
|
|
import org.springframework.data.domain.PageRequest;
|
|
@@ -24,8 +29,12 @@ import org.springframework.http.ResponseEntity;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.*;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -46,6 +55,9 @@ public class PaperApi {
|
|
@Autowired
|
|
@Autowired
|
|
private MarkTaskRepo markTaskRepo;
|
|
private MarkTaskRepo markTaskRepo;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private MarkSubjectRepo markSubjectRepo;
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private MarkTaskAssembler markTaskAssembler;
|
|
private MarkTaskAssembler markTaskAssembler;
|
|
|
|
|
|
@@ -55,6 +67,9 @@ public class PaperApi {
|
|
@Autowired
|
|
@Autowired
|
|
ExamQuestionRepo examQuestionRepo;
|
|
ExamQuestionRepo examQuestionRepo;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ SystemConfig systemConfig;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 单个试卷信息
|
|
* 单个试卷信息
|
|
*
|
|
*
|
|
@@ -292,7 +307,7 @@ public class PaperApi {
|
|
* 考生成绩查询
|
|
* 考生成绩查询
|
|
*
|
|
*
|
|
* @param workId
|
|
* @param workId
|
|
- * @param areaCode
|
|
|
|
|
|
+ * @param questionId
|
|
* @param subject
|
|
* @param subject
|
|
* @param number
|
|
* @param number
|
|
* @param studentName
|
|
* @param studentName
|
|
@@ -300,18 +315,18 @@ public class PaperApi {
|
|
*/
|
|
*/
|
|
@RequestMapping(value = "/studentScore", method = RequestMethod.GET)
|
|
@RequestMapping(value = "/studentScore", method = RequestMethod.GET)
|
|
public List<Map> markTasks(@RequestParam Long workId,
|
|
public List<Map> markTasks(@RequestParam Long workId,
|
|
- @RequestParam(required = false) String areaCode,
|
|
|
|
- @RequestParam(required = false) Subject subject,
|
|
|
|
- @RequestParam(required = false) String type,
|
|
|
|
- @RequestParam(required = false) String number,
|
|
|
|
- @RequestParam(required = false) String studentName) {
|
|
|
|
|
|
+ @RequestParam(required = false) Long questionId,
|
|
|
|
+ @RequestParam(required = false) Subject subject,
|
|
|
|
+ @RequestParam(required = false) String type,
|
|
|
|
+ @RequestParam(required = false) String number,
|
|
|
|
+ @RequestParam(required = false) String studentName) {
|
|
Specification<Paper> specification = (root, query, builder) -> {
|
|
Specification<Paper> specification = (root, query, builder) -> {
|
|
List<Predicate> predicates = new ArrayList<>();
|
|
List<Predicate> predicates = new ArrayList<>();
|
|
if (!StringUtils.isEmpty(workId)) {
|
|
if (!StringUtils.isEmpty(workId)) {
|
|
predicates.add(builder.equal(root.get("workId"), workId));
|
|
predicates.add(builder.equal(root.get("workId"), workId));
|
|
}
|
|
}
|
|
- if (!StringUtils.isEmpty(areaCode)) {
|
|
|
|
- predicates.add(builder.equal(root.get("areaCode"), areaCode));
|
|
|
|
|
|
+ if (!StringUtils.isEmpty(questionId)) {
|
|
|
|
+ predicates.add(builder.equal(root.get("questionId"), questionId));
|
|
}
|
|
}
|
|
if (!StringUtils.isEmpty(subject)) {
|
|
if (!StringUtils.isEmpty(subject)) {
|
|
predicates.add(builder.equal(root.get("subject"), subject));
|
|
predicates.add(builder.equal(root.get("subject"), subject));
|
|
@@ -341,13 +356,13 @@ public class PaperApi {
|
|
//根据考生分组
|
|
//根据考生分组
|
|
Map<String, List<Paper>> groupPaper = papers.stream().collect(Collectors.groupingBy(p -> p.getExamNumber() + ":" + p.getStudentName()));
|
|
Map<String, List<Paper>> groupPaper = papers.stream().collect(Collectors.groupingBy(p -> p.getExamNumber() + ":" + p.getStudentName()));
|
|
List<Map> mapList = new ArrayList<>();
|
|
List<Map> mapList = new ArrayList<>();
|
|
- for (Map.Entry<String, List<Paper>> entry :groupPaper.entrySet()) {
|
|
|
|
|
|
+ for (Map.Entry<String, List<Paper>> entry : groupPaper.entrySet()) {
|
|
Map map = new HashMap();
|
|
Map map = new HashMap();
|
|
String key = entry.getKey();
|
|
String key = entry.getKey();
|
|
List<Paper> paperList = entry.getValue();
|
|
List<Paper> paperList = entry.getValue();
|
|
map.put("examNumber", key.split(":")[0]);
|
|
map.put("examNumber", key.split(":")[0]);
|
|
map.put("name", key.split(":")[1]);
|
|
map.put("name", key.split(":")[1]);
|
|
- double sumScore = paperList.stream().filter(m->Objects.nonNull(m.getScore())).mapToDouble(Paper::getScore).sum();
|
|
|
|
|
|
+ double sumScore = paperList.stream().filter(m -> Objects.nonNull(m.getScore())).mapToDouble(Paper::getScore).sum();
|
|
map.put("sumScore", Optional.ofNullable(sumScore).orElse(0D).intValue());
|
|
map.put("sumScore", Optional.ofNullable(sumScore).orElse(0D).intValue());
|
|
List<PaperDTO> paperDTOs = new ArrayList<>();
|
|
List<PaperDTO> paperDTOs = new ArrayList<>();
|
|
paperList.forEach(p -> paperDTOs.add(paperAssembler.toDTO(p)));
|
|
paperList.forEach(p -> paperDTOs.add(paperAssembler.toDTO(p)));
|
|
@@ -357,4 +372,137 @@ public class PaperApi {
|
|
return mapList;
|
|
return mapList;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 上传试题列表
|
|
|
|
+ *
|
|
|
|
+ * @param workId
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(value = "/{workId}/listUploadPaper", method = {RequestMethod.GET})
|
|
|
|
+ public List<Map> uploadPaperFile(@PathVariable Long workId) {
|
|
|
|
+ List<Object[]> questions = examQuestionRepo.findByWorkId(workId);
|
|
|
|
+ List<MarkSubject> subjects = markSubjectRepo.findAllByWorkId(workId);
|
|
|
|
+ List<Map> mapList = new ArrayList<>();
|
|
|
|
+ for (Object[] question : questions) {
|
|
|
|
+ Map map = new HashMap();
|
|
|
|
+ map.put("questionId", question[0]);
|
|
|
|
+ map.put("questionName", question[1]);
|
|
|
|
+ List<Map> subjectList = new ArrayList<>();
|
|
|
|
+ for (MarkSubject subject : subjects) {
|
|
|
|
+ //科目信息
|
|
|
|
+ Map subjectMap = new HashMap();
|
|
|
|
+ subjectMap.put("subject", subject.getSubject().name());
|
|
|
|
+ subjectMap.put("subjectName", subject.getName());
|
|
|
|
+ subjectMap.put("enable", subject.isEnable());
|
|
|
|
+ //上传路径,已有上传,取文件路径,没有为null
|
|
|
|
+ String subjectUrl = null;
|
|
|
|
+ String url = systemConfig.getLocalhostPath() + File.separator + workId + File.separator + question[0] + File.separator + subject.getSubject().name();
|
|
|
|
+ File path = new File(url);
|
|
|
|
+ if (path.exists()) {
|
|
|
|
+ File[] file = path.listFiles();
|
|
|
|
+ if (file.length > 0) {
|
|
|
|
+ subjectUrl = file[0].getAbsolutePath();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ subjectMap.put("url", subjectUrl);
|
|
|
|
+ subjectList.add(subjectMap);
|
|
|
|
+ }
|
|
|
|
+ map.put("subjects", subjectList);
|
|
|
|
+ mapList.add(map);
|
|
|
|
+ }
|
|
|
|
+ return mapList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 上传试卷
|
|
|
|
+ *
|
|
|
|
+ * @param workId
|
|
|
|
+ * @param questionId
|
|
|
|
+ * @param subject
|
|
|
|
+ * @param file
|
|
|
|
+ * @param request
|
|
|
|
+ * @param response
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(value = "/{workId}/{questionId}/{subject}/uploadPaperFile", method = {RequestMethod.POST})
|
|
|
|
+ public void uploadPaperFile(@PathVariable Long workId,
|
|
|
|
+ @PathVariable Long questionId,
|
|
|
|
+ @PathVariable Subject subject,
|
|
|
|
+ @RequestParam MultipartFile file,
|
|
|
|
+ HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
|
|
+ if (Objects.isNull(file)) {
|
|
|
|
+ throw new Exception("file文件不能为空");
|
|
|
|
+ }
|
|
|
|
+ int temp = file.getOriginalFilename().indexOf(".");
|
|
|
|
+ String format = file.getOriginalFilename().substring(temp);
|
|
|
|
+ if (Objects.nonNull(format) && !(format.equalsIgnoreCase(".jpg")
|
|
|
|
+ || format.equalsIgnoreCase(".jpeg")
|
|
|
|
+ || format.equalsIgnoreCase(".png")
|
|
|
|
+ || format.equalsIgnoreCase(".pdf"))) {
|
|
|
|
+ throw new Exception("file文件格式只能为jpg,jpeg,png,pdf");
|
|
|
|
+ }
|
|
|
|
+ InputStream inputStream = file.getInputStream();
|
|
|
|
+ //保存原图
|
|
|
|
+ String savePath = systemConfig.getLocalhostPath() + File.separator + workId + File.separator + questionId + File.separator + subject.name();
|
|
|
|
+ File fileSave = new File(savePath);
|
|
|
|
+ if (!fileSave.exists()) {
|
|
|
|
+ fileSave.mkdirs();
|
|
|
|
+ }
|
|
|
|
+ File outSheetFile = new File(savePath + File.separator + DigestUtils.md5Hex(workId + "-" + questionId + "-" + subject.name()) + format);
|
|
|
|
+ OutputStream outputSheetStream = new FileOutputStream(outSheetFile);
|
|
|
|
+ int index = 0;
|
|
|
|
+ byte[] bytes = new byte[1024 * 8];
|
|
|
|
+ while ((index = inputStream.read(bytes)) != -1) {
|
|
|
|
+ outputSheetStream.write(bytes, 0, index);
|
|
|
|
+ }
|
|
|
|
+ inputStream.close();
|
|
|
|
+ outputSheetStream.flush();
|
|
|
|
+ outputSheetStream.close();
|
|
|
|
+
|
|
|
|
+ String md5 = request.getHeader("md5");
|
|
|
|
+ if (Objects.isNull(md5)) {
|
|
|
|
+ throw new Exception("request的md5为空");
|
|
|
|
+ }
|
|
|
|
+ FileInputStream in = new FileInputStream(outSheetFile);
|
|
|
|
+ String sliceMD5 = DigestUtils.md5Hex(in);
|
|
|
|
+ if (!md5.equalsIgnoreCase(sliceMD5)) {
|
|
|
|
+ throw new Exception("图片md5值不一致");
|
|
|
|
+ }
|
|
|
|
+ in.close();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查看试题
|
|
|
|
+ *
|
|
|
|
+ * @param workId
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(value = "/{workId}/{subject}/viewUploadPaper", method = {RequestMethod.GET})
|
|
|
|
+ public List<Map> viewPaperFile(@PathVariable Long workId, @PathVariable Subject subject) {
|
|
|
|
+ List<ExamQuestion> questions = examQuestionRepo.findByWorkIdAndSubject(workId, subject);
|
|
|
|
+ List<Map> mapList = new ArrayList<>();
|
|
|
|
+ for (ExamQuestion question : questions) {
|
|
|
|
+ Map map = new HashMap();
|
|
|
|
+ map.put("questionId", question.getAreaCode());
|
|
|
|
+ map.put("questionName", question.getAreaName());
|
|
|
|
+ //科目信息
|
|
|
|
+ MarkSubject markSubject = markSubjectRepo.findOne(workId + "-" + subject.name());
|
|
|
|
+ map.put("subject", markSubject.getSubject().name());
|
|
|
|
+ map.put("subjectName", markSubject.getName());
|
|
|
|
+ //上传路径,已有上传,取文件路径,没有为null
|
|
|
|
+ String subjectUrl = null;
|
|
|
|
+ String url = systemConfig.getLocalhostPath() + File.separator + workId + File.separator + question.getAreaCode() + File.separator + markSubject.getSubject().name();
|
|
|
|
+ File path = new File(url);
|
|
|
|
+ if (path.exists()) {
|
|
|
|
+ File[] file = path.listFiles();
|
|
|
|
+ if (file.length > 0) {
|
|
|
|
+ subjectUrl = file[0].getAbsolutePath();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ map.put("url", subjectUrl);
|
|
|
|
+ mapList.add(map);
|
|
|
|
+ }
|
|
|
|
+ return mapList;
|
|
|
|
+ }
|
|
}
|
|
}
|