diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/ApiController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/ApiController.java index 3dcef1a..837005b 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/ApiController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/ApiController.java @@ -21,6 +21,7 @@ import org.jeecg.modules.ocr.utils.ImageUtils; import org.jeecg.modules.ocr.dto.OcrIdentifyDTO; import org.jeecg.modules.ocr.dto.OcrRuleCheckDTO; 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.EnableAsync; import org.springframework.transaction.annotation.Transactional; @@ -54,12 +55,16 @@ public class ApiController { private RedisUtil redisUtil; @Resource private TaskService taskService; - ////===================================================================伪接口 + @Value("${spring.profiles.active}") + private String profiles; @ApiOperation(value = "通用识别") @RequestMapping("/identify") @Transactional @ResponseBody public Result pushSemantic(@RequestBody JSONObject requestBody) throws InterruptedException { + if (!"test".equals(profiles)) { + return Result.error("当前环境不支持该功能,请访问测试环境"); + } if (requestBody == null) { return Result.error("请输入请求参数"); } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/controller/OcrIdentifyController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/controller/OcrIdentifyController.java index 2ed548a..00153c9 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/controller/OcrIdentifyController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/controller/OcrIdentifyController.java @@ -5,6 +5,7 @@ import java.util.*; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; 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.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; @@ -70,6 +72,9 @@ public class OcrIdentifyController extends JeecgController> queryPageList(OcrIdentify ocrIdentify, - @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, - @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, - HttpServletRequest req) { + @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, + HttpServletRequest req) { if (StringUtils.isNotBlank(ocrIdentify.getTaskName())) { - ocrIdentify.setTaskName("*"+ocrIdentify.getTaskName()+"*"); + ocrIdentify.setTaskName("*" + ocrIdentify.getTaskName() + "*"); } if (StringUtils.isNotBlank(ocrIdentify.getIdentifyUrl())) { - ocrIdentify.setIdentifyUrl("*"+ocrIdentify.getIdentifyUrl()+"*"); + ocrIdentify.setIdentifyUrl("*" + ocrIdentify.getIdentifyUrl() + "*"); } if (StringUtils.isNotBlank(ocrIdentify.getCreateBy())) { - ocrIdentify.setCreateBy("*"+ocrIdentify.getCreateBy()+"*"); + ocrIdentify.setCreateBy("*" + ocrIdentify.getCreateBy() + "*"); } - Date startTime=ocrIdentify.getStartTime(); - Date endTime=ocrIdentify.getEndTime(); - if (startTime!=null&&endTime!=null) { + Date startTime = ocrIdentify.getStartTime(); + Date endTime = ocrIdentify.getEndTime(); + if (startTime != null && endTime != null) { ocrIdentify.setStartTime(null); ocrIdentify.setEndTime(null); } QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(ocrIdentify, req.getParameterMap()); - queryWrapper.ne("task_source","模拟实验");//排除模拟实验的数据 - if (startTime!=null&&endTime!=null) { - endTime.setTime(endTime.getTime()+86400000l); - queryWrapper.between("end_time",startTime,endTime); + queryWrapper.ne("task_source", "模拟实验");//排除模拟实验的数据 + if (startTime != null && endTime != null) { + endTime.setTime(endTime.getTime() + 86400000l); + queryWrapper.between("end_time", startTime, endTime); } Page page = new Page<>(pageNo, pageSize); Map ocrRuleCheckMap = ocrRuleCheckService.listToMap(null); Map metadataConfigMap = ocrMetadataConfigService.listToMap(null); Map taskNameMap = ocrTaskTypeService.listNameToMap(null); IPage 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 identifyIdList = pageList.getRecords().stream().map(p -> p.getId()).collect(Collectors.toList()); - List identifyDetailList = ocrIdentifyDetailService.list(new LambdaQueryWrapper().in(OcrIdentifyDetail::getIdentifyId,identifyIdList)); + List identifyDetailList = ocrIdentifyDetailService.list(new LambdaQueryWrapper().in(OcrIdentifyDetail::getIdentifyId, identifyIdList)); for (OcrIdentify record : pageList.getRecords()) { long count = identifyDetailList.stream().filter(i -> i.getIdentifyId().equals(record.getId())).count(); record.setImgNum(count); @@ -124,15 +129,15 @@ public class OcrIdentifyController extends JeecgController o.getRuleValidation()).count(); record.setTagNum(tagNum); record.setTagSuccessNum(successNum); - record.setSuccessRate(successNum+"/"+tagNum); + record.setSuccessRate(successNum + "/" + tagNum); record.setTaskResultInfoList(ocrResultDTOS); } 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.setMetadataConfigId(ocrRuleCheckVo.getMetadataConfigId()); OcrMetadataConfigDTO ocrMetadataConfigDTO = metadataConfigMap.get(ocrRuleCheckVo.getMetadataConfigId()); - if (ocrMetadataConfigDTO !=null) { + if (ocrMetadataConfigDTO != null) { record.setTaskType(ocrMetadataConfigDTO.getTaskType()); record.setTaskType_dictText(taskNameMap.get(ocrMetadataConfigDTO.getTaskType())); } @@ -153,6 +158,9 @@ public class OcrIdentifyController extends JeecgController add(@RequestBody OcrIdentify ocrIdentify) { + if (!"test".equals(profiles)) { + return Result.error("当前环境不支持该功能,请访问测试环境"); + } AssertUtils.notEmpty(ocrIdentify.getTaskName(), "[任务名称]-不可为空"); AssertUtils.notEmpty(ocrIdentify.getIdentifyUrl(), "[识别路径]不可为空"); AssertUtils.notEmpty(ocrIdentify.getRuleCheck(), "请选择[规则检查配置]"); @@ -162,15 +170,15 @@ public class OcrIdentifyController extends JeecgController ocr_relative_path = sysDictService.queryDictItemsByCode("ocr_relative_path"); - String relativePath=null; - if (ocr_relative_path!=null && ocr_relative_path.size()>0) { + String relativePath = null; + if (ocr_relative_path != null && ocr_relative_path.size() > 0) { for (DictModel dictModel : ocr_relative_path) { if (dictModel.getValue().equals("0")) { - relativePath= dictModel.getText(); + relativePath = dictModel.getText(); } } } - List fileUrlList = FileOUtils.fileLists(relativePath,ocrIdentify.getIdentifyUrl()); + List fileUrlList = FileOUtils.fileLists(relativePath, ocrIdentify.getIdentifyUrl()); AssertUtils.notNull(fileUrlList, "图片地址不存在"); for (String fileUrl : fileUrlList) { //判断附件是否是 图片格式 @@ -183,7 +191,7 @@ public class OcrIdentifyController extends JeecgController ocrRuleCheckMap = ocrRuleCheckService.listToMap(null); Map metadataConfigMap = ocrMetadataConfigService.listToMap(null); Map taskNameMap = ocrTaskTypeService.listNameToMap(null); - List identifyDetailList = ocrIdentifyDetailService.list(new LambdaQueryWrapper().eq(OcrIdentifyDetail::getIdentifyId,id)); - ocrIdentify.setImgNum((long)identifyDetailList.size()); + List identifyDetailList = ocrIdentifyDetailService.list(new LambdaQueryWrapper().eq(OcrIdentifyDetail::getIdentifyId, id)); + ocrIdentify.setImgNum((long) identifyDetailList.size()); if (StringUtils.isNotBlank(ocrIdentify.getTaskResultInfo())) { List ocrResultDTOList = JSONObject.parseArray(ocrIdentify.getTaskResultInfo()).toJavaList(OcrResultDTO.class); int tagNum = ocrResultDTOList.size(); int successNum = (int) ocrResultDTOList.stream().filter(o -> o.getRuleValidation()).count(); ocrIdentify.setTagNum(tagNum); ocrIdentify.setTagSuccessNum(successNum); - ocrIdentify.setSuccessRate(successNum+"/"+tagNum); + ocrIdentify.setSuccessRate(successNum + "/" + tagNum); ocrIdentify.setTaskResultInfoList(ocrResultDTOList); } 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.setRuleCheck_dictText(ocrRuleCheckVo.getConfigName()); ocrIdentify.setMetadataConfigId(ocrRuleCheckVo.getMetadataConfigId()); ocrIdentify.setMetadataConfigId_dictText(ocrRuleCheckVo.getMetadataConfigName()); OcrMetadataConfigDTO ocrMetadataConfigDTO = metadataConfigMap.get(ocrRuleCheckVo.getMetadataConfigId()); - if (ocrMetadataConfigDTO !=null) { + if (ocrMetadataConfigDTO != null) { ocrIdentify.setTaskType(ocrMetadataConfigDTO.getTaskType()); ocrIdentify.setTaskType_dictText(taskNameMap.get(ocrMetadataConfigDTO.getTaskType())); } @@ -327,17 +335,17 @@ public class OcrIdentifyController extends JeecgController ocrIdentifyList=new ArrayList<>(); + List ocrIdentifyList = new ArrayList<>(); for (OcrIdentifyExcel ocrIdentifyExcel : list) { - OcrIdentify ocrIdentify=new OcrIdentify(); - BeanUtils.copyProperties(ocrIdentifyExcel,ocrIdentify); + OcrIdentify ocrIdentify = new OcrIdentify(); + BeanUtils.copyProperties(ocrIdentifyExcel, ocrIdentify); //通过规则检查配置名称 反查 规则检查配置id if (StringUtils.isNotBlank(ocrIdentifyExcel.getRuleCheck())) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper().eq(OcrRuleCheck::getConfigName, ocrIdentifyExcel.getRuleCheck()); List ruleChecklist = ocrRuleCheckService.list(queryWrapper); - if (ruleChecklist!=null&&ruleChecklist.size()>0) { + if (ruleChecklist != null && ruleChecklist.size() > 0) { ocrIdentify.setRuleCheck(ruleChecklist.get(0).getId()); } } @@ -352,16 +360,16 @@ public class OcrIdentifyController extends JeecgController=0){ + if (msg != null && msg.indexOf("Duplicate entry") >= 0) { return Result.error("文件导入失败:有重复数据!"); - }else{ + } else { return Result.error("文件导入失败:" + e.getMessage()); } //update-end-author:taoyan date:20211124 for: 导入数据重复增加提示 @@ -417,37 +425,37 @@ public class OcrIdentifyController extends JeecgController restartTask(@RequestBody OcrIdentify ocrIdentify){ + public Result restartTask(@RequestBody OcrIdentify ocrIdentify) { AssertUtils.notEmpty(ocrIdentify.getId(), "[id]不可为空"); 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("当前任务不可重新执行"); } //更新状态 OcrIdentify newOcrIdentify = new OcrIdentify(); - BeanUtils.copyProperties(identify,newOcrIdentify); + BeanUtils.copyProperties(identify, newOcrIdentify); newOcrIdentify.setStatus("0"); newOcrIdentify.setId(null); ocrIdentifyService.save(newOcrIdentify); //TODO 重新执行操作 List identifyUrlList = FileOUtils.fileLists(null, newOcrIdentify.getIdentifyUrl()); //List identifyUrlList = Arrays.asList("1","2"); - taskService.postSemantic(newOcrIdentify,identifyUrlList); + taskService.postSemantic(newOcrIdentify, identifyUrlList); return Result.OK("操作成功"); } @ApiOperation(value = "上报通知给无量云") @PostMapping(value = "/pushNotice") - public Result pushNotice(@RequestBody OcrIdentify ocrIdentify){ + public Result pushNotice(@RequestBody OcrIdentify ocrIdentify) { String id = ocrIdentify.getId(); List ocrIdentifyList = ocrIdentifyService.listByIds(Arrays.asList(id.split(","))); - if (ocrIdentifyList==null|| ocrIdentifyList.size()==0) { + if (ocrIdentifyList == null || ocrIdentifyList.size() == 0) { return Result.error("未获取到任务"); } for (OcrIdentify entity : ocrIdentifyList) { - AssertUtils.isTrue("1".equals(entity.getStatus()),String.format("[任务名称]-%s 当前正在识别中,不可进行上报",entity.getTaskName())); - AssertUtils.isTrue(entity.getNoticeStatus().equals("0"),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())); } for (String identifyId : Arrays.asList(id.split(","))) { ocrIdentifyService.callbackWlyAsync(identifyId); diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/controller/OcrSimulatorController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/controller/OcrSimulatorController.java index 99edf47..7781441 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/controller/OcrSimulatorController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/controller/OcrSimulatorController.java @@ -43,6 +43,8 @@ public class OcrSimulatorController{ private IOcrIdentifyService ocrIdentifyService; @Resource private IOcrIdentifyDetailService ocrIdentifyDetailService; + @Value("${spring.profiles.active}") + private String profiles; @Value("${jeecg.path.upload}") private String uploadFilePath; @@ -51,6 +53,9 @@ public class OcrSimulatorController{ @ApiOperation(value = "场景识别") @PostMapping(value = "/identify") public Result identify(@RequestBody JSONObject requestBody) { + if (!"test".equals(profiles)) { + return Result.error("当前环境不支持该功能,请访问测试环境"); + } JSONObject responseBody = new JSONObject(); JSONArray images = requestBody.getJSONArray("images"); AssertUtils.hasSize(images,"请先上传图片");