master
周文涛 2 years ago
parent 508d2afba3
commit 3005edc34f

@ -20,6 +20,7 @@ import org.jeecg.modules.ocr.service.IOcrIdentifyService;
import org.jeecg.modules.ocr.service.IOcrRuleCheckService;
import org.jeecg.modules.ocr.service.impl.TaskService;
import org.jeecg.modules.ocr.utils.FileOUtils;
import org.jeecg.modules.ocr.utils.ImageUtils;
import org.jeecg.modules.ocr.vo.OcrRuleCheckVo;
import org.jeecg.modules.system.service.ISysDictService;
import org.springframework.scheduling.annotation.Async;
@ -28,6 +29,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -205,12 +207,46 @@ public class ApiController {
@Async
public Result restartTask() throws InterruptedException {
//获取未执行完的任务
/*List<OcrIdentify> list = ocrIdentifyService.list(new LambdaQueryWrapper<OcrIdentify>().eq(OcrIdentify::getStatus,"0"));*/
List<OcrIdentify> list = ocrIdentifyService.list(new LambdaQueryWrapper<OcrIdentify>());
/*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<OcrIdentifyDetail> list1 = ocrIdentifyDetailService.list(new LambdaQueryWrapper<OcrIdentifyDetail>().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, maxWidth, maxHeight);
}
ocrIdentifyDetail.setThumbnailImageUrl(outputImagePath);
}
}
ocrIdentifyDetailService.updateBatchById(list1);
}
//ocrIdentifyService.updateBatchById(list);
/*List<OcrIdentify> list = ocrIdentifyService.list(new LambdaQueryWrapper<OcrIdentify>().eq(OcrIdentify::getStatus,"1"));*/
/*for (OcrIdentify ocrIdentify : list) {
ocrIdentifyService.updateTaskResultInfo(ocrIdentify.getId());
}*/
List<OcrIdentify> list = ocrIdentifyService.list(new LambdaQueryWrapper<OcrIdentify>().in(OcrIdentify::getStatus, "0","2"));
/*List<OcrIdentify> list = ocrIdentifyService.list(new LambdaQueryWrapper<OcrIdentify>().in(OcrIdentify::getStatus, "0","2"));
List<String> identifyIdList = list.stream().map(l -> l.getId()).collect(Collectors.toList());
if (identifyIdList.size()>0) {
ocrIdentifyDetailService.remove(new LambdaQueryWrapper<OcrIdentifyDetail>().in(OcrIdentifyDetail::getIdentifyId,identifyIdList));
@ -220,7 +256,9 @@ public class ApiController {
//List<String> identifyUrlList = Arrays.asList("1","2");
taskService.postSemantic(ocrIdentify,identifyUrlList);
}
}
}*/
return Result.OK(list.size()+"个任务.");
}
}
//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"}'

@ -90,25 +90,15 @@ public class OcrIdentifyDetailController extends JeecgController<OcrIdentifyDeta
//客户测试服务器
if (!record.getImageUrl().contains("http:")&&!record.getImageUrl().contains("https:")) {
//压缩图片
File file=new File(record.getImageUrl());
if (StringUtils.isNotBlank(record.getThumbnailImageUrl())) {
File file=new File(record.getThumbnailImageUrl());
//当原图片存在时.
if (file.exists()) {
int maxWidth = 800;// 压缩后图片的最大宽度
int maxHeight = 600;// 压缩后图片的最大高度
int i = record.getImageUrl().lastIndexOf("/");
String fileUrl= "/data/thumbnail"+record.getImageUrl().substring(0,i);
//判断新目录是否存在,不存在则新建
ImageUtils.folderCreate(fileUrl);
String outputImagePath=fileUrl+record.getImageUrl().substring(i + 1, record.getImageUrl().length());
File thumbnailFile = new File(outputImagePath);
//如果上次生成过缩率图,就不生成了
if (!thumbnailFile.exists()) {
ImageUtils.compressImage(file.getAbsolutePath(), outputImagePath, maxWidth, maxHeight);
}
record.setThumbnailImagePreviewUrl("http://47.103.213.109:8072/files"+outputImagePath);
record.setThumbnailImagePreviewUrl("http://47.103.213.109:8072/files"+record.getThumbnailImageUrl());
}
}
String imagePreviewUrl="http://47.103.213.109:8072/files"+record.getImageUrl();
record.setImagePreviewUrl(imagePreviewUrl);
}
}else{
record.setImagePreviewUrl(record.getImageUrl());
}

