Commit b05c24c1 authored by 刘基明's avatar 刘基明

图片审核结果记录

parent 9b11bd9b
...@@ -23,6 +23,11 @@ public final class CommunityConstant { ...@@ -23,6 +23,11 @@ public final class CommunityConstant {
//图片压缩比例:50% //图片压缩比例:50%
public static final String OSS_RESIZE_RATIO = "?x-oss-process=image/resize,p_50"; public static final String OSS_RESIZE_RATIO = "?x-oss-process=image/resize,p_50";
// 图片审核不通过的替换默认图片
public static final String OSS_CHECK_FAIL_DEFAULT = "https://tamp-sit.oss-cn-shanghai.aliyuncs.com/community/pic/default/check_fail.png";
public static final Integer OSS_CHECK_FAIL_DEFAULT_WIDTH = 1035;
public static final Integer OSS_CHECK_FAIL_DEFAULT_HEIGHT = 1115;
public static final String THEME_PREFIX ="NEW_THEME_"; public static final String THEME_PREFIX ="NEW_THEME_";
public static final String OLD_FILE_UPLOAD_URL ="http://tp-fatools-svc/fatools/h5/rest/common/uploadSingleFile"; public static final String OLD_FILE_UPLOAD_URL ="http://tp-fatools-svc/fatools/h5/rest/common/uploadSingleFile";
......
...@@ -29,25 +29,27 @@ public class CallBackController { ...@@ -29,25 +29,27 @@ public class CallBackController {
* 阿里云图片审核回调接口 * 阿里云图片审核回调接口
* 回调时间:6秒以内 * 回调时间:6秒以内
* 文档地址:https://help.aliyun.com/document_detail/129946.html?spm=a2c4g.11186623.6.562.19a05f3aNkd2Oo#table-s9e-grd-408 * 文档地址:https://help.aliyun.com/document_detail/129946.html?spm=a2c4g.11186623.6.562.19a05f3aNkd2Oo#table-s9e-grd-408
*
* @param checksum * @param checksum
* @param content * @param content
* @return * @return
*/ */
@ApiOperation("oss图片审核回调") @ApiOperation("oss图片审核回调")
@PostMapping(value = "/picCheck/callback") @PostMapping(value = "/picCheck/callback")
public String picCheck(String checksum,String content) { public String picCheck(String checksum, String content) {
log.info("checksum:{}", checksum); log.info("checksum:{}", checksum);
Map<String, Object> response = JsonUtil.toMap(content); Map<String, Object> response = JsonUtil.toMap(content);
String fileKey = (String) response.get("object"); String fileKey = (String) response.get("object");
boolean freezed = (boolean) response.get("freezed"); boolean freezed = (boolean) response.get("freezed");
HashMap<String,Object> scanResult = (HashMap<String, Object>) response.get("scanResult"); HashMap<String, Object> scanResult = (HashMap<String, Object>) response.get("scanResult");
String taskId = (String) scanResult.get("taskId"); String taskId = (String) scanResult.get("taskId");
fileManager.updateCheckResult(fileKey,freezed,taskId); String resultLog = JsonUtil.toJson(scanResult.get("results"));
fileManager.updateCheckResult(fileKey, freezed, taskId, resultLog);
return "success"; return "success";
} }
@ApiOperation("oss图片审核回调") @ApiOperation("oss图片审核结果查询")
@PostMapping(value = "/picCheck/queryTask") @PostMapping(value = "/picCheck/queryTask")
public CommonResp<JSONArray> queryTask(@RequestParam String taskId) { public CommonResp<JSONArray> queryTask(@RequestParam String taskId) {
......
...@@ -62,10 +62,12 @@ public class FileRecordEntity implements Serializable { ...@@ -62,10 +62,12 @@ public class FileRecordEntity implements Serializable {
@ApiModelProperty(value = "阿里云校验任务id(用于同步查询结果)") @ApiModelProperty(value = "阿里云校验任务id(用于同步查询结果)")
private String checkTaskId; private String checkTaskId;
@ApiModelProperty(value = "审核结果记录")
private String checkResultLog;
public String getUrl(){ public String getUrl(){
return getPreviewUrl().substring(0,getPreviewUrl().indexOf("?")); return getPreviewUrl().substring(0,getPreviewUrl().indexOf("?"));
} }
public Long getId() { public Long getId() {
return id; return id;
} }
...@@ -162,6 +164,14 @@ public class FileRecordEntity implements Serializable { ...@@ -162,6 +164,14 @@ public class FileRecordEntity implements Serializable {
this.checkTaskId = checkTaskId; this.checkTaskId = checkTaskId;
} }
public String getCheckResultLog() {
return checkResultLog;
}
public void setCheckResultLog(String checkResultLog) {
this.checkResultLog = checkResultLog;
}
@Override @Override
public String toString() { public String toString() {
return "FileRecordEntity{" + return "FileRecordEntity{" +
...@@ -177,6 +187,7 @@ public class FileRecordEntity implements Serializable { ...@@ -177,6 +187,7 @@ public class FileRecordEntity implements Serializable {
", extInfo=" + extInfo + ", extInfo=" + extInfo +
", checkStatus=" + checkStatus + ", checkStatus=" + checkStatus +
", checkTaskId=" + checkTaskId + ", checkTaskId=" + checkTaskId +
", checkResultLog=" + checkResultLog +
"}"; "}";
} }
} }
...@@ -5,8 +5,6 @@ import com.alibaba.fastjson.JSONArray; ...@@ -5,8 +5,6 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient; import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient; import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.green.model.v20180509.ImageAsyncScanResultsRequest; import com.aliyuncs.green.model.v20180509.ImageAsyncScanResultsRequest;
import com.aliyuncs.http.FormatType; import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.HttpResponse; import com.aliyuncs.http.HttpResponse;
...@@ -75,27 +73,28 @@ public class FileManager { ...@@ -75,27 +73,28 @@ public class FileManager {
.collect(Collectors.toMap(FileRecordEntity::getFileId, FileRecordEntity::getUrl)); .collect(Collectors.toMap(FileRecordEntity::getFileId, FileRecordEntity::getUrl));
} }
public void updateCheckResult(String fileKey, boolean check, String taskId) { public void updateCheckResult(String fileKey, boolean check, String taskId, String resultLog) {
FileRecordEntity fileRecordEntity = ossFileService.queryByOssKey(fileKey); FileRecordEntity fileRecordEntity = ossFileService.queryByOssKey(fileKey);
if (fileRecordEntity==null){ if (fileRecordEntity == null) {
throw new BizException("图片未找到:"+fileKey); throw new BizException("图片未找到:" + fileKey);
} }
if (check){ if (check) {
// 审核失败 // 审核失败
fileRecordEntity.setCheckStatus(2); fileRecordEntity.setCheckStatus(2);
}else { } else {
// 审核通过 // 审核通过
fileRecordEntity.setCheckStatus(1); fileRecordEntity.setCheckStatus(1);
} }
fileRecordEntity.setCheckTaskId(taskId); fileRecordEntity.setCheckTaskId(taskId);
fileRecordEntity.setCheckResultLog(resultLog);
ossFileService.update(fileRecordEntity); ossFileService.update(fileRecordEntity);
} }
// 同步查询,使用taskId,且1/24小时内才能查询 // 同步查询,使用taskId,且1/24小时内才能查询
public JSONArray queryTask(String taskId) throws Exception { public JSONArray queryTask(String taskId) throws Exception {
IClientProfile profile = DefaultProfile.getProfile("cn-shanghai","LTAIAKEzVydP0Q9P", "59V9ke9txaIFzWxHFKTb1eoOOpmKpJ"); IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", "LTAIAKEzVydP0Q9P", "59V9ke9txaIFzWxHFKTb1eoOOpmKpJ");
DefaultProfile.addEndpoint("cn-shanghai", "cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com"); DefaultProfile.addEndpoint("cn-shanghai", "cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");
IAcsClient client = new DefaultAcsClient(profile); IAcsClient client = new DefaultAcsClient(profile);
...@@ -119,41 +118,34 @@ public class FileManager { ...@@ -119,41 +118,34 @@ public class FileManager {
imageAsyncScanResultsRequest.setConnectTimeout(3000); imageAsyncScanResultsRequest.setConnectTimeout(3000);
imageAsyncScanResultsRequest.setReadTimeout(6000); imageAsyncScanResultsRequest.setReadTimeout(6000);
try {
HttpResponse httpResponse = client.doAction(imageAsyncScanResultsRequest); HttpResponse httpResponse = client.doAction(imageAsyncScanResultsRequest);
if(httpResponse.isSuccess()){ if (httpResponse.isSuccess()) {
JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8")); JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8"));
System.out.println(JSON.toJSONString(scrResponse, true)); System.out.println(JSON.toJSONString(scrResponse, true));
if (200 == scrResponse.getInteger("code")) { if (200 == scrResponse.getInteger("code")) {
JSONArray taskResults = scrResponse.getJSONArray("data"); JSONArray taskResults = scrResponse.getJSONArray("data");
for (Object taskResult : taskResults) { for (Object taskResult : taskResults) {
if(200 == ((JSONObject)taskResult).getInteger("code")){ if (200 == ((JSONObject) taskResult).getInteger("code")) {
JSONArray sceneResults = ((JSONObject)taskResult).getJSONArray("results"); JSONArray sceneResults = ((JSONObject) taskResult).getJSONArray("results");
for (Object sceneResult : sceneResults) { for (Object sceneResult : sceneResults) {
String scene = ((JSONObject)sceneResult).getString("scene"); String scene = ((JSONObject) sceneResult).getString("scene");
String suggestion = ((JSONObject)sceneResult).getString("suggestion"); String suggestion = ((JSONObject) sceneResult).getString("suggestion");
// 根据scene和suggestion做相关的处理。 // 根据scene和suggestion做相关的处理。
// 根据不同的suggestion结果做业务上的不同处理。例如,将违规数据删除等。 // 根据不同的suggestion结果做业务上的不同处理。例如,将违规数据删除等。
} }
return sceneResults; return sceneResults;
}else{ } else {
throw new BizException("task process fail:" + ((JSONObject)taskResult).getInteger("code")); throw new BizException("task process fail:" + ((JSONObject) taskResult).getInteger("code"));
} }
} }
} else { } else {
throw new BizException("detect not success. code:" + scrResponse.getInteger("code")); throw new BizException("detect not success. code:" + scrResponse.getInteger("code"));
} }
}else{ } else {
throw new BizException("response not success. status:" + httpResponse.getStatus()); throw new BizException("response not success. status:" + httpResponse.getStatus());
} }
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
} catch (Exception e){
e.printStackTrace();
}
return null; return null;
} }
} }
...@@ -442,10 +442,10 @@ public class BatchFeignCallService { ...@@ -442,10 +442,10 @@ public class BatchFeignCallService {
.build(); .build();
// 图片审核屏蔽 // 图片审核屏蔽
if (FileChechStatusEnum.FAILED.getCode().equals(imgEntity.getCheckStatus())){ if (FileChechStatusEnum.FAILED.getCode().equals(imgEntity.getCheckStatus())){
imagesDTO.setRemark("https://tamp-sit.oss-cn-shanghai.aliyuncs.com/community/pic/default/check_fail.png"); imagesDTO.setRemark(CommunityConstant.OSS_CHECK_FAIL_DEFAULT);
imagesDTO.setResizeUrl("https://tamp-sit.oss-cn-shanghai.aliyuncs.com/community/pic/default/check_fail.png?x-oss-process=image/resize,p_50"); imagesDTO.setResizeUrl(CommunityConstant.OSS_CHECK_FAIL_DEFAULT+ CommunityConstant.OSS_RESIZE_RATIO);
imagesDTO.setImgWidth(1035); imagesDTO.setImgWidth(CommunityConstant.OSS_CHECK_FAIL_DEFAULT_WIDTH);
imagesDTO.setImgHeight(1115); imagesDTO.setImgHeight(CommunityConstant.OSS_CHECK_FAIL_DEFAULT_HEIGHT);
} }
themeContent.setImgList(Collections.singletonList(imagesDTO)); themeContent.setImgList(Collections.singletonList(imagesDTO));
} }
...@@ -457,12 +457,12 @@ public class BatchFeignCallService { ...@@ -457,12 +457,12 @@ public class BatchFeignCallService {
if (imgUrlMap.containsKey(imagesDTO.getRelId())) { if (imgUrlMap.containsKey(imagesDTO.getRelId())) {
FileRecordEntity imgEntity = imgUrlMap.get(imagesDTO.getRelId()); FileRecordEntity imgEntity = imgUrlMap.get(imagesDTO.getRelId());
// 图片审核不通过,替换为默认图片 // 图片审核不通过,替换为默认图片 todo 配置移除
if (FileChechStatusEnum.FAILED.getCode().equals(imgEntity.getCheckStatus())){ if (FileChechStatusEnum.FAILED.getCode().equals(imgEntity.getCheckStatus())){
imagesDTO.setRemark("https://tamp-sit.oss-cn-shanghai.aliyuncs.com/community/pic/default/check_fail.png"); imagesDTO.setRemark(CommunityConstant.OSS_CHECK_FAIL_DEFAULT);
imagesDTO.setResizeUrl("https://tamp-sit.oss-cn-shanghai.aliyuncs.com/community/pic/default/check_fail.png?x-oss-process=image/resize,p_50"); imagesDTO.setResizeUrl(CommunityConstant.OSS_CHECK_FAIL_DEFAULT+ CommunityConstant.OSS_RESIZE_RATIO);
imagesDTO.setImgWidth(1035); imagesDTO.setImgWidth(CommunityConstant.OSS_CHECK_FAIL_DEFAULT_WIDTH);
imagesDTO.setImgHeight(1115); imagesDTO.setImgHeight(CommunityConstant.OSS_CHECK_FAIL_DEFAULT_HEIGHT);
}else { }else {
imagesDTO.setRemark(imgEntity.getUrl()); imagesDTO.setRemark(imgEntity.getUrl());
imagesDTO.setResizeUrl(imgEntity.getUrl() + CommunityConstant.OSS_RESIZE_RATIO); imagesDTO.setResizeUrl(imgEntity.getUrl() + CommunityConstant.OSS_RESIZE_RATIO);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
<result column="ext_info" property="extInfo" /> <result column="ext_info" property="extInfo" />
<result column="check_status" property="checkStatus" /> <result column="check_status" property="checkStatus" />
<result column="check_task_id" property="checkTaskId" /> <result column="check_task_id" property="checkTaskId" />
<result column="check_result_log" property="checkResultLog" />
</resultMap> </resultMap>
</mapper> </mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment