Browse Source

修复视频审核结果服务问题

glx_phase2
glx 4 hours ago
parent
commit
b84e0491b3
  1. 24
      src/main/java/com/youlai/boot/admin/service/impl/AuditExecutorServiceImpl.java
  2. 9
      src/main/java/com/youlai/boot/admin/service/impl/ContentLookupServiceImpl.java
  3. 26
      src/main/java/com/youlai/boot/common/util/AliyunContentAuditUtil.java

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

@ -251,6 +251,8 @@ 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 (!isApiSuccess(response)) { if (!isApiSuccess(response)) {
log.warn("图片异步审核提交失败, taskId={}, statusCode={}, code={}, service={}",
task.getId(), getStatusCode(response), getBodyCode(response), serviceName);
throw new MsgException("图片异步审核提交失败"); throw new MsgException("图片异步审核提交失败");
} }
String reqId = extractReqIdFromImageResponse(response); String reqId = extractReqIdFromImageResponse(response);
@ -275,6 +277,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 (!isApiSuccess(response)) { if (!isApiSuccess(response)) {
log.warn("视频审核提交失败, taskId={}, statusCode={}, code={}, service={}",
task.getId(), getStatusCode(response), getBodyCode(response), serviceName);
throw new MsgException("视频审核提交失败"); throw new MsgException("视频审核提交失败");
} }
String asyncTaskId = extractVideoTaskIdFromResponse(response); String asyncTaskId = extractVideoTaskIdFromResponse(response);
@ -323,6 +327,24 @@ public class AuditExecutorServiceImpl implements AuditExecutorService {
} }
} }
private Integer getStatusCode(Object response) {
try {
return (Integer) response.getClass().getMethod("getStatusCode").invoke(response);
} catch (Exception e) {
return null;
}
}
private Integer getBodyCode(Object response) {
try {
Object body = response.getClass().getMethod("getBody").invoke(response);
if (body == null) return null;
return (Integer) body.getClass().getMethod("getCode").invoke(body);
} catch (Exception e) {
return null;
}
}
/** 反射提取 body.requestId */ /** 反射提取 body.requestId */
private String extractRequestIdFromResponse(Object response) { private String extractRequestIdFromResponse(Object response) {
try { try {
@ -492,7 +514,7 @@ public class AuditExecutorServiceImpl implements AuditExecutorService {
private boolean processSingleVideoTask(MiniContentAuditTask task) { private boolean processSingleVideoTask(MiniContentAuditTask task) {
String asyncTaskId = task.getTaskId(); String asyncTaskId = task.getTaskId();
VideoModerationResultResponse response = aliyunContentAuditUtil.videoModerationResult(asyncTaskId); VideoModerationResultResponse response = aliyunContentAuditUtil.videoModerationResult(asyncTaskId, task.getServiceName());
if (!isApiSuccess(response)) { if (!isApiSuccess(response)) {
log.info("视频审核结果查询未就绪, taskId={}", task.getId()); log.info("视频审核结果查询未就绪, taskId={}", task.getId());

9
src/main/java/com/youlai/boot/admin/service/impl/ContentLookupServiceImpl.java

@ -57,7 +57,8 @@ public class ContentLookupServiceImpl implements ContentLookupService {
if (post.getContent() != null) texts.add(post.getContent()); if (post.getContent() != null) texts.add(post.getContent());
return buildContentResult(texts, lookupMedia(userPostMediaMapper, return buildContentResult(texts, lookupMedia(userPostMediaMapper,
new LambdaQueryWrapper<MiniUserPostMedia>().eq(MiniUserPostMedia::getPostId, id))); new LambdaQueryWrapper<MiniUserPostMedia>().eq(MiniUserPostMedia::getPostId, id)
.eq(MiniUserPostMedia::getDeleted, false)));
} }
private AuditContentDTO lookupAdoptionDiary(Long id) { private AuditContentDTO lookupAdoptionDiary(Long id) {
@ -69,7 +70,8 @@ public class ContentLookupServiceImpl implements ContentLookupService {
if (diary.getContent() != null) texts.add(diary.getContent()); if (diary.getContent() != null) texts.add(diary.getContent());
return buildContentResult(texts, lookupMedia(adoptionDiaryMediaMapper, return buildContentResult(texts, lookupMedia(adoptionDiaryMediaMapper,
new LambdaQueryWrapper<MiniAdoptionDiaryMedia>().eq(MiniAdoptionDiaryMedia::getDiaryId, id))); new LambdaQueryWrapper<MiniAdoptionDiaryMedia>().eq(MiniAdoptionDiaryMedia::getDiaryId, id)
.eq(MiniAdoptionDiaryMedia::getDeleted, false)));
} }
private AuditContentDTO lookupAnimalNote(Long id) { private AuditContentDTO lookupAnimalNote(Long id) {
@ -81,7 +83,8 @@ public class ContentLookupServiceImpl implements ContentLookupService {
if (note.getContent() != null) texts.add(note.getContent()); if (note.getContent() != null) texts.add(note.getContent());
return buildContentResult(texts, lookupMedia(strayAnimalNoteMediaMapper, return buildContentResult(texts, lookupMedia(strayAnimalNoteMediaMapper,
new LambdaQueryWrapper<MiniStrayAnimalNoteMedia>().eq(MiniStrayAnimalNoteMedia::getNoteId, id))); new LambdaQueryWrapper<MiniStrayAnimalNoteMedia>().eq(MiniStrayAnimalNoteMedia::getNoteId, id)
.eq(MiniStrayAnimalNoteMedia::getDeleted, false)));
} }
private AuditContentDTO lookupPostComment(Long id) { private AuditContentDTO lookupPostComment(Long id) {

26
src/main/java/com/youlai/boot/common/util/AliyunContentAuditUtil.java

@ -21,10 +21,6 @@ import org.springframework.stereotype.Component;
* 3. 视频审核异步 * 3. 视频审核异步
* 4. 取消视频审核任务直播流 * 4. 取消视频审核任务直播流
* *
* 特性
* - 自动切换备用节点cn-beijing
* - application.yml 中读取配置
* - 返回 null 表示请求失败业务层自行判断
*/ */
@Slf4j @Slf4j
@Component @Component
@ -105,7 +101,7 @@ public class AliyunContentAuditUtil {
} }
} }
// ===================== 文本审核 ===================== // ===================== 普通文本审核 =====================
public TextModerationResponse textModeration(String content) { public TextModerationResponse textModeration(String content) {
return executeWithFailover(client -> { return executeWithFailover(client -> {
JSONObject params = new JSONObject(); JSONObject params = new JSONObject();
@ -120,7 +116,7 @@ public class AliyunContentAuditUtil {
} }
/** /**
* 批量文本审核上限100条单条不超过600字 * 批量普通文本审核上限100条单条不超过600字
*/ */
public TextModerationResponse batchTextModeration(List<String> contents) { public TextModerationResponse batchTextModeration(List<String> contents) {
if (contents == null || contents.isEmpty()) { if (contents == null || contents.isEmpty()) {
@ -150,8 +146,8 @@ public class AliyunContentAuditUtil {
} }
// ===================== 文本审核Plus ===================== // ===================== 文本审核Plus =====================
//nickname_detection_pro 用户昵称检测_专业版(用户昵称) ;ugc_moderation_byllm_pro UGC场景文本审核大模型服务_专业版(个人简介 / 作品内容) //nickname_detection_pro 用户昵称检测_专业版; ugc_moderation_byllm_pro UGC 场景文本审核大模型服务_专业版;
//comment_detection_pro 公聊评论内容检测_专业版(评论); ugc_moderation_byllm UGC场景文本审核大模型服务 (作品标题) //comment_detection_pro 公聊评论内容检测_专业版(评论); ugc_moderation_byllm UGC 场景文本审核大模型服务;
public TextModerationPlusResponse textModerationPlus(String content, String service) { public TextModerationPlusResponse textModerationPlus(String content, String service) {
return executeWithFailover(client -> { return executeWithFailover(client -> {
JSONObject params = new JSONObject(); JSONObject params = new JSONObject();
@ -196,9 +192,8 @@ public class AliyunContentAuditUtil {
} }
// ===================== 图片审核 ===================== // ===================== 图片审核 =====================
// 头像图片检测:profilePhotoCheck (头像) ; AI生成图片鉴别_含隐式标识版:aigcDetectorFull(AI生成图片) ; // 头像图片检测:profilePhotoCheck; AI生成图片鉴别_含隐式标识版:aigcDetectorFull;大小模型融合图片审核服务:postlmageCheckByVL;
// 大小模型融合图片审核服务:postlmageCheckByVL (用户上传的图片) ; OSS基线检测(OSS普惠版专用):oss_baselineCheck // 通用图片审核大模型服务:baselineCheckByVL; 图片万物识别:generalRecognition; 营销素材检测:advertisingCheck
// 通用图片审核大模型服务:baselineCheckByVL(用户作品);图片万物识别:generalRecognition ;营销素材检测:advertisingCheck
public ImageModerationResponse imageModeration(String imageUrl, String service) { public ImageModerationResponse imageModeration(String imageUrl, String service) {
return executeWithFailover(client -> { return executeWithFailover(client -> {
JSONObject params = new JSONObject(); JSONObject params = new JSONObject();
@ -217,7 +212,7 @@ public class AliyunContentAuditUtil {
return executeWithFailover(client -> { return executeWithFailover(client -> {
JSONObject params = new JSONObject(); JSONObject params = new JSONObject();
params.put("imageUrl", imageUrl); params.put("imageUrl", imageUrl);
params.put("dataId", java.util.UUID.randomUUID().toString()); // params.put("dataId", java.util.UUID.randomUUID().toString());
ImageAsyncModerationRequest request = new ImageAsyncModerationRequest() ImageAsyncModerationRequest request = new ImageAsyncModerationRequest()
.setService(service != null ? service : "baselineCheckByVL") .setService(service != null ? service : "baselineCheckByVL")
@ -227,6 +222,7 @@ public class AliyunContentAuditUtil {
}); });
} }
// ===================== 查询图片审核异步结果 =====================
public DescribeImageModerationResultResponse describeImageModerationResult(String reqId) { public DescribeImageModerationResultResponse describeImageModerationResult(String reqId) {
return executeWithFailover(client -> { return executeWithFailover(client -> {
DescribeImageModerationResultRequest request = new DescribeImageModerationResultRequest() DescribeImageModerationResultRequest request = new DescribeImageModerationResultRequest()
@ -250,16 +246,14 @@ public class AliyunContentAuditUtil {
}); });
} }
// 视频审核不支持批量,使用 videoModeration 逐个调用
// ===================== 查询视频审核结果 ===================== // ===================== 查询视频审核结果 =====================
public VideoModerationResultResponse videoModerationResult(String taskId) { public VideoModerationResultResponse videoModerationResult(String taskId, String service) {
return executeWithFailover(client -> { return executeWithFailover(client -> {
JSONObject params = new JSONObject(); JSONObject params = new JSONObject();
params.put("taskId", taskId); params.put("taskId", taskId);
VideoModerationResultRequest request = new VideoModerationResultRequest() VideoModerationResultRequest request = new VideoModerationResultRequest()
.setService("videoDetection") .setService(service != null ? service : "videoDetection")
.setServiceParameters(params.toJSONString()); .setServiceParameters(params.toJSONString());
return client.videoModerationResult(request); return client.videoModerationResult(request);

Loading…
Cancel
Save