|
@@ -1,6 +1,8 @@
|
|
|
package cn.com.qmth.stmms.ms.marking.api;
|
|
|
|
|
|
import cn.com.qmth.stmms.ms.commons.config.ScoreConfig;
|
|
|
+import cn.com.qmth.stmms.ms.commons.lock.LockService;
|
|
|
+import cn.com.qmth.stmms.ms.commons.lock.LockType;
|
|
|
import cn.com.qmth.stmms.ms.commons.utils.SqlUtil;
|
|
|
import cn.com.qmth.stmms.ms.commons.web.PageableDTO;
|
|
|
import cn.com.qmth.stmms.ms.core.cache.ParamCache;
|
|
@@ -11,7 +13,6 @@ import cn.com.qmth.stmms.ms.core.domain.user.MarkUser;
|
|
|
import cn.com.qmth.stmms.ms.core.repository.*;
|
|
|
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.MarkerAssembler;
|
|
|
import cn.com.qmth.stmms.ms.marking.assembler.PaperAssembler;
|
|
|
import cn.com.qmth.stmms.ms.marking.dto.LevelDetailDTO;
|
|
|
import cn.com.qmth.stmms.ms.marking.dto.MarkTaskDTO;
|
|
@@ -27,12 +28,10 @@ import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
-import org.springframework.orm.jpa.vendor.OpenJpaDialect;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import javax.persistence.criteria.CriteriaBuilder;
|
|
|
import javax.persistence.criteria.Join;
|
|
|
import javax.persistence.criteria.JoinType;
|
|
|
import javax.persistence.criteria.Predicate;
|
|
@@ -81,6 +80,9 @@ public class MarkTaskApi {
|
|
|
@Autowired
|
|
|
SqlUtil sqlUtil;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ LockService lockService;
|
|
|
+
|
|
|
/**
|
|
|
* 评卷员的评卷任务
|
|
|
*
|
|
@@ -108,15 +110,15 @@ public class MarkTaskApi {
|
|
|
Long scoreBatchNo = null;
|
|
|
if (stage == MarkStage.LEVEL) {
|
|
|
List<Object> batchNos = paperRepo.findBatchNoByWorkIdAndSubject(workId, markUser.getSubject().name());
|
|
|
- if(batchNos !=null && batchNos.size() > 0){
|
|
|
+ if (batchNos != null && batchNos.size() > 0) {
|
|
|
Object object = batchNos.get(0);
|
|
|
batchNo = Long.valueOf(object.toString());
|
|
|
}
|
|
|
} else if (stage == MarkStage.SCORE) {
|
|
|
List<Object> batchNos = paperRepo.findScoreBatchNoByWorkIdAndSubject(workId, markUser.getSubject().name());
|
|
|
- if(batchNos !=null && batchNos.size() > 0){
|
|
|
+ if (batchNos != null && batchNos.size() > 0) {
|
|
|
Object object = batchNos.get(0);
|
|
|
- if(Objects.nonNull(object)) {
|
|
|
+ if (Objects.nonNull(object)) {
|
|
|
scoreBatchNo = Long.valueOf(object.toString());
|
|
|
}
|
|
|
}
|
|
@@ -143,7 +145,7 @@ public class MarkTaskApi {
|
|
|
} else if (stage == MarkStage.LEVEL) {
|
|
|
//查询
|
|
|
predicates.add(builder.equal(root.get("result"), level));
|
|
|
- if(levelShowAllPaper == 0) {
|
|
|
+ if (levelShowAllPaper == 0) {
|
|
|
if (!Objects.isNull(finalBatchNo)) {
|
|
|
onPredicates.add(builder.equal(join.get("batchNo"), finalBatchNo));
|
|
|
}
|
|
@@ -152,7 +154,7 @@ public class MarkTaskApi {
|
|
|
onPredicates.add(builder.equal(join.get("level"), level));
|
|
|
predicates.add(builder.isNotNull(root.get("result")));
|
|
|
onPredicates.add(builder.equal(join.get("isShift"), false));
|
|
|
- if(scoreShowAllPaper == 1){
|
|
|
+ if (scoreShowAllPaper == 1) {
|
|
|
onPredicates.add(builder.isNotNull(join.get("scoreBatchNo")));
|
|
|
} else {
|
|
|
onPredicates.add(builder.equal(join.get("scoreBatchNo"), finalScoreBatchNo));
|
|
@@ -174,7 +176,7 @@ public class MarkTaskApi {
|
|
|
join.on(onPredicates.toArray(new Predicate[onPredicates.size()]));
|
|
|
return builder.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
};
|
|
|
- Sort sort = new Sort( "randomSeq", "randomSeqNew");
|
|
|
+ Sort sort = new Sort("randomSeq", "randomSeqNew");
|
|
|
Pageable pageable1 = new PageRequest(pageable.getPageNumber(), pageable.getPageSize(), sort);
|
|
|
Page<MarkTask> markTasks = markTaskRepo.findAll(specification, pageable1);
|
|
|
|
|
@@ -231,14 +233,14 @@ public class MarkTaskApi {
|
|
|
if (isShift != null) {
|
|
|
//查询
|
|
|
predicates.add(builder.equal(root.get("paper").get("isShift"), isShift));
|
|
|
- if(isShift){
|
|
|
+ if (isShift) {
|
|
|
predicates.add(builder.equal(root.get("stage"), MarkStage.LEVEL));
|
|
|
predicates.add(builder.isNull(root.get("result")));
|
|
|
}
|
|
|
}
|
|
|
if (isShiftScore != null && isShiftScore && !isShift) {
|
|
|
predicates.add(builder.equal(root.get("paper").get("isShiftScore"), isShiftScore));
|
|
|
- if(isShiftScore){
|
|
|
+ if (isShiftScore) {
|
|
|
predicates.add(builder.equal(root.get("stage"), MarkStage.SCORE));
|
|
|
predicates.add(builder.isNull(root.get("result")));
|
|
|
}
|
|
@@ -262,10 +264,10 @@ public class MarkTaskApi {
|
|
|
*/
|
|
|
@RequestMapping(value = "/manualScore", method = RequestMethod.GET)
|
|
|
public PageableDTO listManualScore(@RequestParam Long markerId,
|
|
|
- @RequestParam(required = false) Long workId,
|
|
|
- @RequestParam Subject subject,
|
|
|
- @RequestParam Long questionId,
|
|
|
- Pageable pageable) {
|
|
|
+ @RequestParam(required = false) Long workId,
|
|
|
+ @RequestParam Subject subject,
|
|
|
+ @RequestParam Long questionId,
|
|
|
+ Pageable pageable) {
|
|
|
List<MarkTaskDTO> markTaskDTOs = new ArrayList<>();
|
|
|
Specification<MarkTask> specification = (root, query, builder) -> {
|
|
|
List<Predicate> predicates = new ArrayList<>();
|
|
@@ -327,8 +329,13 @@ public class MarkTaskApi {
|
|
|
}
|
|
|
switch (stage) {
|
|
|
case LEVEL:
|
|
|
- synchronized (this) {
|
|
|
+ try {
|
|
|
+ lockService.waitlock(LockType.LEVEL, markTask.getPaper().getId());
|
|
|
markingService.levelMark(markTask, result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("分档异常");
|
|
|
+ } finally {
|
|
|
+ lockService.unlock(LockType.LEVEL, markTask.getPaper().getId());
|
|
|
}
|
|
|
break;
|
|
|
case SCORE:
|
|
@@ -336,8 +343,13 @@ public class MarkTaskApi {
|
|
|
//是否手工输入分数
|
|
|
String manualScore = body.get("manualScore");
|
|
|
markTask.setManualScore(StringUtils.isEmpty(manualScore) ? 0 : Integer.parseInt(manualScore));
|
|
|
- synchronized (this) {
|
|
|
+ try {
|
|
|
+ lockService.waitlock(LockType.SCORE, markTask.getPaper().getId());
|
|
|
markingService.scoring(markTask, score);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("打分异常");
|
|
|
+ } finally {
|
|
|
+ lockService.unlock(LockType.SCORE, markTask.getPaper().getId());
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
@@ -347,7 +359,7 @@ public class MarkTaskApi {
|
|
|
/**
|
|
|
* 批量提交评卷任务
|
|
|
*
|
|
|
- * @param body 评卷内容
|
|
|
+ * @param body 评卷内容
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "batch", method = RequestMethod.PATCH)
|
|
@@ -355,7 +367,7 @@ public class MarkTaskApi {
|
|
|
MarkStage stage = MarkStage.valueOf(body.get("stage"));
|
|
|
String markIds = body.get("taskIds");
|
|
|
String result = body.get("result");
|
|
|
- if(Objects.isNull(markIds)){
|
|
|
+ if (Objects.isNull(markIds)) {
|
|
|
throw new RuntimeException("请选择待评试卷");
|
|
|
}
|
|
|
String[] ids = markIds.split(",");
|
|
@@ -370,8 +382,13 @@ public class MarkTaskApi {
|
|
|
}
|
|
|
switch (stage) {
|
|
|
case LEVEL:
|
|
|
- synchronized (this) {
|
|
|
+ try {
|
|
|
+ lockService.waitlock(LockType.LEVEL, markTask.getPaper().getId());
|
|
|
markingService.levelMark(markTask, result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("分档异常");
|
|
|
+ } finally {
|
|
|
+ lockService.unlock(LockType.LEVEL, markTask.getPaper().getId());
|
|
|
}
|
|
|
break;
|
|
|
case SCORE:
|
|
@@ -421,8 +438,8 @@ public class MarkTaskApi {
|
|
|
Long socreBatchNo = null;
|
|
|
if (stage == MarkStage.LEVEL) {
|
|
|
batchNo = paperRepo.findByQuestionId(questionId);
|
|
|
- }else if (stage == MarkStage.SCORE) {
|
|
|
- socreBatchNo=paperRepo.findScoreBatchNoByQuestionId(questionId);
|
|
|
+ } else if (stage == MarkStage.SCORE) {
|
|
|
+ socreBatchNo = paperRepo.findScoreBatchNoByQuestionId(questionId);
|
|
|
}
|
|
|
|
|
|
Long finalBatchNo = batchNo;
|