From 5c112ee9ecbb7cf9e276396937745ddd456945e4 Mon Sep 17 00:00:00 2001 From: glx <783262171@qq.com> Date: Mon, 15 Jun 2026 14:17:13 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E8=B0=83=E7=94=A8=E5=AE=A1?= =?UTF-8?q?=E6=A0=B8=E6=9C=8D=E5=8A=A1=E6=A0=A1=E9=AA=8C=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/AuditExecutorServiceImpl.java | 81 ++++++++++++------- .../mini/model/form/ReportSubmitForm.java | 2 +- 2 files changed, 52 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/youlai/boot/admin/service/impl/AuditExecutorServiceImpl.java b/src/main/java/com/youlai/boot/admin/service/impl/AuditExecutorServiceImpl.java index 013bd15..7b836d0 100644 --- a/src/main/java/com/youlai/boot/admin/service/impl/AuditExecutorServiceImpl.java +++ b/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.MiniContentAuditTask; import com.youlai.boot.admin.service.*; +import com.youlai.boot.common.exception.MsgException; import com.youlai.boot.common.util.AliyunContentAuditUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -110,6 +111,9 @@ public class AuditExecutorServiceImpl implements AuditExecutorService { for (MiniContentAuditTask task : textTasks) { try { TextModerationPlusResponse r = aliyunContentAuditUtil.textModerationPlus(task.getContentValue(), textService); + if (!isApiSuccess(r)) { + throw new MsgException("文本审核请求失败"); + } processSingleTextResponse(task, r, strictness); contentAuditTaskService.lambdaUpdate() .eq(MiniContentAuditTask::getId, task.getId()) @@ -140,7 +144,14 @@ public class AuditExecutorServiceImpl implements AuditExecutorService { List videoTasks = grouped.getOrDefault("video", List.of()); 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) { ImageAsyncModerationResponse response = aliyunContentAuditUtil.imageAsyncModeration(imageUrl, serviceName); - if (response == null || response.getBody() == null) { - log.warn("图片异步审核请求返回null, taskId={}", task.getId()); - return; + if (!isApiSuccess(response)) { + throw new MsgException("图片异步审核提交失败"); } - if (response.getBody().getCode() == null || response.getBody().getCode() != 200) { - log.warn("图片异步审核提交失败, taskId={}, code={}", task.getId(), response.getBody().getCode()); - return; - } - if (response.getBody().getData() != null && response.getBody().getData().getReqId() != null) { + String reqId = extractReqIdFromImageResponse(response); + if (reqId != null) { contentAuditTaskService.lambdaUpdate() .eq(MiniContentAuditTask::getId, task.getId()) - .set(MiniContentAuditTask::getTaskId, response.getBody().getData().getReqId()) + .set(MiniContentAuditTask::getTaskId, reqId) .set(MiniContentAuditTask::getMachineResult, JSON.toJSONString(response)) .set(MiniContentAuditTask::getServiceName, serviceName) .set(MiniContentAuditTask::getUpdateTime, new Date()) .set(MiniContentAuditTask::getUpdateTimestamp, System.currentTimeMillis()) .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) { VideoModerationResponse response = aliyunContentAuditUtil.videoModeration(videoUrl, serviceName); - if (response == null) { - log.warn("视频审核请求返回null, taskId={}", task.getId()); - return; + if (!isApiSuccess(response)) { + throw new MsgException("视频审核提交失败"); } String asyncTaskId = extractVideoTaskIdFromResponse(response); if (asyncTaskId != null) { @@ -277,6 +285,8 @@ public class AuditExecutorServiceImpl implements AuditExecutorService { .set(MiniContentAuditTask::getServiceName, serviceName) .update(); 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(); } + 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 */ private String extractRequestIdFromResponse(Object response) { try { @@ -461,14 +494,8 @@ public class AuditExecutorServiceImpl implements AuditExecutorService { String asyncTaskId = task.getTaskId(); VideoModerationResultResponse response = aliyunContentAuditUtil.videoModerationResult(asyncTaskId); - if (response == null || response.getBody() == null) { - log.info("视频审核结果查询返回null, taskId={}", task.getId()); - return false; - } - - Integer code = response.getBody().getCode(); - if (code == null || code != 200) { - log.info("视频审核结果查询失败, taskId={}, code={}", task.getId(), code); + if (!isApiSuccess(response)) { + log.info("视频审核结果查询未就绪, taskId={}", task.getId()); return false; } @@ -570,14 +597,8 @@ public class AuditExecutorServiceImpl implements AuditExecutorService { String reqId = task.getTaskId(); DescribeImageModerationResultResponse response = aliyunContentAuditUtil.describeImageModerationResult(reqId); - if (response == null || response.getBody() == null) { - log.info("图片审核结果查询返回null, taskId={}", task.getId()); - return false; - } - - Integer code = response.getBody().getCode(); - if (code == null || code != 200) { - log.info("图片审核结果查询失败, taskId={}, code={}", task.getId(), code); + if (!isApiSuccess(response)) { + log.info("图片审核结果查询未就绪, taskId={}", task.getId()); return false; } diff --git a/src/main/java/com/youlai/boot/mini/model/form/ReportSubmitForm.java b/src/main/java/com/youlai/boot/mini/model/form/ReportSubmitForm.java index 0170be4..c70d30d 100644 --- a/src/main/java/com/youlai/boot/mini/model/form/ReportSubmitForm.java +++ b/src/main/java/com/youlai/boot/mini/model/form/ReportSubmitForm.java @@ -19,7 +19,7 @@ public class ReportSubmitForm { private String targetUuid; @NotBlank(message = "举报原因类别不能为空") - @Schema(description = "举报原因: 违法违规 / 侵权冒犯 / 垃圾虚假 / 违规操作 / 其他") + @Schema(description = "举报原因:illegal_or_violent-违法违规,spam_or_fake-侵权冒犯,spam_or_fake-垃圾虚假,abusive_behavior-违规操作,other-其他") private String reasonCategory; @Schema(description = "证据图片URL列表,逗号分隔")