Browse Source

统一调用审核服务校验方法

glx_phase2
glx 5 hours ago
parent
commit
5c112ee9ec
  1. 81
      src/main/java/com/youlai/boot/admin/service/impl/AuditExecutorServiceImpl.java
  2. 2
      src/main/java/com/youlai/boot/mini/model/form/ReportSubmitForm.java

81
src/main/java/com/youlai/boot/admin/service/impl/AuditExecutorServiceImpl.java

@ -11,6 +11,7 @@ import com.youlai.boot.admin.model.entity.MiniContentAudit;
import com.youlai.boot.admin.model.entity.MiniContentAuditConfig; import com.youlai.boot.admin.model.entity.MiniContentAuditConfig;
import com.youlai.boot.admin.model.entity.MiniContentAuditTask; import com.youlai.boot.admin.model.entity.MiniContentAuditTask;
import com.youlai.boot.admin.service.*; import com.youlai.boot.admin.service.*;
import com.youlai.boot.common.exception.MsgException;
import com.youlai.boot.common.util.AliyunContentAuditUtil; import com.youlai.boot.common.util.AliyunContentAuditUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -110,6 +111,9 @@ public class AuditExecutorServiceImpl implements AuditExecutorService {
for (MiniContentAuditTask task : textTasks) { for (MiniContentAuditTask task : textTasks) {
try { try {
TextModerationPlusResponse r = aliyunContentAuditUtil.textModerationPlus(task.getContentValue(), textService); TextModerationPlusResponse r = aliyunContentAuditUtil.textModerationPlus(task.getContentValue(), textService);
if (!isApiSuccess(r)) {
throw new MsgException("文本审核请求失败");
}
processSingleTextResponse(task, r, strictness); processSingleTextResponse(task, r, strictness);
contentAuditTaskService.lambdaUpdate() contentAuditTaskService.lambdaUpdate()
.eq(MiniContentAuditTask::getId, task.getId()) .eq(MiniContentAuditTask::getId, task.getId())
@ -140,7 +144,14 @@ public class AuditExecutorServiceImpl implements AuditExecutorService {
List<MiniContentAuditTask> videoTasks = grouped.getOrDefault("video", List.of()); List<MiniContentAuditTask> videoTasks = grouped.getOrDefault("video", List.of());
for (MiniContentAuditTask task : videoTasks) { for (MiniContentAuditTask task : videoTasks) {
handleVideoAudit(task, task.getContentValue(), videoService); try {
handleVideoAudit(task, task.getContentValue(), videoService);
} catch (Exception e) {
log.error("视频异步审核提交失败, taskId={}", task.getId(), e);
contentAuditTaskService.updateTaskMachineResult(
task.getId(), null, null, AuditConstants.STATUS_MANUAL_REVIEW,
null, null, null, null);
}
} }
} }
@ -239,24 +250,22 @@ public class AuditExecutorServiceImpl implements AuditExecutorService {
*/ */
private void handleImageAsyncAudit(MiniContentAuditTask task, String imageUrl, String serviceName) { private void handleImageAsyncAudit(MiniContentAuditTask task, String imageUrl, String serviceName) {
ImageAsyncModerationResponse response = aliyunContentAuditUtil.imageAsyncModeration(imageUrl, serviceName); ImageAsyncModerationResponse response = aliyunContentAuditUtil.imageAsyncModeration(imageUrl, serviceName);
if (response == null || response.getBody() == null) { if (!isApiSuccess(response)) {
log.warn("图片异步审核请求返回null, taskId={}", task.getId()); throw new MsgException("图片异步审核提交失败");
return;
} }
if (response.getBody().getCode() == null || response.getBody().getCode() != 200) { String reqId = extractReqIdFromImageResponse(response);
log.warn("图片异步审核提交失败, taskId={}, code={}", task.getId(), response.getBody().getCode()); if (reqId != null) {
return;
}
if (response.getBody().getData() != null && response.getBody().getData().getReqId() != null) {
contentAuditTaskService.lambdaUpdate() contentAuditTaskService.lambdaUpdate()
.eq(MiniContentAuditTask::getId, task.getId()) .eq(MiniContentAuditTask::getId, task.getId())
.set(MiniContentAuditTask::getTaskId, response.getBody().getData().getReqId()) .set(MiniContentAuditTask::getTaskId, reqId)
.set(MiniContentAuditTask::getMachineResult, JSON.toJSONString(response)) .set(MiniContentAuditTask::getMachineResult, JSON.toJSONString(response))
.set(MiniContentAuditTask::getServiceName, serviceName) .set(MiniContentAuditTask::getServiceName, serviceName)
.set(MiniContentAuditTask::getUpdateTime, new Date()) .set(MiniContentAuditTask::getUpdateTime, new Date())
.set(MiniContentAuditTask::getUpdateTimestamp, System.currentTimeMillis()) .set(MiniContentAuditTask::getUpdateTimestamp, System.currentTimeMillis())
.update(); .update();
log.info("图片异步审核已提交, taskId={}, reqId={}, service={}", task.getId(), response.getBody().getData().getReqId(), serviceName); log.info("图片异步审核已提交, taskId={}, reqId={}, service={}", task.getId(), reqId, serviceName);
} else {
throw new MsgException("图片异步审核提交返回空reqId");
} }
} }
@ -265,9 +274,8 @@ public class AuditExecutorServiceImpl implements AuditExecutorService {
*/ */
private void handleVideoAudit(MiniContentAuditTask task, String videoUrl, String serviceName) { private void handleVideoAudit(MiniContentAuditTask task, String videoUrl, String serviceName) {
VideoModerationResponse response = aliyunContentAuditUtil.videoModeration(videoUrl, serviceName); VideoModerationResponse response = aliyunContentAuditUtil.videoModeration(videoUrl, serviceName);
if (response == null) { if (!isApiSuccess(response)) {
log.warn("视频审核请求返回null, taskId={}", task.getId()); throw new MsgException("视频审核提交失败");
return;
} }
String asyncTaskId = extractVideoTaskIdFromResponse(response); String asyncTaskId = extractVideoTaskIdFromResponse(response);
if (asyncTaskId != null) { if (asyncTaskId != null) {
@ -277,6 +285,8 @@ public class AuditExecutorServiceImpl implements AuditExecutorService {
.set(MiniContentAuditTask::getServiceName, serviceName) .set(MiniContentAuditTask::getServiceName, serviceName)
.update(); .update();
log.info("视频异步审核已提交, taskId={}, aliyunTaskId={}, service={}", task.getId(), asyncTaskId, serviceName); log.info("视频异步审核已提交, taskId={}, aliyunTaskId={}, service={}", task.getId(), asyncTaskId, serviceName);
} else {
throw new MsgException("视频审核提交返回空taskId");
} }
} }
@ -290,6 +300,29 @@ public class AuditExecutorServiceImpl implements AuditExecutorService {
return response.getBody().getData().getTaskId(); return response.getBody().getData().getTaskId();
} }
private String extractReqIdFromImageResponse(ImageAsyncModerationResponse response) {
if (response.getBody() == null) return null;
if (response.getBody().getData() == null) return null;
return response.getBody().getData().getReqId();
}
/**
* 校验阿里云API响应两层状态码HTTP statusCode 200 + 业务 code 200
*/
private boolean isApiSuccess(Object response) {
if (response == null) return false;
try {
Integer statusCode = (Integer) response.getClass().getMethod("getStatusCode").invoke(response);
if (statusCode == null || statusCode != 200) return false;
Object body = response.getClass().getMethod("getBody").invoke(response);
if (body == null) return false;
Integer code = (Integer) body.getClass().getMethod("getCode").invoke(body);
return code != null && code == 200;
} catch (Exception e) {
return false;
}
}
/** 反射提取 body.requestId */ /** 反射提取 body.requestId */
private String extractRequestIdFromResponse(Object response) { private String extractRequestIdFromResponse(Object response) {
try { try {
@ -461,14 +494,8 @@ public class AuditExecutorServiceImpl implements AuditExecutorService {
String asyncTaskId = task.getTaskId(); String asyncTaskId = task.getTaskId();
VideoModerationResultResponse response = aliyunContentAuditUtil.videoModerationResult(asyncTaskId); VideoModerationResultResponse response = aliyunContentAuditUtil.videoModerationResult(asyncTaskId);
if (response == null || response.getBody() == null) { if (!isApiSuccess(response)) {
log.info("视频审核结果查询返回null, taskId={}", task.getId()); log.info("视频审核结果查询未就绪, taskId={}", task.getId());
return false;
}
Integer code = response.getBody().getCode();
if (code == null || code != 200) {
log.info("视频审核结果查询失败, taskId={}, code={}", task.getId(), code);
return false; return false;
} }
@ -570,14 +597,8 @@ public class AuditExecutorServiceImpl implements AuditExecutorService {
String reqId = task.getTaskId(); String reqId = task.getTaskId();
DescribeImageModerationResultResponse response = aliyunContentAuditUtil.describeImageModerationResult(reqId); DescribeImageModerationResultResponse response = aliyunContentAuditUtil.describeImageModerationResult(reqId);
if (response == null || response.getBody() == null) { if (!isApiSuccess(response)) {
log.info("图片审核结果查询返回null, taskId={}", task.getId()); log.info("图片审核结果查询未就绪, taskId={}", task.getId());
return false;
}
Integer code = response.getBody().getCode();
if (code == null || code != 200) {
log.info("图片审核结果查询失败, taskId={}, code={}", task.getId(), code);
return false; return false;
} }

2
src/main/java/com/youlai/boot/mini/model/form/ReportSubmitForm.java

@ -19,7 +19,7 @@ public class ReportSubmitForm {
private String targetUuid; private String targetUuid;
@NotBlank(message = "举报原因类别不能为空") @NotBlank(message = "举报原因类别不能为空")
@Schema(description = "举报原因: 违法违规 / 侵权冒犯 / 垃圾虚假 / 违规操作 / 其他") @Schema(description = "举报原因:illegal_or_violent-违法违规,spam_or_fake-侵权冒犯,spam_or_fake-垃圾虚假,abusive_behavior-违规操作,other-其他")
private String reasonCategory; private String reasonCategory;
@Schema(description = "证据图片URL列表,逗号分隔") @Schema(description = "证据图片URL列表,逗号分隔")

Loading…
Cancel
Save