@ -54,6 +54,10 @@ public class OcrIdentifyDetail implements Serializable {
@Excel(name = "图片地址", width = 15)
@ApiModelProperty(value = "图片地址")
private java.lang.String imageUrl;
/**预览图片地址*/
@Excel(name = "预览图片地址", width = 15)
@ApiModelProperty(value = "预览图片地址")
private java.lang.String thumbnailImageUrl;
/**识别描述*/
@Excel(name = "识别描述", width = 15)
@ApiModelProperty(value = "识别描述")
@ -96,8 +100,8 @@ public class OcrIdentifyDetail implements Serializable {
@ApiModelProperty(value = "图片预览地址")
private String imagePreviewUrl;
@TableField(exist = false)
@ApiModelProperty(value = "缩率图片预览地址")
@TableField(exist = false)
private String thumbnailImagePreviewUrl;
///===========================================
/*字段校验成功对象.*//*

@ -18,6 +18,7 @@ import org.jeecg.modules.ocr.mapper.OcrIdentifyMapper;
import org.jeecg.modules.ocr.model.*;
import org.jeecg.modules.ocr.service.*;
import org.jeecg.modules.ocr.utils.ArrayOUtils;
import org.jeecg.modules.ocr.utils.ImageUtils;
import org.jeecg.modules.ocr.utils.StrCharUtil;
import org.jeecg.modules.ocr.vo.OcrIdentifyVo;
import org.jeecg.modules.ocr.vo.OcrRuleCheckVo;
@ -28,6 +29,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.File;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
@ -101,6 +103,24 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
ocrIdentifyDetail.setIdentifyId(identifyId);
ocrIdentifyDetail.setImageName(imgName);
ocrIdentifyDetail.setImageUrl(imgPath);
//压缩图片
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, maxWidth, maxHeight);
}
ocrIdentifyDetail.setThumbnailImageUrl(outputImagePath);
}
//ocrIdentifyDetail.setStatus(taskStatus);
ocrIdentifyDetail.setStatus("");
ocrIdentifyDetail.setMessage(message);
@ -243,7 +263,6 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
//4.更新主任务状态
OcrIdentifyVo ocrIdentifyVo = this.findById(id);
OcrRuleCheckVo ocrRuleCheckVo = ocrIdentifyVo.getOcrRuleCheckVo();
Map<String, Map<String, String>> configRuleTypeMap = ocrRuleCheckVo.getConfigRuleTypeMap();
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<OcrIdentify>();
updateWrapper.eq(OcrIdentify::getId, id);
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.listByIdentifyId(id);
@ -265,6 +284,8 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
if (ruleValidation) {
fieldRightMap.put(tag, result);
} else if (lastResult == null || !lastResult.getRuleValidation()) {
//失败时就是未获取到结果
result.setFailureReason(result.getTagName()+"未获取到结果");
fieldRightMap.put(tag, result);
}
}
@ -286,19 +307,6 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
//匹配成功.
updateWrapper.set(OcrIdentify::getTaskResult, 1);
}
/*}else if (configRuleTypeMap.containsKey(OcrConstant.ruleCheckOrChar)){
Map<String, String> fieldMap = configRuleTypeMap.get(OcrConstant.ruleCheckSplitChar);
//获取成功的字段.
List<String> successFields = ocrResults.stream().filter(o -> o.getRuleValidation()).map(c->c.getTag()).collect(Collectors.toList());
updateWrapper.set(OcrIdentify::getErrorMsg, errorMsg);
updateWrapper.set(OcrIdentify::getTaskResult, 0);
fieldMapFor: for (String s : fieldMap.keySet()) {
if (successFields.contains(s)) {
updateWrapper.set(OcrIdentify::getTaskResult, 1);
break fieldMapFor;
}
}
}*/
String taskResultInfo = JSONArray.toJSONString(ocrResults);
updateWrapper.set(OcrIdentify::getStatus,"1");
updateWrapper.set(OcrIdentify::getEndTime,new Date());

Loading…
Cancel
Save