|
@@ -1,8 +1,11 @@
|
|
package cn.com.qmth.am.service.impl;
|
|
package cn.com.qmth.am.service.impl;
|
|
|
|
|
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.FileOutputStream;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
import java.util.Comparator;
|
|
import java.util.Comparator;
|
|
@@ -13,6 +16,8 @@ import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
+import javax.imageio.ImageIO;
|
|
|
|
+
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
@@ -35,17 +40,21 @@ import com.qmth.boot.tools.models.ByteArray;
|
|
import cn.com.qmth.am.bean.AiMarkingDto;
|
|
import cn.com.qmth.am.bean.AiMarkingDto;
|
|
import cn.com.qmth.am.bean.AnswerImageDto;
|
|
import cn.com.qmth.am.bean.AnswerImageDto;
|
|
import cn.com.qmth.am.bean.AutoScoreEnRequest;
|
|
import cn.com.qmth.am.bean.AutoScoreEnRequest;
|
|
|
|
+import cn.com.qmth.am.bean.ImagePosition;
|
|
|
|
+import cn.com.qmth.am.bean.ImageSize;
|
|
import cn.com.qmth.am.bean.ImageSlice;
|
|
import cn.com.qmth.am.bean.ImageSlice;
|
|
import cn.com.qmth.am.bean.ModelSpeed;
|
|
import cn.com.qmth.am.bean.ModelSpeed;
|
|
import cn.com.qmth.am.bean.OcrDto;
|
|
import cn.com.qmth.am.bean.OcrDto;
|
|
import cn.com.qmth.am.bean.StudentScoreImageDto;
|
|
import cn.com.qmth.am.bean.StudentScoreImageDto;
|
|
import cn.com.qmth.am.bean.StudentScoreInfo;
|
|
import cn.com.qmth.am.bean.StudentScoreInfo;
|
|
import cn.com.qmth.am.bean.StudentScoreVo;
|
|
import cn.com.qmth.am.bean.StudentScoreVo;
|
|
|
|
+import cn.com.qmth.am.bean.StudentVo;
|
|
import cn.com.qmth.am.bean.ds.AutoScoreResult;
|
|
import cn.com.qmth.am.bean.ds.AutoScoreResult;
|
|
import cn.com.qmth.am.config.SysProperty;
|
|
import cn.com.qmth.am.config.SysProperty;
|
|
import cn.com.qmth.am.dao.local.StudentScoreDao;
|
|
import cn.com.qmth.am.dao.local.StudentScoreDao;
|
|
import cn.com.qmth.am.entity.QuestionEntity;
|
|
import cn.com.qmth.am.entity.QuestionEntity;
|
|
import cn.com.qmth.am.entity.StudentScoreEntity;
|
|
import cn.com.qmth.am.entity.StudentScoreEntity;
|
|
|
|
+import cn.com.qmth.am.enums.AnswerRangeType;
|
|
import cn.com.qmth.am.enums.DataStatus;
|
|
import cn.com.qmth.am.enums.DataStatus;
|
|
import cn.com.qmth.am.service.DsMarkingService;
|
|
import cn.com.qmth.am.service.DsMarkingService;
|
|
import cn.com.qmth.am.service.QuestionService;
|
|
import cn.com.qmth.am.service.QuestionService;
|
|
@@ -77,20 +86,20 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
@Override
|
|
@Override
|
|
- public void saveByQuestion(List<QuestionEntity> qlist, List<String> examNumbers) {
|
|
|
|
|
|
+ public void saveByQuestion(List<QuestionEntity> qlist, List<StudentVo> stuVo) {
|
|
if (CollectionUtils.isEmpty(qlist)) {
|
|
if (CollectionUtils.isEmpty(qlist)) {
|
|
throw new StatusException("试题信息为空");
|
|
throw new StatusException("试题信息为空");
|
|
}
|
|
}
|
|
Set<String> allStudent = getAllStudent();
|
|
Set<String> allStudent = getAllStudent();
|
|
|
|
|
|
- BatchSetDataUtil<String> bs = new BatchSetDataUtil<String>() {
|
|
|
|
|
|
+ BatchSetDataUtil<StudentVo> bs = new BatchSetDataUtil<StudentVo>() {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- protected void setData(List<String> dataList) {
|
|
|
|
|
|
+ protected void setData(List<StudentVo> dataList) {
|
|
List<StudentScoreEntity> adds = new ArrayList<>();
|
|
List<StudentScoreEntity> adds = new ArrayList<>();
|
|
- for (String examNumber : dataList) {
|
|
|
|
|
|
+ for (StudentVo vo : dataList) {
|
|
for (QuestionEntity q : qlist) {
|
|
for (QuestionEntity q : qlist) {
|
|
- String scorekey = q.getId() + "-" + examNumber;
|
|
|
|
|
|
+ String scorekey = q.getId() + "-" + vo.getExamNumber();
|
|
if (!allStudent.contains(scorekey)) {
|
|
if (!allStudent.contains(scorekey)) {
|
|
StudentScoreEntity stu = new StudentScoreEntity();
|
|
StudentScoreEntity stu = new StudentScoreEntity();
|
|
adds.add(stu);
|
|
adds.add(stu);
|
|
@@ -98,7 +107,11 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
|
|
stu.setQuestionId(q.getId());
|
|
stu.setQuestionId(q.getId());
|
|
stu.setAnswerStatus(DataStatus.WAITING);
|
|
stu.setAnswerStatus(DataStatus.WAITING);
|
|
stu.setScoreStatus(DataStatus.WAITING);
|
|
stu.setScoreStatus(DataStatus.WAITING);
|
|
- stu.setExamNumber(examNumber);
|
|
|
|
|
|
+ if (vo.getSheetCount() != null && vo.getSheetCount() != 0) {
|
|
|
|
+ stu.setSheetCount(vo.getSheetCount());
|
|
|
|
+ }
|
|
|
|
+ stu.setExamNumber(vo.getExamNumber());
|
|
|
|
+ stu.setStudentId(vo.getStudentId());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -107,7 +120,7 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
};
|
|
- bs.setDataForBatch(examNumbers, 500);
|
|
|
|
|
|
+ bs.setDataForBatch(stuVo, 500);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -157,6 +170,16 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
|
|
}
|
|
}
|
|
|
|
|
|
private void getSlice(StudentScoreEntity score, QuestionEntity q, StudentScoreImageDto dto) {
|
|
private void getSlice(StudentScoreEntity score, QuestionEntity q, StudentScoreImageDto dto) {
|
|
|
|
+ if (AnswerRangeType.FIXED.equals(q.getAnswerRangeType())) {
|
|
|
|
+ getFixedSlice(score, q, dto);
|
|
|
|
+ } else if (AnswerRangeType.TRACK.equals(q.getAnswerRangeType())) {
|
|
|
|
+ getTrackSlice(score, q, dto);
|
|
|
|
+ } else if (AnswerRangeType.ALL.equals(q.getAnswerRangeType())) {
|
|
|
|
+ getAllSheet(score, q, dto);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void getFixedSlice(StudentScoreEntity score, QuestionEntity q, StudentScoreImageDto dto) {
|
|
List<byte[]> ret = new ArrayList<>();
|
|
List<byte[]> ret = new ArrayList<>();
|
|
String suff = null;
|
|
String suff = null;
|
|
Map<Integer, AnswerImageDto> answerImages = new LinkedHashMap<>();
|
|
Map<Integer, AnswerImageDto> answerImages = new LinkedHashMap<>();
|
|
@@ -177,6 +200,75 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void getTrackSlice(StudentScoreEntity score, QuestionEntity q, StudentScoreImageDto dto) {
|
|
|
|
+ List<byte[]> ret = new ArrayList<>();
|
|
|
|
+ String suff = null;
|
|
|
|
+ Map<Integer, AnswerImageDto> answerImages = new LinkedHashMap<>();
|
|
|
|
+ for (ImagePosition s : score.getImagePosition()) {
|
|
|
|
+ AnswerImageDto sheet = getSheet(score, q, s.getPageIndex(), answerImages);
|
|
|
|
+ ImageSize is = getSize(sheet.getImage());
|
|
|
|
+ suff = sheet.getSuff();
|
|
|
|
+ int x = 0;
|
|
|
|
+ int y = 0;
|
|
|
|
+ int w = is.getWidth() / 2;
|
|
|
|
+ int h = is.getHeight();
|
|
|
|
+ if (!s.getLeft()) {
|
|
|
|
+ x = w;
|
|
|
|
+ }
|
|
|
|
+ ret.add(ImageUtil.cutImage(sheet.getImage(), sheet.getSuff(), x, y, w, h));
|
|
|
|
+ }
|
|
|
|
+ if (sysProperty.getSaveImage()) {
|
|
|
|
+ saveSheetImage(q, score, answerImages);
|
|
|
|
+ }
|
|
|
|
+ dto.setSuff(suff);
|
|
|
|
+ if (ret.size() > 1) {
|
|
|
|
+ dto.setImage(ImageUtil.joinImages(ret, suff));
|
|
|
|
+ } else {
|
|
|
|
+ dto.setImage(ret.get(0));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void getAllSheet(StudentScoreEntity score, QuestionEntity q, StudentScoreImageDto dto) {
|
|
|
|
+ List<byte[]> ret = new ArrayList<>();
|
|
|
|
+ String suff = null;
|
|
|
|
+ Map<Integer, AnswerImageDto> answerImages = new LinkedHashMap<>();
|
|
|
|
+ for (int i = 1; i <= score.getSheetCount(); i++) {
|
|
|
|
+ AnswerImageDto sheet = getSheet(score, q, i, answerImages);
|
|
|
|
+ suff = sheet.getSuff();
|
|
|
|
+ ret.add(sheet.getImage());
|
|
|
|
+ }
|
|
|
|
+ if (sysProperty.getSaveImage()) {
|
|
|
|
+ saveSheetImage(q, score, answerImages);
|
|
|
|
+ }
|
|
|
|
+ dto.setSuff(suff);
|
|
|
|
+ if (ret.size() > 1) {
|
|
|
|
+ dto.setImage(ImageUtil.joinImages(ret, suff));
|
|
|
|
+ } else {
|
|
|
|
+ dto.setImage(ret.get(0));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private ImageSize getSize(byte[] iamge) {
|
|
|
|
+ InputStream is = null;
|
|
|
|
+ try {
|
|
|
|
+ byte[] bytes = Arrays.copyOf(iamge, iamge.length);
|
|
|
|
+ is = new ByteArrayInputStream(bytes);
|
|
|
|
+ BufferedImage image = ImageIO.read(is);
|
|
|
|
+ int width = image.getWidth();
|
|
|
|
+ int height = image.getHeight();
|
|
|
|
+ return new ImageSize(width, height);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ } finally {
|
|
|
|
+ if (is != null) {
|
|
|
|
+ try {
|
|
|
|
+ is.close();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private AnswerImageDto getSheet(StudentScoreEntity score, QuestionEntity q, Integer pageIndex,
|
|
private AnswerImageDto getSheet(StudentScoreEntity score, QuestionEntity q, Integer pageIndex,
|
|
Map<Integer, AnswerImageDto> answerImages) {
|
|
Map<Integer, AnswerImageDto> answerImages) {
|
|
AnswerImageDto ret = answerImages.get(pageIndex);
|
|
AnswerImageDto ret = answerImages.get(pageIndex);
|
|
@@ -676,4 +768,14 @@ public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreDao, Studen
|
|
public List<StudentScoreVo> getAllInfoForUpdateScore() {
|
|
public List<StudentScoreVo> getAllInfoForUpdateScore() {
|
|
return this.baseMapper.getAllInfoForUpdateScore();
|
|
return this.baseMapper.getAllInfoForUpdateScore();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void updateMarkingScoreAndTrack(StudentScoreVo score) {
|
|
|
|
+ UpdateWrapper<StudentScoreEntity> wrapper = new UpdateWrapper<>();
|
|
|
|
+ LambdaUpdateWrapper<StudentScoreEntity> lw = wrapper.lambda();
|
|
|
|
+ lw.set(StudentScoreEntity::getMarkingScore, score.getMarkingScore());
|
|
|
|
+ lw.set(StudentScoreEntity::getImagePosition, JSONArray.toJSONString(score.getIps()));
|
|
|
|
+ lw.eq(StudentScoreEntity::getId, score.getId());
|
|
|
|
+ this.update(wrapper);
|
|
|
|
+ }
|
|
}
|
|
}
|