|
@@ -1,7 +1,10 @@
|
|
|
package shop.alien.second.service.impl;
|
|
package shop.alien.second.service.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
|
|
+import com.alibaba.nacos.api.config.annotation.NacosValue;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
@@ -13,9 +16,10 @@ import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
+import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
|
-import shop.alien.entity.VideoModerationTask;
|
|
|
|
|
|
|
+import shop.alien.entity.SecondVideoTask;
|
|
|
import shop.alien.entity.second.SecondGoods;
|
|
import shop.alien.entity.second.SecondGoods;
|
|
|
import shop.alien.entity.second.SecondGoodsAudit;
|
|
import shop.alien.entity.second.SecondGoodsAudit;
|
|
|
import shop.alien.entity.second.enums.SecondGoodsStatusEnum;
|
|
import shop.alien.entity.second.enums.SecondGoodsStatusEnum;
|
|
@@ -50,10 +54,10 @@ import java.util.stream.Collectors;
|
|
|
public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, SecondGoods> implements SecondGoodsService {
|
|
public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, SecondGoods> implements SecondGoodsService {
|
|
|
|
|
|
|
|
|
|
|
|
|
- @Value("${video.moderation.enabled:false}")
|
|
|
|
|
|
|
+ @Value("${video.moderation.enabled}")
|
|
|
private boolean videoModerationEnabled;
|
|
private boolean videoModerationEnabled;
|
|
|
|
|
|
|
|
- @Value("${video.moderation.block-on-failure:true}")
|
|
|
|
|
|
|
+ @Value("${video.moderation.block-on-failure}")
|
|
|
private boolean videoModerationBlockOnFailure;
|
|
private boolean videoModerationBlockOnFailure;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -230,6 +234,7 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
|
|
|
// TODO 后续配置到数据库 中
|
|
// TODO 后续配置到数据库 中
|
|
|
imgServicesList.add(ImageReviewServiceEnum.TONALITY_IMPROVE.getService());
|
|
imgServicesList.add(ImageReviewServiceEnum.TONALITY_IMPROVE.getService());
|
|
|
imgServicesList.add(ImageReviewServiceEnum.AIGC_CHECK.getService());
|
|
imgServicesList.add(ImageReviewServiceEnum.AIGC_CHECK.getService());
|
|
|
|
|
+// imgServicesList.add(ImageReviewServiceEnum.IMG_QUERY_SECURITY_CHECK.getService());
|
|
|
ImageModerationResultVO response = imageModerationUtil.productPublishCheck(imageUrl,imgServicesList);
|
|
ImageModerationResultVO response = imageModerationUtil.productPublishCheck(imageUrl,imgServicesList);
|
|
|
if ("high".equals(response.getRiskLevel())) {
|
|
if ("high".equals(response.getRiskLevel())) {
|
|
|
// 图片审核不通过或存在高风险
|
|
// 图片审核不通过或存在高风险
|
|
@@ -824,8 +829,114 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
|
|
|
* @param task 视频审核任务
|
|
* @param task 视频审核任务
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
- public void processVideoModerationResult(VideoModerationTask task) {
|
|
|
|
|
-
|
|
|
|
|
|
|
+ public void processVideoModerationResult(SecondVideoTask task) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 查找关联的商品
|
|
|
|
|
+ QueryWrapper<SecondGoods> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
+ queryWrapper.eq("video_task_id", task.getTaskId());
|
|
|
|
|
+ SecondGoods goods = getOne(queryWrapper);
|
|
|
|
|
+
|
|
|
|
|
+ if (goods == null) {
|
|
|
|
|
+ log.warn("未找到关联的商品,任务ID: {}", task.getTaskId());
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 根据审核结果更新商品状态
|
|
|
|
|
+ if ("none".equals(task.getRiskLevel())) {
|
|
|
|
|
+ // 审核通过
|
|
|
|
|
+ goods.setGoodsStatus(SecondGoodsStatusEnum.LISTED.getCode());
|
|
|
|
|
+ goods.setFailedReason("");
|
|
|
|
|
+ goods.setReleaseTime(new Date());
|
|
|
|
|
+ updateById(goods);
|
|
|
|
|
+
|
|
|
|
|
+ // 更新审核记录
|
|
|
|
|
+ createGoodsAudit(goods, "", Constants.AuditStatus.PASSED);
|
|
|
|
|
+
|
|
|
|
|
+ // 发送审核成功消息
|
|
|
|
|
+ sendMessage(goods);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 审核不通过
|
|
|
|
|
+ goods.setGoodsStatus(SecondGoodsStatusEnum.REVIEW_FAILED.getCode());
|
|
|
|
|
+
|
|
|
|
|
+ // 解析审核结果,生成具体的失败原因
|
|
|
|
|
+ String failedReason = parseVideoModerationFailureReason(task);
|
|
|
|
|
+ goods.setFailedReason(failedReason);
|
|
|
|
|
+ updateById(goods);
|
|
|
|
|
+
|
|
|
|
|
+ // 更新审核记录
|
|
|
|
|
+ createGoodsAudit(goods, failedReason, Constants.AuditStatus.FAILED);
|
|
|
|
|
+
|
|
|
|
|
+ // 发送审核失败消息
|
|
|
|
|
+ sendFailedMsg(goods);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("处理视频审核结果时发生异常,任务ID: {}", task.getTaskId(), e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 解析视频审核失败原因
|
|
|
|
|
+ * @param task 视频审核任务
|
|
|
|
|
+ * @return 失败原因
|
|
|
|
|
+ */
|
|
|
|
|
+ private String parseVideoModerationFailureReason(SecondVideoTask task) {
|
|
|
|
|
+ StringBuilder reasonBuilder = new StringBuilder("视频审核不通过,风险等级: " + task.getRiskLevel());
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 解析审核结果JSON
|
|
|
|
|
+ JSONObject resultJson = JSON.parseObject(task.getResult());
|
|
|
|
|
+ if (resultJson != null && resultJson.containsKey("data")) {
|
|
|
|
|
+ JSONObject data = resultJson.getJSONObject("data");
|
|
|
|
|
+
|
|
|
|
|
+ // 处理帧结果(视频画面)
|
|
|
|
|
+ if (data.containsKey("FrameResult")) {
|
|
|
|
|
+ JSONObject frameResult = data.getJSONObject("FrameResult");
|
|
|
|
|
+ if (frameResult != null && frameResult.containsKey("FrameSummarys")) {
|
|
|
|
|
+ JSONArray frameSummarys = frameResult.getJSONArray("FrameSummarys");
|
|
|
|
|
+ if (frameSummarys != null && !frameSummarys.isEmpty()) {
|
|
|
|
|
+ reasonBuilder.append("。检测到违规内容:");
|
|
|
|
|
+ for (int i = 0; i < frameSummarys.size(); i++) {
|
|
|
|
|
+ JSONObject summary = frameSummarys.getJSONObject(i);
|
|
|
|
|
+ String label = summary.getString("Label");
|
|
|
|
|
+ String description = summary.getString("Description");
|
|
|
|
|
+ Integer labelSum = summary.getInteger("LabelSum");
|
|
|
|
|
+
|
|
|
|
|
+ if (label != null && !label.isEmpty()) {
|
|
|
|
|
+ reasonBuilder.append("[").append(description != null ? description : label)
|
|
|
|
|
+ .append("]出现").append(labelSum != null ? labelSum : 1).append("次;");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 处理音频结果
|
|
|
|
|
+ if (data.containsKey("AudioResult")) {
|
|
|
|
|
+ JSONObject audioResult = data.getJSONObject("AudioResult");
|
|
|
|
|
+ if (audioResult != null && audioResult.containsKey("AudioSummarys")) {
|
|
|
|
|
+ JSONArray audioSummarys = audioResult.getJSONArray("AudioSummarys");
|
|
|
|
|
+ if (audioSummarys != null && !audioSummarys.isEmpty()) {
|
|
|
|
|
+ reasonBuilder.append("。检测到违规音频:");
|
|
|
|
|
+ for (int i = 0; i < audioSummarys.size(); i++) {
|
|
|
|
|
+ JSONObject summary = audioSummarys.getJSONObject(i);
|
|
|
|
|
+ String label = summary.getString("Label");
|
|
|
|
|
+ String description = summary.getString("Description");
|
|
|
|
|
+ Integer labelSum = summary.getInteger("LabelSum");
|
|
|
|
|
+
|
|
|
|
|
+ if (label != null && !label.isEmpty()) {
|
|
|
|
|
+ reasonBuilder.append("[").append(description != null ? description : label)
|
|
|
|
|
+ .append("]出现").append(labelSum != null ? labelSum : 1).append("次;");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("解析视频审核结果失败,使用默认原因,任务ID: {}", task.getTaskId(), e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return reasonBuilder.toString();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|