修复月核定流量接口

master
cxw 2025-01-22 17:31:01 +08:00
parent dd8d82f3a5
commit 80024e0b44
2 changed files with 20 additions and 3 deletions

View File

@ -93,9 +93,12 @@ public class StWaterRController {
@GetMapping("/getResMonthEcoFlow") @GetMapping("/getResMonthEcoFlow")
public R<Map<Integer, Object>> getResMonthEcoFlow(@Schema(name = "startTime", description = "开始时间") @RequestParam("startTime") String startTime, @Schema(name = "endTime", description = "开始时间") @RequestParam("endTime") String endTime) { public R<Map<Integer, Object>> getResMonthEcoFlow(@Schema(name = "startTime", description = "开始时间") @RequestParam("startTime") String startTime, @Schema(name = "endTime", description = "开始时间") @RequestParam("endTime") String endTime) {
Map<Integer, Object> resMap = new HashMap<>(); Map<Integer, Object> resMap = new HashMap<>();
QueryWrapper<ResMonthEcoFlow> wrapper = new QueryWrapper<ResMonthEcoFlow>() QueryWrapper<ResMonthEcoFlow> wrapper = new QueryWrapper<>();
.ge(StringUtils.isNotEmpty(startTime), "month", Integer.valueOf(startTime.substring(5, 7))) wrapper.orderByAsc("month");
.le(StringUtils.isNotEmpty(endTime), "month", Integer.valueOf(endTime.substring(5, 7))); if(StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)){
List<Integer> monthsBetweenDates = DateUtil.getMonthsBetweenDates(startTime, endTime);
wrapper.in("month", monthsBetweenDates);
}
List<ResMonthEcoFlow> list = resMonthEcoFlowService.list(wrapper); List<ResMonthEcoFlow> list = resMonthEcoFlowService.list(wrapper);
if(CollectionUtils.isNotEmpty(list)){ if(CollectionUtils.isNotEmpty(list)){
resMap = list.stream().collect(Collectors.toMap(ResMonthEcoFlow::getMonth, ResMonthEcoFlow::getValue)); resMap = list.stream().collect(Collectors.toMap(ResMonthEcoFlow::getMonth, ResMonthEcoFlow::getValue));

View File

@ -250,4 +250,18 @@ public class DateUtil {
private static SimpleDateFormat getThreadSafeFormatter(String format) { private static SimpleDateFormat getThreadSafeFormatter(String format) {
return DATE_FORMAT_CACHE.computeIfAbsent(format, key -> ThreadLocal.withInitial(() -> new SimpleDateFormat(key))).get(); return DATE_FORMAT_CACHE.computeIfAbsent(format, key -> ThreadLocal.withInitial(() -> new SimpleDateFormat(key))).get();
} }
public static List<Integer> getMonthsBetweenDates(String startDateStr, String endDateStr) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDate startDate = LocalDate.parse(startDateStr, formatter);
LocalDate endDate = LocalDate.parse(endDateStr, formatter);
List<Integer> months = new ArrayList<>();
while (startDate.isBefore(endDate)) {
months.add(startDate.getMonthValue());
startDate = startDate.plusMonths(1);
}
return months;
}
} }