Răsfoiți Sursa

bugfix:5392 (测试环境-1回)评价(提测0616):评价受限10天应该到10天的零点

刘云鑫 1 zi în urmă
părinte
comite
18857b5af6

+ 1 - 1
alien-store/src/main/java/shop/alien/store/service/StoreCommentAppealService.java

@@ -108,7 +108,7 @@ public interface StoreCommentAppealService extends IService<StoreCommentAppeal>
      * 判断用户是否可以评价,并返回最新申诉通过记录及10天冷却倒计时
      *
      * @param userId 用户ID
-     * @return canRate-是否可评价, passedCount-近30天申诉通过次数, latestPassedAppeal-最新通过记录, countdown-10天内剩余冷却(X天X小时
+     * @return canRate-是否可评价, passedCount-近30天申诉通过次数, latestPassedAppeal-最新通过记录, countdown-10天内剩余冷却(X天)
      */
     Map<String, Object> canRate(Integer userId);
 }

+ 26 - 26
alien-store/src/main/java/shop/alien/store/service/impl/StoreCommentAppealServiceImpl.java

@@ -36,8 +36,8 @@ import shop.alien.util.common.safe.TextModerationUtil;
 
 import java.net.URLEncoder;
 import java.text.SimpleDateFormat;
-import java.time.Duration;
-import java.time.LocalDateTime;
+import java.time.temporal.ChronoUnit;
+import java.time.LocalDate;
 import java.time.ZoneId;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -727,51 +727,51 @@ public class StoreCommentAppealServiceImpl extends ServiceImpl<StoreCommentAppea
         int passedCount = passedAppealList.size();
         // 列表已按 updated_time 降序,第一条即为最新通过记录
         StoreCommentAppeal latestPassedAppeal = passedAppealList.isEmpty() ? null : passedAppealList.get(0);
-        long countdownMillis = 0l;
+        String countdown = "0天";
+        long remainingDays = 0L;
         if (passedCount > 3) {
-            countdownMillis = calculateAppealPassCooldownCountdown(latestPassedAppeal);
+            remainingDays = resolveAppealPassCooldownRemainingDays(latestPassedAppeal);
+            countdown = calculateAppealPassCooldownCountdown(remainingDays);
         }
 
-        boolean canRate = passedCount <= 3 || countdownMillis <= 0;
+        boolean canRate = passedCount <= 3 || remainingDays <= 0;
         resultMap.put("canRate", canRate);
         resultMap.put("passedCount", passedCount);
         resultMap.put("latestPassedAppeal", latestPassedAppeal);
-        resultMap.put("countdown", formatCountdownToDayHour(countdownMillis));
+        resultMap.put("countdown", countdown);
 
         log.info("StoreCommentAppealServiceImpl.canRate result, userId={}, canRate={}, passedCount={}, countdown={}",
-                userId, canRate, passedCount, formatCountdownToDayHour(countdownMillis));
+                userId, canRate, passedCount, countdown);
         return resultMap;
     }
 
     /**
-     * 将毫秒倒计时转换为「X天X小时」格式
+     * 计算申诉通过后的10天冷却倒计时(仅天数)
      */
-    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 + "小时";
+    private String calculateAppealPassCooldownCountdown(long remainingDays) {
+        String countdown = remainingDays + "天";
+        log.debug("calculateAppealPassCooldownCountdown, remainingDays={}, countdown={}", remainingDays, countdown);
+        return countdown;
     }
 
     /**
-     * 计算申诉通过后的10天冷却倒计时(毫秒
-     * 以申诉更新时间(通过时间)为起点,10天内返回剩余毫秒数,否则返回0
+     * 解析申诉通过后10天冷却剩余天数(按自然日计算,不含小时)
+     * 以申诉更新日期(通过日期)为起点,满10个自然日后冷却结束
      */
-    private long calculateAppealPassCooldownCountdown(StoreCommentAppeal latestPassedAppeal) {
+    private long resolveAppealPassCooldownRemainingDays(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();
+        LocalDate passDate = latestPassedAppeal.getUpdatedTime().toInstant()
+                .atZone(ZoneId.systemDefault()).toLocalDate();
+        LocalDate cooldownEndDate = passDate.plusDays(10);
+        LocalDate today = LocalDate.now();
+        if (!today.isBefore(cooldownEndDate)) {
+            log.debug("resolveAppealPassCooldownRemainingDays: 冷却已结束, passDate={}, cooldownEndDate={}",
+                    passDate, cooldownEndDate);
+            return 0L;
         }
-        return 0L;
+        return ChronoUnit.DAYS.between(today, cooldownEndDate);
     }
 
     /**