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

图片审核表修改

parent ead3fd2d
package com.tanpu.community.api.beans.req;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class OSSCheckExtras {
private String sexRate;
private String normRate;
private String pornRate;
}
package com.tanpu.community.api.beans.req; package com.tanpu.community.api.beans.req;
import com.google.gson.JsonObject;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
...@@ -16,6 +17,6 @@ public class OSSCheckReq { ...@@ -16,6 +17,6 @@ public class OSSCheckReq {
private boolean stock; private boolean stock;
private String region; private String region;
private String freezed; private String freezed;
private String scanResult; private JsonObject scanResult;
private String auditResult; private JsonObject auditResult;
} }
package com.tanpu.community.api.beans.req;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class OSSCheckResult {
private String label;
private double rate;
private String scene;
private String suggestion;
}
package com.tanpu.community.api.beans.req;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class OSSCheckScanResult {
private String code;
private String dataId;
private OSSCheckExtras extras;
private String msg;
private List<OSSCheckResult> results;
private String taskId;
}
package com.tanpu.community.api.enums;
import org.apache.commons.collections4.SetUtils;
import java.util.HashSet;
public enum FileChechStatusEnum {
INIT(0,"初始化"),
PASS(1,"审核通过"),
NOT_PASS(2,"审核不通过");
public static final HashSet<String> ossTypeSet = SetUtils.hashSet("jpg", "jpeg", "png", "txt");
private Integer code;
private String type;
FileChechStatusEnum(Integer code, String type) {
this.code = code;
this.type = type;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
package com.tanpu.community.controller; package com.tanpu.community.controller;
import com.tanpu.common.util.JsonUtil;
import com.tanpu.community.manager.FileManager;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -14,16 +18,34 @@ import java.util.Map; ...@@ -14,16 +18,34 @@ import java.util.Map;
@RequestMapping(value = "/api") @RequestMapping(value = "/api")
public class CallBackController { public class CallBackController {
@Autowired
private FileManager fileManager;
/**
* 阿里云图片审核回调接口
* 回调时间:6秒以内
* 文档地址:https://help.aliyun.com/document_detail/129946.html?spm=a2c4g.11186623.6.562.19a05f3aNkd2Oo#table-s9e-grd-408
* @param checksum
* @param content
* @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) {
Map<String, String> params = new HashMap<>();
log.info("params:{}", checksum); log.info("checksum:{}", checksum);
log.info("content:{}", content); Map<String, Object> response = JsonUtil.toMap(content);
String fileKey = (String) response.get("object");
boolean freezed = (boolean) response.get("freezed");
HashMap<String,Object> scanResult = (HashMap<String, Object>) response.get("scanResult");
String taskId = (String) scanResult.get("taskId");
fileManager.updateCheckResult(fileKey,freezed,taskId);
return "success"; return "success";
} }
public static void main(String[] args) {
System.out.println(new Date());
}
} }
...@@ -23,7 +23,7 @@ public class CodeAutoGenerator { ...@@ -23,7 +23,7 @@ public class CodeAutoGenerator {
String mysqlPassword = "@imeng123"; String mysqlPassword = "@imeng123";
String jdbcUrl = "jdbc:mysql://rm-uf6r22t3d798q4kmkao.mysql.rds.aliyuncs.com:3306/tamp_community"; String jdbcUrl = "jdbc:mysql://rm-uf6r22t3d798q4kmkao.mysql.rds.aliyuncs.com:3306/tamp_community";
// String[] tables = new String[]{"theme"}; // String[] tables = new String[]{"theme"};
String[] tables = new String[]{"notification"}; String[] tables = new String[]{"file_record"};
String basePackage = "com.tanpu.community"; String basePackage = "com.tanpu.community";
String mapperPackage = "dao.mapper.community"; String mapperPackage = "dao.mapper.community";
String entityPackage = "dao.entity.community"; String entityPackage = "dao.entity.community";
......
...@@ -18,7 +18,7 @@ import java.time.LocalDateTime; ...@@ -18,7 +18,7 @@ import java.time.LocalDateTime;
* </p> * </p>
* *
* @author xudong * @author xudong
* @since 2021-07-12 * @since 2021-08-18
*/ */
@TableName("file_record") @TableName("file_record")
@Builder @Builder
...@@ -31,9 +31,9 @@ public class FileRecordEntity implements Serializable { ...@@ -31,9 +31,9 @@ public class FileRecordEntity implements Serializable {
@ApiModelProperty(value = "id") @ApiModelProperty(value = "id")
@TableId(value = "id", type = IdType.AUTO) @TableId(value = "id", type = IdType.AUTO)
private Integer id; private Long id;
@ApiModelProperty(value = "文件Id") @ApiModelProperty(value = "文件主键Id")
private String fileId; private String fileId;
@ApiModelProperty(value = "类型:1:图片") @ApiModelProperty(value = "类型:1:图片")
...@@ -45,7 +45,7 @@ public class FileRecordEntity implements Serializable { ...@@ -45,7 +45,7 @@ public class FileRecordEntity implements Serializable {
@ApiModelProperty(value = "阿里云key") @ApiModelProperty(value = "阿里云key")
private String fileOssKey; private String fileOssKey;
@ApiModelProperty(value = "预览url") @ApiModelProperty(value = "预签名预览url")
private String previewUrl; private String previewUrl;
private LocalDateTime createTime; private LocalDateTime createTime;
...@@ -56,16 +56,21 @@ public class FileRecordEntity implements Serializable { ...@@ -56,16 +56,21 @@ public class FileRecordEntity implements Serializable {
private String extInfo; private String extInfo;
@ApiModelProperty(value = "审核状态 0:初试化 1:通过 2:不通过")
private Integer checkStatus;
@ApiModelProperty(value = "阿里云校验任务id(用于同步查询结果)")
private String checkTaskId;
public String getUrl(){ public String getUrl(){
return getPreviewUrl().substring(0,getPreviewUrl().indexOf("?")); return getPreviewUrl().substring(0,getPreviewUrl().indexOf("?"));
} }
public Long getId() {
public Integer getId() {
return id; return id;
} }
public void setId(Integer id) { public void setId(Long id) {
this.id = id; this.id = id;
} }
...@@ -141,6 +146,22 @@ public class FileRecordEntity implements Serializable { ...@@ -141,6 +146,22 @@ public class FileRecordEntity implements Serializable {
this.extInfo = extInfo; this.extInfo = extInfo;
} }
public Integer getCheckStatus() {
return checkStatus;
}
public void setCheckStatus(Integer checkStatus) {
this.checkStatus = checkStatus;
}
public String getCheckTaskId() {
return checkTaskId;
}
public void setCheckTaskId(String checkTaskId) {
this.checkTaskId = checkTaskId;
}
@Override @Override
public String toString() { public String toString() {
return "FileRecordEntity{" + return "FileRecordEntity{" +
...@@ -154,6 +175,8 @@ public class FileRecordEntity implements Serializable { ...@@ -154,6 +175,8 @@ public class FileRecordEntity implements Serializable {
", updateTime=" + updateTime + ", updateTime=" + updateTime +
", deleteTag=" + deleteTag + ", deleteTag=" + deleteTag +
", extInfo=" + extInfo + ", extInfo=" + extInfo +
", checkStatus=" + checkStatus +
", checkTaskId=" + checkTaskId +
"}"; "}";
} }
} }
...@@ -9,7 +9,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; ...@@ -9,7 +9,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* </p> * </p>
* *
* @author xudong * @author xudong
* @since 2021-07-07 * @since 2021-08-18
*/ */
public interface FileRecordMapper extends BaseMapper<FileRecordEntity> { public interface FileRecordMapper extends BaseMapper<FileRecordEntity> {
......
...@@ -10,7 +10,6 @@ import com.tanpu.community.util.ConvertUtil; ...@@ -10,7 +10,6 @@ import com.tanpu.community.util.ConvertUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -61,4 +60,21 @@ public class FileManager { ...@@ -61,4 +60,21 @@ 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) {
FileRecordEntity fileRecordEntity = ossFileService.queryByOssKey(fileKey);
if (fileRecordEntity==null){
throw new BizException("图片未找到:"+fileKey);
}
if (check){
// 审核失败
fileRecordEntity.setCheckStatus(2);
}else {
// 审核通过
fileRecordEntity.setCheckStatus(1);
}
fileRecordEntity.setCheckTaskId(taskId);
ossFileService.update(fileRecordEntity);
}
} }
...@@ -134,8 +134,9 @@ public class OSSFileService { ...@@ -134,8 +134,9 @@ public class OSSFileService {
.in(FileRecordEntity::getFileId,fileIds)); .in(FileRecordEntity::getFileId,fileIds));
} }
// 同步查询,使用taskId,且1/24小时内才能查询
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", "请填写您的accessKeyId", "请填写您的accessKeySecret"); 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);
...@@ -150,7 +151,7 @@ public class OSSFileService { ...@@ -150,7 +151,7 @@ public class OSSFileService {
List<String> taskIds = new ArrayList<String>(); List<String> taskIds = new ArrayList<String>();
taskIds.add("img4hDosCHcrFk5jAMR80XWJN-1pZ@0p"); taskIds.add("img5B0C6GGD4uq41U3aPy6qpD-1uRam9");
imageAsyncScanResultsRequest.setHttpContent(JSON.toJSONString(taskIds).getBytes("UTF-8"), "UTF-8", FormatType.JSON); imageAsyncScanResultsRequest.setHttpContent(JSON.toJSONString(taskIds).getBytes("UTF-8"), "UTF-8", FormatType.JSON);
/** /**
...@@ -194,4 +195,14 @@ public class OSSFileService { ...@@ -194,4 +195,14 @@ public class OSSFileService {
e.printStackTrace(); e.printStackTrace();
} }
} }
public FileRecordEntity queryByOssKey(String fileKey) {
return fileRecordMapper.selectOne(new LambdaQueryWrapper<FileRecordEntity>().eq(FileRecordEntity::getFileOssKey,fileKey));
}
public void update(FileRecordEntity fileRecordEntity) {
fileRecordMapper.updateById(fileRecordEntity);
}
} }
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
<result column="update_time" property="updateTime" /> <result column="update_time" property="updateTime" />
<result column="delete_tag" property="deleteTag" /> <result column="delete_tag" property="deleteTag" />
<result column="ext_info" property="extInfo" /> <result column="ext_info" property="extInfo" />
<result column="check_status" property="checkStatus" />
<result column="check_task_id" property="checkTaskId" />
</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