diff --git a/jeecg-module-system/jeecg-system-biz/pom.xml b/jeecg-module-system/jeecg-system-biz/pom.xml
index 6bfc85c..d01abda 100644
--- a/jeecg-module-system/jeecg-system-biz/pom.xml
+++ b/jeecg-module-system/jeecg-system-biz/pom.xml
@@ -39,18 +39,25 @@
drag-free
1.0.1
-
+
net.coobird
thumbnailator
0.4.8
-
-
+
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 0513154..70f02de 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
@@ -27,6 +27,7 @@ import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
+import org.xm.Similarity;
import javax.annotation.Resource;
import java.io.File;
@@ -202,67 +203,34 @@ public class ApiController {
}
//==========================================================================================
- @ApiOperation(value = "刷新为完成的任务", notes = "任务完结通知")
- @GetMapping("/restartTask")
+ @ApiOperation(value = "刷新任务", notes = "任务完结通知")
+ @PostMapping("/restartTask")
@Async
- public Result restartTask() throws InterruptedException {
- //获取未执行完的任务
+ public Result restartTask(@RequestBody JSONObject jsonObject) throws InterruptedException {
+ System.out.println(jsonObject.toJSONString());
+ //获取已执行完的任务
List list = ocrIdentifyService.list(new LambdaQueryWrapper());
- /*long allTime=0l;
- for (OcrIdentify ocrIdentify : list) {
- long time = ocrIdentify.getStartTime().getTime();
- long endTime = ocrIdentify.getEndTime().getTime();
- allTime+=(endTime-time)/1000;
- }
- System.out.println(allTime);*/
- for (OcrIdentify ocrIdentify : list) {
- List list1 = ocrIdentifyDetailService.list(new LambdaQueryWrapper().eq(OcrIdentifyDetail::getIdentifyId, ocrIdentify.getId()));
- for (OcrIdentifyDetail ocrIdentifyDetail : list1) {
- String imgPath =ocrIdentifyDetail.getImageUrl();
- //压缩图片
- File file = new File(imgPath);
- //当原图片存在时
- if (file.exists()) {
- int maxWidth = 800;// 压缩后图片的最大宽度
- int maxHeight = 600;// 压缩后图片的最大高度
- int i = imgPath.lastIndexOf("/");
- String fileUrl = "/data/thumbnail" + imgPath.substring(0, i);
- //判断新目录是否存在,不存在则新建
- ImageUtils.folderCreate(fileUrl);
- String outputImagePath = fileUrl + imgPath.substring(i + 1, imgPath.length());
- File thumbnailFile = new File(outputImagePath);
- //如果上次生成过缩率图,就不生成了
- if (!thumbnailFile.exists()) {
- ImageUtils.compressImage(file.getAbsolutePath(), outputImagePath,0.5f, 0.5f);
- }
- ocrIdentifyDetail.setThumbnailImageUrl(outputImagePath);
- }
- ocrIdentifyDetail.setExecutionTime(ocrIdentifyDetail.getExecutionTime()/1000);
- }
- ocrIdentifyDetailService.updateBatchById(list1);
- }
- //ocrIdentifyService.updateBatchById(list);
- /*List list = ocrIdentifyService.list(new LambdaQueryWrapper().eq(OcrIdentify::getStatus,"1"));
int i =0;
for (OcrIdentify ocrIdentify : list) {
- ocrIdentifyService.updateTaskResultInfo(ocrIdentify.getId());
+ if (ocrIdentify.getStatus().equals("1")) {
+ ocrIdentifyService.updateTaskResultInfo(ocrIdentify.getId());
+ }else{}
i++;
- System.out.println(i);
- }*/
-
- /*List list = ocrIdentifyService.list(new LambdaQueryWrapper().in(OcrIdentify::getStatus, "0","2"));
- List identifyIdList = list.stream().map(l -> l.getId()).collect(Collectors.toList());
- if (identifyIdList.size()>0) {
- ocrIdentifyDetailService.remove(new LambdaQueryWrapper().in(OcrIdentifyDetail::getIdentifyId,identifyIdList));
- for (OcrIdentify ocrIdentify : list) {
- log.info("打印ocrIdentifyId:"+ocrIdentify.getId());
- List identifyUrlList = FileOUtils.fileLists(null, ocrIdentify.getIdentifyUrl());
- //List identifyUrlList = Arrays.asList("1","2");
- taskService.postSemantic(ocrIdentify,identifyUrlList);
- }
- }*/
+ }
return Result.OK(list.size()+"个任务.");
}
+
+
+ @ApiOperation(value = "调试101")
+ @PostMapping(value = "/test_101")
+ public Result test101(@RequestBody JSONObject jsonObject){
+
+ return Result.OK("");
+ }
+
+ public static void main(String[] args) {
+ System.out.println(Similarity.pinyinSimilarity("张三","张三"));
+ }
}
//curl --request POST --url http://127.0.0.1:8000/semantic --header 'content-type: application/json' --data '{ "task_id": "1682299148529958914","img_path": "http://47.103.213.109:8072/files/nfs/ocr/shared_directory/09360a383f464ea0ad056145ec5b62e9/4abf97c877bbe4e4d091aef8411edd81.jpeg"}'
\ No newline at end of file
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 07e6e1c..810c177 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,10 +1,12 @@
package org.jeecg.modules.ocr.controller;
+import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.lang.StringUtils;
@@ -23,20 +25,26 @@ import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.ocr.entity.OcrIdentify;
import org.jeecg.modules.ocr.entity.OcrIdentifyDetail;
import org.jeecg.modules.ocr.entity.OcrMetadataConfig;
+import org.jeecg.modules.ocr.entity.OcrRuleCheck;
import org.jeecg.modules.ocr.model.OcrResult2;
import org.jeecg.modules.ocr.service.*;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.ocr.service.impl.TaskService;
import org.jeecg.modules.ocr.utils.DownloadTemplateUtil;
import org.jeecg.modules.ocr.utils.FileOUtils;
+import org.jeecg.modules.ocr.vo.OcrIdentifyExcelVo;
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.jeecgframework.poi.excel.ExcelImportUtil;
+import org.jeecgframework.poi.excel.entity.ImportParams;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -313,6 +321,98 @@ public class OcrIdentifyController extends JeecgController importExcel(HttpServletRequest request, HttpServletResponse response) {
+ MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
+ Map fileMap = multipartRequest.getFileMap();
+ for (Map.Entry entity : fileMap.entrySet()) {
+ // 获取上传文件对象
+ MultipartFile file = entity.getValue();
+ ImportParams params = new ImportParams();
+ params.setTitleRows(2);
+ params.setHeadRows(1);
+ params.setNeedSave(true);
+ try {
+ List list = ExcelImportUtil.importExcel(file.getInputStream(), OcrIdentifyExcelVo.class, params);
+ //update-begin-author:taoyan date:20190528 for:批量插入数据
+ long start = System.currentTimeMillis();
+ //service.saveBatch(list);
+ List ocrIdentifyList=new ArrayList<>();
+
+ for (OcrIdentifyExcelVo ocrIdentifyExcelVo : list) {
+ OcrIdentify ocrIdentify=new OcrIdentify();
+ BeanUtils.copyProperties(ocrIdentifyExcelVo,ocrIdentify);
+
+ //通过规则检查配置名称 反查 规则检查配置id
+ if (StringUtils.isNotBlank(ocrIdentifyExcelVo.getRuleCheck())) {
+ LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper().eq(OcrRuleCheck::getConfigName, ocrIdentifyExcelVo.getRuleCheck());
+ List ruleChecklist = ocrRuleCheckService.list(queryWrapper);
+ if (ruleChecklist!=null&&ruleChecklist.size()>0) {
+ ocrIdentify.setRuleCheck(ruleChecklist.get(0).getId());
+ }
+ }
+
+
+ String checkDataSource = ocrIdentifyExcelVo.getCheckDataSource();
+ String[] split = checkDataSource.split("&");
+ List sourceJson = new ArrayList<>();
+
+ //遍历 校验数据源
+ for (String s : split) {
+ String[] s2 = s.split("=");
+ String tag = s2[0];
+ String inputText = s2[1];
+ JSONObject jsonObject=new JSONObject();
+ jsonObject.put("tag",tag);
+ jsonObject.put("inputText",inputText);
+ sourceJson.add(jsonObject);
+ }
+ if (StringUtils.isNotBlank(ocrIdentify.getPriority())) {
+ if ("加急".equals(ocrIdentify.getPriority())) {
+ //优先
+ ocrIdentify.setPriority("1");
+ }else{
+ ocrIdentify.setPriority("0");
+ }
+ }
+
+ String sourceJsonStr = JSONArray.toJSONString(sourceJson);
+ ocrIdentify.setSourceJson(sourceJsonStr);
+
+ ocrIdentify.setTaskType("1683412752926986241");//任务类型
+ ocrIdentify.setTaskSource("平台导入");//任务来源
+ ocrIdentify.setCreateBy("平台导入");//创建人
+ ocrIdentify.setStatus("0");//任务进行中
+ ocrIdentifyList.add(ocrIdentify);
+ }
+ ocrIdentifyService.saveBatch(ocrIdentifyList);
+ //400条 saveBatch消耗时间1592毫秒 循环插入消耗时间1947毫秒
+ //1200条 saveBatch消耗时间3687毫秒 循环插入消耗时间5212毫秒
+ log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
+ //update-end-author:taoyan date:20190528 for:批量插入数据
+ return Result.ok("文件导入成功!数据行数:" + list.size());
+ } catch (Exception e) {
+ //update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示
+ String msg = e.getMessage();
+ log.error(msg, e);
+ if(msg!=null && msg.indexOf("Duplicate entry")>=0){
+ return Result.error("文件导入失败:有重复数据!");
+ }else{
+ return Result.error("文件导入失败:" + e.getMessage());
+ }
+ //update-end-author:taoyan date:20211124 for: 导入数据重复增加提示
+ } finally {
+ try {
+ file.getInputStream().close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return null;
+ }
+
/**
* 通过excel导入数据
*
@@ -321,8 +421,8 @@ public class OcrIdentifyController extends JeecgController importExcel(HttpServletRequest request, HttpServletResponse response) {
+ @RequestMapping(value = "/importExcel1", method = RequestMethod.POST)
+ public Result> importExcel1(HttpServletRequest request, HttpServletResponse response) {
return super.importExcel(request, response, OcrIdentify.class);
}
diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/impl/OcrIdentifyServiceImpl.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/impl/OcrIdentifyServiceImpl.java
index 967f31d..a2d384a 100644
--- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/impl/OcrIdentifyServiceImpl.java
+++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/impl/OcrIdentifyServiceImpl.java
@@ -115,7 +115,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl fieldNameList = Arrays.asList(fieldName.split(","));
diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/utils/ImageUtils.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/utils/ImageUtils.java
index a025ed7..a500c6c 100644
--- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/utils/ImageUtils.java
+++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/utils/ImageUtils.java
@@ -19,6 +19,9 @@ public class ImageUtils {
当涉及到图像压缩时,Java中有几个可以使用的库,比如ImageIO、Thumbnails和Java Advanced Imaging API(JAI)。以下是一个使用ImageIO库来进行图片压缩的示例:
*/
public static void main(String[] args) throws FileNotFoundException {
+ String sourceImagePath="C:\\Users\\Denim\\Desktop\\aabebdf71887c6c2707c65211cac2d3a.jpeg";
+ String outputImagePath="C:\\Users\\Denim\\Desktop\\ds-aabebdf71887c6c2707c65211cac2d3a.jpeg";
+ compressImage(sourceImagePath,outputImagePath,0.25f,0.25f);
}
/**
diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/vo/OcrIdentifyExcelVo.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/vo/OcrIdentifyExcelVo.java
new file mode 100644
index 0000000..c5e0df4
--- /dev/null
+++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/vo/OcrIdentifyExcelVo.java
@@ -0,0 +1,59 @@
+package org.jeecg.modules.ocr.vo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecg.common.aspect.annotation.Dict;
+import org.jeecg.modules.ocr.model.OcrResult2;
+import org.jeecgframework.poi.excel.annotation.Excel;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author 社恐的橙子
+ * @date 2023/8/16 19:05
+ */
+@Data
+@Accessors(chain = true)
+@EqualsAndHashCode(callSuper = false)
+public class OcrIdentifyExcelVo implements Serializable {
+ @Excel(name = "RequestId",width = 15)
+ @ApiModelProperty(value = "请求id")
+ public String requestId;
+
+ /**任务名称*/
+ @Excel(name = "任务名称", width = 15)
+ @ApiModelProperty(value = "任务名称")
+ private String taskName;
+
+ /**规则检查配置*/
+ @Excel(name = "规则检查配置", width = 15)
+ @ApiModelProperty(value = "规则检查配置")
+ private String ruleCheck;
+
+ /**校验数据源*/
+ @Excel(name = "校验数据源", width = 15)
+ @ApiModelProperty(value = "校验数据源")
+ private String checkDataSource;
+
+ /**识别任务优先级*/
+ @ApiModelProperty(value = "识别任务优先级")
+ @Excel(name = "优先级", width = 15)
+ private String priority;
+
+ /**识别路径*/
+ @Excel(name = "识别路径", width = 15)
+ @ApiModelProperty(value = "识别路径")
+ private String identifyUrl;
+}
diff --git a/jeecg-module-system/jeecg-system-biz/src/main/lib/similarity-1.1.6.jar b/jeecg-module-system/jeecg-system-biz/src/main/lib/similarity-1.1.6.jar
new file mode 100644
index 0000000..066d02a
Binary files /dev/null and b/jeecg-module-system/jeecg-system-biz/src/main/lib/similarity-1.1.6.jar differ
diff --git a/pom.xml b/pom.xml
index 8aa4c80..50adaad 100644
--- a/pom.xml
+++ b/pom.xml
@@ -361,12 +361,19 @@
UTF-8
-
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+ true
+
+
+
org.apache.maven.plugins
maven-surefire-plugin
- true
+ true