|
@@ -10,9 +10,12 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
+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.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.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;
|
|
@@ -26,10 +29,12 @@ import shop.alien.mapper.second.SecondGoodsAuditMapper;
|
|
|
import shop.alien.mapper.second.SecondGoodsMapper;
|
|
import shop.alien.mapper.second.SecondGoodsMapper;
|
|
|
import shop.alien.second.feign.AlienStoreFeign;
|
|
import shop.alien.second.feign.AlienStoreFeign;
|
|
|
import shop.alien.second.service.SecondGoodsService;
|
|
import shop.alien.second.service.SecondGoodsService;
|
|
|
|
|
+import shop.alien.second.service.VideoModerationService;
|
|
|
import shop.alien.util.common.Constants;
|
|
import shop.alien.util.common.Constants;
|
|
|
import shop.alien.util.common.VideoUtils;
|
|
import shop.alien.util.common.VideoUtils;
|
|
|
import shop.alien.util.common.safe.*;
|
|
import shop.alien.util.common.safe.*;
|
|
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -39,10 +44,26 @@ import java.util.stream.Collectors;
|
|
|
/**
|
|
/**
|
|
|
* 二手商品服务实现类
|
|
* 二手商品服务实现类
|
|
|
*/
|
|
*/
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
@Service
|
|
|
@RequiredArgsConstructor
|
|
@RequiredArgsConstructor
|
|
|
public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, SecondGoods> implements SecondGoodsService {
|
|
public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, SecondGoods> implements SecondGoodsService {
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ @Value("${video.moderation.enabled:false}")
|
|
|
|
|
+ private boolean videoModerationEnabled;
|
|
|
|
|
+
|
|
|
|
|
+ @Value("${video.moderation.block-on-failure:true}")
|
|
|
|
|
+ private boolean videoModerationBlockOnFailure;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 视频审核服务
|
|
|
|
|
+ */
|
|
|
|
|
+ private final VideoModerationService videoModerationService;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 视频工具类
|
|
|
|
|
+ */
|
|
|
private final VideoUtils videoUtils;
|
|
private final VideoUtils videoUtils;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -174,7 +195,7 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
/**
|
|
/**
|
|
|
- * 执行内容审核(图片和文本)
|
|
|
|
|
|
|
+ * 执行内容审核(图片、文本和视频)
|
|
|
* @param goods 商品信息
|
|
* @param goods 商品信息
|
|
|
* @param goodsDTO 商品DTO信息
|
|
* @param goodsDTO 商品DTO信息
|
|
|
* @return 审核结果
|
|
* @return 审核结果
|
|
@@ -211,7 +232,7 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
|
|
|
imgServicesList.add(ImageReviewServiceEnum.AIGC_CHECK.getService());
|
|
imgServicesList.add(ImageReviewServiceEnum.AIGC_CHECK.getService());
|
|
|
ImageModerationResultVO response = imageModerationUtil.productPublishCheck(imageUrl,imgServicesList);
|
|
ImageModerationResultVO response = imageModerationUtil.productPublishCheck(imageUrl,imgServicesList);
|
|
|
if ("high".equals(response.getRiskLevel())) {
|
|
if ("high".equals(response.getRiskLevel())) {
|
|
|
- // 文本审核不通过或存在高风险
|
|
|
|
|
|
|
+ // 图片审核不通过或存在高风险
|
|
|
goods.setGoodsStatus(SecondGoodsStatusEnum.REVIEW_FAILED.getCode()); // 审核失败
|
|
goods.setGoodsStatus(SecondGoodsStatusEnum.REVIEW_FAILED.getCode()); // 审核失败
|
|
|
goods.setFailedReason("图片审核不通过:图片中包含" + (response.getDescriptions() != null ? response.getDescriptions() : "高风险内容"));
|
|
goods.setFailedReason("图片审核不通过:图片中包含" + (response.getDescriptions() != null ? response.getDescriptions() : "高风险内容"));
|
|
|
// 插入审核记录
|
|
// 插入审核记录
|
|
@@ -222,6 +243,41 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // 视频审核
|
|
|
|
|
+ if (videoModerationEnabled) {
|
|
|
|
|
+ List<String> videoUrls = extractVideoUrls(goodsDTO.getImgUrl());
|
|
|
|
|
+ if (!videoUrls.isEmpty()) {
|
|
|
|
|
+ // 提交视频审核任务
|
|
|
|
|
+ List<String> taskIds = new ArrayList<>();
|
|
|
|
|
+ for (String videoUrl : videoUrls) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ String taskId = videoModerationService.submitVideoModerationTask(videoUrl);
|
|
|
|
|
+ taskIds.add(taskId);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("提交视频审核任务失败,视频URL: {}", videoUrl, e);
|
|
|
|
|
+ if (videoModerationBlockOnFailure) {
|
|
|
|
|
+ // 视频审核提交失败,设置为审核失败状态
|
|
|
|
|
+ goods.setGoodsStatus(SecondGoodsStatusEnum.REVIEW_FAILED.getCode());
|
|
|
|
|
+ goods.setFailedReason("视频审核提交失败: " + e.getMessage());
|
|
|
|
|
+ createGoodsAudit(goods, "视频审核提交失败", Constants.AuditStatus.FAILED);
|
|
|
|
|
+ sendFailedMsg(goods);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 如果成功提交了视频审核任务,设置商品状态为审核中
|
|
|
|
|
+ if (!taskIds.isEmpty()) {
|
|
|
|
|
+ goods.setGoodsStatus(SecondGoodsStatusEnum.UNDER_REVIEW.getCode()); // 审核中
|
|
|
|
|
+ goods.setVideoTaskId(taskIds.get(0)); // 保存第一个任务ID到商品表
|
|
|
|
|
+ goods.setFailedReason("");
|
|
|
|
|
+ updateById(goods);
|
|
|
|
|
+ createGoodsAudit(goods, "", SecondGoodsStatusEnum.UNDER_REVIEW.getCode());
|
|
|
|
|
+ return true; // 异步处理,直接返回
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// 如果所有审核都通过,设置为上架状态
|
|
// 如果所有审核都通过,设置为上架状态
|
|
|
goods.setGoodsStatus(SecondGoodsStatusEnum.LISTED.getCode()); // 上架
|
|
goods.setGoodsStatus(SecondGoodsStatusEnum.LISTED.getCode()); // 上架
|
|
@@ -234,6 +290,25 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
|
|
|
sendMessage(goods);
|
|
sendMessage(goods);
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 从图片URL列表中提取视频URL
|
|
|
|
|
+ * @param imageUrls 图片URL列表
|
|
|
|
|
+ * @return 视频URL列表
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<String> extractVideoUrls(List<String> imageUrls) {
|
|
|
|
|
+ if (CollectionUtil.isEmpty(imageUrls)) {
|
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<String> videoUrls = new ArrayList<>();
|
|
|
|
|
+ for (String url : imageUrls) {
|
|
|
|
|
+ if (isVideoUrl(url)) {
|
|
|
|
|
+ videoUrls.add(url);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return videoUrls;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 创建商品审核记录
|
|
* 创建商品审核记录
|
|
@@ -745,6 +820,15 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * 处理视频审核结果
|
|
|
|
|
+ * @param task 视频审核任务
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void processVideoModerationResult(VideoModerationTask task) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* 查询搜索结果
|
|
* 查询搜索结果
|
|
|
* @param page 分页参数
|
|
* @param page 分页参数
|
|
|
* @param secondGoodsVo 查询参数
|
|
* @param secondGoodsVo 查询参数
|
|
@@ -896,4 +980,5 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
}
|
|
}
|