Browse Source

修改审核api日志

dev_shibei_match
jianjun 5 years ago
parent
commit
857c7ec592
  1. 4
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SuggestionEnum.java
  2. 1
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SysResponseEnum.java
  3. 104
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java

4
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;

1
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 {

104
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<ImgAsyncScanResult>().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<ScanTaskResult> scanTaskResults = scrResponse.getJSONArray(SysConstant.DATA).toJavaList(ScanTaskResult.class);
for (ScanTaskResult taskResult : scanTaskResults) {
result.getDetails().add(taskResult);
//又根据场景不同
if (HttpStatus.SC_OK == taskResult.getCode()) {
//如果是多个场景 则为对个 BaseScanResult
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){
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<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 {
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) {

Loading…
Cancel
Save