|
@@ -67,7 +67,6 @@ import java.util.*;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
-import java.util.stream.Stream;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class MarkServiceImpl implements MarkService {
|
|
public class MarkServiceImpl implements MarkService {
|
|
@@ -1520,6 +1519,45 @@ public class MarkServiceImpl implements MarkService {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void ocrMarkQuestion(MarkQuestion markQuestion) {
|
|
|
|
+ Long examId = markQuestion.getExamId();
|
|
|
|
+ String paperNumber = markQuestion.getPaperNumber();
|
|
|
|
+ Long questionId = markQuestion.getId();
|
|
|
|
+
|
|
|
|
+ // 终止AI评卷
|
|
|
|
+ if (!markQuestion.getEnableAi()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // AI评卷且未设置评卷参数
|
|
|
|
+ if (MarkPaperAiMark.NONE.equals(markQuestion.getAiMark())
|
|
|
|
+ || !markAiQuestionParamService.existMarkAiQuestionPointOrLevel(examId, paperNumber, questionId)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ BasicSchool basicSchool = basicSchoolMapper.selectByExamId(examId);
|
|
|
|
+ List<MarkTask> markTasks;
|
|
|
|
+ int pageNumber = 1;
|
|
|
|
+ do {
|
|
|
|
+ markTasks = markTaskService.findAiUnMarked(new Page<>(pageNumber, 20), examId, paperNumber, questionId);
|
|
|
|
+ if (markTasks.isEmpty() || !markQuestion.getEnableAi()) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ for (MarkTask t : markTasks) {
|
|
|
|
+ // 考生作答
|
|
|
|
+ try {
|
|
|
|
+ this.ocrStudentQuestionResult(basicSchool, t.getStudentId(), t.getQuestionId());
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("OCR识别错误:", e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ pageNumber++;
|
|
|
|
+ // 获取终止评卷标记
|
|
|
|
+ markQuestion = markQuestionService.getById(questionId);
|
|
|
|
+ markTasks = markTaskService.findAiUnMarked(new Page<>(pageNumber, 20), examId, paperNumber, questionId);
|
|
|
|
+ } while (CollectionUtils.isNotEmpty(markTasks));
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void aiMark(MarkQuestion markQuestion) {
|
|
public void aiMark(MarkQuestion markQuestion) {
|
|
Long examId = markQuestion.getExamId();
|
|
Long examId = markQuestion.getExamId();
|
|
@@ -1556,7 +1594,10 @@ public class MarkServiceImpl implements MarkService {
|
|
// 考生作答
|
|
// 考生作答
|
|
try {
|
|
try {
|
|
long startTime = System.currentTimeMillis();
|
|
long startTime = System.currentTimeMillis();
|
|
- List<MarkOcrStudentQuestion> markOcrStudentQuestions = this.listStudentQuestionOcrResult(basicSchool, t.getStudentId(), t.getQuestionId());
|
|
|
|
|
|
+ List<MarkOcrStudentQuestion> markOcrStudentQuestions = markOcrStudentQuestionService.listByStudentIdAndQuestionId(t.getStudentId(), t.getQuestionId());
|
|
|
|
+ if (CollectionUtils.isEmpty(markOcrStudentQuestions)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
String studentQuestionAnswer = this.mergeQuestionOcrResult(markOcrStudentQuestions);
|
|
String studentQuestionAnswer = this.mergeQuestionOcrResult(markOcrStudentQuestions);
|
|
|
|
|
|
AutoScoreRequest request = new AutoScoreRequest();
|
|
AutoScoreRequest request = new AutoScoreRequest();
|
|
@@ -1570,7 +1611,7 @@ public class MarkServiceImpl implements MarkService {
|
|
// AI评卷
|
|
// AI评卷
|
|
AutoScoreResult autoScoreResult = aiService.autoScore(request, AiUtil.signatureAi(basicSchool));
|
|
AutoScoreResult autoScoreResult = aiService.autoScore(request, AiUtil.signatureAi(basicSchool));
|
|
long endTime = System.currentTimeMillis();
|
|
long endTime = System.currentTimeMillis();
|
|
- submitAiTask(t, aiUser.getId(), markQuestion, autoScoreResult, buildTrack(autoScoreResult, markQuestion, markOcrStudentQuestions), endTime - startTime);
|
|
|
|
|
|
+ submitAiTask(t, aiUser.getId(), markQuestion, autoScoreResult, buildTrack(markAiQuestionParam.getMode(), autoScoreResult, markQuestion, markOcrStudentQuestions), endTime - startTime);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
t.setAiMarkErrorMsg(e.getMessage());
|
|
t.setAiMarkErrorMsg(e.getMessage());
|
|
} finally {
|
|
} finally {
|
|
@@ -1632,16 +1673,20 @@ public class MarkServiceImpl implements MarkService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private List<TrackDTO> buildTrack(AutoScoreResult autoScoreResult, MarkQuestion markQuestion, List<MarkOcrStudentQuestion> markOcrStudentQuestions) {
|
|
|
|
|
|
+ private List<TrackDTO> buildTrack(AiQuestionParamModeStatus mode, AutoScoreResult autoScoreResult, MarkQuestion markQuestion, List<MarkOcrStudentQuestion> markOcrStudentQuestions) {
|
|
List<TrackDTO> list = new ArrayList<>();
|
|
List<TrackDTO> list = new ArrayList<>();
|
|
if (markOcrStudentQuestions.isEmpty()) {
|
|
if (markOcrStudentQuestions.isEmpty()) {
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|
|
double[] doubles = autoScoreResult.getStepScore();
|
|
double[] doubles = autoScoreResult.getStepScore();
|
|
|
|
+ // 按档次时,stepScore中为所有档次的分值,实际使用只需要一个最终档次的值
|
|
|
|
+ if (AiQuestionParamModeStatus.LEVEL.equals(mode)) {
|
|
|
|
+ doubles = new double[]{autoScoreResult.getTotalScore()};
|
|
|
|
+ }
|
|
// 轨迹打印在第一个评卷区上
|
|
// 轨迹打印在第一个评卷区上
|
|
List<MarkConfigItem> pictureConfigList = markQuestion.getPictureConfigList();
|
|
List<MarkConfigItem> pictureConfigList = markQuestion.getPictureConfigList();
|
|
|
|
|
|
- int initXAdd = 100, initYAdd = 100, stepXAdd = 100, stepYAdd = 30;
|
|
|
|
|
|
+ int initXAdd = 100, initYAdd = 100, stepXAdd = 100, stepYAdd = 50;
|
|
int count = 0;
|
|
int count = 0;
|
|
for (int i = 0; i < pictureConfigList.size(); i++) {
|
|
for (int i = 0; i < pictureConfigList.size(); i++) {
|
|
MarkConfigItem markConfigItem = pictureConfigList.get(i);
|
|
MarkConfigItem markConfigItem = pictureConfigList.get(i);
|
|
@@ -1724,26 +1769,28 @@ public class MarkServiceImpl implements MarkService {
|
|
return markOcrStudentQuestionList.stream().filter(m -> StringUtils.isNotBlank(m.getOcrContent())).map(MarkOcrStudentQuestion::getOcrContent).collect(Collectors.joining(SystemConstant.COMMA_OF_CHINESE));
|
|
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) {
|
|
|
|
|
|
+ private void ocrStudentQuestionResult(BasicSchool basicSchool, Long studentId, Long questionId) {
|
|
List<MarkOcrStudentQuestion> markOcrStudentQuestionList = markOcrStudentQuestionService.listByStudentIdAndQuestionId(studentId, questionId);
|
|
List<MarkOcrStudentQuestion> markOcrStudentQuestionList = markOcrStudentQuestionService.listByStudentIdAndQuestionId(studentId, questionId);
|
|
if (CollectionUtils.isNotEmpty(markOcrStudentQuestionList)) {
|
|
if (CollectionUtils.isNotEmpty(markOcrStudentQuestionList)) {
|
|
- return markOcrStudentQuestionList;
|
|
|
|
- }
|
|
|
|
- MarkQuestion markQuestion = markQuestionService.getById(questionId);
|
|
|
|
- if (markQuestion == null || StringUtils.isBlank(markQuestion.getPicList())) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("大题号[" + markQuestion.getMainNumber() + "]、小题号[" + markQuestion.getSubNumber() + "]未设置评卷区");
|
|
|
|
- }
|
|
|
|
- // 读取考生图片
|
|
|
|
- MarkStudent markStudent = markStudentService.getById(studentId);
|
|
|
|
- if (markStudent == null) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("未找到考生" + ",考生ID[" + studentId);
|
|
|
|
- } else if (StringUtils.isBlank(markStudent.getSheetPath())) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("未查询到原图" + ",考号[" + markStudent.getStudentCode());
|
|
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
List<File> deleteFileList = new ArrayList<>();
|
|
List<File> deleteFileList = new ArrayList<>();
|
|
- Map<Integer, SheetImageDto> fileMap = new HashMap<>();
|
|
|
|
- //考生题卡原图
|
|
|
|
try {
|
|
try {
|
|
|
|
+ MarkQuestion markQuestion = markQuestionService.getById(questionId);
|
|
|
|
+ if (markQuestion == null || StringUtils.isBlank(markQuestion.getPicList())) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("大题号[" + markQuestion.getMainNumber() + "]、小题号[" + markQuestion.getSubNumber() + "]未设置评卷区");
|
|
|
|
+ }
|
|
|
|
+ // 读取考生图片
|
|
|
|
+ MarkStudent markStudent = markStudentService.getById(studentId);
|
|
|
|
+ if (markStudent == null) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("未找到考生" + ",考生ID[" + studentId);
|
|
|
|
+ } else if (StringUtils.isBlank(markStudent.getSheetPath())) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("未查询到原图" + ",考号[" + markStudent.getStudentCode());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Map<Integer, SheetImageDto> fileMap = new HashMap<>();
|
|
|
|
+ //考生题卡原图
|
|
|
|
+
|
|
List<FilePathVo> filePathVoList = markStudent.listSheetPath();
|
|
List<FilePathVo> filePathVoList = markStudent.listSheetPath();
|
|
for (int i = 0; i < filePathVoList.size(); i++) {
|
|
for (int i = 0; i < filePathVoList.size(); i++) {
|
|
FilePathVo filePathVo = filePathVoList.get(i);
|
|
FilePathVo filePathVo = filePathVoList.get(i);
|
|
@@ -1790,7 +1837,6 @@ public class MarkServiceImpl implements MarkService {
|
|
deleteFileList.add(file);
|
|
deleteFileList.add(file);
|
|
}
|
|
}
|
|
markOcrStudentQuestionService.saveBatch(markOcrStudentQuestions);
|
|
markOcrStudentQuestionService.saveBatch(markOcrStudentQuestions);
|
|
- return markOcrStudentQuestions;
|
|
|
|
} catch (RuntimeException e) {
|
|
} catch (RuntimeException e) {
|
|
throw ExceptionResultEnum.ERROR.exception(e.getMessage());
|
|
throw ExceptionResultEnum.ERROR.exception(e.getMessage());
|
|
} finally {
|
|
} finally {
|