master
周文涛 2 years ago
parent 1794a5a6f8
commit ee705dfc4e

@ -10,9 +10,12 @@ import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.AssertUtils;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.ocr.entity.OcrIdentify;
import org.jeecg.modules.ocr.entity.OcrRuleCheck;
import org.jeecg.modules.ocr.model.TaskModel;
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.springframework.scheduling.annotation.Async;
import org.springframework.transaction.annotation.Transactional;
@ -21,6 +24,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@ -37,29 +41,69 @@ public class ApiController {
@Resource
private IOcrRuleCheckService ocrRuleCheckService;
@Resource
private IOcrIdentifyService ocrIdentifyService;
@Resource
private RedisUtil redisUtil;
////===================================================================伪接口
@ApiOperation(value = "通用识别", notes = "通用识别")
@PostMapping(value = "/identify")
@Transactional(rollbackFor = Exception.class)
public JSONObject identify(@RequestBody JSONObject jsonObject) {
String requestId = jsonObject.getString("requestId");//请求唯一标识
String scenes = jsonObject.getString("scenes");//场景类型door=门头照片cases=病例bill=票据
String ruleId = jsonObject.getString("ruleId");//规则标识
String sourceImages = jsonObject.getString("sourceImages");//ocr图片集
String priority = jsonObject.getString("priority");//任务优先级1=加急0=不加急
JSONArray sourceJson = jsonObject.getJSONArray("sourceJson");//校验数据源
List<JSONObject> sourceJsonList = sourceJson.toJavaList(JSONObject.class);
@ApiOperation(value = "通用识别")
@RequestMapping("/identify")
@Transactional
public Result<?> pushSemantic(@RequestBody JSONObject requestBody){
if (requestBody==null) {
return Result.error("请输入请求参数");
}
//1.获取请求参数
String requestId = requestBody.getString("requestId");//请求唯一标识
String scenes = requestBody.getString("scenes");//场景类型door=门头照片cases=病例bill=票据
String ruleId = requestBody.getString("ruleId");//规则标识
Integer priority = requestBody.getInteger("priority");//任务优先级1=加急0=不加急
String sourceImages = requestBody.getString("sourceImages");//ocr图片集
JSONArray sourceJson = requestBody.getJSONArray("sourceJson");
List<JSONObject> sourceJsonList = sourceJson.toJavaList(JSONObject.class);//校验数据源
//=============================================================
//2.参数判断
AssertUtils.notNull(requestId,"[requestId]-不可为空");
AssertUtils.notTrue(!"door".equals(scenes),String.format("暂不支持该场景类型[%s]",scenes));
AssertUtils.notNull(ruleId,"[ruleId]-不可为空");
OcrRuleCheckVo ruleCheck = ocrRuleCheckService.findById(ruleId);
AssertUtils.notNull(ruleCheck,"[ruleId]-不存在");
AssertUtils.notNull(priority,"[priority]-不可为空");
AssertUtils.notNull(sourceJson,"[sourceJson]-不可为空");
AssertUtils.notEmpty(requestId, "请输入[请求唯一标识]");
AssertUtils.notEmpty(scenes, "请输入[场景类型]");
AssertUtils.notEmpty(ruleId, "请输入[规则标识]");
AssertUtils.notEmpty(sourceImages, "请输入[ocr图片集]");
AssertUtils.notEmpty(priority, "请输入[任务优先级]");
AssertUtils.notNull(sourceJson, "请输入[校验数据源]");
return JSONObject.parseObject("{\"error_code\": 1, \"error_msg\": \"请求成功\"}");
//获取识别的图片
List<String> fileList=new ArrayList<>();
List<String> fileUrlList= FileOUtils.fileLists(sourceImages);
for (String fileUrl : fileUrlList) {
//判断附件是否是 图片格式
if (fileUrl.lastIndexOf(".png")!=-1 || fileUrl.lastIndexOf(".jpg")!=-1|| fileUrl.lastIndexOf(".jpeg")!=-1) {
fileList.add(fileUrl);
}
}
AssertUtils.hasSize(fileList,"图片目录下未获取到可使用的图片格式文件");
OcrIdentify ocrIdentify=new OcrIdentify();
//2.创建识别任务
if(true){
ocrIdentify.setTaskName(requestId);
ocrIdentify.setRequestId(requestId);
ocrIdentify.setStatus("0");//任务进行中
ocrIdentify.setRuleCheck(ruleId);//配置规则检查id
ocrIdentify.setStartTime(new Date());//开始时间
if (scenes.equals("door")) {
ocrIdentify.setTaskType("1683412752926986241");//任务类型
}
ocrIdentify.setPriority(priority.toString());
ocrIdentify.setMetadataConfigId(ruleCheck.getMetadataConfigId());//规则配置的元数据id
ocrIdentify.setTaskSource("API");//任务来源
ocrIdentify.setIdentifyUrl(sourceImages);//识别图片地址
ocrIdentify.setCreateBy("API请求");//创建人
ocrIdentify.setSourceJson(requestBody.getJSONArray("sourceJson").toJSONString());//校验数据源
ocrIdentifyService.save(ocrIdentify);
}
//3.请求python ocr识别异步执行
ocrIdentifyService.postSemantic(ocrIdentify,fileList);
return Result.OK("请求成功");
}
@ApiOperation(value = "获取规则", notes = "获取规则")

@ -49,62 +49,6 @@ public class OcrApiController {
IOcrTaskTypeService ocrTaskTypeService;
public static final String semanticUrl="http://47.103.213.109:9099/semantic";
@ApiOperation(value = "通用识别")
@RequestMapping("/identify")
@Transactional
public Result<?> pushSemantic(@RequestBody JSONObject requestBody){
//1.获取请求参数
String requestId = requestBody.getString("requestId");//请求唯一标识
String scenes = requestBody.getString("scenes");//场景类型door=门头照片cases=病例bill=票据
String ruleId = requestBody.getString("ruleId");//规则标识
Integer priority = requestBody.getInteger("priority");//任务优先级1=加急0=不加急
String sourceImages = requestBody.getString("sourceImages");//ocr图片集
JSONArray sourceJson = requestBody.getJSONArray("sourceJson");
List<JSONObject> sourceJsonList = sourceJson.toJavaList(JSONObject.class);//校验数据源
//=============================================================
//2.参数判断
AssertUtils.notNull(requestId,"[requestId]-不可为空");
AssertUtils.notTrue(!"door".equals(scenes),String.format("暂不支持该场景类型[%s]",scenes));
AssertUtils.notNull(ruleId,"[ruleId]-不可为空");
OcrRuleCheckVo ruleCheck = ruleCheckService.findById(ruleId);
AssertUtils.notNull(ruleCheck,"[ruleId]-不存在");
AssertUtils.notNull(priority,"[priority]-不可为空");
AssertUtils.notNull(sourceJson,"[sourceJson]-不可为空");
//获取识别的图片
List<String> fileList=new ArrayList<>();
List<String> fileUrlList= FileOUtils.fileLists(sourceImages);
for (String fileUrl : fileUrlList) {
//判断附件是否是 图片格式
if (fileUrl.lastIndexOf(".png")!=-1 || fileUrl.lastIndexOf(".jpg")!=-1|| fileUrl.lastIndexOf(".jpeg")!=-1) {
fileList.add(fileUrl);
}
}
AssertUtils.hasSize(fileList,"图片目录下未获取到可使用的图片格式文件");
OcrIdentify ocrIdentify=new OcrIdentify();
//2.创建识别任务
if(true){
ocrIdentify.setTaskName(requestId);
ocrIdentify.setRequestId(requestId);
ocrIdentify.setStatus("0");//任务进行中
ocrIdentify.setRuleCheck(ruleId);//配置规则检查id
ocrIdentify.setStartTime(new Date());//开始时间
if (scenes.equals("door")) {
ocrIdentify.setTaskType("1683412752926986241");//任务类型
}
ocrIdentify.setPriority(priority.toString());
ocrIdentify.setMetadataConfigId(ruleCheck.getMetadataConfigId());//规则配置的元数据id
ocrIdentify.setTaskSource("API");//任务来源
ocrIdentify.setIdentifyUrl(sourceImages);//识别图片地址
ocrIdentify.setCreateBy("API请求");//创建人
ocrIdentify.setSourceJson(requestBody.getJSONArray("sourceJson").toJSONString());//校验数据源
ocrIdentifyService.save(ocrIdentify);
}
//3.请求python ocr识别异步执行
ocrIdentifyService.postSemantic(ocrIdentify,fileList);
return Result.OK("请求成功");
}
public static void main(String[] args) {
String scenes = "door";
AssertUtils.notTrue(!"door".equals(scenes),String.format("暂不支持该场景类型[%s]",scenes));

Loading…
Cancel
Save