|
|
|
|
@ -3,6 +3,7 @@ package org.jeecg.modules.ocr.service.impl;
|
|
|
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.checkerframework.checker.units.qual.C;
|
|
|
|
|
@ -22,6 +23,7 @@ import org.jeecg.modules.ocr.vo.OcrIdentifyVo;
|
|
|
|
|
import org.jeecg.modules.ocr.vo.OcrRuleCheckVo;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
|
|
import org.springframework.scheduling.annotation.EnableAsync;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
|
|
|
|
|
@ -36,6 +38,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
* @Version: V1.0
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
@EnableAsync
|
|
|
|
|
public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrIdentify> implements IOcrIdentifyService {
|
|
|
|
|
@Resource
|
|
|
|
|
IOcrRuleCheckService ocrRuleCheckService;
|
|
|
|
|
@ -64,6 +67,11 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void getSemanticInfo(JSONObject responseBody) {
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(10000l);
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
log.debug("打印 ocr 结果:"+responseBody.toString());
|
|
|
|
|
String identifyId = responseBody.getString("task_id");//任务id
|
|
|
|
|
String imgPath = responseBody.getString("img_path");//图片路径
|
|
|
|
|
@ -145,10 +153,11 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
rMessage.append(field+"_未查到ocr结果");
|
|
|
|
|
ocrResultAdd(ocrResultList,field,inputText,null,0d,imgPath,"ocr结果未获取",false);
|
|
|
|
|
fieldRightMap.put(field,false);
|
|
|
|
|
}
|
|
|
|
|
rMessage.append(field+"_未查到ocr结果");
|
|
|
|
|
ocrResultAdd(ocrResultList,field,inputText,null,0d,imgPath,"ocr结果未获取",false);
|
|
|
|
|
fieldRightMap.put(field,false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//其中有一个字段 全部都是 失败,则该图片失败.
|
|
|
|
|
@ -165,10 +174,24 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
//=========================
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Async
|
|
|
|
|
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}";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Async
|
|
|
|
|
public void postSemantic(String id, String identifyUrl) {
|
|
|
|
|
//3.请求python ocr识别
|
|
|
|
|
JSONObject semanticResponseJson = JSONObject.parseObject(semanticResponse);
|
|
|
|
|
semanticResponseJson.put("task_id",id);
|
|
|
|
|
this.getSemanticInfo(semanticResponseJson);
|
|
|
|
|
|
|
|
|
|
//4.更新主任务状态
|
|
|
|
|
OcrIdentify ocrIdentify=new OcrIdentify();
|
|
|
|
|
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<OcrIdentify>();
|
|
|
|
|
updateWrapper.eq(OcrIdentify::getId, id);
|
|
|
|
|
updateWrapper.set(OcrIdentify::getEndTime, new Date());
|
|
|
|
|
updateWrapper.set(OcrIdentify::getStatus,"1");
|
|
|
|
|
this.update(updateWrapper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void mapPutIfTrue(Map map,String key,Boolean flag){
|
|
|
|
|
@ -199,7 +222,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
SourceImage sourceImage = new SourceImage();
|
|
|
|
|
sourceImage.setPath(imgPath);
|
|
|
|
|
int i = imgPath.lastIndexOf("/");
|
|
|
|
|
sourceImage.setFileName(imgPath.substring(i,imgPath.length()));
|
|
|
|
|
sourceImage.setFileName(imgPath.substring(i+1,imgPath.length()));
|
|
|
|
|
ocrResult.setSourceImage(sourceImage);
|
|
|
|
|
}
|
|
|
|
|
ocrResult.setFailureReason(failureReason);
|
|
|
|
|
|