|
|
@ -1,10 +1,12 @@
|
|
|
|
package org.jeecg.modules.ocr.controller;
|
|
|
|
package org.jeecg.modules.ocr.controller;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
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.OcrIdentify;
|
|
|
|
import org.jeecg.modules.ocr.entity.OcrIdentifyDetail;
|
|
|
|
import org.jeecg.modules.ocr.entity.OcrIdentifyDetail;
|
|
|
|
import org.jeecg.modules.ocr.entity.OcrMetadataConfig;
|
|
|
|
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.model.OcrResult2;
|
|
|
|
import org.jeecg.modules.ocr.service.*;
|
|
|
|
import org.jeecg.modules.ocr.service.*;
|
|
|
|
import org.jeecg.common.system.base.controller.JeecgController;
|
|
|
|
import org.jeecg.common.system.base.controller.JeecgController;
|
|
|
|
import org.jeecg.modules.ocr.service.impl.TaskService;
|
|
|
|
import org.jeecg.modules.ocr.service.impl.TaskService;
|
|
|
|
import org.jeecg.modules.ocr.utils.DownloadTemplateUtil;
|
|
|
|
import org.jeecg.modules.ocr.utils.DownloadTemplateUtil;
|
|
|
|
import org.jeecg.modules.ocr.utils.FileOUtils;
|
|
|
|
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.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.ISysDictItemService;
|
|
|
|
import org.jeecg.modules.system.service.ISysDictService;
|
|
|
|
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.BeanUtils;
|
|
|
|
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.multipart.MultipartFile;
|
|
|
|
|
|
|
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
@ -313,6 +321,98 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
|
|
|
|
return downloadTemplateUtil.downloadTemplate(OcrIdentify.class, "ocr识别");
|
|
|
|
return downloadTemplateUtil.downloadTemplate(OcrIdentify.class, "ocr识别");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
|
|
|
|
|
|
|
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
|
|
|
|
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
|
|
|
|
|
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
|
|
|
|
|
|
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
|
|
|
|
|
|
// 获取上传文件对象
|
|
|
|
|
|
|
|
MultipartFile file = entity.getValue();
|
|
|
|
|
|
|
|
ImportParams params = new ImportParams();
|
|
|
|
|
|
|
|
params.setTitleRows(2);
|
|
|
|
|
|
|
|
params.setHeadRows(1);
|
|
|
|
|
|
|
|
params.setNeedSave(true);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
List<OcrIdentifyExcelVo> list = ExcelImportUtil.importExcel(file.getInputStream(), OcrIdentifyExcelVo.class, params);
|
|
|
|
|
|
|
|
//update-begin-author:taoyan date:20190528 for:批量插入数据
|
|
|
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
|
|
|
|
//service.saveBatch(list);
|
|
|
|
|
|
|
|
List<OcrIdentify> ocrIdentifyList=new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (OcrIdentifyExcelVo ocrIdentifyExcelVo : list) {
|
|
|
|
|
|
|
|
OcrIdentify ocrIdentify=new OcrIdentify();
|
|
|
|
|
|
|
|
BeanUtils.copyProperties(ocrIdentifyExcelVo,ocrIdentify);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//通过规则检查配置名称 反查 规则检查配置id
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(ocrIdentifyExcelVo.getRuleCheck())) {
|
|
|
|
|
|
|
|
LambdaQueryWrapper<OcrRuleCheck> queryWrapper = new LambdaQueryWrapper<OcrRuleCheck>().eq(OcrRuleCheck::getConfigName, ocrIdentifyExcelVo.getRuleCheck());
|
|
|
|
|
|
|
|
List<OcrRuleCheck> 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<JSONObject> 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导入数据
|
|
|
|
* 通过excel导入数据
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -321,8 +421,8 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
// @RequiresPermissions("org.jeecg.modules.ocr:ocr_identify:importExcel")
|
|
|
|
// @RequiresPermissions("org.jeecg.modules.ocr:ocr_identify:importExcel")
|
|
|
|
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
|
|
|
@RequestMapping(value = "/importExcel1", method = RequestMethod.POST)
|
|
|
|
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
public Result<?> importExcel1(HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
return super.importExcel(request, response, OcrIdentify.class);
|
|
|
|
return super.importExcel(request, response, OcrIdentify.class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|