From 45e54beae2898c75f41ac4ccb8d20771b9e5108a Mon Sep 17 00:00:00 2001 From: jianjun Date: Tue, 9 Jun 2020 09:19:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E7=89=87=E6=A3=80=E6=B5=8B=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E8=B0=83=E6=95=B4-=E6=B7=BB=E5=8A=A0=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scan/common/constant/SysConstant.java | 3 + .../scan/common/util/HttpClientManager.java | 6 +- .../scan/common/util/IAcsClientUtil.java | 1 - .../scan/controller/ScanController.java | 2 +- .../scan/service/impl/ScanServiceImpl.java | 56 +++++++++---------- .../scan/support/result/ImgAcsReponse.java | 18 ------ .../scan/support/result/ScanTaskResult.java | 6 +- ...ScanResult.java => SceneDetailResult.java} | 4 +- .../scan/support/result/SyncScanResult.java | 9 ++- .../scan/support/result/TextScanResult.java | 41 -------------- 10 files changed, 48 insertions(+), 98 deletions(-) delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ImgAcsReponse.java rename epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/{BaseScanResult.java => SceneDetailResult.java} (84%) delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/TextScanResult.java diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/constant/SysConstant.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/constant/SysConstant.java index 53eaad58d0..a23795e538 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/constant/SysConstant.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/constant/SysConstant.java @@ -12,4 +12,7 @@ public class SysConstant { public static final Integer MAX_TEXT_TASKS = 100; public static final Integer MAX_IMG_TASKS = 10; + + public static final String CODE = "code"; + public static final String DATA = "data"; } diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/HttpClientManager.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/HttpClientManager.java index 978ca23004..7ca0302331 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/HttpClientManager.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/HttpClientManager.java @@ -58,7 +58,7 @@ public class HttpClientManager { /** * desc: 发送json post 请求 * param: url,jsonStrParam - * return: CallResult + * return: Result * date: 2019/2/21 9:12 * * @author: jianjun liu @@ -89,7 +89,7 @@ public class HttpClientManager { /** * desc: 发送json post 请求 * param: url,jsonStrParam - * return: CallResult + * return: Result * date: 2019/2/21 9:12 * * @author: jianjun liu @@ -116,7 +116,7 @@ public class HttpClientManager { /** * desc: 发送get请求 * param:url, params - * return: CallResult + * return: Result * date: 2019/2/21 9:16 * * @author: jianjun liu diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/IAcsClientUtil.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/IAcsClientUtil.java index d9e815348c..c0c8362727 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/IAcsClientUtil.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/IAcsClientUtil.java @@ -2,7 +2,6 @@ package com.epmet.openapi.scan.common.util; /** * @author jianjun liu - * @email liujianjun@yunzongnet.com * @date 2020-06-05 10:03 **/ diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java index e98076abd9..96848bfc84 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java @@ -48,7 +48,7 @@ public class ScanController { return scanResultResult; } - @RequestMapping("imgAsyncScan") + //@RequestMapping("imgAsyncScan") public Result ImgAsyncScan(@RequestBody ImgScanParam param) { Result scanResultResult = scanService.sendASyncImgScan(param); return scanResultResult; 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 d125084273..f69824ca14 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 @@ -23,11 +23,12 @@ import com.epmet.openapi.scan.support.param.ImgScanParam; import com.epmet.openapi.scan.support.param.ImgTask; import com.epmet.openapi.scan.support.param.TextScanParam; import com.epmet.openapi.scan.support.param.TextTask; -import com.epmet.openapi.scan.support.result.BaseScanResult; +import com.epmet.openapi.scan.support.result.SceneDetailResult; import com.epmet.openapi.scan.support.result.ImgAsyncScanResult; import com.epmet.openapi.scan.support.result.ScanTaskResult; import com.epmet.openapi.scan.support.result.SyncScanResult; import lombok.extern.slf4j.Slf4j; +import org.apache.http.HttpStatus; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; @@ -176,17 +177,18 @@ 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 (200 == scrResponse.getInteger("code")) { + //System.out.println(JSON.toJSONString(scrResponse, true)); + if (HttpStatus.SC_OK == scrResponse.getInteger(SysConstant.CODE)) { //任务 列表 - List scanTaskResults = scrResponse.getJSONArray("data").toJavaList(ScanTaskResult.class); + List scanTaskResults = scrResponse.getJSONArray(SysConstant.DATA).toJavaList(ScanTaskResult.class); for (ScanTaskResult taskResult : scanTaskResults) { + result.getDetails().add(taskResult); //又根据场景不同 - if (200 == taskResult.getCode()) { + if (HttpStatus.SC_OK == taskResult.getCode()) { //如果是多个场景 则为对个 BaseScanResult - List sceneResults = taskResult.getResults(); + List sceneResults = taskResult.getResults(); //是文本检测 目前就一种场景 - for (BaseScanResult sceneResult : sceneResults) { + for (SceneDetailResult sceneResult : sceneResults) { String suggestion = sceneResult.getSuggestion(); if (SuggestionEnum.BLOCK.getCode().equals(suggestion)) { result.getFailDataIds().add(taskResult.getDataId()); @@ -202,7 +204,7 @@ public class ScanServiceImpl implements ScanService { } return result; } else { - throw new ExeCuteHttpException("executeSyncText detect not success. code:" + scrResponse.getInteger("code")); + throw new ExeCuteHttpException("executeSyncText detect not success. code:" + scrResponse.getInteger(SysConstant.CODE)); } } else { log.warn("executeSyncText response not success. status:" + httpResponse.getStatus()); @@ -227,28 +229,26 @@ public class ScanServiceImpl implements ScanService { try { HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(request); if (httpResponse.isSuccess()) { - JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8")); - System.out.println(JSON.toJSONString(scrResponse, true)); - if (200 == scrResponse.getInteger("code")) { - JSONArray taskResults = scrResponse.getJSONArray("data"); + 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 (200 == ((JSONObject) taskResult).getInteger("code")) { + if (HttpStatus.SC_OK == ((JSONObject) taskResult).getInteger(SysConstant.CODE)) { String taskId = ((JSONObject) taskResult).getString("taskId"); // 将taskId 保存下来,间隔一段时间来轮询结果, 参照ImageAsyncScanResultsRequest - System.out.println("args = [" + taskId + "]"); result.getSuccessTaskIds().add(taskId); } else { - //TODO 细化失败结果 属性 code等 String taskId = ((JSONObject) taskResult).getString("taskId"); result.getFailTaskIds().add(taskId); - log.warn("task process fail:{}", ((JSONObject) taskResult).getInteger("code")); - throw new ExeCuteHttpException("task process fail:" + ((JSONObject) taskResult).getInteger("code")); + log.warn("task process fail:{}", ((JSONObject) taskResult).getInteger(SysConstant.CODE)); + continue; } } return result; } else { - System.out.println("detect not success. code:" + scrResponse.getInteger("code")); - throw new ExeCuteHttpException("detect not success. code:" + scrResponse.getInteger("code")); + 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()); @@ -269,22 +269,22 @@ public class ScanServiceImpl implements ScanService { try { HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(request); if (httpResponse.isSuccess()) { - JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8")); - System.out.println(JSON.toJSONString(scrResponse, true)); - if (200 == scrResponse.getInteger("code")) { - JSONArray taskResults = scrResponse.getJSONArray("data"); + JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), SysConstant.UTF8)); + if (HttpStatus.SC_OK == scrResponse.getInteger(SysConstant.CODE)) { + JSONArray taskResults = scrResponse.getJSONArray(SysConstant.DATA); List scanTaskResults = taskResults.toJavaList(ScanTaskResult.class); for (ScanTaskResult taskResult : scanTaskResults) { - if(200 != taskResult.getCode()){ + result.getDetails().add(taskResult); + if (HttpStatus.SC_OK != taskResult.getCode()) { if (!result.getFailDataIds().contains(taskResult.getDataId())) { result.getFailDataIds().add(taskResult.getDataId()); } continue; } //如果是多个场景 则为对个 BaseScanResult - List sceneResults = taskResult.getResults(); + List sceneResults = taskResult.getResults(); //是文本检测 目前就一种场景 - for (BaseScanResult sceneResult : sceneResults) { + for (SceneDetailResult sceneResult : sceneResults) { String suggestion = sceneResult.getSuggestion(); if (SuggestionEnum.BLOCK.getCode().equals(suggestion)) { if (result.getFailDataIds().contains(taskResult.getDataId())) { @@ -301,8 +301,8 @@ public class ScanServiceImpl implements ScanService { } return result; } else { - log.warn("executeSyncImg detect not success. code:", scrResponse.getInteger("code")); - throw new ExeCuteHttpException("detect not success. code:" + scrResponse.getInteger("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()); diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ImgAcsReponse.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ImgAcsReponse.java deleted file mode 100644 index b3a2f65ef1..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ImgAcsReponse.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.epmet.openapi.scan.support.result; - -import com.aliyuncs.AcsResponse; -import com.aliyuncs.exceptions.ClientException; -import com.aliyuncs.exceptions.ServerException; -import com.aliyuncs.transform.UnmarshallerContext; - -/** - * @author jianjun liu - * @email liujianjun@yunzongnet.com - * @date 2020-06-05 10:24 - **/ -public class ImgAcsReponse extends AcsResponse { - @Override - public AcsResponse getInstance(UnmarshallerContext context) throws ClientException, ServerException { - return null; - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ScanTaskResult.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ScanTaskResult.java index 6ff3c512ea..d358a570fa 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ScanTaskResult.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ScanTaskResult.java @@ -2,6 +2,7 @@ package com.epmet.openapi.scan.support.result; import lombok.Data; +import java.io.Serializable; import java.util.List; /** @@ -11,8 +12,9 @@ import java.util.List; * @date 2020-06-05 14:24 **/ @Data -public class ScanTaskResult { +public class ScanTaskResult implements Serializable { + private static final long serialVersionUID = -7905091710384256911L; private Integer code; @@ -22,5 +24,5 @@ public class ScanTaskResult { private String dataId; - private List results; + private List results; } diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/BaseScanResult.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SceneDetailResult.java similarity index 84% rename from epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/BaseScanResult.java rename to epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SceneDetailResult.java index 76226d75d3..4023153d10 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/BaseScanResult.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SceneDetailResult.java @@ -3,12 +3,12 @@ package com.epmet.openapi.scan.support.result; import lombok.Data; /** + * desc:场景扫描结果 * @author jianjun liu - * @email liujianjun@yunzongnet.com * @date 2020-06-05 14:24 **/ @Data -public class BaseScanResult { +public class SceneDetailResult { /** * 结果为该分类的概率 */ diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SyncScanResult.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SyncScanResult.java index 59b2a04f94..c50589d7ce 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SyncScanResult.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SyncScanResult.java @@ -2,6 +2,7 @@ package com.epmet.openapi.scan.support.result; import lombok.Data; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -9,11 +10,10 @@ import java.util.List; * 检测结果 * * @author jianjun liu - * @email liujianjun@yunzongnet.com * @date 2020-06-05 10:52 **/ @Data -public class SyncScanResult { +public class SyncScanResult implements Serializable { /** * 执行成功的任务Id集合 */ @@ -23,6 +23,11 @@ public class SyncScanResult { */ private List failDataIds = new ArrayList<>(); + /** + * desc:检测详情 + */ + private List details = new ArrayList<>(); + /** * 本地是否全部通过 */ diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/TextScanResult.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/TextScanResult.java deleted file mode 100644 index c24f2bed6e..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/TextScanResult.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.epmet.openapi.scan.support.result; - -import lombok.Data; - -import java.util.ArrayList; -import java.util.List; - -/** - * 检测结果 - * - * @author jianjun liu - * @email liujianjun@yunzongnet.com - * @date 2020-06-05 10:52 - **/ -@Data -public class TextScanResult { - /** - * 执行成功的任务Id集合 - */ - private List successDataIds = new ArrayList<>(); - /** - * 执行失败的任务Id集合 - */ - private List failDataIds = new ArrayList<>(); - - /** - * 本地是否全部通过 - */ - private boolean isAllPass; - - public boolean isAllPass() { - if (failDataIds.isEmpty() && !successDataIds.isEmpty()) { - return true; - } - return isAllPass; - } - - public void setAllPass(boolean allPass) { - isAllPass = allPass; - } -}