master
周文涛 2 years ago
parent b0d9be39c7
commit 69677d5e8a

@ -21,6 +21,7 @@ import org.jeecg.modules.ocr.utils.ImageUtils;
import org.jeecg.modules.ocr.dto.OcrIdentifyDTO; import org.jeecg.modules.ocr.dto.OcrIdentifyDTO;
import org.jeecg.modules.ocr.dto.OcrRuleCheckDTO; import org.jeecg.modules.ocr.dto.OcrRuleCheckDTO;
import org.jeecg.modules.system.service.ISysDictService; import org.jeecg.modules.system.service.ISysDictService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async; 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;
@ -54,12 +55,16 @@ public class ApiController {
private RedisUtil redisUtil; private RedisUtil redisUtil;
@Resource @Resource
private TaskService taskService; private TaskService taskService;
////===================================================================伪接口 @Value("${spring.profiles.active}")
private String profiles;
@ApiOperation(value = "通用识别") @ApiOperation(value = "通用识别")
@RequestMapping("/identify") @RequestMapping("/identify")
@Transactional @Transactional
@ResponseBody @ResponseBody
public Result<?> pushSemantic(@RequestBody JSONObject requestBody) throws InterruptedException { public Result<?> pushSemantic(@RequestBody JSONObject requestBody) throws InterruptedException {
if (!"test".equals(profiles)) {
return Result.error("当前环境不支持该功能,请访问测试环境");
}
if (requestBody == null) { if (requestBody == null) {
return Result.error("请输入请求参数"); return Result.error("请输入请求参数");
} }

@ -5,6 +5,7 @@ import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -35,6 +36,7 @@ import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ImportParams; import org.jeecgframework.poi.excel.entity.ImportParams;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.multipart.MultipartHttpServletRequest;
@ -70,6 +72,9 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
private ISysDictService sysDictService; private ISysDictService sysDictService;
@Autowired @Autowired
private TaskService taskService; private TaskService taskService;
@Value("${spring.profiles.active}")
private String profiles;
/** /**
* *
* *
@ -83,38 +88,38 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
@ApiOperation(value = "ocr识别-分页列表查询", notes = "ocr识别-分页列表查询") @ApiOperation(value = "ocr识别-分页列表查询", notes = "ocr识别-分页列表查询")
@GetMapping(value = "/list") @GetMapping(value = "/list")
public Result<IPage<OcrIdentify>> queryPageList(OcrIdentify ocrIdentify, public Result<IPage<OcrIdentify>> queryPageList(OcrIdentify ocrIdentify,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest req) { HttpServletRequest req) {
if (StringUtils.isNotBlank(ocrIdentify.getTaskName())) { if (StringUtils.isNotBlank(ocrIdentify.getTaskName())) {
ocrIdentify.setTaskName("*"+ocrIdentify.getTaskName()+"*"); ocrIdentify.setTaskName("*" + ocrIdentify.getTaskName() + "*");
} }
if (StringUtils.isNotBlank(ocrIdentify.getIdentifyUrl())) { if (StringUtils.isNotBlank(ocrIdentify.getIdentifyUrl())) {
ocrIdentify.setIdentifyUrl("*"+ocrIdentify.getIdentifyUrl()+"*"); ocrIdentify.setIdentifyUrl("*" + ocrIdentify.getIdentifyUrl() + "*");
} }
if (StringUtils.isNotBlank(ocrIdentify.getCreateBy())) { if (StringUtils.isNotBlank(ocrIdentify.getCreateBy())) {
ocrIdentify.setCreateBy("*"+ocrIdentify.getCreateBy()+"*"); ocrIdentify.setCreateBy("*" + ocrIdentify.getCreateBy() + "*");
} }
Date startTime=ocrIdentify.getStartTime(); Date startTime = ocrIdentify.getStartTime();
Date endTime=ocrIdentify.getEndTime(); Date endTime = ocrIdentify.getEndTime();
if (startTime!=null&&endTime!=null) { if (startTime != null && endTime != null) {
ocrIdentify.setStartTime(null); ocrIdentify.setStartTime(null);
ocrIdentify.setEndTime(null); ocrIdentify.setEndTime(null);
} }
QueryWrapper<OcrIdentify> queryWrapper = QueryGenerator.initQueryWrapper(ocrIdentify, req.getParameterMap()); QueryWrapper<OcrIdentify> queryWrapper = QueryGenerator.initQueryWrapper(ocrIdentify, req.getParameterMap());
queryWrapper.ne("task_source","模拟实验");//排除模拟实验的数据 queryWrapper.ne("task_source", "模拟实验");//排除模拟实验的数据
if (startTime!=null&&endTime!=null) { if (startTime != null && endTime != null) {
endTime.setTime(endTime.getTime()+86400000l); endTime.setTime(endTime.getTime() + 86400000l);
queryWrapper.between("end_time",startTime,endTime); queryWrapper.between("end_time", startTime, endTime);
} }
Page<OcrIdentify> page = new Page<>(pageNo, pageSize); Page<OcrIdentify> page = new Page<>(pageNo, pageSize);
Map<String, OcrRuleCheckDTO> ocrRuleCheckMap = ocrRuleCheckService.listToMap(null); Map<String, OcrRuleCheckDTO> ocrRuleCheckMap = ocrRuleCheckService.listToMap(null);
Map<String, OcrMetadataConfigDTO> metadataConfigMap = ocrMetadataConfigService.listToMap(null); Map<String, OcrMetadataConfigDTO> metadataConfigMap = ocrMetadataConfigService.listToMap(null);
Map<String, String> taskNameMap = ocrTaskTypeService.listNameToMap(null); Map<String, String> taskNameMap = ocrTaskTypeService.listNameToMap(null);
IPage<OcrIdentify> pageList = ocrIdentifyService.page(page, queryWrapper); IPage<OcrIdentify> pageList = ocrIdentifyService.page(page, queryWrapper);
if (pageList != null && pageList.getRecords() != null &&pageList.getRecords().size()>0) { if (pageList != null && pageList.getRecords() != null && pageList.getRecords().size() > 0) {
List<String> identifyIdList = pageList.getRecords().stream().map(p -> p.getId()).collect(Collectors.toList()); List<String> identifyIdList = pageList.getRecords().stream().map(p -> p.getId()).collect(Collectors.toList());
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.list(new LambdaQueryWrapper<OcrIdentifyDetail>().in(OcrIdentifyDetail::getIdentifyId,identifyIdList)); List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.list(new LambdaQueryWrapper<OcrIdentifyDetail>().in(OcrIdentifyDetail::getIdentifyId, identifyIdList));
for (OcrIdentify record : pageList.getRecords()) { for (OcrIdentify record : pageList.getRecords()) {
long count = identifyDetailList.stream().filter(i -> i.getIdentifyId().equals(record.getId())).count(); long count = identifyDetailList.stream().filter(i -> i.getIdentifyId().equals(record.getId())).count();
record.setImgNum(count); record.setImgNum(count);
@ -124,15 +129,15 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
int successNum = (int) ocrResultDTOS.stream().filter(o -> o.getRuleValidation()).count(); int successNum = (int) ocrResultDTOS.stream().filter(o -> o.getRuleValidation()).count();
record.setTagNum(tagNum); record.setTagNum(tagNum);
record.setTagSuccessNum(successNum); record.setTagSuccessNum(successNum);
record.setSuccessRate(successNum+"/"+tagNum); record.setSuccessRate(successNum + "/" + tagNum);
record.setTaskResultInfoList(ocrResultDTOS); record.setTaskResultInfoList(ocrResultDTOS);
} }
OcrRuleCheckDTO ocrRuleCheckVo = ocrRuleCheckMap.get(record.getRuleCheck()); OcrRuleCheckDTO ocrRuleCheckVo = ocrRuleCheckMap.get(record.getRuleCheck());
if (ocrRuleCheckVo!=null && StringUtils.isNotBlank(ocrRuleCheckVo.getMetadataConfigId())) { if (ocrRuleCheckVo != null && StringUtils.isNotBlank(ocrRuleCheckVo.getMetadataConfigId())) {
record.setOcrRuleCheckInfoConfigRule(ocrRuleCheckVo.getConfigRule()); record.setOcrRuleCheckInfoConfigRule(ocrRuleCheckVo.getConfigRule());
record.setMetadataConfigId(ocrRuleCheckVo.getMetadataConfigId()); record.setMetadataConfigId(ocrRuleCheckVo.getMetadataConfigId());
OcrMetadataConfigDTO ocrMetadataConfigDTO = metadataConfigMap.get(ocrRuleCheckVo.getMetadataConfigId()); OcrMetadataConfigDTO ocrMetadataConfigDTO = metadataConfigMap.get(ocrRuleCheckVo.getMetadataConfigId());
if (ocrMetadataConfigDTO !=null) { if (ocrMetadataConfigDTO != null) {
record.setTaskType(ocrMetadataConfigDTO.getTaskType()); record.setTaskType(ocrMetadataConfigDTO.getTaskType());
record.setTaskType_dictText(taskNameMap.get(ocrMetadataConfigDTO.getTaskType())); record.setTaskType_dictText(taskNameMap.get(ocrMetadataConfigDTO.getTaskType()));
} }
@ -153,6 +158,9 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
// @RequiresPermissions("org.jeecg.modules.ocr:ocr_identify:add") // @RequiresPermissions("org.jeecg.modules.ocr:ocr_identify:add")
@PostMapping(value = "/add") @PostMapping(value = "/add")
public Result<String> add(@RequestBody OcrIdentify ocrIdentify) { public Result<String> add(@RequestBody OcrIdentify ocrIdentify) {
if (!"test".equals(profiles)) {
return Result.error("当前环境不支持该功能,请访问测试环境");
}
AssertUtils.notEmpty(ocrIdentify.getTaskName(), "[任务名称]-不可为空"); AssertUtils.notEmpty(ocrIdentify.getTaskName(), "[任务名称]-不可为空");
AssertUtils.notEmpty(ocrIdentify.getIdentifyUrl(), "[识别路径]不可为空"); AssertUtils.notEmpty(ocrIdentify.getIdentifyUrl(), "[识别路径]不可为空");
AssertUtils.notEmpty(ocrIdentify.getRuleCheck(), "请选择[规则检查配置]"); AssertUtils.notEmpty(ocrIdentify.getRuleCheck(), "请选择[规则检查配置]");
@ -162,15 +170,15 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
//获取相对路径 //获取相对路径
List<DictModel> ocr_relative_path = sysDictService.queryDictItemsByCode("ocr_relative_path"); List<DictModel> ocr_relative_path = sysDictService.queryDictItemsByCode("ocr_relative_path");
String relativePath=null; String relativePath = null;
if (ocr_relative_path!=null && ocr_relative_path.size()>0) { if (ocr_relative_path != null && ocr_relative_path.size() > 0) {
for (DictModel dictModel : ocr_relative_path) { for (DictModel dictModel : ocr_relative_path) {
if (dictModel.getValue().equals("0")) { if (dictModel.getValue().equals("0")) {
relativePath= dictModel.getText(); relativePath = dictModel.getText();
} }
} }
} }
List<String> fileUrlList = FileOUtils.fileLists(relativePath,ocrIdentify.getIdentifyUrl()); List<String> fileUrlList = FileOUtils.fileLists(relativePath, ocrIdentify.getIdentifyUrl());
AssertUtils.notNull(fileUrlList, "图片地址不存在"); AssertUtils.notNull(fileUrlList, "图片地址不存在");
for (String fileUrl : fileUrlList) { for (String fileUrl : fileUrlList) {
//判断附件是否是 图片格式 //判断附件是否是 图片格式
@ -183,7 +191,7 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
ocrIdentify.setStatus("0"); ocrIdentify.setStatus("0");
ocrIdentifyService.save(ocrIdentify); ocrIdentifyService.save(ocrIdentify);
//3.请求python ocr识别异步执行 //3.请求python ocr识别异步执行
taskService.postSemantic(ocrIdentify,fileList); taskService.postSemantic(ocrIdentify, fileList);
//ocrIdentifyService.postSemantic(ocrIdentify, fileList); //ocrIdentifyService.postSemantic(ocrIdentify, fileList);
//请求ocr识别接口 //请求ocr识别接口
//ocrIdentifyService.postSemantic(ocrIdentify.getId(),Arrays.asList(ocrIdentify.getIdentifyUrl())); //ocrIdentifyService.postSemantic(ocrIdentify.getId(),Arrays.asList(ocrIdentify.getIdentifyUrl()));
@ -263,26 +271,26 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
Map<String, OcrRuleCheckDTO> ocrRuleCheckMap = ocrRuleCheckService.listToMap(null); Map<String, OcrRuleCheckDTO> ocrRuleCheckMap = ocrRuleCheckService.listToMap(null);
Map<String, OcrMetadataConfigDTO> metadataConfigMap = ocrMetadataConfigService.listToMap(null); Map<String, OcrMetadataConfigDTO> metadataConfigMap = ocrMetadataConfigService.listToMap(null);
Map<String, String> taskNameMap = ocrTaskTypeService.listNameToMap(null); Map<String, String> taskNameMap = ocrTaskTypeService.listNameToMap(null);
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.list(new LambdaQueryWrapper<OcrIdentifyDetail>().eq(OcrIdentifyDetail::getIdentifyId,id)); List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.list(new LambdaQueryWrapper<OcrIdentifyDetail>().eq(OcrIdentifyDetail::getIdentifyId, id));
ocrIdentify.setImgNum((long)identifyDetailList.size()); ocrIdentify.setImgNum((long) identifyDetailList.size());
if (StringUtils.isNotBlank(ocrIdentify.getTaskResultInfo())) { if (StringUtils.isNotBlank(ocrIdentify.getTaskResultInfo())) {
List<OcrResultDTO> ocrResultDTOList = JSONObject.parseArray(ocrIdentify.getTaskResultInfo()).toJavaList(OcrResultDTO.class); List<OcrResultDTO> ocrResultDTOList = JSONObject.parseArray(ocrIdentify.getTaskResultInfo()).toJavaList(OcrResultDTO.class);
int tagNum = ocrResultDTOList.size(); int tagNum = ocrResultDTOList.size();
int successNum = (int) ocrResultDTOList.stream().filter(o -> o.getRuleValidation()).count(); int successNum = (int) ocrResultDTOList.stream().filter(o -> o.getRuleValidation()).count();
ocrIdentify.setTagNum(tagNum); ocrIdentify.setTagNum(tagNum);
ocrIdentify.setTagSuccessNum(successNum); ocrIdentify.setTagSuccessNum(successNum);
ocrIdentify.setSuccessRate(successNum+"/"+tagNum); ocrIdentify.setSuccessRate(successNum + "/" + tagNum);
ocrIdentify.setTaskResultInfoList(ocrResultDTOList); ocrIdentify.setTaskResultInfoList(ocrResultDTOList);
} }
OcrRuleCheckDTO ocrRuleCheckVo = ocrRuleCheckMap.get(ocrIdentify.getRuleCheck()); OcrRuleCheckDTO ocrRuleCheckVo = ocrRuleCheckMap.get(ocrIdentify.getRuleCheck());
if (ocrRuleCheckVo!=null && StringUtils.isNotBlank(ocrRuleCheckVo.getMetadataConfigId())) { if (ocrRuleCheckVo != null && StringUtils.isNotBlank(ocrRuleCheckVo.getMetadataConfigId())) {
ocrIdentify.setOcrRuleCheckInfoConfigRule(ocrRuleCheckVo.getConfigRule()); ocrIdentify.setOcrRuleCheckInfoConfigRule(ocrRuleCheckVo.getConfigRule());
ocrIdentify.setRuleCheck_dictText(ocrRuleCheckVo.getConfigName()); ocrIdentify.setRuleCheck_dictText(ocrRuleCheckVo.getConfigName());
ocrIdentify.setMetadataConfigId(ocrRuleCheckVo.getMetadataConfigId()); ocrIdentify.setMetadataConfigId(ocrRuleCheckVo.getMetadataConfigId());
ocrIdentify.setMetadataConfigId_dictText(ocrRuleCheckVo.getMetadataConfigName()); ocrIdentify.setMetadataConfigId_dictText(ocrRuleCheckVo.getMetadataConfigName());
OcrMetadataConfigDTO ocrMetadataConfigDTO = metadataConfigMap.get(ocrRuleCheckVo.getMetadataConfigId()); OcrMetadataConfigDTO ocrMetadataConfigDTO = metadataConfigMap.get(ocrRuleCheckVo.getMetadataConfigId());
if (ocrMetadataConfigDTO !=null) { if (ocrMetadataConfigDTO != null) {
ocrIdentify.setTaskType(ocrMetadataConfigDTO.getTaskType()); ocrIdentify.setTaskType(ocrMetadataConfigDTO.getTaskType());
ocrIdentify.setTaskType_dictText(taskNameMap.get(ocrMetadataConfigDTO.getTaskType())); ocrIdentify.setTaskType_dictText(taskNameMap.get(ocrMetadataConfigDTO.getTaskType()));
} }
@ -327,17 +335,17 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
//update-begin-author:taoyan date:20190528 for:批量插入数据 //update-begin-author:taoyan date:20190528 for:批量插入数据
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
//service.saveBatch(list); //service.saveBatch(list);
List<OcrIdentify> ocrIdentifyList=new ArrayList<>(); List<OcrIdentify> ocrIdentifyList = new ArrayList<>();
for (OcrIdentifyExcel ocrIdentifyExcel : list) { for (OcrIdentifyExcel ocrIdentifyExcel : list) {
OcrIdentify ocrIdentify=new OcrIdentify(); OcrIdentify ocrIdentify = new OcrIdentify();
BeanUtils.copyProperties(ocrIdentifyExcel,ocrIdentify); BeanUtils.copyProperties(ocrIdentifyExcel, ocrIdentify);
//通过规则检查配置名称 反查 规则检查配置id //通过规则检查配置名称 反查 规则检查配置id
if (StringUtils.isNotBlank(ocrIdentifyExcel.getRuleCheck())) { if (StringUtils.isNotBlank(ocrIdentifyExcel.getRuleCheck())) {
LambdaQueryWrapper<OcrRuleCheck> queryWrapper = new LambdaQueryWrapper<OcrRuleCheck>().eq(OcrRuleCheck::getConfigName, ocrIdentifyExcel.getRuleCheck()); LambdaQueryWrapper<OcrRuleCheck> queryWrapper = new LambdaQueryWrapper<OcrRuleCheck>().eq(OcrRuleCheck::getConfigName, ocrIdentifyExcel.getRuleCheck());
List<OcrRuleCheck> ruleChecklist = ocrRuleCheckService.list(queryWrapper); List<OcrRuleCheck> ruleChecklist = ocrRuleCheckService.list(queryWrapper);
if (ruleChecklist!=null&&ruleChecklist.size()>0) { if (ruleChecklist != null && ruleChecklist.size() > 0) {
ocrIdentify.setRuleCheck(ruleChecklist.get(0).getId()); ocrIdentify.setRuleCheck(ruleChecklist.get(0).getId());
} }
} }
@ -352,16 +360,16 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
String[] s2 = s.split("="); String[] s2 = s.split("=");
String tag = s2[0]; String tag = s2[0];
String inputText = s2[1]; String inputText = s2[1];
JSONObject jsonObject=new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("tag",tag); jsonObject.put("tag", tag);
jsonObject.put("inputText",inputText); jsonObject.put("inputText", inputText);
sourceJson.add(jsonObject); sourceJson.add(jsonObject);
} }
if (StringUtils.isNotBlank(ocrIdentify.getPriority())) { if (StringUtils.isNotBlank(ocrIdentify.getPriority())) {
if ("加急".equals(ocrIdentify.getPriority())) { if ("加急".equals(ocrIdentify.getPriority())) {
//优先 //优先
ocrIdentify.setPriority("1"); ocrIdentify.setPriority("1");
}else{ } else {
ocrIdentify.setPriority("0"); ocrIdentify.setPriority("0");
} }
} }
@ -385,9 +393,9 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
//update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示 //update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示
String msg = e.getMessage(); String msg = e.getMessage();
log.error(msg, e); log.error(msg, e);
if(msg!=null && msg.indexOf("Duplicate entry")>=0){ if (msg != null && msg.indexOf("Duplicate entry") >= 0) {
return Result.error("文件导入失败:有重复数据!"); return Result.error("文件导入失败:有重复数据!");
}else{ } else {
return Result.error("文件导入失败:" + e.getMessage()); return Result.error("文件导入失败:" + e.getMessage());
} }
//update-end-author:taoyan date:20211124 for: 导入数据重复增加提示 //update-end-author:taoyan date:20211124 for: 导入数据重复增加提示
@ -417,37 +425,37 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
@ApiOperation(value = "重新执行") @ApiOperation(value = "重新执行")
@PostMapping(value = "/restartTask") @PostMapping(value = "/restartTask")
public Result<?> restartTask(@RequestBody OcrIdentify ocrIdentify){ public Result<?> restartTask(@RequestBody OcrIdentify ocrIdentify) {
AssertUtils.notEmpty(ocrIdentify.getId(), "[id]不可为空"); AssertUtils.notEmpty(ocrIdentify.getId(), "[id]不可为空");
OcrIdentify identify = ocrIdentifyService.getById(ocrIdentify.getId()); OcrIdentify identify = ocrIdentifyService.getById(ocrIdentify.getId());
if (!Arrays.asList("1","9").contains(identify.getStatus())) { if (!Arrays.asList("1", "9").contains(identify.getStatus())) {
return Result.error("当前任务不可重新执行"); return Result.error("当前任务不可重新执行");
} }
//更新状态 //更新状态
OcrIdentify newOcrIdentify = new OcrIdentify(); OcrIdentify newOcrIdentify = new OcrIdentify();
BeanUtils.copyProperties(identify,newOcrIdentify); BeanUtils.copyProperties(identify, newOcrIdentify);
newOcrIdentify.setStatus("0"); newOcrIdentify.setStatus("0");
newOcrIdentify.setId(null); newOcrIdentify.setId(null);
ocrIdentifyService.save(newOcrIdentify); ocrIdentifyService.save(newOcrIdentify);
//TODO 重新执行操作 //TODO 重新执行操作
List<String> identifyUrlList = FileOUtils.fileLists(null, newOcrIdentify.getIdentifyUrl()); List<String> identifyUrlList = FileOUtils.fileLists(null, newOcrIdentify.getIdentifyUrl());
//List<String> identifyUrlList = Arrays.asList("1","2"); //List<String> identifyUrlList = Arrays.asList("1","2");
taskService.postSemantic(newOcrIdentify,identifyUrlList); taskService.postSemantic(newOcrIdentify, identifyUrlList);
return Result.OK("操作成功"); return Result.OK("操作成功");
} }
@ApiOperation(value = "上报通知给无量云") @ApiOperation(value = "上报通知给无量云")
@PostMapping(value = "/pushNotice") @PostMapping(value = "/pushNotice")
public Result<?> pushNotice(@RequestBody OcrIdentify ocrIdentify){ public Result<?> pushNotice(@RequestBody OcrIdentify ocrIdentify) {
String id = ocrIdentify.getId(); String id = ocrIdentify.getId();
List<OcrIdentify> ocrIdentifyList = ocrIdentifyService.listByIds(Arrays.asList(id.split(","))); List<OcrIdentify> ocrIdentifyList = ocrIdentifyService.listByIds(Arrays.asList(id.split(",")));
if (ocrIdentifyList==null|| ocrIdentifyList.size()==0) { if (ocrIdentifyList == null || ocrIdentifyList.size() == 0) {
return Result.error("未获取到任务"); return Result.error("未获取到任务");
} }
for (OcrIdentify entity : ocrIdentifyList) { for (OcrIdentify entity : ocrIdentifyList) {
AssertUtils.isTrue("1".equals(entity.getStatus()),String.format("[任务名称]-%s 当前正在识别中,不可进行上报",entity.getTaskName())); AssertUtils.isTrue("1".equals(entity.getStatus()), String.format("[任务名称]-%s 当前正在识别中,不可进行上报", entity.getTaskName()));
AssertUtils.isTrue(entity.getNoticeStatus().equals("0"),String.format("[任务名称]-%s 当前已上报,不可再次进行上报",entity.getTaskName())); AssertUtils.isTrue(entity.getNoticeStatus().equals("0"), String.format("[任务名称]-%s 当前已上报,不可再次进行上报", entity.getTaskName()));
} }
for (String identifyId : Arrays.asList(id.split(","))) { for (String identifyId : Arrays.asList(id.split(","))) {
ocrIdentifyService.callbackWlyAsync(identifyId); ocrIdentifyService.callbackWlyAsync(identifyId);

@ -43,6 +43,8 @@ public class OcrSimulatorController{
private IOcrIdentifyService ocrIdentifyService; private IOcrIdentifyService ocrIdentifyService;
@Resource @Resource
private IOcrIdentifyDetailService ocrIdentifyDetailService; private IOcrIdentifyDetailService ocrIdentifyDetailService;
@Value("${spring.profiles.active}")
private String profiles;
@Value("${jeecg.path.upload}") @Value("${jeecg.path.upload}")
private String uploadFilePath; private String uploadFilePath;
@ -51,6 +53,9 @@ public class OcrSimulatorController{
@ApiOperation(value = "场景识别") @ApiOperation(value = "场景识别")
@PostMapping(value = "/identify") @PostMapping(value = "/identify")
public Result<?> identify(@RequestBody JSONObject requestBody) { public Result<?> identify(@RequestBody JSONObject requestBody) {
if (!"test".equals(profiles)) {
return Result.error("当前环境不支持该功能,请访问测试环境");
}
JSONObject responseBody = new JSONObject(); JSONObject responseBody = new JSONObject();
JSONArray images = requestBody.getJSONArray("images"); JSONArray images = requestBody.getJSONArray("images");
AssertUtils.hasSize(images,"请先上传图片"); AssertUtils.hasSize(images,"请先上传图片");

Loading…
Cancel
Save