master
周文涛 2 years ago
parent 463debeb89
commit 333df0f37e

@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.OcrConstant; import org.jeecg.common.constant.OcrConstant;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.common.util.AssertUtils; import org.jeecg.common.util.AssertUtils;
import org.jeecg.common.util.RedisUtil; import org.jeecg.common.util.RedisUtil;
import org.jeecg.common.util.RestUtil; import org.jeecg.common.util.RestUtil;
@ -19,6 +20,7 @@ import org.jeecg.modules.ocr.service.IOcrIdentifyService;
import org.jeecg.modules.ocr.service.IOcrRuleCheckService; import org.jeecg.modules.ocr.service.IOcrRuleCheckService;
import org.jeecg.modules.ocr.utils.FileOUtils; import org.jeecg.modules.ocr.utils.FileOUtils;
import org.jeecg.modules.ocr.vo.OcrRuleCheckVo; import org.jeecg.modules.ocr.vo.OcrRuleCheckVo;
import org.jeecg.modules.system.service.ISysDictService;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -46,6 +48,8 @@ public class ApiController {
@Resource @Resource
private IOcrIdentifyService ocrIdentifyService; private IOcrIdentifyService ocrIdentifyService;
@Resource @Resource
private ISysDictService sysDictService;
@Resource
private RedisUtil redisUtil; private RedisUtil redisUtil;
@ -78,7 +82,17 @@ public class ApiController {
//获取识别的图片 //获取识别的图片
List<String> fileList=new ArrayList<>(); List<String> fileList=new ArrayList<>();
List<String> fileUrlList= FileOUtils.fileLists(sourceImages); //获取相对路径
List<DictModel> ocr_relative_path = sysDictService.queryDictItemsByCode("ocr_relative_path");
String relativePath=null;
if (ocr_relative_path!=null && ocr_relative_path.size()>0) {
for (DictModel dictModel : ocr_relative_path) {
if (dictModel.getValue().equals("0")) {
relativePath= dictModel.getText();
}
}
}
List<String> fileUrlList= FileOUtils.fileLists(relativePath,sourceImages);
for (String fileUrl : fileUrlList) { for (String fileUrl : fileUrlList) {
//判断附件是否是 图片格式 //判断附件是否是 图片格式
if (fileUrl.lastIndexOf(".png")!=-1 || fileUrl.lastIndexOf(".jpg")!=-1|| fileUrl.lastIndexOf(".jpeg")!=-1) { if (fileUrl.lastIndexOf(".png")!=-1 || fileUrl.lastIndexOf(".jpg")!=-1|| fileUrl.lastIndexOf(".jpeg")!=-1) {

@ -1,5 +1,6 @@
package org.jeecg.modules.ocr.controller; package org.jeecg.modules.ocr.controller;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -17,6 +18,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.common.util.AssertUtils; import org.jeecg.common.util.AssertUtils;
import org.jeecg.common.util.RedisUtil; import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.ocr.entity.OcrIdentify; import org.jeecg.modules.ocr.entity.OcrIdentify;
@ -31,6 +33,8 @@ import org.jeecg.modules.ocr.utils.FileOUtils;
import org.jeecg.modules.ocr.vo.OcrIdentifyVo; import org.jeecg.modules.ocr.vo.OcrIdentifyVo;
import org.jeecg.modules.ocr.vo.OcrMetadataConfigVo; import org.jeecg.modules.ocr.vo.OcrMetadataConfigVo;
import org.jeecg.modules.ocr.vo.OcrRuleCheckVo; import org.jeecg.modules.ocr.vo.OcrRuleCheckVo;
import org.jeecg.modules.system.service.ISysDictItemService;
import org.jeecg.modules.system.service.ISysDictService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
@ -61,6 +65,10 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
@Autowired @Autowired
private IOcrRuleCheckService ocrRuleCheckService; private IOcrRuleCheckService ocrRuleCheckService;
@Autowired @Autowired
private ISysDictService sysDictService;
@Autowired
private ISysDictItemService sysDictItemService;
@Autowired
private RedisUtil redisUtil; private RedisUtil redisUtil;
/** /**
* *
@ -117,7 +125,18 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
AssertUtils.notEmpty(ocrIdentify.getPriority(), "请选择[优先级]"); AssertUtils.notEmpty(ocrIdentify.getPriority(), "请选择[优先级]");
//获取识别的图片 //获取识别的图片
List<String> fileList = new ArrayList<>(); List<String> fileList = new ArrayList<>();
List<String> fileUrlList = FileOUtils.fileLists(ocrIdentify.getIdentifyUrl());
//获取相对路径
List<DictModel> ocr_relative_path = sysDictService.queryDictItemsByCode("ocr_relative_path");
String relativePath=null;
if (ocr_relative_path!=null && ocr_relative_path.size()>0) {
for (DictModel dictModel : ocr_relative_path) {
if (dictModel.getValue().equals("0")) {
relativePath= dictModel.getText();
}
}
}
List<String> fileUrlList = FileOUtils.fileLists(relativePath,ocrIdentify.getIdentifyUrl());
AssertUtils.notNull(fileUrlList, "图片地址不存在"); AssertUtils.notNull(fileUrlList, "图片地址不存在");
for (String fileUrl : fileUrlList) { for (String fileUrl : fileUrlList) {
//判断附件是否是 图片格式 //判断附件是否是 图片格式

@ -1,6 +1,7 @@
package org.jeecg.modules.ocr.utils; package org.jeecg.modules.ocr.utils;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.exception.JeecgBootException; import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.util.AssertUtils; import org.jeecg.common.util.AssertUtils;
@ -19,10 +20,11 @@ import java.util.List;
public class FileOUtils { public class FileOUtils {
/** /**
* *
* @param relativePath
* @param sourceImages * @param sourceImages
* @return * @return
*/ */
public static List<String> fileLists(String sourceImages) { public static List<String> fileLists(String relativePath,String sourceImages) {
List<String> files=new ArrayList<>(); List<String> files=new ArrayList<>();
if (sourceImages.indexOf("http://")!=-1||sourceImages.indexOf("https://")!=-1) { if (sourceImages.indexOf("http://")!=-1||sourceImages.indexOf("https://")!=-1) {
//网络目录 //网络目录
@ -39,15 +41,27 @@ public class FileOUtils {
return null; return null;
} }
}else{ }else{
File file = new File(sourceImages); if (StringUtils.isNotBlank(relativePath)) {
if (file.exists()) { String path = relativePath + File.separator + sourceImages.replace(relativePath, "").replace("//","");
File[] files1 = file.listFiles(); File file=new File(path);
for (File file1 : files1) { if (file.exists()) {
files.add(file1.getAbsolutePath()); File[] files1 = file.listFiles();
for (File file1 : files1) {
files.add(file1.getAbsolutePath());
}
} }
}else{ }else{
//AssertUtils.isTrue(file.exists(),"该目录不存在"); File file = new File(sourceImages);
if (file.exists()) {
File[] files1 = file.listFiles();
for (File file1 : files1) {
files.add(file1.getAbsolutePath());
}
}else{
//AssertUtils.isTrue(file.exists(),"该目录不存在");
}
} }
//本地文件 //本地文件
//throw new JeecgBootException("当前不支持本地目录"); //throw new JeecgBootException("当前不支持本地目录");
} }
@ -55,7 +69,7 @@ public class FileOUtils {
} }
public static void main(String[] args) { public static void main(String[] args) {
List<String> stringList = fileLists("E:\\workspace_2\\ocr\\images1"); List<String> stringList = fileLists(null,"E:\\workspace_2\\ocr\\images1");
System.out.println(stringList); System.out.println(stringList);
} }
} }

Loading…
Cancel
Save