|
@ -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.ImgTask; |
|
|
import com.epmet.openapi.scan.support.param.TextScanParam; |
|
|
import com.epmet.openapi.scan.support.param.TextScanParam; |
|
|
import com.epmet.openapi.scan.support.param.TextTask; |
|
|
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.ImgAsyncScanResult; |
|
|
import com.epmet.openapi.scan.support.result.ScanTaskResult; |
|
|
import com.epmet.openapi.scan.support.result.ScanTaskResult; |
|
|
import com.epmet.openapi.scan.support.result.SyncScanResult; |
|
|
import com.epmet.openapi.scan.support.result.SyncScanResult; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.apache.http.HttpStatus; |
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
import org.springframework.util.CollectionUtils; |
|
@ -176,17 +177,18 @@ public class ScanServiceImpl implements ScanService { |
|
|
|
|
|
|
|
|
if (httpResponse.isSuccess()) { |
|
|
if (httpResponse.isSuccess()) { |
|
|
JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), SysConstant.UTF8)); |
|
|
JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), SysConstant.UTF8)); |
|
|
System.out.println(JSON.toJSONString(scrResponse, true)); |
|
|
//System.out.println(JSON.toJSONString(scrResponse, true));
|
|
|
if (200 == scrResponse.getInteger("code")) { |
|
|
if (HttpStatus.SC_OK == scrResponse.getInteger(SysConstant.CODE)) { |
|
|
//任务 列表
|
|
|
//任务 列表
|
|
|
List<ScanTaskResult> scanTaskResults = scrResponse.getJSONArray("data").toJavaList(ScanTaskResult.class); |
|
|
List<ScanTaskResult> scanTaskResults = scrResponse.getJSONArray(SysConstant.DATA).toJavaList(ScanTaskResult.class); |
|
|
for (ScanTaskResult taskResult : scanTaskResults) { |
|
|
for (ScanTaskResult taskResult : scanTaskResults) { |
|
|
|
|
|
result.getDetails().add(taskResult); |
|
|
//又根据场景不同
|
|
|
//又根据场景不同
|
|
|
if (200 == taskResult.getCode()) { |
|
|
if (HttpStatus.SC_OK == taskResult.getCode()) { |
|
|
//如果是多个场景 则为对个 BaseScanResult
|
|
|
//如果是多个场景 则为对个 BaseScanResult
|
|
|
List<BaseScanResult> sceneResults = taskResult.getResults(); |
|
|
List<SceneDetailResult> sceneResults = taskResult.getResults(); |
|
|
//是文本检测 目前就一种场景
|
|
|
//是文本检测 目前就一种场景
|
|
|
for (BaseScanResult sceneResult : sceneResults) { |
|
|
for (SceneDetailResult sceneResult : sceneResults) { |
|
|
String suggestion = sceneResult.getSuggestion(); |
|
|
String suggestion = sceneResult.getSuggestion(); |
|
|
if (SuggestionEnum.BLOCK.getCode().equals(suggestion)) { |
|
|
if (SuggestionEnum.BLOCK.getCode().equals(suggestion)) { |
|
|
result.getFailDataIds().add(taskResult.getDataId()); |
|
|
result.getFailDataIds().add(taskResult.getDataId()); |
|
@ -202,7 +204,7 @@ public class ScanServiceImpl implements ScanService { |
|
|
} |
|
|
} |
|
|
return result; |
|
|
return result; |
|
|
} else { |
|
|
} 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 { |
|
|
} else { |
|
|
log.warn("executeSyncText response not success. status:" + httpResponse.getStatus()); |
|
|
log.warn("executeSyncText response not success. status:" + httpResponse.getStatus()); |
|
@ -227,28 +229,26 @@ public class ScanServiceImpl implements ScanService { |
|
|
try { |
|
|
try { |
|
|
HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(request); |
|
|
HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(request); |
|
|
if (httpResponse.isSuccess()) { |
|
|
if (httpResponse.isSuccess()) { |
|
|
JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8")); |
|
|
JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), SysConstant.UTF8)); |
|
|
System.out.println(JSON.toJSONString(scrResponse, true)); |
|
|
//System.out.println(JSON.toJSONString(scrResponse, true));
|
|
|
if (200 == scrResponse.getInteger("code")) { |
|
|
if (HttpStatus.SC_OK == scrResponse.getInteger(SysConstant.CODE)) { |
|
|
JSONArray taskResults = scrResponse.getJSONArray("data"); |
|
|
JSONArray taskResults = scrResponse.getJSONArray(SysConstant.DATA); |
|
|
for (Object taskResult : taskResults) { |
|
|
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"); |
|
|
String taskId = ((JSONObject) taskResult).getString("taskId"); |
|
|
// 将taskId 保存下来,间隔一段时间来轮询结果, 参照ImageAsyncScanResultsRequest
|
|
|
// 将taskId 保存下来,间隔一段时间来轮询结果, 参照ImageAsyncScanResultsRequest
|
|
|
System.out.println("args = [" + taskId + "]"); |
|
|
|
|
|
result.getSuccessTaskIds().add(taskId); |
|
|
result.getSuccessTaskIds().add(taskId); |
|
|
} else { |
|
|
} else { |
|
|
//TODO 细化失败结果 属性 code等
|
|
|
|
|
|
String taskId = ((JSONObject) taskResult).getString("taskId"); |
|
|
String taskId = ((JSONObject) taskResult).getString("taskId"); |
|
|
result.getFailTaskIds().add(taskId); |
|
|
result.getFailTaskIds().add(taskId); |
|
|
log.warn("task process fail:{}", ((JSONObject) taskResult).getInteger("code")); |
|
|
log.warn("task process fail:{}", ((JSONObject) taskResult).getInteger(SysConstant.CODE)); |
|
|
throw new ExeCuteHttpException("task process fail:" + ((JSONObject) taskResult).getInteger("code")); |
|
|
continue; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return result; |
|
|
return result; |
|
|
} else { |
|
|
} else { |
|
|
System.out.println("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("code")); |
|
|
throw new ExeCuteHttpException("detect not success. code:" + scrResponse.getInteger(SysConstant.CODE)); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
System.out.println("response not success. status:" + httpResponse.getStatus()); |
|
|
System.out.println("response not success. status:" + httpResponse.getStatus()); |
|
@ -269,22 +269,22 @@ public class ScanServiceImpl implements ScanService { |
|
|
try { |
|
|
try { |
|
|
HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(request); |
|
|
HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(request); |
|
|
if (httpResponse.isSuccess()) { |
|
|
if (httpResponse.isSuccess()) { |
|
|
JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8")); |
|
|
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)) { |
|
|
if (200 == scrResponse.getInteger("code")) { |
|
|
JSONArray taskResults = scrResponse.getJSONArray(SysConstant.DATA); |
|
|
JSONArray taskResults = scrResponse.getJSONArray("data"); |
|
|
|
|
|
List<ScanTaskResult> scanTaskResults = taskResults.toJavaList(ScanTaskResult.class); |
|
|
List<ScanTaskResult> scanTaskResults = taskResults.toJavaList(ScanTaskResult.class); |
|
|
for (ScanTaskResult taskResult : scanTaskResults) { |
|
|
for (ScanTaskResult taskResult : scanTaskResults) { |
|
|
if(200 != taskResult.getCode()){ |
|
|
result.getDetails().add(taskResult); |
|
|
|
|
|
if (HttpStatus.SC_OK != taskResult.getCode()) { |
|
|
if (!result.getFailDataIds().contains(taskResult.getDataId())) { |
|
|
if (!result.getFailDataIds().contains(taskResult.getDataId())) { |
|
|
result.getFailDataIds().add(taskResult.getDataId()); |
|
|
result.getFailDataIds().add(taskResult.getDataId()); |
|
|
} |
|
|
} |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
//如果是多个场景 则为对个 BaseScanResult
|
|
|
//如果是多个场景 则为对个 BaseScanResult
|
|
|
List<BaseScanResult> sceneResults = taskResult.getResults(); |
|
|
List<SceneDetailResult> sceneResults = taskResult.getResults(); |
|
|
//是文本检测 目前就一种场景
|
|
|
//是文本检测 目前就一种场景
|
|
|
for (BaseScanResult sceneResult : sceneResults) { |
|
|
for (SceneDetailResult sceneResult : sceneResults) { |
|
|
String suggestion = sceneResult.getSuggestion(); |
|
|
String suggestion = sceneResult.getSuggestion(); |
|
|
if (SuggestionEnum.BLOCK.getCode().equals(suggestion)) { |
|
|
if (SuggestionEnum.BLOCK.getCode().equals(suggestion)) { |
|
|
if (result.getFailDataIds().contains(taskResult.getDataId())) { |
|
|
if (result.getFailDataIds().contains(taskResult.getDataId())) { |
|
@ -301,8 +301,8 @@ public class ScanServiceImpl implements ScanService { |
|
|
} |
|
|
} |
|
|
return result; |
|
|
return result; |
|
|
} else { |
|
|
} else { |
|
|
log.warn("executeSyncImg 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("code")); |
|
|
throw new ExeCuteHttpException("detect not success. code:" + scrResponse.getInteger(SysConstant.CODE)); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
log.warn("executeSyncImg response not success. status:" + httpResponse.getStatus()); |
|
|
log.warn("executeSyncImg response not success. status:" + httpResponse.getStatus()); |
|
|