|
@@ -25,6 +25,7 @@ import com.qmth.teachcloud.mark.dto.mark.manage.MarkArbitrateSettingDto;
|
|
|
import com.qmth.teachcloud.mark.dto.mark.manage.Task;
|
|
|
import com.qmth.teachcloud.mark.entity.*;
|
|
|
import com.qmth.teachcloud.mark.enums.LockType;
|
|
|
+import com.qmth.teachcloud.mark.enums.OmrTaskStatus;
|
|
|
import com.qmth.teachcloud.mark.lock.LockService;
|
|
|
import com.qmth.teachcloud.mark.mapper.MarkArbitrateHistoryMapper;
|
|
|
import com.qmth.teachcloud.mark.params.MarkArbitrateResult;
|
|
@@ -49,7 +50,7 @@ import java.util.*;
|
|
|
public class MarkArbitrateHistoryServiceImpl extends ServiceImpl<MarkArbitrateHistoryMapper, MarkArbitrateHistory> implements MarkArbitrateHistoryService {
|
|
|
|
|
|
// 并发处理互斥锁
|
|
|
- private Map<Long, Integer> currentTaskMap = new HashMap<>();
|
|
|
+ private Map<Long, Long> currentTaskMap = new HashMap<>();
|
|
|
|
|
|
@Resource
|
|
|
private BasicCourseService basicCourseService;
|
|
@@ -68,8 +69,6 @@ public class MarkArbitrateHistoryServiceImpl extends ServiceImpl<MarkArbitrateHi
|
|
|
@Resource
|
|
|
private TaskService taskService;
|
|
|
@Resource
|
|
|
- private FileUploadService fileUploadService;
|
|
|
- @Resource
|
|
|
private MarkService markService;
|
|
|
@Resource
|
|
|
private LockService lockService;
|
|
@@ -126,7 +125,7 @@ public class MarkArbitrateHistoryServiceImpl extends ServiceImpl<MarkArbitrateHi
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public MarkArbitrateSettingDto getArbitrateSetting(Long arbitrateId, Long examId, String paperNumber, Long questionId) {
|
|
|
+ public MarkArbitrateSettingDto getArbitrateSetting(Long arbitrateId, Long examId, String paperNumber) {
|
|
|
SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
MarkArbitrateHistory markArbitrateHistory;
|
|
|
if (arbitrateId != null) {
|
|
@@ -137,7 +136,7 @@ public class MarkArbitrateHistoryServiceImpl extends ServiceImpl<MarkArbitrateHi
|
|
|
examId = markArbitrateHistory.getExamId();
|
|
|
paperNumber = markArbitrateHistory.getPaperNumber();
|
|
|
} else {
|
|
|
- if (examId == null || StringUtils.isBlank(paperNumber) || questionId == null) {
|
|
|
+ if (examId == null || StringUtils.isBlank(paperNumber)) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("参数有误");
|
|
|
}
|
|
|
}
|
|
@@ -168,18 +167,24 @@ public class MarkArbitrateHistoryServiceImpl extends ServiceImpl<MarkArbitrateHi
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Task getArbitrateTask(Long arbitrateId, Long examId, String paperNumber, Long questionId) {
|
|
|
+ public Task getArbitrateTask(Long arbitrateId, Long examId, String paperNumber) {
|
|
|
+ Long userId = ServletUtil.getRequestUserId();
|
|
|
MarkArbitrateHistory markArbitrateHistory;
|
|
|
if (arbitrateId != null) {
|
|
|
markArbitrateHistory = this.getById(arbitrateId);
|
|
|
- if (MarkArbitrateStatus.MARKED.equals(markArbitrateHistory.getStatus())) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("数据已处理,请刷新数据列表");
|
|
|
+ if (this.applyTask(markArbitrateHistory.getId(), userId)) {
|
|
|
+ if (MarkArbitrateStatus.MARKED.equals(markArbitrateHistory.getStatus())) {
|
|
|
+ this.releaseTask(markArbitrateHistory.getId());
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("数据已处理,请刷新数据列表");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("任务已经其它人占用");
|
|
|
}
|
|
|
} else {
|
|
|
- if (examId == null || StringUtils.isBlank(paperNumber) || questionId == null) {
|
|
|
+ if (examId == null || StringUtils.isBlank(paperNumber)) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("参数有误");
|
|
|
}
|
|
|
- markArbitrateHistory = this.baseMapper.getArbitrateWaitingOne(examId, paperNumber, questionId);
|
|
|
+ markArbitrateHistory = this.findWaitingTask(examId, paperNumber, userId);
|
|
|
}
|
|
|
if (markArbitrateHistory == null) {
|
|
|
return null;
|
|
@@ -188,6 +193,29 @@ public class MarkArbitrateHistoryServiceImpl extends ServiceImpl<MarkArbitrateHi
|
|
|
return taskService.build(markArbitrateHistory, markQuestion);
|
|
|
}
|
|
|
|
|
|
+ private MarkArbitrateHistory findWaitingTask(Long examId, String paperNumber, Long userId) {
|
|
|
+ int retry = 0;
|
|
|
+ MarkArbitrateHistory markArbitrateHistory = null;
|
|
|
+ while (markArbitrateHistory == null) {
|
|
|
+ Page<MarkArbitrateHistory> page = new Page<>(retry * 20, 20);
|
|
|
+ IPage<MarkArbitrateHistory> historyIPage = this.baseMapper.getArbitrateWaiting(page, examId, paperNumber);
|
|
|
+ List<MarkArbitrateHistory> list = historyIPage.getRecords();
|
|
|
+ if (list.isEmpty()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ for (MarkArbitrateHistory mh : list) {
|
|
|
+ if (this.applyTask(mh.getId(), userId)) {
|
|
|
+ markArbitrateHistory = mh;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (markArbitrateHistory == null) {
|
|
|
+ retry++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return markArbitrateHistory;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void saveArbitrateTask(MarkArbitrateResult markResult) {
|
|
|
SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
@@ -217,12 +245,11 @@ public class MarkArbitrateHistoryServiceImpl extends ServiceImpl<MarkArbitrateHi
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public JSONObject getArbitrateStatus(Long examId, String paperNumber, Long questionId) {
|
|
|
+ public JSONObject getArbitrateStatus(Long examId, String paperNumber) {
|
|
|
Long userId = ServletUtil.getRequestUserId();
|
|
|
QueryWrapper<MarkArbitrateHistory> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.lambda().eq(MarkArbitrateHistory::getExamId, examId)
|
|
|
- .eq(MarkArbitrateHistory::getPaperNumber, paperNumber)
|
|
|
- .eq(MarkArbitrateHistory::getQuestionId, questionId);
|
|
|
+ .eq(MarkArbitrateHistory::getPaperNumber, paperNumber);
|
|
|
List<MarkArbitrateHistory> markArbitrateHistoryList = this.list(queryWrapper);
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
if (CollectionUtils.isEmpty(markArbitrateHistoryList)) {
|
|
@@ -277,6 +304,16 @@ public class MarkArbitrateHistoryServiceImpl extends ServiceImpl<MarkArbitrateHi
|
|
|
this.remove(updateWrapper);
|
|
|
}
|
|
|
|
|
|
+ private boolean applyTask(Long taskId, Long userId) {
|
|
|
+ synchronized (currentTaskMap) {
|
|
|
+ if (currentTaskMap.containsKey(taskId)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ currentTaskMap.put(taskId, userId);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void releaseTask(Long taskId) {
|
|
|
synchronized (currentTaskMap) {
|
|
|
currentTaskMap.remove(taskId);
|
|
@@ -288,7 +325,7 @@ public class MarkArbitrateHistoryServiceImpl extends ServiceImpl<MarkArbitrateHi
|
|
|
taskIds.addAll(currentTaskMap.keySet());
|
|
|
synchronized (currentTaskMap) {
|
|
|
for (Long taskId : taskIds) {
|
|
|
- Integer value = currentTaskMap.get(taskId);
|
|
|
+ Long value = currentTaskMap.get(taskId);
|
|
|
if (value != null && value.equals(userId)) {
|
|
|
currentTaskMap.remove(taskId);
|
|
|
}
|