From 333df0f37e9dd0589363f8939875f67369b6ea1c Mon Sep 17 00:00:00 2001 From: zhouwentao <1577701412@qq.com> Date: Fri, 28 Jul 2023 15:40:48 +0800 Subject: [PATCH] updates --- .../modules/api/controller/ApiController.java | 16 +++++++++- .../ocr/controller/OcrIdentifyController.java | 21 ++++++++++++- .../jeecg/modules/ocr/utils/FileOUtils.java | 30 ++++++++++++++----- 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/ApiController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/ApiController.java index 2c0dd70..2e7c23b 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/ApiController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/ApiController.java @@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.jeecg.common.api.vo.Result; import org.jeecg.common.constant.OcrConstant; +import org.jeecg.common.system.vo.DictModel; import org.jeecg.common.util.AssertUtils; import org.jeecg.common.util.RedisUtil; 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.utils.FileOUtils; 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.EnableAsync; import org.springframework.transaction.annotation.Transactional; @@ -46,6 +48,8 @@ public class ApiController { @Resource private IOcrIdentifyService ocrIdentifyService; @Resource + private ISysDictService sysDictService; + @Resource private RedisUtil redisUtil; @@ -78,7 +82,17 @@ public class ApiController { //获取识别的图片 List fileList=new ArrayList<>(); - List fileUrlList= FileOUtils.fileLists(sourceImages); + //获取相对路径 + List 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 fileUrlList= FileOUtils.fileLists(relativePath,sourceImages); for (String fileUrl : fileUrlList) { //判断附件是否是 图片格式 if (fileUrl.lastIndexOf(".png")!=-1 || fileUrl.lastIndexOf(".jpg")!=-1|| fileUrl.lastIndexOf(".jpeg")!=-1) { diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/controller/OcrIdentifyController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/controller/OcrIdentifyController.java index 01316c4..6d56095 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/controller/OcrIdentifyController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/controller/OcrIdentifyController.java @@ -1,5 +1,6 @@ package org.jeecg.modules.ocr.controller; +import java.io.File; import java.util.ArrayList; import java.util.Arrays; 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.extension.plugins.pagination.Page; import lombok.extern.slf4j.Slf4j; +import org.jeecg.common.system.vo.DictModel; import org.jeecg.common.util.AssertUtils; import org.jeecg.common.util.RedisUtil; 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.OcrMetadataConfigVo; 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.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; @@ -61,6 +65,10 @@ public class OcrIdentifyController extends JeecgController fileList = new ArrayList<>(); - List fileUrlList = FileOUtils.fileLists(ocrIdentify.getIdentifyUrl()); + + //获取相对路径 + List 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 fileUrlList = FileOUtils.fileLists(relativePath,ocrIdentify.getIdentifyUrl()); AssertUtils.notNull(fileUrlList, "图片地址不存在"); for (String fileUrl : fileUrlList) { //判断附件是否是 图片格式 diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/utils/FileOUtils.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/utils/FileOUtils.java index 8b41c9d..c579aa2 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/utils/FileOUtils.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/utils/FileOUtils.java @@ -1,6 +1,7 @@ package org.jeecg.modules.ocr.utils; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.StringUtils; import org.jeecg.common.exception.JeecgBootException; import org.jeecg.common.util.AssertUtils; @@ -19,10 +20,11 @@ import java.util.List; public class FileOUtils { /** * 判断附件目录是否存在,并返回目录下的附件目录 + * @param relativePath 服务器本地相对路径 * @param sourceImages * @return */ - public static List fileLists(String sourceImages) { + public static List fileLists(String relativePath,String sourceImages) { List files=new ArrayList<>(); if (sourceImages.indexOf("http://")!=-1||sourceImages.indexOf("https://")!=-1) { //网络目录 @@ -39,15 +41,27 @@ public class FileOUtils { return null; } }else{ - File file = new File(sourceImages); - if (file.exists()) { - File[] files1 = file.listFiles(); - for (File file1 : files1) { - files.add(file1.getAbsolutePath()); + if (StringUtils.isNotBlank(relativePath)) { + String path = relativePath + File.separator + sourceImages.replace(relativePath, "").replace("//",""); + File file=new File(path); + if (file.exists()) { + File[] files1 = file.listFiles(); + for (File file1 : files1) { + files.add(file1.getAbsolutePath()); + } } }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("当前不支持本地目录"); } @@ -55,7 +69,7 @@ public class FileOUtils { } public static void main(String[] args) { - List stringList = fileLists("E:\\workspace_2\\ocr\\images1"); + List stringList = fileLists(null,"E:\\workspace_2\\ocr\\images1"); System.out.println(stringList); } }