From 857c7ec592b94dcd1410522dc30840d0f7ec42c3 Mon Sep 17 00:00:00 2001 From: jianjun Date: Tue, 7 Jul 2020 10:55:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=A1=E6=A0=B8api?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scan/common/enu/SuggestionEnum.java | 4 +- .../scan/common/enu/SysResponseEnum.java | 1 - .../scan/service/impl/ScanServiceImpl.java | 104 +++++------------- 3 files changed, 31 insertions(+), 78 deletions(-) diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SuggestionEnum.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SuggestionEnum.java index 455b2975f4..3881508341 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SuggestionEnum.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SuggestionEnum.java @@ -4,14 +4,14 @@ import java.util.ArrayList; import java.util.List; /** - * desc:文本检测建议 + * desc:检测建议 * @author jianjun liu * @date 2020-06-04 21:39 **/ public enum SuggestionEnum { PASS("pass", "正常"), REVIEW("review", "需要人工审核"), - BLOCK("block", "文本违规"); + BLOCK("block", "内容违规"); private String code; private String desc; diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SysResponseEnum.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SysResponseEnum.java index 330cdb87e8..67ee3cc9d2 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SysResponseEnum.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SysResponseEnum.java @@ -2,7 +2,6 @@ package com.epmet.openapi.scan.common.enu; /** * @author jianjun liu - * @email liujianjun@yunzongnet.com * @date 2020-06-04 21:39 **/ public enum SysResponseEnum { diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java index 709fc7aef4..58fd107bc0 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java @@ -4,8 +4,6 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.aliyuncs.AcsRequest; -import com.aliyuncs.exceptions.ClientException; -import com.aliyuncs.exceptions.ServerException; import com.aliyuncs.green.model.v20180509.ImageAsyncScanRequest; import com.aliyuncs.green.model.v20180509.ImageSyncScanRequest; import com.aliyuncs.green.model.v20180509.TextScanRequest; @@ -162,7 +160,7 @@ public class ScanServiceImpl implements ScanService { imageAsyncScanRequest.setReadTimeout(6000); try { - ImgAsyncScanResult scanResult = executeAsyncImg(imageAsyncScanRequest); + ImgAsyncScanResult scanResult = null;//executeAsyncImg(imageAsyncScanRequest); return new Result().ok(scanResult); } catch (Exception e) { log.error("sendImgScan execute Exception", e); @@ -177,98 +175,52 @@ public class ScanServiceImpl implements ScanService { if (httpResponse.isSuccess()) { JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), SysConstant.UTF8)); - //System.out.println(JSON.toJSONString(scrResponse, true)); if (HttpStatus.SC_OK == scrResponse.getInteger(SysConstant.CODE)) { //任务 列表 List scanTaskResults = scrResponse.getJSONArray(SysConstant.DATA).toJavaList(ScanTaskResult.class); for (ScanTaskResult taskResult : scanTaskResults) { result.getDetails().add(taskResult); //又根据场景不同 - if (HttpStatus.SC_OK == taskResult.getCode()) { - //如果是多个场景 则为对个 BaseScanResult - List sceneResults = taskResult.getResults(); - //是文本检测 目前就一种场景 - boolean isSuccess = true; - for (SceneDetailResult sceneResult : sceneResults) { - String suggestion = sceneResult.getSuggestion(); - if (SuggestionEnum.PASS.getCode().equals(suggestion)) { - isSuccess = false; - break; - } - } - if (isSuccess){ + if (HttpStatus.SC_OK != taskResult.getCode()) { + if (!result.getFailDataIds().contains(taskResult.getDataId())) { result.getFailDataIds().add(taskResult.getDataId()); - } else { - result.getSuccessDataIds().add(taskResult.getDataId()); + log.warn("executeSyncText task process fail:code:{},result:{}", taskResult.getCode(), JSON.toJSONString(taskResult)); } + continue; + } + //如果是多个场景 则为对个 BaseScanResult + List sceneResults = taskResult.getResults(); + //是文本检测 目前就一种场景 + boolean isSuccess = true; + for (SceneDetailResult sceneResult : sceneResults) { + String suggestion = sceneResult.getSuggestion(); + if (SuggestionEnum.BLOCK.getCode().equals(suggestion)) { + isSuccess = false; + break; + } + } + if (isSuccess) { + result.getSuccessDataIds().add(taskResult.getDataId()); } else { + log.warn("executeSyncText dataId:{} block:{}", taskResult.getDataId(), JSON.toJSONString(taskResult.getResults())); result.getFailDataIds().add(taskResult.getDataId()); - log.warn("executeSyncText task process fail:code:{},msg:{}", taskResult.getCode(), taskResult.getMsg()); - throw new ExeCuteHttpException(" executeSyncTexttask process fail:code:" + taskResult.getCode() + ",msg:" + taskResult.getMsg()); } } return result; } else { + log.warn("executeSyncText response not success. code:{}", scrResponse.getInteger(SysConstant.CODE)); throw new ExeCuteHttpException("executeSyncText detect not success. code:" + scrResponse.getInteger(SysConstant.CODE)); } } else { - log.warn("executeSyncText response not success. status:" + httpResponse.getStatus()); + log.warn("executeSyncText response not success. status:{}", httpResponse.getStatus()); throw new ExeCuteHttpException("response not success. status:" + httpResponse.getStatus()); } - } catch (Exception e) { - log.warn("executeSyncImg exception", e); + log.warn("executeSyncText exception", e); throw new ExeCuteHttpException(SysResponseEnum.EXCEPTION.getCode(), SysResponseEnum.EXCEPTION.getMsg()); } } - - /** - * desc:异步 检查图片 TODO 结果处理 - * - * @param request - * @return - */ - private ImgAsyncScanResult executeAsyncImg(AcsRequest request) { - ImgAsyncScanResult result = new ImgAsyncScanResult(); - try { - HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(request); - if (httpResponse.isSuccess()) { - JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), SysConstant.UTF8)); - //System.out.println(JSON.toJSONString(scrResponse, true)); - if (HttpStatus.SC_OK == scrResponse.getInteger(SysConstant.CODE)) { - JSONArray taskResults = scrResponse.getJSONArray(SysConstant.DATA); - for (Object taskResult : taskResults) { - if (HttpStatus.SC_OK == ((JSONObject) taskResult).getInteger(SysConstant.CODE)) { - String taskId = ((JSONObject) taskResult).getString("taskId"); - // 将taskId 保存下来,间隔一段时间来轮询结果, 参照ImageAsyncScanResultsRequest - result.getSuccessTaskIds().add(taskId); - } else { - String taskId = ((JSONObject) taskResult).getString("taskId"); - result.getFailTaskIds().add(taskId); - log.warn("task process fail:{}", ((JSONObject) taskResult).getInteger(SysConstant.CODE)); - continue; - } - } - return result; - } else { - System.out.println("detect not success. code:" + scrResponse.getInteger(SysConstant.CODE)); - throw new ExeCuteHttpException("detect not success. code:" + scrResponse.getInteger(SysConstant.CODE)); - } - } else { - System.out.println("response not success. status:" + httpResponse.getStatus()); - throw new ExeCuteHttpException("response not success. status:" + httpResponse.getStatus()); - } - } catch (ServerException e) { - e.printStackTrace(); - } catch (ClientException e) { - e.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - return result; - } - private SyncScanResult executeSyncImg(AcsRequest request) { SyncScanResult result = new SyncScanResult(); try { @@ -283,6 +235,7 @@ public class ScanServiceImpl implements ScanService { if (HttpStatus.SC_OK != taskResult.getCode()) { if (!result.getFailDataIds().contains(taskResult.getDataId())) { result.getFailDataIds().add(taskResult.getDataId()); + log.warn("executeSyncImg detect not success. code:{},result:{}", taskResult.getCode(), JSON.toJSONString(taskResult)); } continue; } @@ -297,19 +250,20 @@ public class ScanServiceImpl implements ScanService { break; } } - if (isSuccess){ + if (isSuccess) { result.getSuccessDataIds().add(taskResult.getDataId()); - }else{ + } else { + log.warn("executeSyncImg dataId:{} block:{}", taskResult.getDataId(), JSON.toJSONString(taskResult.getResults())); result.getFailDataIds().add(taskResult.getDataId()); } } return result; } else { - log.warn("executeSyncImg detect not success. code:", scrResponse.getInteger(SysConstant.CODE)); + log.warn("executeSyncImg detect not success. code:{}", scrResponse.getInteger(SysConstant.CODE)); throw new ExeCuteHttpException("detect not success. code:" + scrResponse.getInteger(SysConstant.CODE)); } } else { - log.warn("executeSyncImg response not success. status:" + httpResponse.getStatus()); + log.warn("executeSyncImg response not success. status:{}", httpResponse.getStatus()); throw new ExeCuteHttpException("response not success. status:" + httpResponse.getStatus()); } } catch (Exception e) {