diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/HistoricalTop1QryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/HistoricalTop1QryExe.java index 845c8a16..3997da9e 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/HistoricalTop1QryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/HistoricalTop1QryExe.java @@ -51,7 +51,7 @@ public class HistoricalTop1QryExe { // 查询最近10周的Top1 List historicalList = new ArrayList<>(); - for (int i = 0; i < 5; i++) { + for (int i = 1; i <= 5; i++) { // 获取往前推i周的周一cycleKey String cycleKey = getWeekMondayCycleKey(i); @@ -75,7 +75,7 @@ public class HistoricalTop1QryExe { HistoricalWeekTop1CO weekTop1 = new HistoricalWeekTop1CO(); weekTop1.setCycleKey(cycleKey); - weekTop1.setCycleDisplay(generateCycleDisplay(cycleKey)); + weekTop1.setCycleDisplay(generateWeekEndDate(cycleKey)); weekTop1.setTopUser(rankingList.getRankingList().get(0)); historicalList.add(weekTop1); } @@ -112,24 +112,25 @@ public class HistoricalTop1QryExe { } /** - * 生成周期显示文本 - * - * @param cycleKey 周期标识(yyyyMMdd格式) - * @return 周期显示文本(示例:2025年第1周) + * 根据任意日期,返回其所在 ISO 周的周日(即该周最后一天) + * ISO 周:周一为第一天,周日为最后一天 + * + * @param dateKey 任意日期,格式 yyyyMMdd + * @return 该 ISO 周周日的日期,格式 yyyy-MM-dd */ - private String generateCycleDisplay(String cycleKey) { + private String generateWeekEndDate(String dateKey) { try { - LocalDate date = LocalDate.parse(cycleKey, DateTimeFormatter.ofPattern("yyyyMMdd")); - int year = date.getYear(); - - // 获取周数(ISO 8601标准) - WeekFields weekFields = WeekFields.of(Locale.getDefault()); - int weekOfYear = date.get(weekFields.weekOfWeekBasedYear()); - - return String.format("%d年第%d周", year, weekOfYear); + LocalDate inputDate = LocalDate.parse(dateKey, DateTimeFormatter.ofPattern("yyyyMMdd")); + + // 获取该日期所在 ISO 周的周一 + LocalDate monday = inputDate.with(DayOfWeek.MONDAY); + // 周一 + 6 天 = 周日 + LocalDate sunday = monday.plusDays(6); + + return sunday.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); } catch (Exception e) { - log.warn("生成周期显示文本失败, cycleKey={}", cycleKey, e); - return cycleKey; + log.warn("生成周结束日期失败, dateKey={}", dateKey, e); + return dateKey; } } }