历史top1 字段修复
This commit is contained in:
parent
f7590e05a5
commit
6b298b336e
@ -51,7 +51,7 @@ public class HistoricalTop1QryExe {
|
|||||||
|
|
||||||
// 查询最近10周的Top1
|
// 查询最近10周的Top1
|
||||||
List<HistoricalWeekTop1CO> historicalList = new ArrayList<>();
|
List<HistoricalWeekTop1CO> historicalList = new ArrayList<>();
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 1; i <= 5; i++) {
|
||||||
// 获取往前推i周的周一cycleKey
|
// 获取往前推i周的周一cycleKey
|
||||||
String cycleKey = getWeekMondayCycleKey(i);
|
String cycleKey = getWeekMondayCycleKey(i);
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ public class HistoricalTop1QryExe {
|
|||||||
|
|
||||||
HistoricalWeekTop1CO weekTop1 = new HistoricalWeekTop1CO();
|
HistoricalWeekTop1CO weekTop1 = new HistoricalWeekTop1CO();
|
||||||
weekTop1.setCycleKey(cycleKey);
|
weekTop1.setCycleKey(cycleKey);
|
||||||
weekTop1.setCycleDisplay(generateCycleDisplay(cycleKey));
|
weekTop1.setCycleDisplay(generateWeekEndDate(cycleKey));
|
||||||
weekTop1.setTopUser(rankingList.getRankingList().get(0));
|
weekTop1.setTopUser(rankingList.getRankingList().get(0));
|
||||||
historicalList.add(weekTop1);
|
historicalList.add(weekTop1);
|
||||||
}
|
}
|
||||||
@ -112,24 +112,25 @@ public class HistoricalTop1QryExe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成周期显示文本
|
* 根据任意日期,返回其所在 ISO 周的周日(即该周最后一天)
|
||||||
*
|
* ISO 周:周一为第一天,周日为最后一天
|
||||||
* @param cycleKey 周期标识(yyyyMMdd格式)
|
*
|
||||||
* @return 周期显示文本(示例:2025年第1周)
|
* @param dateKey 任意日期,格式 yyyyMMdd
|
||||||
|
* @return 该 ISO 周周日的日期,格式 yyyy-MM-dd
|
||||||
*/
|
*/
|
||||||
private String generateCycleDisplay(String cycleKey) {
|
private String generateWeekEndDate(String dateKey) {
|
||||||
try {
|
try {
|
||||||
LocalDate date = LocalDate.parse(cycleKey, DateTimeFormatter.ofPattern("yyyyMMdd"));
|
LocalDate inputDate = LocalDate.parse(dateKey, DateTimeFormatter.ofPattern("yyyyMMdd"));
|
||||||
int year = date.getYear();
|
|
||||||
|
// 获取该日期所在 ISO 周的周一
|
||||||
// 获取周数(ISO 8601标准)
|
LocalDate monday = inputDate.with(DayOfWeek.MONDAY);
|
||||||
WeekFields weekFields = WeekFields.of(Locale.getDefault());
|
// 周一 + 6 天 = 周日
|
||||||
int weekOfYear = date.get(weekFields.weekOfWeekBasedYear());
|
LocalDate sunday = monday.plusDays(6);
|
||||||
|
|
||||||
return String.format("%d年第%d周", year, weekOfYear);
|
return sunday.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("生成周期显示文本失败, cycleKey={}", cycleKey, e);
|
log.warn("生成周结束日期失败, dateKey={}", dateKey, e);
|
||||||
return cycleKey;
|
return dateKey;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user