master
周文涛 2 years ago
parent e95faf2f7e
commit 1157cd3835

@ -7,9 +7,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.OcrConstant;
import org.jeecg.common.system.vo.DictModel; import org.jeecg.common.system.vo.DictModel;
import org.jeecg.common.util.AssertUtils; import org.jeecg.common.util.AssertUtils;
import org.jeecg.common.util.RedisUtil; import org.jeecg.common.util.RedisUtil;
@ -17,22 +15,18 @@ import org.jeecg.common.util.RestUtil;
import org.jeecg.modules.ocr.entity.OcrIdentify; import org.jeecg.modules.ocr.entity.OcrIdentify;
import org.jeecg.modules.ocr.entity.OcrIdentifyDetail; import org.jeecg.modules.ocr.entity.OcrIdentifyDetail;
import org.jeecg.modules.ocr.entity.OcrRuleCheck; import org.jeecg.modules.ocr.entity.OcrRuleCheck;
import org.jeecg.modules.ocr.model.TaskModel;
import org.jeecg.modules.ocr.service.IOcrIdentifyDetailService; import org.jeecg.modules.ocr.service.IOcrIdentifyDetailService;
import org.jeecg.modules.ocr.service.IOcrIdentifyService; import org.jeecg.modules.ocr.service.IOcrIdentifyService;
import org.jeecg.modules.ocr.service.IOcrRuleCheckService; import org.jeecg.modules.ocr.service.IOcrRuleCheckService;
import org.jeecg.modules.ocr.utils.FileOUtils; import org.jeecg.modules.ocr.utils.FileOUtils;
import org.jeecg.modules.ocr.vo.OcrRuleCheckVo; import org.jeecg.modules.ocr.vo.OcrRuleCheckVo;
import org.jeecg.modules.system.service.ISysDictService; import org.jeecg.modules.system.service.ISysDictService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -57,7 +51,6 @@ public class ApiController {
@Resource @Resource
private RedisUtil redisUtil; private RedisUtil redisUtil;
////===================================================================伪接口 ////===================================================================伪接口
@ApiOperation(value = "通用识别") @ApiOperation(value = "通用识别")
@RequestMapping("/identify") @RequestMapping("/identify")
@ -112,7 +105,7 @@ public class ApiController {
ocrIdentify.setRequestId(requestId); ocrIdentify.setRequestId(requestId);
ocrIdentify.setStatus("0");//任务进行中 ocrIdentify.setStatus("0");//任务进行中
ocrIdentify.setRuleCheck(ruleId);//配置规则检查id ocrIdentify.setRuleCheck(ruleId);//配置规则检查id
ocrIdentify.setStartTime(new Date());//开始时间 //ocrIdentify.setStartTime(new Date());//开始时间
if (scenes.equals("door")) { if (scenes.equals("door")) {
ocrIdentify.setTaskType("1683412752926986241");//任务类型 ocrIdentify.setTaskType("1683412752926986241");//任务类型
} }
@ -201,6 +194,15 @@ public class ApiController {
return JSONObject.parseObject("{\"requestId\":\"10001\",\"result\":{\"retrieveReviewCompliance\":\"80\",\"imageTagRetrievePercentage\":\"66.6\",\"failureReason\":\"图片不清晰\"}}"); return JSONObject.parseObject("{\"requestId\":\"10001\",\"result\":{\"retrieveReviewCompliance\":\"80\",\"imageTagRetrievePercentage\":\"66.6\",\"failureReason\":\"图片不清晰\"}}");
} }
//========================================================================================== //==========================================================================================
@ApiOperation(value = "刷新为完成的任务", notes = "任务完结通知")
@GetMapping("/test")
public Result test(){
JSONObject jsonObject=new JSONObject();
for (int i = 0; i < 100; i++) {
}
return Result.OK("111");
}
@ApiOperation(value = "刷新为完成的任务", notes = "任务完结通知") @ApiOperation(value = "刷新为完成的任务", notes = "任务完结通知")
@GetMapping("/restartTask") @GetMapping("/restartTask")

@ -16,22 +16,35 @@ import java.util.List;
* @Version: V1.0 * @Version: V1.0
*/ */
public interface IOcrIdentifyService extends IService<OcrIdentify> { public interface IOcrIdentifyService extends IService<OcrIdentify> {
//单条根据id自定义返回结果对象方法
public OcrIdentifyVo findById(String id); public OcrIdentifyVo findById(String id);
/**
*
* @param ocrIdentifyId
*/
public void callbackWly(String ocrIdentifyId);
/** /**
* ocr * ocr
* @param responseBody * @param responseBody
*/ */
public void getSemanticInfo(JSONObject responseBody); void getSemanticInfo(JSONObject responseBody);
@Async @Async
void postSemantic(OcrIdentify ocrIdentify, List<String> identifyUrlList); void postSemantic(OcrIdentify ocrIdentify, List<String> identifyUrlList);
void updateOcrIdentifyStatus(String id,String status); void updateOcrIdentifyStatus(String id,String status);
/** /**
* *
* @param jsonObject * @param jsonObject
* @return * @return
*/ */
Result pushTask(JSONObject jsonObject); Result pushTask(JSONObject jsonObject);
void updateMasterTaskStartTime(String id);
} }

@ -75,12 +75,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
@Override @Override
public void getSemanticInfo(JSONObject responseBody) { public void getSemanticInfo(JSONObject responseBody) {
String ocrApiCallStatisticsId = null; String ocrApiCallStatisticsId = null;
try {
ocrApiCallStatisticsId = ocrApiCallStatisticsService.saveLogs("通用识别", "/ocr/ocrApi/identify", 1); ocrApiCallStatisticsId = ocrApiCallStatisticsService.saveLogs("通用识别", "/ocr/ocrApi/identify", 1);
Thread.sleep(1000l);
} catch (InterruptedException e) {
e.printStackTrace();
}
log.debug("打印 ocr 结果:" + responseBody.toString()); log.debug("打印 ocr 结果:" + responseBody.toString());
String identifyId = responseBody.getString("identifyId");//任务id String identifyId = responseBody.getString("identifyId");//任务id
String imgPath = responseBody.getString("img_path");//图片路径 String imgPath = responseBody.getString("img_path");//图片路径
@ -100,7 +95,6 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
if (semanticResult != null) { if (semanticResult != null) {
long count = ocrIdentifyDetailService.count(new LambdaUpdateWrapper<OcrIdentifyDetail>().eq(OcrIdentifyDetail::getIdentifyId, identifyId).eq(OcrIdentifyDetail::getImageUrl, imgPath)); long count = ocrIdentifyDetailService.count(new LambdaUpdateWrapper<OcrIdentifyDetail>().eq(OcrIdentifyDetail::getIdentifyId, identifyId).eq(OcrIdentifyDetail::getImageUrl, imgPath));
if (count > 0) { if (count > 0) {
//该图片已识别过
log.error("该图片已识别过了"); log.error("该图片已识别过了");
return; return;
} }
@ -243,22 +237,32 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
} }
@Override @Override
@Async
public void updateOcrIdentifyStatus(String id, String status) { public void updateOcrIdentifyStatus(String id, String status) {
//4.更新主任务状态 //4.更新主任务状态
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<OcrIdentify>(); LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<OcrIdentify>();
updateWrapper.eq(OcrIdentify::getId, id); updateWrapper.eq(OcrIdentify::getId, id);
updateWrapper.set(OcrIdentify::getEndTime, new Date()); updateWrapper.set(OcrIdentify::getEndTime, new Date());
updateWrapper.set(OcrIdentify::getStatus, "1"); updateWrapper.set(OcrIdentify::getStatus, "1");
super.update(updateWrapper);
this.callbackWly(id);
}
@Override
@Async
public void callbackWly(String ocrIdentifyId){
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<OcrIdentify>();
updateWrapper.eq(OcrIdentify::getId, ocrIdentifyId);
long time = new Date().getTime(); long time = new Date().getTime();
//回调 无量云接口 //回调 无量云接口
if (true) { OcrIdentify ocrIdentify = super.getById(ocrIdentifyId);
OcrIdentify ocrIdentify = super.getById(id); if (ocrIdentify!=null) {
if (StringUtils.isBlank(ocrIdentify.getRequestId())) { if (StringUtils.isBlank(ocrIdentify.getRequestId())) {
ocrIdentify.setRequestId(time + ""); ocrIdentify.setRequestId(time + "");
} }
if (StringUtils.isNotBlank(ocrIdentify.getRequestId())) { if (StringUtils.isNotBlank(ocrIdentify.getRequestId())) {
LambdaQueryWrapper<OcrIdentifyDetail> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<OcrIdentifyDetail> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(OcrIdentifyDetail::getIdentifyId, id); queryWrapper.eq(OcrIdentifyDetail::getIdentifyId, ocrIdentifyId);
queryWrapper.isNotNull(OcrIdentifyDetail::getDataStructured); queryWrapper.isNotNull(OcrIdentifyDetail::getDataStructured);
List<OcrIdentifyDetail> identifyDetails = ocrIdentifyDetailService.list(queryWrapper); List<OcrIdentifyDetail> identifyDetails = ocrIdentifyDetailService.list(queryWrapper);
if (identifyDetails != null) { if (identifyDetails != null) {
@ -313,11 +317,9 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
} else { } else {
updateWrapper.set(OcrIdentify::getNoticeStatus, "0"); updateWrapper.set(OcrIdentify::getNoticeStatus, "0");
} }
} }
} }
super.update(updateWrapper); super.update(updateWrapper);
} }
public static void mapPutIfTrue(Map map, String key, Boolean flag) { public static void mapPutIfTrue(Map map, String key, Boolean flag) {
@ -475,6 +477,15 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
return Result.OK("已追加到任务"); return Result.OK("已追加到任务");
} }
@Override
public void updateMasterTaskStartTime(String id) {
LambdaUpdateWrapper<OcrIdentify> updateWrapper=new LambdaUpdateWrapper<>();
updateWrapper.set(OcrIdentify::getStartTime,new Date());
updateWrapper.isNull(OcrIdentify::getStartTime);
updateWrapper.eq(OcrIdentify::getId,id);
super.update(updateWrapper);
}
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void executeTask() { public void executeTask() {
//获取任务 //获取任务
@ -555,6 +566,10 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
JSONObject requestBody = new JSONObject(); JSONObject requestBody = new JSONObject();
requestBody.put("task_id", task_id); requestBody.put("task_id", task_id);
requestBody.put("img_path", image); requestBody.put("img_path", image);
//更新主任务,正在识别中.
this.updateMasterTaskStartTime(task_id.split("_")[0]);
JSONObject semanticResponseJson = RestUtil.post(OcrConstant.api_test2_identify_url, requestBody); JSONObject semanticResponseJson = RestUtil.post(OcrConstant.api_test2_identify_url, requestBody);
semanticResponseJson.put("identifyId", masterTaskId); semanticResponseJson.put("identifyId", masterTaskId);
log.info("ocr识别返回数据:"); log.info("ocr识别返回数据:");
@ -577,7 +592,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
} }
} }
} else { } else {
Thread.sleep(20000l); Thread.sleep(2000l);
} }

Loading…
Cancel
Save