|
|
@@ -9,18 +9,13 @@ import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.google.common.collect.Lists;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
|
-import org.springframework.http.HttpEntity;
|
|
|
-import org.springframework.http.HttpHeaders;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
-import org.springframework.http.MediaType;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.http.*;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
@@ -28,25 +23,22 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.multipart.MultipartRequest;
|
|
|
import shop.alien.entity.store.*;
|
|
|
import shop.alien.entity.store.excelVo.util.ExcelExporter;
|
|
|
-import shop.alien.entity.store.vo.StoreCommentAppealLogVo;
|
|
|
-import shop.alien.entity.store.vo.StoreCommentAppealInfoVo;
|
|
|
-import shop.alien.entity.store.vo.StoreCommentAppealSupplementVo;
|
|
|
-import shop.alien.entity.store.vo.StoreCommentAppealVo;
|
|
|
-import shop.alien.entity.store.vo.WebSocketVo;
|
|
|
+import shop.alien.entity.store.vo.*;
|
|
|
import shop.alien.mapper.*;
|
|
|
import shop.alien.store.config.WebSocketProcess;
|
|
|
import shop.alien.store.service.CommonRatingService;
|
|
|
import shop.alien.store.service.StoreCommentAppealService;
|
|
|
import shop.alien.store.util.FileUploadUtil;
|
|
|
import shop.alien.store.util.ai.AiAuthTokenUtil;
|
|
|
+import shop.alien.util.common.constant.CommentSourceTypeEnum;
|
|
|
import shop.alien.util.common.netease.TextCheckUtil;
|
|
|
-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.constant.CommentSourceTypeEnum;
|
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.Duration;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -190,13 +182,13 @@ public class StoreCommentAppealServiceImpl extends ServiceImpl<StoreCommentAppea
|
|
|
return 3;
|
|
|
}*/
|
|
|
|
|
|
- List<String> servicesList = Lists.newArrayList();
|
|
|
- servicesList.add(TextReviewServiceEnum.COMMENT_DETECTION_PRO.getService());
|
|
|
- servicesList.add(TextReviewServiceEnum.LLM_QUERY_MODERATION.getService());
|
|
|
- TextModerationResultVO textCheckResult = textModerationUtil.invokeFunction(appealReason, servicesList);
|
|
|
- if ("high".equals(textCheckResult.getRiskLevel())) {
|
|
|
- return 3;
|
|
|
- }
|
|
|
+// List<String> servicesList = Lists.newArrayList();
|
|
|
+// servicesList.add(TextReviewServiceEnum.COMMENT_DETECTION_PRO.getService());
|
|
|
+// servicesList.add(TextReviewServiceEnum.LLM_QUERY_MODERATION.getService());
|
|
|
+// TextModerationResultVO textCheckResult = textModerationUtil.invokeFunction(appealReason, servicesList);
|
|
|
+// if ("high".equals(textCheckResult.getRiskLevel())) {
|
|
|
+// return 3;
|
|
|
+// }
|
|
|
|
|
|
List<String> fileNameSet = new ArrayList<>(multipartRequest.getMultiFileMap().keySet());
|
|
|
LambdaQueryWrapper<StoreCommentAppeal> wrapper = new LambdaQueryWrapper<>();
|
|
|
@@ -274,14 +266,14 @@ public class StoreCommentAppealServiceImpl extends ServiceImpl<StoreCommentAppea
|
|
|
// return storeCommentAppealInfoVo;
|
|
|
// }
|
|
|
|
|
|
- List<String> servicesList = Lists.newArrayList();
|
|
|
- servicesList.add(TextReviewServiceEnum.COMMENT_DETECTION_PRO.getService());
|
|
|
- servicesList.add(TextReviewServiceEnum.LLM_QUERY_MODERATION.getService());
|
|
|
- TextModerationResultVO textCheckResult = textModerationUtil.invokeFunction(appealReason, servicesList);
|
|
|
- if ("high".equals(textCheckResult.getRiskLevel())) {
|
|
|
- storeCommentAppealInfoVo.setResult(3);
|
|
|
- return storeCommentAppealInfoVo;
|
|
|
- }
|
|
|
+// List<String> servicesList = Lists.newArrayList();
|
|
|
+// servicesList.add(TextReviewServiceEnum.COMMENT_DETECTION_PRO.getService());
|
|
|
+// servicesList.add(TextReviewServiceEnum.LLM_QUERY_MODERATION.getService());
|
|
|
+// TextModerationResultVO textCheckResult = textModerationUtil.invokeFunction(appealReason, servicesList);
|
|
|
+// if ("high".equals(textCheckResult.getRiskLevel())) {
|
|
|
+// storeCommentAppealInfoVo.setResult(3);
|
|
|
+// return storeCommentAppealInfoVo;
|
|
|
+// }
|
|
|
|
|
|
LambdaQueryWrapper<StoreCommentAppeal> wrapper = new LambdaQueryWrapper<>();
|
|
|
//待审批, 已通过
|
|
|
@@ -722,9 +714,64 @@ public class StoreCommentAppealServiceImpl extends ServiceImpl<StoreCommentAppea
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 判断用户是否可以评价
|
|
|
+ * 规则:近30天申诉通过次数不超过3次,且距最近一次申诉通过未满10天不可评价
|
|
|
+ */
|
|
|
@Override
|
|
|
- public Boolean canRate(Integer userId) {
|
|
|
- return storeCommentAppealMapper.canRate(userId) > 3;
|
|
|
+ public Map<String, Object> canRate(Integer userId) {
|
|
|
+ log.info("StoreCommentAppealServiceImpl.canRate, userId={}", userId);
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+ List<StoreCommentAppeal> passedAppealList = storeCommentAppealMapper.canRate(userId);
|
|
|
+
|
|
|
+ int passedCount = passedAppealList.size();
|
|
|
+ // 列表已按 updated_time 降序,第一条即为最新通过记录
|
|
|
+ StoreCommentAppeal latestPassedAppeal = passedAppealList.isEmpty() ? null : passedAppealList.get(0);
|
|
|
+ long countdownMillis = 0l;
|
|
|
+ if (passedCount > 3) {
|
|
|
+ countdownMillis = calculateAppealPassCooldownCountdown(latestPassedAppeal);
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean canRate = passedCount <= 3 || countdownMillis <= 0;
|
|
|
+ resultMap.put("canRate", canRate);
|
|
|
+ resultMap.put("passedCount", passedCount);
|
|
|
+ resultMap.put("latestPassedAppeal", latestPassedAppeal);
|
|
|
+ resultMap.put("countdown", formatCountdownToDayHour(countdownMillis));
|
|
|
+
|
|
|
+ log.info("StoreCommentAppealServiceImpl.canRate result, userId={}, canRate={}, passedCount={}, countdown={}",
|
|
|
+ userId, canRate, passedCount, formatCountdownToDayHour(countdownMillis));
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将毫秒倒计时转换为「X天X小时」格式
|
|
|
+ */
|
|
|
+ private String formatCountdownToDayHour(long countdownMillis) {
|
|
|
+ if (countdownMillis <= 0) {
|
|
|
+ return "0天0小时";
|
|
|
+ }
|
|
|
+ long totalHours = countdownMillis / (1000 * 60 * 60);
|
|
|
+ long days = totalHours / 24;
|
|
|
+ long hours = totalHours % 24;
|
|
|
+ return days + "天" + hours + "小时";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算申诉通过后的10天冷却倒计时(毫秒)
|
|
|
+ * 以申诉更新时间(通过时间)为起点,10天内返回剩余毫秒数,否则返回0
|
|
|
+ */
|
|
|
+ private long calculateAppealPassCooldownCountdown(StoreCommentAppeal latestPassedAppeal) {
|
|
|
+ if (latestPassedAppeal == null || latestPassedAppeal.getUpdatedTime() == null) {
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
+ LocalDateTime passTime = latestPassedAppeal.getUpdatedTime().toInstant()
|
|
|
+ .atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
+ LocalDateTime cooldownEndTime = passTime.plusDays(10);
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ if (now.isBefore(cooldownEndTime)) {
|
|
|
+ return Duration.between(now, cooldownEndTime).toMillis();
|
|
|
+ }
|
|
|
+ return 0L;
|
|
|
}
|
|
|
|
|
|
/**
|