|
@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
|
import com.qmth.boot.core.ai.client.OcrApiClient;
|
|
|
+import com.qmth.boot.core.ai.model.llm.score.AutoScoreModel;
|
|
|
import com.qmth.boot.core.ai.model.llm.score.AutoScoreRequest;
|
|
|
import com.qmth.boot.core.ai.model.llm.score.AutoScoreResult;
|
|
|
import com.qmth.boot.core.ai.model.llm.score.StandardAnswer;
|
|
@@ -753,7 +754,8 @@ public class MarkServiceImpl implements MarkService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void updateMarkTaskCount(Long examId, String paperNumber, Long questionId) {
|
|
|
+ @Override
|
|
|
+ public void updateMarkTaskCount(Long examId, String paperNumber, Long questionId) {
|
|
|
int count = markTaskService.countByExamIdAndPaperNumberAndQuestionIdAndUserId(examId, paperNumber, questionId,
|
|
|
null);
|
|
|
markQuestionService.updateTaskCount(questionId, count);
|
|
@@ -1528,7 +1530,8 @@ public class MarkServiceImpl implements MarkService {
|
|
|
return;
|
|
|
}
|
|
|
// AI评卷且未设置评卷参数
|
|
|
- if (!MarkPaperAiMark.NONE.equals(markQuestion.getAiMark()) && !markAiQuestionParamService.existMarkAiQuestionPointOrLevel(examId, paperNumber, questionId)) {
|
|
|
+ if (MarkPaperAiMark.NONE.equals(markQuestion.getAiMark())
|
|
|
+ || !markAiQuestionParamService.existMarkAiQuestionPointOrLevel(examId, paperNumber, questionId)) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -1542,33 +1545,36 @@ public class MarkServiceImpl implements MarkService {
|
|
|
do {
|
|
|
Set<Long> questions = new HashSet<>(Arrays.asList(questionId));
|
|
|
markTasks = markTaskService.findAiUnMarked(new Page<>(pageNumber, 20), examId, paperNumber, questionId);
|
|
|
- if (markTasks.isEmpty() || markQuestion.getEnableAi()) {
|
|
|
+ if (markTasks.isEmpty() || !markQuestion.getEnableAi()) {
|
|
|
break;
|
|
|
}
|
|
|
for (MarkTask t : markTasks) {
|
|
|
- if (this.applyTask(examId, paperNumber, t.getStudentId(), null, questions, Arrays.asList(t.getId()))) {
|
|
|
- break;
|
|
|
+ if (this.applyTask(examId, paperNumber, t.getStudentId(), aiUser.getId(), questions, Arrays.asList(t.getId()))) {
|
|
|
+ continue;
|
|
|
}
|
|
|
// 考生作答
|
|
|
try {
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
- Map<Integer, SheetImageDto> fileMap = new HashMap<>();
|
|
|
- String studentQuestionAnswer = this.mergeQuestionOcrResult(this.listStudentQuestionOcrResult(basicSchool, t.getStudentId(), t.getQuestionId(), fileMap));
|
|
|
+ List<MarkOcrStudentQuestion> markOcrStudentQuestions = this.listStudentQuestionOcrResult(basicSchool, t.getStudentId(), t.getQuestionId());
|
|
|
+ String studentQuestionAnswer = this.mergeQuestionOcrResult(markOcrStudentQuestions);
|
|
|
|
|
|
AutoScoreRequest request = new AutoScoreRequest();
|
|
|
request.setSubjectName(basicCourse.getName());
|
|
|
+ request.setScoreModel(AutoScoreModel.valueOf(markAiQuestionParam.getMode().name()));
|
|
|
request.setTotalScore(markQuestion.getTotalScore());
|
|
|
request.setIntervalScore(markAiQuestionParam.getMinScore());
|
|
|
request.setQuestionBody(markAiQuestionParam.getMainTitle());
|
|
|
request.setStudentAnswer(studentQuestionAnswer);
|
|
|
request.setStandardAnswer(buildStandardAnswer(markAiQuestionParam));
|
|
|
// AI评卷
|
|
|
- AutoScoreResult autoScoreResult = aiService.autoScore(request, AiUtil.signature(basicSchool));
|
|
|
+ AutoScoreResult autoScoreResult = aiService.autoScore(request, AiUtil.signatureAi(basicSchool));
|
|
|
long endTime = System.currentTimeMillis();
|
|
|
- submitAiTask(t, aiUser.getId(), markQuestion, autoScoreResult, buildTrack(autoScoreResult, markQuestion, fileMap), endTime - startTime);
|
|
|
+ submitAiTask(t, aiUser.getId(), markQuestion, autoScoreResult, buildTrack(autoScoreResult, markQuestion, markOcrStudentQuestions), endTime - startTime);
|
|
|
} catch (Exception e) {
|
|
|
t.setAiMarkErrorMsg(e.getMessage());
|
|
|
} finally {
|
|
|
+ this.releaseStudent(examId, paperNumber, t.getStudentId(), aiUser.getId());
|
|
|
+ this.updateMarkedCount(examId, paperNumber, t.getQuestionId());
|
|
|
t.setAiMarkErrorMsg(null);
|
|
|
markTaskService.updateAiMarkErrorMsg(t);
|
|
|
}
|
|
@@ -1593,16 +1599,14 @@ public class MarkServiceImpl implements MarkService {
|
|
|
return;
|
|
|
}
|
|
|
if (markPaper.getStatus() == MarkPaperStatus.FORMAL) {
|
|
|
+ List<MarkTaskStatus> statusList = Arrays.asList(MarkTaskStatus.WAITING);
|
|
|
+ boolean pointOrLevel = markAiQuestionParamService.existMarkAiQuestionPointOrLevel(examId, paperNumber, questionId);
|
|
|
// 未设置AI智能评卷参数,删除所有任务
|
|
|
- if (!markAiQuestionParamService.existMarkAiQuestionPointOrLevel(examId, paperNumber, questionId)) {
|
|
|
- markTaskService.deleteByExamIdAndPaperNumberAndQuestionId(examId, paperNumber, questionId);
|
|
|
- markSubjectiveScoreService.deleteByExamIdAndPaperNumberAndQuestionId(examId, paperNumber, questionId);
|
|
|
- markRejectHistoryService.deleteByExamIdAndPaperNumberAndQuestionId(examId, paperNumber, questionId);
|
|
|
- markArbitrateHistoryService.deleteByExamIdAndPaperNumberAndQuestionId(examId, paperNumber, questionId);
|
|
|
+ if (!pointOrLevel) {
|
|
|
+ this.deleteMarkTask(markQuestion, true);
|
|
|
this.checkStudentSubjectiveScore(examId, markPaper.getCoursePaperId());
|
|
|
} else {
|
|
|
// 遍历相关评卷任务的模式
|
|
|
- List<MarkTaskStatus> statusList = Arrays.asList(MarkTaskStatus.WAITING);
|
|
|
List<MarkTask> markTaskList = markTaskService.listByExamIdAndPaperNumberAndQuestionIdAndAiMarkedAndStatusNotIn(examId, paperNumber, questionId, true, statusList);
|
|
|
for (MarkTask markTask : markTaskList) {
|
|
|
Long studentId = markTask.getStudentId();
|
|
@@ -1621,24 +1625,27 @@ public class MarkServiceImpl implements MarkService {
|
|
|
markOcrStudentQuestionService.deleteByExamIdAndPaperNumberAndQuestionId(examId, paperNumber, questionId);
|
|
|
markQuestionService.updateClearOcrResult(questionId, false);
|
|
|
}
|
|
|
+
|
|
|
+ this.updateMarkTaskCount(examId, paperNumber, questionId);
|
|
|
+ this.updateMarkedCount(examId, paperNumber, questionId);
|
|
|
}
|
|
|
- this.updateMarkedCount(examId, paperNumber, questionId);
|
|
|
}
|
|
|
|
|
|
- private List<TrackDTO> buildTrack(AutoScoreResult autoScoreResult, MarkQuestion markQuestion, Map<Integer, SheetImageDto> fileMap) {
|
|
|
+ private List<TrackDTO> buildTrack(AutoScoreResult autoScoreResult, MarkQuestion markQuestion, List<MarkOcrStudentQuestion> markOcrStudentQuestions) {
|
|
|
List<TrackDTO> list = new ArrayList<>();
|
|
|
- if (fileMap.isEmpty()) {
|
|
|
+ if (markOcrStudentQuestions.isEmpty()) {
|
|
|
return list;
|
|
|
}
|
|
|
double[] doubles = autoScoreResult.getStepScore();
|
|
|
// 轨迹打印在第一个评卷区上
|
|
|
List<MarkConfigItem> pictureConfigList = markQuestion.getPictureConfigList();
|
|
|
MarkConfigItem markConfigItem = pictureConfigList.get(0);
|
|
|
- SheetImageDto sheetImageDto = fileMap.get(markConfigItem.getI());
|
|
|
- int step = 10;
|
|
|
+// SheetImageDto sheetImageDto = fileMap.get(markConfigItem.getI());
|
|
|
+ MarkOcrStudentQuestion markOcrStudentQuestion = markOcrStudentQuestions.stream().filter(m -> m.getNumber().equals(markConfigItem.getI())).findFirst().get();
|
|
|
+ int step = 150;
|
|
|
for (int i = 0; i < doubles.length; i++) {
|
|
|
- int offsetX = (int) (sheetImageDto.getWidth() * markConfigItem.getX()) + step * (i + 1);
|
|
|
- int offsetY = (int) (sheetImageDto.getHeight() * markConfigItem.getY()) + step;
|
|
|
+ int offsetX = (int) (markOcrStudentQuestion.getImageWidth() * markConfigItem.getX()) + 200 + step * (i + 1);
|
|
|
+ int offsetY = (int) (markOcrStudentQuestion.getImageHeight() * markConfigItem.getY()) + 300;
|
|
|
list.add(new TrackDTO(markQuestion, i + 1, doubles[i], markConfigItem.getI(), offsetX, offsetY));
|
|
|
}
|
|
|
return list;
|
|
@@ -1685,7 +1692,7 @@ public class MarkServiceImpl implements MarkService {
|
|
|
return markOcrStudentQuestionList.stream().filter(m -> StringUtils.isNotBlank(m.getOcrContent())).map(MarkOcrStudentQuestion::getOcrContent).collect(Collectors.joining(SystemConstant.COMMA_OF_CHINESE));
|
|
|
}
|
|
|
|
|
|
- private List<MarkOcrStudentQuestion> listStudentQuestionOcrResult(BasicSchool basicSchool, Long studentId, Long questionId, Map<Integer, SheetImageDto> fileMap) {
|
|
|
+ private List<MarkOcrStudentQuestion> listStudentQuestionOcrResult(BasicSchool basicSchool, Long studentId, Long questionId) {
|
|
|
List<MarkOcrStudentQuestion> markOcrStudentQuestionList = markOcrStudentQuestionService.listByStudentIdAndQuestionId(studentId, questionId);
|
|
|
if (CollectionUtils.isNotEmpty(markOcrStudentQuestionList)) {
|
|
|
return markOcrStudentQuestionList;
|
|
@@ -1702,6 +1709,7 @@ public class MarkServiceImpl implements MarkService {
|
|
|
throw ExceptionResultEnum.ERROR.exception("未查询到原图" + ",考号[" + markStudent.getStudentCode());
|
|
|
}
|
|
|
List<File> deleteFileList = new ArrayList<>();
|
|
|
+ Map<Integer, SheetImageDto> fileMap = new HashMap<>();
|
|
|
//考生题卡原图
|
|
|
try {
|
|
|
List<FilePathVo> filePathVoList = markStudent.listSheetPath();
|
|
@@ -1709,7 +1717,7 @@ public class MarkServiceImpl implements MarkService {
|
|
|
FilePathVo filePathVo = filePathVoList.get(i);
|
|
|
File file = SystemConstant.getFileTempDirVar(SystemConstant.JPG_PREFIX);
|
|
|
try {
|
|
|
- fileUploadService.downloadFile(filePathVo.getPath(), filePathVo.getUploadType(), filePathVo.getType(), file.getPath());
|
|
|
+ fileUploadService.downloadFile(filePathVo.getType(), filePathVo.getUploadType(), filePathVo.getPath(), file.getPath());
|
|
|
} catch (Exception e) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("读取考生原图失败" + ",考号[" + markStudent.getStudentCode() + "。" + e.getMessage());
|
|
|
}
|
|
@@ -1730,7 +1738,7 @@ public class MarkServiceImpl implements MarkService {
|
|
|
// OCR识别
|
|
|
String ocrResult;
|
|
|
try {
|
|
|
- ocrResult = ocrApiClient.forImage(AiUtil.signature(basicSchool), OcrType.HANDWRITING, UploadFile.build("image", "", file));
|
|
|
+ ocrResult = ocrApiClient.forImage(AiUtil.signatureOcr(basicSchool), OcrType.HANDWRITING, UploadFile.build("image", "", file));
|
|
|
} catch (Exception e) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("OCR识别失败" + ",考号[" + markStudent.getStudentCode() + "。" + e.getMessage());
|
|
|
}
|
|
@@ -1742,6 +1750,8 @@ public class MarkServiceImpl implements MarkService {
|
|
|
markOcrStudentQuestion.setQuestionId(questionId);
|
|
|
markOcrStudentQuestion.setNumber(i + 1);
|
|
|
markOcrStudentQuestion.setMd5(sheetImageDto.getMd5());
|
|
|
+ markOcrStudentQuestion.setImageWidth(sheetImageDto.getWidth());
|
|
|
+ markOcrStudentQuestion.setImageHeight(sheetImageDto.getHeight());
|
|
|
markOcrStudentQuestion.setOcrContent(ocrResult);
|
|
|
markOcrStudentQuestion.setCreateTime(System.currentTimeMillis());
|
|
|
markOcrStudentQuestions.add(markOcrStudentQuestion);
|
|
@@ -1801,6 +1811,10 @@ public class MarkServiceImpl implements MarkService {
|
|
|
markTaskService.updateStatusByStudentIdAndQuestionId(task.getStudentId(), task.getQuestionId(), MarkTaskStatus.WAIT_ARBITRATE);
|
|
|
// 未评完
|
|
|
resetStudentStatus(task.getStudentId());
|
|
|
+ } else {
|
|
|
+ // 判断当前分组是否已完成评卷
|
|
|
+ markQuestion.setMarkScore(result.getTotalScore());
|
|
|
+ checkStudentQuestion(task.getStudentId(), markQuestion);
|
|
|
}
|
|
|
return true;
|
|
|
}
|