|
@@ -299,6 +299,7 @@ public class PaperLibraryServiceImpl extends ServiceImpl<PaperLibraryMapper, Pap
|
|
|
JSONObject jsonObject = objectList.get(index);
|
|
|
|
|
|
String rootPath = fileStoreUtil.buildPath(UploadFileEnum.DOWNLOAD, true);
|
|
|
+ String cutRootPath = fileStoreUtil.buildPath(UploadFileEnum.CUT, true);
|
|
|
File file;
|
|
|
try {
|
|
|
file = paperLibraryCommonService.downloadFile(rootPath, jsonObject.getString(SystemConstant.PATH), jsonObject.getString(SystemConstant.UPLOAD_TYPE), jsonObject.getString(SystemConstant.TYPE));
|
|
@@ -306,14 +307,17 @@ public class PaperLibraryServiceImpl extends ServiceImpl<PaperLibraryMapper, Pap
|
|
|
throw ExceptionResultEnum.ERROR.exception("下载图片失败:" + e.getMessage());
|
|
|
}
|
|
|
// 裁剪
|
|
|
- File outFile = new File(rootPath, "sub" + file.getName());
|
|
|
+ File outFile = new File(cutRootPath, "sub" + file.getName());
|
|
|
+ if(!outFile.exists()){
|
|
|
+ outFile.getParentFile().mkdirs();
|
|
|
+ }
|
|
|
File subFile = ImageUtil.subImg(file, x, y, width, height, outFile);
|
|
|
if (subFile == null) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("识别区域图片生成失败");
|
|
|
}
|
|
|
|
|
|
// 旋转
|
|
|
- File rotateOutFile = new File(rootPath, "rotate" + file.getName());
|
|
|
+ File rotateOutFile = new File(cutRootPath, "rotate" + file.getName());
|
|
|
File rotateFile = ImageUtil.rotate(subFile, rotate, rotateOutFile);
|
|
|
|
|
|
List<String> stringList = new ArrayList<>();
|
|
@@ -339,25 +343,27 @@ public class PaperLibraryServiceImpl extends ServiceImpl<PaperLibraryMapper, Pap
|
|
|
if (jsonArray.length() == 0) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("未正确识别出内容");
|
|
|
} else {
|
|
|
- // 保存识别数据
|
|
|
- UpdateWrapper<PaperLibrary> updateWrapper = new UpdateWrapper<>();
|
|
|
- updateWrapper.lambda().set(PaperLibrary::getWordsResult, jsonArray.toString()).eq(PaperLibrary::getId, paperLibraryId);
|
|
|
- this.updateById(paperLibrary);
|
|
|
-
|
|
|
jsonArray.forEach(m -> {
|
|
|
org.json.JSONObject object = (org.json.JSONObject) m;
|
|
|
if (object.has(SystemConstant.OCR_WORDS)) {
|
|
|
stringList.add(object.getString(SystemConstant.OCR_WORDS));
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ // 保存识别数据
|
|
|
+ UpdateWrapper<PaperLibrary> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.lambda().set(PaperLibrary::getWordsResult, jsonArray.toString())
|
|
|
+ .set(PaperLibrary::getOcrResult, String.join(",", stringList))
|
|
|
+ .eq(PaperLibrary::getId, paperLibraryId);
|
|
|
+ this.update(updateWrapper);
|
|
|
}
|
|
|
} catch (JSONException e) {
|
|
|
throw ExceptionResultEnum.ERROR.exception(e.getMessage());
|
|
|
} finally {
|
|
|
try {
|
|
|
FileUtils.forceDelete(file);
|
|
|
- FileUtils.forceDelete(subFile);
|
|
|
- FileUtils.forceDelete(rotateFile);
|
|
|
+// FileUtils.forceDelete(subFile);
|
|
|
+// FileUtils.forceDelete(rotateFile);
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|