|
|
|
@ -5,6 +5,7 @@ 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;
|
|
|
|
@ -35,6 +36,7 @@ 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.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
|
|
@ -70,6 +72,9 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
|
|
|
|
|
private ISysDictService sysDictService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private TaskService taskService;
|
|
|
|
|
@Value("${spring.profiles.active}")
|
|
|
|
|
private String profiles;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分页列表查询
|
|
|
|
|
*
|
|
|
|
@ -83,38 +88,38 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
|
|
|
|
|
@ApiOperation(value = "ocr识别-分页列表查询", notes = "ocr识别-分页列表查询")
|
|
|
|
|
@GetMapping(value = "/list")
|
|
|
|
|
public Result<IPage<OcrIdentify>> queryPageList(OcrIdentify ocrIdentify,
|
|
|
|
|
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
|
|
|
|
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
|
|
|
|
HttpServletRequest req) {
|
|
|
|
|
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
|
|
|
|
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
|
|
|
|
HttpServletRequest req) {
|
|
|
|
|
if (StringUtils.isNotBlank(ocrIdentify.getTaskName())) {
|
|
|
|
|
ocrIdentify.setTaskName("*"+ocrIdentify.getTaskName()+"*");
|
|
|
|
|
ocrIdentify.setTaskName("*" + ocrIdentify.getTaskName() + "*");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(ocrIdentify.getIdentifyUrl())) {
|
|
|
|
|
ocrIdentify.setIdentifyUrl("*"+ocrIdentify.getIdentifyUrl()+"*");
|
|
|
|
|
ocrIdentify.setIdentifyUrl("*" + ocrIdentify.getIdentifyUrl() + "*");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(ocrIdentify.getCreateBy())) {
|
|
|
|
|
ocrIdentify.setCreateBy("*"+ocrIdentify.getCreateBy()+"*");
|
|
|
|
|
ocrIdentify.setCreateBy("*" + ocrIdentify.getCreateBy() + "*");
|
|
|
|
|
}
|
|
|
|
|
Date startTime=ocrIdentify.getStartTime();
|
|
|
|
|
Date endTime=ocrIdentify.getEndTime();
|
|
|
|
|
if (startTime!=null&&endTime!=null) {
|
|
|
|
|
Date startTime = ocrIdentify.getStartTime();
|
|
|
|
|
Date endTime = ocrIdentify.getEndTime();
|
|
|
|
|
if (startTime != null && endTime != null) {
|
|
|
|
|
ocrIdentify.setStartTime(null);
|
|
|
|
|
ocrIdentify.setEndTime(null);
|
|
|
|
|
}
|
|
|
|
|
QueryWrapper<OcrIdentify> queryWrapper = QueryGenerator.initQueryWrapper(ocrIdentify, req.getParameterMap());
|
|
|
|
|
queryWrapper.ne("task_source","模拟实验");//排除模拟实验的数据
|
|
|
|
|
if (startTime!=null&&endTime!=null) {
|
|
|
|
|
endTime.setTime(endTime.getTime()+86400000l);
|
|
|
|
|
queryWrapper.between("end_time",startTime,endTime);
|
|
|
|
|
queryWrapper.ne("task_source", "模拟实验");//排除模拟实验的数据
|
|
|
|
|
if (startTime != null && endTime != null) {
|
|
|
|
|
endTime.setTime(endTime.getTime() + 86400000l);
|
|
|
|
|
queryWrapper.between("end_time", startTime, endTime);
|
|
|
|
|
}
|
|
|
|
|
Page<OcrIdentify> page = new Page<>(pageNo, pageSize);
|
|
|
|
|
Map<String, OcrRuleCheckDTO> ocrRuleCheckMap = ocrRuleCheckService.listToMap(null);
|
|
|
|
|
Map<String, OcrMetadataConfigDTO> metadataConfigMap = ocrMetadataConfigService.listToMap(null);
|
|
|
|
|
Map<String, String> taskNameMap = ocrTaskTypeService.listNameToMap(null);
|
|
|
|
|
IPage<OcrIdentify> pageList = ocrIdentifyService.page(page, queryWrapper);
|
|
|
|
|
if (pageList != null && pageList.getRecords() != null &&pageList.getRecords().size()>0) {
|
|
|
|
|
if (pageList != null && pageList.getRecords() != null && pageList.getRecords().size() > 0) {
|
|
|
|
|
List<String> identifyIdList = pageList.getRecords().stream().map(p -> p.getId()).collect(Collectors.toList());
|
|
|
|
|
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.list(new LambdaQueryWrapper<OcrIdentifyDetail>().in(OcrIdentifyDetail::getIdentifyId,identifyIdList));
|
|
|
|
|
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.list(new LambdaQueryWrapper<OcrIdentifyDetail>().in(OcrIdentifyDetail::getIdentifyId, identifyIdList));
|
|
|
|
|
for (OcrIdentify record : pageList.getRecords()) {
|
|
|
|
|
long count = identifyDetailList.stream().filter(i -> i.getIdentifyId().equals(record.getId())).count();
|
|
|
|
|
record.setImgNum(count);
|
|
|
|
@ -124,15 +129,15 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
|
|
|
|
|
int successNum = (int) ocrResultDTOS.stream().filter(o -> o.getRuleValidation()).count();
|
|
|
|
|
record.setTagNum(tagNum);
|
|
|
|
|
record.setTagSuccessNum(successNum);
|
|
|
|
|
record.setSuccessRate(successNum+"/"+tagNum);
|
|
|
|
|
record.setSuccessRate(successNum + "/" + tagNum);
|
|
|
|
|
record.setTaskResultInfoList(ocrResultDTOS);
|
|
|
|
|
}
|
|
|
|
|
OcrRuleCheckDTO ocrRuleCheckVo = ocrRuleCheckMap.get(record.getRuleCheck());
|
|
|
|
|
if (ocrRuleCheckVo!=null && StringUtils.isNotBlank(ocrRuleCheckVo.getMetadataConfigId())) {
|
|
|
|
|
if (ocrRuleCheckVo != null && StringUtils.isNotBlank(ocrRuleCheckVo.getMetadataConfigId())) {
|
|
|
|
|
record.setOcrRuleCheckInfoConfigRule(ocrRuleCheckVo.getConfigRule());
|
|
|
|
|
record.setMetadataConfigId(ocrRuleCheckVo.getMetadataConfigId());
|
|
|
|
|
OcrMetadataConfigDTO ocrMetadataConfigDTO = metadataConfigMap.get(ocrRuleCheckVo.getMetadataConfigId());
|
|
|
|
|
if (ocrMetadataConfigDTO !=null) {
|
|
|
|
|
if (ocrMetadataConfigDTO != null) {
|
|
|
|
|
record.setTaskType(ocrMetadataConfigDTO.getTaskType());
|
|
|
|
|
record.setTaskType_dictText(taskNameMap.get(ocrMetadataConfigDTO.getTaskType()));
|
|
|
|
|
}
|
|
|
|
@ -153,6 +158,9 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
|
|
|
|
|
// @RequiresPermissions("org.jeecg.modules.ocr:ocr_identify:add")
|
|
|
|
|
@PostMapping(value = "/add")
|
|
|
|
|
public Result<String> add(@RequestBody OcrIdentify ocrIdentify) {
|
|
|
|
|
if (!"test".equals(profiles)) {
|
|
|
|
|
return Result.error("当前环境不支持该功能,请访问测试环境");
|
|
|
|
|
}
|
|
|
|
|
AssertUtils.notEmpty(ocrIdentify.getTaskName(), "[任务名称]-不可为空");
|
|
|
|
|
AssertUtils.notEmpty(ocrIdentify.getIdentifyUrl(), "[识别路径]不可为空");
|
|
|
|
|
AssertUtils.notEmpty(ocrIdentify.getRuleCheck(), "请选择[规则检查配置]");
|
|
|
|
@ -162,15 +170,15 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
|
|
|
|
|
|
|
|
|
|
//获取相对路径
|
|
|
|
|
List<DictModel> ocr_relative_path = sysDictService.queryDictItemsByCode("ocr_relative_path");
|
|
|
|
|
String relativePath=null;
|
|
|
|
|
if (ocr_relative_path!=null && ocr_relative_path.size()>0) {
|
|
|
|
|
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();
|
|
|
|
|
relativePath = dictModel.getText();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<String> fileUrlList = FileOUtils.fileLists(relativePath,ocrIdentify.getIdentifyUrl());
|
|
|
|
|
List<String> fileUrlList = FileOUtils.fileLists(relativePath, ocrIdentify.getIdentifyUrl());
|
|
|
|
|
AssertUtils.notNull(fileUrlList, "图片地址不存在");
|
|
|
|
|
for (String fileUrl : fileUrlList) {
|
|
|
|
|
//判断附件是否是 图片格式
|
|
|
|
@ -183,7 +191,7 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
|
|
|
|
|
ocrIdentify.setStatus("0");
|
|
|
|
|
ocrIdentifyService.save(ocrIdentify);
|
|
|
|
|
//3.请求python ocr识别,异步执行
|
|
|
|
|
taskService.postSemantic(ocrIdentify,fileList);
|
|
|
|
|
taskService.postSemantic(ocrIdentify, fileList);
|
|
|
|
|
//ocrIdentifyService.postSemantic(ocrIdentify, fileList);
|
|
|
|
|
//请求ocr识别接口
|
|
|
|
|
//ocrIdentifyService.postSemantic(ocrIdentify.getId(),Arrays.asList(ocrIdentify.getIdentifyUrl()));
|
|
|
|
@ -263,26 +271,26 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
|
|
|
|
|
Map<String, OcrRuleCheckDTO> ocrRuleCheckMap = ocrRuleCheckService.listToMap(null);
|
|
|
|
|
Map<String, OcrMetadataConfigDTO> metadataConfigMap = ocrMetadataConfigService.listToMap(null);
|
|
|
|
|
Map<String, String> taskNameMap = ocrTaskTypeService.listNameToMap(null);
|
|
|
|
|
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.list(new LambdaQueryWrapper<OcrIdentifyDetail>().eq(OcrIdentifyDetail::getIdentifyId,id));
|
|
|
|
|
ocrIdentify.setImgNum((long)identifyDetailList.size());
|
|
|
|
|
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.list(new LambdaQueryWrapper<OcrIdentifyDetail>().eq(OcrIdentifyDetail::getIdentifyId, id));
|
|
|
|
|
ocrIdentify.setImgNum((long) identifyDetailList.size());
|
|
|
|
|
if (StringUtils.isNotBlank(ocrIdentify.getTaskResultInfo())) {
|
|
|
|
|
List<OcrResultDTO> ocrResultDTOList = JSONObject.parseArray(ocrIdentify.getTaskResultInfo()).toJavaList(OcrResultDTO.class);
|
|
|
|
|
int tagNum = ocrResultDTOList.size();
|
|
|
|
|
int successNum = (int) ocrResultDTOList.stream().filter(o -> o.getRuleValidation()).count();
|
|
|
|
|
ocrIdentify.setTagNum(tagNum);
|
|
|
|
|
ocrIdentify.setTagSuccessNum(successNum);
|
|
|
|
|
ocrIdentify.setSuccessRate(successNum+"/"+tagNum);
|
|
|
|
|
ocrIdentify.setSuccessRate(successNum + "/" + tagNum);
|
|
|
|
|
ocrIdentify.setTaskResultInfoList(ocrResultDTOList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OcrRuleCheckDTO ocrRuleCheckVo = ocrRuleCheckMap.get(ocrIdentify.getRuleCheck());
|
|
|
|
|
if (ocrRuleCheckVo!=null && StringUtils.isNotBlank(ocrRuleCheckVo.getMetadataConfigId())) {
|
|
|
|
|
if (ocrRuleCheckVo != null && StringUtils.isNotBlank(ocrRuleCheckVo.getMetadataConfigId())) {
|
|
|
|
|
ocrIdentify.setOcrRuleCheckInfoConfigRule(ocrRuleCheckVo.getConfigRule());
|
|
|
|
|
ocrIdentify.setRuleCheck_dictText(ocrRuleCheckVo.getConfigName());
|
|
|
|
|
ocrIdentify.setMetadataConfigId(ocrRuleCheckVo.getMetadataConfigId());
|
|
|
|
|
ocrIdentify.setMetadataConfigId_dictText(ocrRuleCheckVo.getMetadataConfigName());
|
|
|
|
|
OcrMetadataConfigDTO ocrMetadataConfigDTO = metadataConfigMap.get(ocrRuleCheckVo.getMetadataConfigId());
|
|
|
|
|
if (ocrMetadataConfigDTO !=null) {
|
|
|
|
|
if (ocrMetadataConfigDTO != null) {
|
|
|
|
|
ocrIdentify.setTaskType(ocrMetadataConfigDTO.getTaskType());
|
|
|
|
|
ocrIdentify.setTaskType_dictText(taskNameMap.get(ocrMetadataConfigDTO.getTaskType()));
|
|
|
|
|
}
|
|
|
|
@ -327,17 +335,17 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
|
|
|
|
|
//update-begin-author:taoyan date:20190528 for:批量插入数据
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
|
//service.saveBatch(list);
|
|
|
|
|
List<OcrIdentify> ocrIdentifyList=new ArrayList<>();
|
|
|
|
|
List<OcrIdentify> ocrIdentifyList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for (OcrIdentifyExcel ocrIdentifyExcel : list) {
|
|
|
|
|
OcrIdentify ocrIdentify=new OcrIdentify();
|
|
|
|
|
BeanUtils.copyProperties(ocrIdentifyExcel,ocrIdentify);
|
|
|
|
|
OcrIdentify ocrIdentify = new OcrIdentify();
|
|
|
|
|
BeanUtils.copyProperties(ocrIdentifyExcel, ocrIdentify);
|
|
|
|
|
|
|
|
|
|
//通过规则检查配置名称 反查 规则检查配置id
|
|
|
|
|
if (StringUtils.isNotBlank(ocrIdentifyExcel.getRuleCheck())) {
|
|
|
|
|
LambdaQueryWrapper<OcrRuleCheck> queryWrapper = new LambdaQueryWrapper<OcrRuleCheck>().eq(OcrRuleCheck::getConfigName, ocrIdentifyExcel.getRuleCheck());
|
|
|
|
|
List<OcrRuleCheck> ruleChecklist = ocrRuleCheckService.list(queryWrapper);
|
|
|
|
|
if (ruleChecklist!=null&&ruleChecklist.size()>0) {
|
|
|
|
|
if (ruleChecklist != null && ruleChecklist.size() > 0) {
|
|
|
|
|
ocrIdentify.setRuleCheck(ruleChecklist.get(0).getId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -352,16 +360,16 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
|
|
|
|
|
String[] s2 = s.split("=");
|
|
|
|
|
String tag = s2[0];
|
|
|
|
|
String inputText = s2[1];
|
|
|
|
|
JSONObject jsonObject=new JSONObject();
|
|
|
|
|
jsonObject.put("tag",tag);
|
|
|
|
|
jsonObject.put("inputText",inputText);
|
|
|
|
|
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{
|
|
|
|
|
} else {
|
|
|
|
|
ocrIdentify.setPriority("0");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -385,9 +393,9 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
|
|
|
|
|
//update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示
|
|
|
|
|
String msg = e.getMessage();
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
if(msg!=null && msg.indexOf("Duplicate entry")>=0){
|
|
|
|
|
if (msg != null && msg.indexOf("Duplicate entry") >= 0) {
|
|
|
|
|
return Result.error("文件导入失败:有重复数据!");
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
return Result.error("文件导入失败:" + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
//update-end-author:taoyan date:20211124 for: 导入数据重复增加提示
|
|
|
|
@ -417,37 +425,37 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "重新执行")
|
|
|
|
|
@PostMapping(value = "/restartTask")
|
|
|
|
|
public Result<?> restartTask(@RequestBody OcrIdentify ocrIdentify){
|
|
|
|
|
public Result<?> restartTask(@RequestBody OcrIdentify ocrIdentify) {
|
|
|
|
|
AssertUtils.notEmpty(ocrIdentify.getId(), "[id]不可为空");
|
|
|
|
|
OcrIdentify identify = ocrIdentifyService.getById(ocrIdentify.getId());
|
|
|
|
|
if (!Arrays.asList("1","9").contains(identify.getStatus())) {
|
|
|
|
|
if (!Arrays.asList("1", "9").contains(identify.getStatus())) {
|
|
|
|
|
return Result.error("当前任务不可重新执行");
|
|
|
|
|
}
|
|
|
|
|
//更新状态
|
|
|
|
|
OcrIdentify newOcrIdentify = new OcrIdentify();
|
|
|
|
|
BeanUtils.copyProperties(identify,newOcrIdentify);
|
|
|
|
|
BeanUtils.copyProperties(identify, newOcrIdentify);
|
|
|
|
|
newOcrIdentify.setStatus("0");
|
|
|
|
|
newOcrIdentify.setId(null);
|
|
|
|
|
ocrIdentifyService.save(newOcrIdentify);
|
|
|
|
|
//TODO 重新执行操作
|
|
|
|
|
List<String> identifyUrlList = FileOUtils.fileLists(null, newOcrIdentify.getIdentifyUrl());
|
|
|
|
|
//List<String> identifyUrlList = Arrays.asList("1","2");
|
|
|
|
|
taskService.postSemantic(newOcrIdentify,identifyUrlList);
|
|
|
|
|
taskService.postSemantic(newOcrIdentify, identifyUrlList);
|
|
|
|
|
return Result.OK("操作成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "上报通知给无量云")
|
|
|
|
|
@PostMapping(value = "/pushNotice")
|
|
|
|
|
public Result<?> pushNotice(@RequestBody OcrIdentify ocrIdentify){
|
|
|
|
|
public Result<?> pushNotice(@RequestBody OcrIdentify ocrIdentify) {
|
|
|
|
|
String id = ocrIdentify.getId();
|
|
|
|
|
List<OcrIdentify> ocrIdentifyList = ocrIdentifyService.listByIds(Arrays.asList(id.split(",")));
|
|
|
|
|
|
|
|
|
|
if (ocrIdentifyList==null|| ocrIdentifyList.size()==0) {
|
|
|
|
|
if (ocrIdentifyList == null || ocrIdentifyList.size() == 0) {
|
|
|
|
|
return Result.error("未获取到任务");
|
|
|
|
|
}
|
|
|
|
|
for (OcrIdentify entity : ocrIdentifyList) {
|
|
|
|
|
AssertUtils.isTrue("1".equals(entity.getStatus()),String.format("[任务名称]-%s 当前正在识别中,不可进行上报",entity.getTaskName()));
|
|
|
|
|
AssertUtils.isTrue(entity.getNoticeStatus().equals("0"),String.format("[任务名称]-%s 当前已上报,不可再次进行上报",entity.getTaskName()));
|
|
|
|
|
AssertUtils.isTrue("1".equals(entity.getStatus()), String.format("[任务名称]-%s 当前正在识别中,不可进行上报", entity.getTaskName()));
|
|
|
|
|
AssertUtils.isTrue(entity.getNoticeStatus().equals("0"), String.format("[任务名称]-%s 当前已上报,不可再次进行上报", entity.getTaskName()));
|
|
|
|
|
}
|
|
|
|
|
for (String identifyId : Arrays.asList(id.split(","))) {
|
|
|
|
|
ocrIdentifyService.callbackWlyAsync(identifyId);
|
|
|
|
|