|
|
@@ -15,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import shop.alien.entity.result.R;
|
|
|
@@ -24,22 +25,24 @@ import shop.alien.entity.store.vo.CommonRatingVo;
|
|
|
import shop.alien.entity.store.vo.StoreInfoScoreVo;
|
|
|
import shop.alien.entity.store.vo.WebSocketVo;
|
|
|
import shop.alien.mapper.*;
|
|
|
-import shop.alien.entity.store.TagsSynonym;
|
|
|
import shop.alien.store.config.WebSocketProcess;
|
|
|
import shop.alien.store.service.CommonCommentService;
|
|
|
import shop.alien.store.service.CommonRatingService;
|
|
|
import shop.alien.store.util.CommonConstant;
|
|
|
+import shop.alien.store.util.ai.AiContentModerationUtil;
|
|
|
+import shop.alien.store.util.ai.AiVideoModerationUtil;
|
|
|
+import shop.alien.util.common.DateUtils;
|
|
|
import shop.alien.util.common.constant.CommentSourceTypeEnum;
|
|
|
import shop.alien.util.common.constant.RatingBusinessTypeEnum;
|
|
|
-import shop.alien.util.common.safe.TextModerationResultVO;
|
|
|
import shop.alien.util.common.safe.TextModerationUtil;
|
|
|
import shop.alien.util.common.safe.TextReviewServiceEnum;
|
|
|
-import shop.alien.util.common.DateUtils;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -72,8 +75,10 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
private final TagsSynonymMapper tagsSynonymMapper;
|
|
|
private final CommonCommentService commonCommentService;
|
|
|
private final StoreCommentAppealMapper storeCommentAppealMapper;
|
|
|
-
|
|
|
-
|
|
|
+ private final AiContentModerationUtil aiContentModerationUtil;
|
|
|
+ @Qualifier("commonVideoTaskExecutor")
|
|
|
+ private final ExecutorService commonVideoTaskExecutor;
|
|
|
+ private final AiVideoModerationUtil aiVideoModerationUtil;
|
|
|
|
|
|
public static final List<String> SERVICES_LIST = ImmutableList.of(
|
|
|
TextReviewServiceEnum.COMMENT_DETECTION_PRO.getService(),
|
|
|
@@ -84,14 +89,8 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
|
|
|
@Override
|
|
|
public Integer saveCommonRating(CommonRating commonRating) {
|
|
|
- // 1. 文本审核
|
|
|
+ // 1. 文本审核 + 视频审核(评价有图片和视频)
|
|
|
try {
|
|
|
- TextModerationResultVO textCheckResult = textModerationUtil.invokeFunction(commonRating.getContent(), SERVICES_LIST);
|
|
|
- if ("high".equals(textCheckResult.getRiskLevel())) {
|
|
|
- return 2;
|
|
|
- }
|
|
|
- // 2.审核通过,设置评价状态为已审核
|
|
|
- commonRating.setAuditStatus(1);
|
|
|
// 手动存评分1,2,3
|
|
|
if (StringUtils.isNotEmpty(commonRating.getOtherScore())) {
|
|
|
JSONObject parse = JSONObject.parse(commonRating.getOtherScore());
|
|
|
@@ -100,8 +99,62 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
commonRating.setScoreThree(parse.getDouble("scoreThree"));
|
|
|
}
|
|
|
int i = this.save(commonRating) ? 0 : 1;
|
|
|
- // 对不同的businessType进行不同的处理,
|
|
|
- doBusinessWithType(commonRating);
|
|
|
+ // 一次遍历完成分类,避免多次流式处理
|
|
|
+ Map<String, List<String>> urlCategoryMap = StoreRenovationRequirementServiceImpl.classifyUrls(Arrays.asList(commonRating.getImageUrls().split(",")));
|
|
|
+ AiContentModerationUtil.AuditResult auditResult = aiContentModerationUtil.auditContent(commonRating.getContent(), urlCategoryMap.get("image"));
|
|
|
+ if (!auditResult.isPassed()) {
|
|
|
+ // 审核不通过
|
|
|
+ CommonRating rating = this.getById(commonRating.getId());
|
|
|
+ rating.setAuditStatus(2);
|
|
|
+ rating.setAuditReason(auditResult.getFailureReason());
|
|
|
+ this.saveOrUpdate(rating);
|
|
|
+ } else{
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ AiVideoModerationUtil.VideoAuditResult videoAuditResult = null;
|
|
|
+ try {
|
|
|
+ // 调用审核接口,增加超时控制(避免接口挂死)
|
|
|
+ videoAuditResult = CompletableFuture.supplyAsync(
|
|
|
+ () -> aiVideoModerationUtil.auditVideos(urlCategoryMap.get("video")),
|
|
|
+ commonVideoTaskExecutor
|
|
|
+ ).get();
|
|
|
+
|
|
|
+ // 审核不通过则更新状态和原因
|
|
|
+ if (Objects.nonNull(videoAuditResult) && !videoAuditResult.isPassed()) {
|
|
|
+ // 重新查询最新的rating,避免并发覆盖
|
|
|
+ CommonRating rating = this.getById(commonRating.getId());
|
|
|
+ if (Objects.isNull(rating)) {
|
|
|
+ log.error("视频审核后更新失败,rating,ID:{}", rating.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ rating.setAuditStatus(2);
|
|
|
+ // 失败原因
|
|
|
+ rating.setAuditReason(videoAuditResult.getFailureReason());
|
|
|
+ this.saveOrUpdate(rating);
|
|
|
+ log.info("视频审核不通过,已更新状态,requirementID:{},原因:{}",
|
|
|
+ rating.getId(), videoAuditResult.getFailureReason());
|
|
|
+ } else if (Objects.nonNull(videoAuditResult) && videoAuditResult.isPassed()) {
|
|
|
+ // 审核通过也更新状态(可选,根据业务需求)
|
|
|
+ CommonRating rating = this.getById(commonRating.getId());
|
|
|
+ if (Objects.nonNull(rating)) {
|
|
|
+ rating.setAuditStatus(1);
|
|
|
+// latestRequirement.setAuditReason(null);
|
|
|
+ this.saveOrUpdate(rating);
|
|
|
+ // 对不同的businessType进行不同的处理,
|
|
|
+ doBusinessWithType(commonRating);
|
|
|
+ log.info("视频审核通过,已更新状态,requirementID:{}", rating.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("视频审核接口调用异常,commonRating:{}", commonRating.getId(), e);
|
|
|
+ CommonRating rating = this.getById(commonRating.getId());
|
|
|
+ if (Objects.nonNull(rating)) {
|
|
|
+ rating.setAuditStatus(2);
|
|
|
+ rating.setAuditReason("视频审核接口调用异常:" + e.getMessage()); // 实际需捕获具体异常信息
|
|
|
+ this.saveOrUpdate(rating);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, commonVideoTaskExecutor);
|
|
|
+ }
|
|
|
return i;
|
|
|
} catch (Exception e) {
|
|
|
log.error("CommonRatingService.saveCommonRating ERROR Msg={}", e.getMessage());
|