Commit ecd7f089 by 范富荣

优化录音复盘生成接口

1 parent 7c8608ec
...@@ -234,28 +234,38 @@ public class SupervisorTaskInfoController { ...@@ -234,28 +234,38 @@ public class SupervisorTaskInfoController {
} }
/** /**
* 生成最近 3 年所有周一到周日 * 生成最近 N 年所有周一到周日(默认为 3 年)
* *
* @return * @param request 请求对象
* @return 返回每周的日期范围列表
*/ */
@ApiOperation(value = "生成最近 3 年所有周一到周日") @ApiOperation(value = "生成最近 N 年所有周一到周日")
@ServiceMethod(method = "dj.api.supervisor.mini.get.generateWeeklyRanges", needInSession = NeedInSessionType.NO) @ServiceMethod(method = "dj.api.supervisor.mini.get.generateWeeklyRanges", needInSession = NeedInSessionType.NO)
public RopResponse<List<Map<String, String>>> generateWeeklyRanges(AbstractRopRequest request) { public RopResponse<List<Map<String, String>>> generateWeeklyRanges(AbstractRopRequest request) {
int yearCount = Integer.parseInt(environment.getProperty("supervisor.weekly.range.years", "3"));
LocalDate now = LocalDate.now(); LocalDate now = LocalDate.now();
// 获取当前周的周一
LocalDate currentMonday = now.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)); LocalDate currentMonday = now.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
LocalDate endMonday = now.minusYears(yearCount).with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
// 从配置中获取年数,默认为 3 年
int yearCount = Integer.parseInt(environment.getProperty("supervisor.weekly.range.years", "3"));
// 计算起始限制日期(N 年前的周一)
LocalDate startDateLimit = now.minusYears(yearCount).with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
// 预估容量:每年约 53 周,避免底层数组频繁扩容 // 预估周数以优化 ArrayList 容量 (每年约 52 周)
List<Map<String, String>> result = new ArrayList<>(yearCount * 53 + 1); List<Map<String, String>> result = new ArrayList<>(yearCount * 53);
while (!currentMonday.isBefore(endMonday)) { while (!currentMonday.isBefore(startDateLimit)) {
Map<String, String> weekRange = new HashMap<>(4); // 初始化容量为 4 LocalDate sunday = currentMonday.plusDays(6);
weekRange.put("startDate", currentMonday.toString()); // 周一
weekRange.put("endDate", currentMonday.plusDays(6).toString()); // 周日 Map<String, String> weekRange = new HashMap<>(4);
weekRange.put("startDate", currentMonday.toString()); // 周一
weekRange.put("endDate", sunday.toString()); // 周日
result.add(weekRange); result.add(weekRange);
currentMonday = currentMonday.minusWeeks(1); // 上一周
// 往前推一周
currentMonday = currentMonday.minusWeeks(1);
} }
return RopResponse.success(result); return RopResponse.success(result);
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!