master
周文涛 2 years ago
parent 27bc36aa53
commit 66ee319396

@ -1,14 +1,21 @@
package org.jeecg.modules.ocr.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.AssertUtils;
import org.jeecg.common.util.RestUtil;
import org.jeecg.modules.ocr.entity.OcrIdentify;
import org.jeecg.modules.ocr.service.IOcrIdentifyService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
@ -20,6 +27,8 @@ import java.util.List;
@RestController
@Slf4j
public class OcrApiController {
@Resource
IOcrIdentifyService ocrIdentifyService;
public static final String semanticUrl="http://47.103.213.109:9099/semantic";
/**
* 1. id[]
@ -64,12 +73,14 @@ public class OcrApiController {
* }
* message: "成功"
*/
@ApiOperation(value = "请求ocr识别")
@RequestMapping("/push/semantic")
public Result<?> pushSemantic(){
String taskId="1681203097437954049";//任务id
List<String> imagesUrl= Arrays.asList("https://h5.mcnetmart.com/tmp/images/dc_demo1.png");//图片路径
for (String image : imagesUrl) {
public static String semanticResponse="{\"execution_time\":69.1751720905304,\"img_path\":\"./static/ocrData/custom_2_44.jpg\",\"message\":\"成功\",\"semantic_result\":{\"医院名称\":[{\"area\":[[227,382],[441,388],[440,422],[226,416]],\"end\":7,\"ocrText\":\"开封市眼病医院\",\"probability\":0.9677108957485778,\"start\":0,\"text\":\"开封市眼病医院\"}],\"姓名\":[{\"area\":[[566,668],[691,668],[691,712],[566,712]],\"end\":3,\"ocrText\":\"闫利霞\",\"probability\":0.884488371938783,\"start\":0,\"text\":\"闫利霞\"}],\"时间\":[{\"area\":[[701,400],[874,400],[874,456],[701,456]],\"end\":5,\"ocrText\":\"10:40\",\"probability\":0.9626484940814066,\"start\":0,\"text\":\"10:40\"},{\"area\":[[502,422],[667,424],[667,452],[502,450]],\"end\":11,\"ocrText\":\"2023年05月17日\",\"probability\":0.815085233546764,\"start\":0,\"text\":\"2023年05月17日\"}],\"科室\":[]},\"task_id\":1}";
@ApiOperation(value = "通用识别")
@RequestMapping("/identify")
public Result<?> pushSemantic(@RequestBody JSONObject requestBody){
//String taskId="1681203097437954049";//任务id
//List<String> imagesUrl= Arrays.asList("https://h5.mcnetmart.com/tmp/images/dc_demo1.png");//图片路径
/*for (String image : imagesUrl) {
JSONObject jsonObject=new JSONObject();
jsonObject.put("taskId",taskId);
jsonObject.put("images",Arrays.asList(image));
@ -77,8 +88,33 @@ public class OcrApiController {
JSONObject postResponse = RestUtil.post("", jsonObject);
//获取返回结果
postResponse.getString("");
}*/
//1.获取请求参数
String requestId = requestBody.getString("requestId");//请求唯一标识
String scenes = requestBody.getString("scenes");//场景类型door=门头照片cases=病例bill=票据
AssertUtils.notTrue(!"door".equals(scenes),String.format("暂不支持该场景类型[%s]",scenes));
String ruleId = requestBody.getString("ruleId");//规则标识
Integer priority = requestBody.getInteger("priority");//任务优先级1=加急0=不加急
JSONArray sourceJson = requestBody.getJSONArray("sourceJson");
List<JSONObject> sourceJsonList = sourceJson.toJavaList(JSONObject.class);//校验数据源
String sourceImages = requestBody.getString("sourceImages");//ocr图片集
//2.创建识别任务
if(true){
OcrIdentify ocrIdentify=new OcrIdentify();
ocrIdentify.setTaskName(requestId);
ocrIdentify.setStatus("0");
ocrIdentify.setRuleCheck(ruleId);
ocrIdentify.setStartTime(new Date());
//ocrIdentify.setTaskType("")
ocrIdentify.setIdentifyUrl("https://h5.mcnetmart.com/tmp/images/dc_demo1.png");
ocrIdentifyService.save(ocrIdentify);
}
return null;
//3.请求python ocr识别
return Result.OK("请求成功");
}
public static void main(String[] args) {
String scenes = "door";
AssertUtils.notTrue(!"door".equals(scenes),String.format("暂不支持该场景类型[%s]",scenes));
}
}

@ -25,6 +25,7 @@ import org.jeecg.modules.ocr.entity.OcrRuleCheck;
import org.jeecg.modules.ocr.entity.OcrTaskType;
import org.jeecg.modules.ocr.model.OcrMetadataConfigSaveModel;
import org.jeecg.modules.ocr.model.OcrRuleCheckSaveModel;
import org.jeecg.modules.ocr.service.IOcrMetadataConfigService;
import org.jeecg.modules.ocr.service.IOcrRuleCheckService;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.ocr.utils.DownloadTemplateUtil;
@ -57,7 +58,8 @@ public class OcrRuleCheckController extends JeecgController<OcrRuleCheck, IOcrRu
private IOcrRuleCheckService ocrRuleCheckService;
@Autowired
private DownloadTemplateUtil downloadTemplateUtil;
@Autowired
private IOcrMetadataConfigService ocrMetadataConfigService;
/**
*
*
@ -234,6 +236,8 @@ public class OcrRuleCheckController extends JeecgController<OcrRuleCheck, IOcrRu
AssertUtils.notTrue(existsFlag,String.format("[配置名称]-%s 已存在",configVo.getConfigName()));
String configRule = configVo.getConfigRule();
String metadataConfigId = configVo.getMetadataConfigId();
OcrMetadataConfigVo ocrMetadataConfigVo = ocrMetadataConfigService.findById(metadataConfigId);
AssertUtils.notNull(ocrMetadataConfigVo,String.format("[元数据配置]-%s 不存在",metadataConfigId));
ocrRuleCheckSaveModel.setConfigRule(configRule);
ocrRuleCheckSaveModel.setMetadataConfigId(metadataConfigId);
saveModelList.add(ocrRuleCheckSaveModel);

Loading…
Cancel
Save