新增方法:计算最近任务创建时间差

devhuozheluoji
DELL 2 years ago
parent 96573a1c92
commit eb50805c86

@ -3,6 +3,7 @@ package org.jeecg.modules.api.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
@ -34,6 +35,7 @@ import javax.annotation.Resource;
import java.awt.*;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
@ -71,6 +73,7 @@ public class ApiController {
}
//1.获取请求参数
String taskName = requestBody.getString("taskName");
AssertUtils.notTrue(ocrIdentifyService.calculateTimeDifference(taskName)<=10,"[任务名称]-"+taskName+" 短时间内已存在,不可再次请求");
String requestId = requestBody.getString("requestId");//请求唯一标识
String scenes = requestBody.getString("scenes");//场景类型door=门头照片cases=病例bill=票据
String ruleId = requestBody.getString("ruleId");//规则标识

@ -153,6 +153,7 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
return Result.error("当前环境不支持该功能,请访问测试环境");
}
AssertUtils.notEmpty(ocrIdentify.getTaskName(), "[任务名称]-不可为空");
AssertUtils.notTrue(ocrIdentifyService.calculateTimeDifference(ocrIdentify.getTaskName())<=10,"[任务名称]-"+ocrIdentify.getTaskName()+" 短时间内已存在,不可再次请求");
AssertUtils.notEmpty(ocrIdentify.getIdentifyUrl(), "[识别路径]不可为空");
AssertUtils.notEmpty(ocrIdentify.getRuleCheck(), "请选择[规则检查配置]");
AssertUtils.notEmpty(ocrIdentify.getPriority(), "请选择[优先级]");
@ -427,4 +428,5 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
}
return Result.OK("操作成功");
}
}

@ -74,4 +74,11 @@ public interface IOcrIdentifyService extends IService<OcrIdentify> {
* @return
*/
List<OcrIdentify> getSemanticTaskList();
/**
*
* @return
*/
long calculateTimeDifference(String taskName);
}

@ -3,6 +3,7 @@ package org.jeecg.modules.ocr.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
@ -62,6 +63,8 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
RedisUtil redisUtil;
@Resource
IOcrIdentifyCallbackLogService ocrIdentifyCallbackLogService;
@Resource
private IOcrIdentifyService ocrIdentifyService;
@Override
public OcrIdentifyDTO findById(String id) {
@ -415,7 +418,6 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
public void callbackWly(String ocrIdentifyId) {
OcrIdentifyCallbackLog ocrIdentifyCallbackLog = new OcrIdentifyCallbackLog();
ocrIdentifyCallbackLog.setIdentifyId(ocrIdentifyId);
Date date = new Date();
ocrIdentifyCallbackLog.setCreateTime(date);
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<OcrIdentify>();
@ -426,7 +428,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.listByIdentifyId(ocrIdentifyId);
ocrIdentifyCallbackLog.setStartTime(date);
boolean b = CallBackWlyUtils.callbackWly(ocrIdentify, identifyDetailList);
ocrIdentifyCallbackLog.setStatus(b?1:0);
ocrIdentifyCallbackLog.setStatus(b?1:0);//0-失败1-成功
ocrIdentifyCallbackLog.setEndTime(new Date());
ocrIdentifyCallbackLogService.save(ocrIdentifyCallbackLog);
if (b) {
@ -903,7 +905,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
} else if (StringUtils.isBlank(inputText)) {
//没有输入值.
fieldRightMap.put(field, false);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", false, ruleInfo);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值", false, ruleInfo);
} else if ("0".equals(ruleInfo)) {
//不必校验,有识别到就行,通过
fieldRightMap.put(field, true);
@ -1221,4 +1223,17 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
return taskList;
}
@Override
public long calculateTimeDifference(String taskName) {
QueryWrapper<OcrIdentify> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("taskName", taskName).orderByDesc("createTime").last("LIMIT 1");
OcrIdentify lastIdentify = ocrIdentifyService.getOne(queryWrapper);
if (lastIdentify != null) {
Date lastCreateTime = lastIdentify.getCreateTime();
Date currentTime = new Date();
return (currentTime.getTime() - lastCreateTime.getTime()) / 1000;
}
return 11; // 如果没有找到数据,返回默认值
}
}

Loading…
Cancel
Save