|
@ -4,8 +4,6 @@ import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.aliyuncs.AcsRequest; |
|
|
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.ImageAsyncScanRequest; |
|
|
import com.aliyuncs.green.model.v20180509.ImageSyncScanRequest; |
|
|
import com.aliyuncs.green.model.v20180509.ImageSyncScanRequest; |
|
|
import com.aliyuncs.green.model.v20180509.TextScanRequest; |
|
|
import com.aliyuncs.green.model.v20180509.TextScanRequest; |
|
@ -162,7 +160,7 @@ public class ScanServiceImpl implements ScanService { |
|
|
imageAsyncScanRequest.setReadTimeout(6000); |
|
|
imageAsyncScanRequest.setReadTimeout(6000); |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
ImgAsyncScanResult scanResult = executeAsyncImg(imageAsyncScanRequest); |
|
|
ImgAsyncScanResult scanResult = null;//executeAsyncImg(imageAsyncScanRequest);
|
|
|
return new Result<ImgAsyncScanResult>().ok(scanResult); |
|
|
return new Result<ImgAsyncScanResult>().ok(scanResult); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
log.error("sendImgScan execute Exception", e); |
|
|
log.error("sendImgScan execute Exception", e); |
|
@ -177,98 +175,52 @@ 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));
|
|
|
|
|
|
if (HttpStatus.SC_OK == scrResponse.getInteger(SysConstant.CODE)) { |
|
|
if (HttpStatus.SC_OK == scrResponse.getInteger(SysConstant.CODE)) { |
|
|
//任务 列表
|
|
|
//任务 列表
|
|
|
List<ScanTaskResult> scanTaskResults = scrResponse.getJSONArray(SysConstant.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); |
|
|
result.getDetails().add(taskResult); |
|
|
//又根据场景不同
|
|
|
//又根据场景不同
|
|
|
if (HttpStatus.SC_OK == taskResult.getCode()) { |
|
|
if (HttpStatus.SC_OK != taskResult.getCode()) { |
|
|
//如果是多个场景 则为对个 BaseScanResult
|
|
|
if (!result.getFailDataIds().contains(taskResult.getDataId())) { |
|
|
List<SceneDetailResult> 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){ |
|
|
|
|
|
result.getFailDataIds().add(taskResult.getDataId()); |
|
|
result.getFailDataIds().add(taskResult.getDataId()); |
|
|
} else { |
|
|
log.warn("executeSyncText task process fail:code:{},result:{}", taskResult.getCode(), JSON.toJSONString(taskResult)); |
|
|
result.getSuccessDataIds().add(taskResult.getDataId()); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
//如果是多个场景 则为对个 BaseScanResult
|
|
|
|
|
|
List<SceneDetailResult> 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 { |
|
|
} else { |
|
|
|
|
|
log.warn("executeSyncText dataId:{} block:{}", taskResult.getDataId(), JSON.toJSONString(taskResult.getResults())); |
|
|
result.getFailDataIds().add(taskResult.getDataId()); |
|
|
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; |
|
|
return result; |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
log.warn("executeSyncText response not success. code:{}", scrResponse.getInteger(SysConstant.CODE)); |
|
|
throw new ExeCuteHttpException("executeSyncText detect not success. code:" + scrResponse.getInteger(SysConstant.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()); |
|
|
throw new ExeCuteHttpException("response not success. status:" + httpResponse.getStatus()); |
|
|
throw new ExeCuteHttpException("response not success. status:" + httpResponse.getStatus()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
log.warn("executeSyncImg exception", e); |
|
|
log.warn("executeSyncText exception", e); |
|
|
throw new ExeCuteHttpException(SysResponseEnum.EXCEPTION.getCode(), SysResponseEnum.EXCEPTION.getMsg()); |
|
|
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) { |
|
|
private SyncScanResult executeSyncImg(AcsRequest<?> request) { |
|
|
SyncScanResult result = new SyncScanResult(); |
|
|
SyncScanResult result = new SyncScanResult(); |
|
|
try { |
|
|
try { |
|
@ -283,6 +235,7 @@ public class ScanServiceImpl implements ScanService { |
|
|
if (HttpStatus.SC_OK != taskResult.getCode()) { |
|
|
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()); |
|
|
|
|
|
log.warn("executeSyncImg detect not success. code:{},result:{}", taskResult.getCode(), JSON.toJSONString(taskResult)); |
|
|
} |
|
|
} |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
@ -297,19 +250,20 @@ public class ScanServiceImpl implements ScanService { |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (isSuccess){ |
|
|
if (isSuccess) { |
|
|
result.getSuccessDataIds().add(taskResult.getDataId()); |
|
|
result.getSuccessDataIds().add(taskResult.getDataId()); |
|
|
}else{ |
|
|
} else { |
|
|
|
|
|
log.warn("executeSyncImg dataId:{} block:{}", taskResult.getDataId(), JSON.toJSONString(taskResult.getResults())); |
|
|
result.getFailDataIds().add(taskResult.getDataId()); |
|
|
result.getFailDataIds().add(taskResult.getDataId()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return result; |
|
|
return result; |
|
|
} else { |
|
|
} 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)); |
|
|
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()); |
|
|
throw new ExeCuteHttpException("response not success. status:" + httpResponse.getStatus()); |
|
|
throw new ExeCuteHttpException("response not success. status:" + httpResponse.getStatus()); |
|
|
} |
|
|
} |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|