|
@@ -28,6 +28,7 @@ import com.qmth.paper.library.common.service.BasicSchoolService;
|
|
import com.qmth.paper.library.common.service.CommonCacheService;
|
|
import com.qmth.paper.library.common.service.CommonCacheService;
|
|
import com.qmth.paper.library.common.service.SysUserService;
|
|
import com.qmth.paper.library.common.service.SysUserService;
|
|
import com.qmth.paper.library.common.util.*;
|
|
import com.qmth.paper.library.common.util.*;
|
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONArray;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -36,6 +37,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
+import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -127,22 +129,36 @@ public class PaperLibraryServiceImpl extends ServiceImpl<PaperLibraryMapper, Pap
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public RecognitionResultVo recognition(PaperScanTask paperScanTask, String studentCode, MultipartFile file, Integer x, Integer y, Integer width, Integer height, Integer rotate) {
|
|
public RecognitionResultVo recognition(PaperScanTask paperScanTask, String studentCode, MultipartFile file, Integer x, Integer y, Integer width, Integer height, Integer rotate) {
|
|
- RecognitionResultVo recognitionResultVo = new RecognitionResultVo();
|
|
|
|
|
|
+ RecognitionResultVo recognitionResultVo = new RecognitionResultVo(studentCode, null);
|
|
BasicSchool basicSchool = basicSchoolService.getById(paperScanTask.getSchoolId());
|
|
BasicSchool basicSchool = basicSchoolService.getById(paperScanTask.getSchoolId());
|
|
String courseNameCode = String.format("%s(%s)", paperScanTask.getCourseName(), paperScanTask.getCourseCode());
|
|
String courseNameCode = String.format("%s(%s)", paperScanTask.getCourseName(), paperScanTask.getCourseCode());
|
|
String cutRootPath = fileStoreUtil.buildPath(UploadFileEnum.CUT, true, basicSchool.getCode(), courseNameCode);
|
|
String cutRootPath = fileStoreUtil.buildPath(UploadFileEnum.CUT, true, basicSchool.getCode(), courseNameCode);
|
|
// 裁剪识别区图片
|
|
// 裁剪识别区图片
|
|
- File outFile = new File(cutRootPath, "bar-" + file.getName());
|
|
|
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
|
+ String prefixFileName = fileName.substring(0, fileName.lastIndexOf("."));
|
|
|
|
+ String suffix = fileName.substring(fileName.lastIndexOf("."));
|
|
|
|
+ File outFile = new File(cutRootPath, prefixFileName + "-" + SystemConstant.getNanoId() + suffix);
|
|
if (!outFile.exists()) {
|
|
if (!outFile.exists()) {
|
|
outFile.getParentFile().mkdirs();
|
|
outFile.getParentFile().mkdirs();
|
|
}
|
|
}
|
|
- File subFile = ImageUtil.subImg((File) file, x, y, width, height, outFile);
|
|
|
|
- if (subFile == null) {
|
|
|
|
- return recognitionResultVo;
|
|
|
|
|
|
+ File tempFile = SystemConstant.getFileTempDirVar(suffix);
|
|
|
|
+ try {
|
|
|
|
+ FileUtils.copyInputStreamToFile(file.getInputStream(), tempFile);
|
|
|
|
+ ImageUtil.subImg(tempFile, x, y, width, height, outFile);
|
|
|
|
+ if (outFile == null) {
|
|
|
|
+ return recognitionResultVo;
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ } finally {
|
|
|
|
+ if (tempFile.exists()) {
|
|
|
|
+ tempFile.delete();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
// 旋转
|
|
// 旋转
|
|
File rotateOutFile = new File(cutRootPath, "rotate" + file.getName());
|
|
File rotateOutFile = new File(cutRootPath, "rotate" + file.getName());
|
|
- File rotateFile = ImageUtil.rotate(subFile, rotate, rotateOutFile);
|
|
|
|
|
|
+ File rotateFile = ImageUtil.rotate(outFile, rotate, rotateOutFile);
|
|
|
|
|
|
List<String> stringList = new ArrayList<>();
|
|
List<String> stringList = new ArrayList<>();
|
|
String wordsResult = null;
|
|
String wordsResult = null;
|
|
@@ -156,7 +172,7 @@ public class PaperLibraryServiceImpl extends ServiceImpl<PaperLibraryMapper, Pap
|
|
if (rotateFile.exists()) {
|
|
if (rotateFile.exists()) {
|
|
callHandwriting = ocrUtil.callHandwriting(rotateFile.getPath());
|
|
callHandwriting = ocrUtil.callHandwriting(rotateFile.getPath());
|
|
} else {
|
|
} else {
|
|
- callHandwriting = ocrUtil.callHandwriting(subFile.getPath());
|
|
|
|
|
|
+ callHandwriting = ocrUtil.callHandwriting(outFile.getPath());
|
|
}
|
|
}
|
|
|
|
|
|
// 未联网提示
|
|
// 未联网提示
|
|
@@ -188,7 +204,7 @@ public class PaperLibraryServiceImpl extends ServiceImpl<PaperLibraryMapper, Pap
|
|
if (rotateFile.exists()) {
|
|
if (rotateFile.exists()) {
|
|
result = BarCodeUtils.decode(rotateFile);
|
|
result = BarCodeUtils.decode(rotateFile);
|
|
} else {
|
|
} else {
|
|
- result = BarCodeUtils.decode(subFile);
|
|
|
|
|
|
+ result = BarCodeUtils.decode(outFile);
|
|
}
|
|
}
|
|
wordsResult = result;
|
|
wordsResult = result;
|
|
} else {
|
|
} else {
|
|
@@ -202,12 +218,6 @@ public class PaperLibraryServiceImpl extends ServiceImpl<PaperLibraryMapper, Pap
|
|
recognitionResultVo.setBindResult(result);
|
|
recognitionResultVo.setBindResult(result);
|
|
recognitionResultVo.setRecognizeResult(wordsResult);
|
|
recognitionResultVo.setRecognizeResult(wordsResult);
|
|
|
|
|
|
- if (outFile.exists()) {
|
|
|
|
- outFile.delete();
|
|
|
|
- }
|
|
|
|
- if (subFile.exists()) {
|
|
|
|
- subFile.delete();
|
|
|
|
- }
|
|
|
|
if (rotateOutFile.exists()) {
|
|
if (rotateOutFile.exists()) {
|
|
rotateOutFile.delete();
|
|
rotateOutFile.delete();
|
|
}
|
|
}
|