|
@@ -0,0 +1,230 @@
|
|
|
|
+package cn.com.qmth.stmms.ms.marking.api;
|
|
|
|
+
|
|
|
|
+import java.util.*;
|
|
|
|
+
|
|
|
|
+import cn.com.qmth.stmms.ms.commons.web.PageableDTO;
|
|
|
|
+import cn.com.qmth.stmms.ms.core.vo.Subject;
|
|
|
|
+import cn.com.qmth.stmms.ms.marking.assembler.MarkTaskAssembler;
|
|
|
|
+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.PaperDTO;
|
|
|
|
+import cn.com.qmth.stmms.ms.marking.service.MarkingService;
|
|
|
|
+import org.assertj.core.util.Strings;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.data.domain.*;
|
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+
|
|
|
|
+import cn.com.qmth.stmms.ms.core.domain.MarkStage;
|
|
|
|
+import cn.com.qmth.stmms.ms.core.domain.Paper;
|
|
|
|
+import cn.com.qmth.stmms.ms.core.repository.MarkTaskRepo;
|
|
|
|
+import cn.com.qmth.stmms.ms.core.repository.PaperRepo;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
+
|
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 试卷相关api
|
|
|
|
+ * Created by zhengmin on 2016/10/10.
|
|
|
|
+ */
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("api/papers")
|
|
|
|
+public class PaperApi {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private PaperAssembler paperAssembler;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private PaperRepo paperRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private MarkTaskRepo markTaskRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private MarkTaskAssembler markTaskAssembler;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private MarkingService markingService;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 单个试卷信息
|
|
|
|
+ * @param paperId 试卷id
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(value = "{paperId}",method = RequestMethod.GET)
|
|
|
|
+ public PaperDTO get(@PathVariable Long paperId){
|
|
|
|
+ return paperAssembler.toDTO(paperRepo.findOne(paperId));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 单个试卷信息
|
|
|
|
+ * @param questionId 试题id
|
|
|
|
+ * @param sn 密号
|
|
|
|
+ * @param examNumber 准考证号
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(value = "/one",method = RequestMethod.GET)
|
|
|
|
+ public PaperDTO getOne(@RequestParam Long questionId,
|
|
|
|
+ @RequestParam(required = false) String sn,
|
|
|
|
+ @RequestParam(required = false) String examNumber){
|
|
|
|
+ PaperDTO paperDTO = null;
|
|
|
|
+ Specification<Paper> specification = (root,query,builder) -> {
|
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
|
+ predicates.add(builder.equal(root.get("questionId"),questionId));
|
|
|
|
+ if(sn != null){
|
|
|
|
+ predicates.add(builder.equal(root.get("secretNumber"),sn));
|
|
|
|
+ }
|
|
|
|
+ if(examNumber != null){
|
|
|
|
+ predicates.add(builder.equal(root.get("examNumber"),examNumber));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return builder.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
|
+ };
|
|
|
|
+ Optional<Paper> paperOptional = paperRepo.findAll(specification,new PageRequest(0,1))
|
|
|
|
+ .getContent().stream().findFirst();
|
|
|
|
+ if(paperOptional.isPresent()){
|
|
|
|
+ paperDTO = paperAssembler.toDTO(paperOptional.get());
|
|
|
|
+ }
|
|
|
|
+ return paperDTO;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RequestMapping(value="listByQuestion",method = RequestMethod.GET)
|
|
|
|
+ public PageableDTO listByQuerion(@RequestParam String areaCode,
|
|
|
|
+ @RequestParam Subject subject,
|
|
|
|
+ @RequestParam(required = false) Long startNumber,
|
|
|
|
+ @RequestParam(required = false) Long endNumber,
|
|
|
|
+ @RequestParam(required = false) Boolean isManual,
|
|
|
|
+ Pageable pageable){
|
|
|
|
+ Specification<Paper> specification = (root,query,builder) -> {
|
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
|
+ predicates.add(builder.equal(root.get("areaCode"),areaCode));
|
|
|
|
+ predicates.add(builder.equal(root.get("subject"),subject));
|
|
|
|
+ if(startNumber != null && endNumber != null){
|
|
|
|
+ predicates.add(builder.between(root.get("examNumber"),startNumber,endNumber));
|
|
|
|
+ }
|
|
|
|
+ else if(startNumber != null){
|
|
|
|
+ predicates.add(builder.equal(root.get("examNumber"),startNumber));
|
|
|
|
+ }
|
|
|
|
+ if(isManual != null){
|
|
|
|
+ predicates.add(builder.equal(root.get("isManual"),isManual));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return builder.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
|
+ };
|
|
|
|
+ List<PaperDTO> paperDTOs = new ArrayList<>();
|
|
|
|
+ Page<Paper> paperPage = paperRepo.findAll(specification,pageable);
|
|
|
|
+ paperPage.getContent().forEach(p -> {
|
|
|
|
+ paperDTOs.add(paperAssembler.toDTO(p));
|
|
|
|
+ });
|
|
|
|
+ return new PageableDTO(paperDTOs,paperPage.getTotalElements(),paperPage.getTotalPages(),pageable.getPageNumber());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 试卷列表
|
|
|
|
+ * @param questionId 试题id
|
|
|
|
+ * @param level 档位,如果为空,则测序待评
|
|
|
|
+ * @param arbi 是否仲裁
|
|
|
|
+ * @param reject 是否打回
|
|
|
|
+ * @param pageable 分页参数
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(method = RequestMethod.GET)
|
|
|
|
+ public PageableDTO list(@RequestParam Long questionId,
|
|
|
|
+ @RequestParam(required = false) String level,
|
|
|
|
+ @RequestParam(required = false) Boolean isSample,
|
|
|
|
+ @RequestParam(required = false) Boolean markedLogic,
|
|
|
|
+ @RequestParam(required = false) Boolean arbi,
|
|
|
|
+ @RequestParam(required = false) Boolean reject,
|
|
|
|
+ Pageable pageable) {
|
|
|
|
+ Specification<Paper> specification = (root,query,builder) -> {
|
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
|
+ predicates.add(builder.equal(root.get("questionId"),questionId));
|
|
|
|
+ if(Objects.isNull(level)){
|
|
|
|
+ predicates.add(builder.isNull(root.get("level")));
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ predicates.add(builder.equal(root.get("level"),level));
|
|
|
|
+ }
|
|
|
|
+ if(arbi != null){
|
|
|
|
+ predicates.add(builder.equal(root.get("isArbitrated"),arbi));
|
|
|
|
+ }
|
|
|
|
+ if(reject != null){
|
|
|
|
+ predicates.add(builder.equal(root.get("isRejected"),reject));
|
|
|
|
+ }
|
|
|
|
+ if(isSample != null){
|
|
|
|
+ predicates.add(builder.equal(root.get("markByLeader"),isSample));
|
|
|
|
+ }
|
|
|
|
+ if(markedLogic != null){
|
|
|
|
+ predicates.add(builder.equal(root.get("markedLogic"),markedLogic));
|
|
|
|
+ }
|
|
|
|
+ return builder.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
|
+
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ Page<Paper> papers = paperRepo.findAll(specification,pageable);
|
|
|
|
+ List<PaperDTO> paperDTOs = new ArrayList<>();
|
|
|
|
+ papers.forEach(p -> {
|
|
|
|
+ paperDTOs.add(paperAssembler.toDTO(p));
|
|
|
|
+ });
|
|
|
|
+ return new PageableDTO(paperDTOs,papers.getTotalElements(),papers.getTotalPages(),pageable.getPageNumber());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 试卷处理。提交评卷
|
|
|
|
+ * @param paper 试卷id
|
|
|
|
+ * @param body 试卷信息
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(value = "{paper}", method = RequestMethod.PATCH)
|
|
|
|
+ @Transactional
|
|
|
|
+ public ResponseEntity marking(@PathVariable Paper paper, @RequestBody HashMap<String, String> body) {
|
|
|
|
+ String action = body.get("action");
|
|
|
|
+ String level = body.get("level");
|
|
|
|
+ String tagged = body.get("tagged");
|
|
|
|
+ if (action != null && level != null) {
|
|
|
|
+ if (action.equals("leveling")) {
|
|
|
|
+ markingService.levelMarkPaper(paper, level);
|
|
|
|
+ } else if (action.equals("reject")) {
|
|
|
|
+ markingService.reject(paper, level);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (tagged != null) {
|
|
|
|
+ boolean isTagged = paper.isTagged();
|
|
|
|
+ paper.setTagged(!isTagged);
|
|
|
|
+ paperRepo.save(paper);
|
|
|
|
+ }
|
|
|
|
+ return new ResponseEntity(paperAssembler.toDTO(paper), HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 标记试卷
|
|
|
|
+ * @param paper 试卷id
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(value = "{paper}/tag", method = RequestMethod.PATCH)
|
|
|
|
+ @Transactional
|
|
|
|
+ public Paper tagging(@PathVariable Paper paper) {
|
|
|
|
+ boolean isTagged = paper.isTagged();
|
|
|
|
+ paper.setTagged(!isTagged);
|
|
|
|
+ paperRepo.save(paper);
|
|
|
|
+ return paper;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 该试卷的评卷记录
|
|
|
|
+ * @param paperId 试卷id
|
|
|
|
+ * @param stage 评卷阶段
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(value = "{paperId}/marktasks", method = RequestMethod.GET)
|
|
|
|
+ public List<MarkTaskDTO> markTasks(@PathVariable Long paperId, @RequestParam MarkStage stage) {
|
|
|
|
+ List<MarkTaskDTO> markTaskDTOs = new ArrayList<>();
|
|
|
|
+ markTaskRepo.findByPaperIdAndStage(paperId, stage).forEach(o -> {
|
|
|
|
+ markTaskDTOs.add(markTaskAssembler.toDTO(o));
|
|
|
|
+ });
|
|
|
|
+ return markTaskDTOs;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|