From 757fc496d5ce65fbf23cc9533f52ff4a8885573e Mon Sep 17 00:00:00 2001 From: Angel <1050374295@qq.com> Date: Fri, 5 Jan 2024 11:33:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=E5=B0=8F=E6=97=B6=E8=8C=83=E5=9B=B4?= =?UTF-8?q?=E6=8F=90=E4=BE=9B=E7=BB=99=E5=89=8D=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PeopleVehicleHourFlowController.java | 59 +++++++++++++++---- .../domain/PeopleVehicleHourFlow.java | 7 +++ 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/gather-app/src/main/java/com/ruoyi/database/controller/PeopleVehicleHourFlowController.java b/gather-app/src/main/java/com/ruoyi/database/controller/PeopleVehicleHourFlowController.java index c802ca6..5919b5e 100644 --- a/gather-app/src/main/java/com/ruoyi/database/controller/PeopleVehicleHourFlowController.java +++ b/gather-app/src/main/java/com/ruoyi/database/controller/PeopleVehicleHourFlowController.java @@ -13,9 +13,11 @@ import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.time.LocalDate; +import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.List; import java.util.Map; @@ -31,25 +33,56 @@ public class PeopleVehicleHourFlowController extends BaseController { @GetMapping @ApiOperation("查询人车记录表") - public AjaxResult list(PeopleVehicleHourFlow peopleVehicleHFlow) { + public AjaxResult list(@RequestParam String statisticTime, @RequestParam int statistictype) { try { - // 创建一个 TreeMap 用于存储每天的数据量 - Map dailyCountsMap = new TreeMap<>(); - List list = peopleVehicleHourFlowService.list(new QueryWrapper<>(peopleVehicleHFlow)); + // 解析前端传递的日期参数 + LocalDate date = LocalDate.parse(statisticTime, DateTimeFormatter.ofPattern("yyyy-MM-dd")); + + // 构建日期时间范围:从当天的00:00到23:59:59 + LocalDateTime startDateTime = date.atStartOfDay(); + LocalDateTime endDateTime = date.plusDays(1).atStartOfDay().minusSeconds(1); + + // 构建查询条件 + PeopleVehicleHourFlow queryFlow = new PeopleVehicleHourFlow(); + queryFlow.setStartTimeRange(startDateTime); + queryFlow.setEndTimeRange(endDateTime); + queryFlow.setStatisticType(statistictype); + + // 查询数据库 + List list = peopleVehicleHourFlowService.list(new QueryWrapper<>(queryFlow)); + + // 处理查询结果 + Map hourlyCountsMap = new TreeMap<>(); for (PeopleVehicleHourFlow flow : list) { - String countString = flow.getStatisticCount(); - String timeString = flow.getStatisticTime(); - // 将时间字符串转换为 LocalDate - LocalDate time = LocalDate.parse(timeString, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")); - - // 将计数字符串转换为 Long - Long count = Long.parseLong(countString); - dailyCountsMap.put(time, count); + LocalDateTime time = LocalDateTime.parse(flow.getStatisticTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")); + Long count = Long.parseLong(flow.getStatisticCount()); + hourlyCountsMap.put(time, count); } - return AjaxResult.success(dailyCountsMap); + return AjaxResult.success(hourlyCountsMap); } catch (Exception e) { logger.info(StringKit.toString(e)); return AjaxResult.error("请求失败,请联系管理员"); } } +// public AjaxResult list(PeopleVehicleHourFlow peopleVehicleHFlow) { +// try { +// // 创建一个 TreeMap 用于存储每天的数据量 +// Map dailyCountsMap = new TreeMap<>(); +// List list = peopleVehicleHourFlowService.list(new QueryWrapper<>(peopleVehicleHFlow)); +// for (PeopleVehicleHourFlow flow : list) { +// String countString = flow.getStatisticCount(); +// String timeString = flow.getStatisticTime(); +// // 将时间字符串转换为 LocalDate +// LocalDate time = LocalDate.parse(timeString, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")); +// +// // 将计数字符串转换为 Long +// Long count = Long.parseLong(countString); +// dailyCountsMap.put(time, count); +// } +// return AjaxResult.success(dailyCountsMap); +// } catch (Exception e) { +// logger.info(StringKit.toString(e)); +// return AjaxResult.error("请求失败,请联系管理员"); +// } +// } } diff --git a/gather-app/src/main/java/com/ruoyi/database/domain/PeopleVehicleHourFlow.java b/gather-app/src/main/java/com/ruoyi/database/domain/PeopleVehicleHourFlow.java index 88499e2..2ac4450 100644 --- a/gather-app/src/main/java/com/ruoyi/database/domain/PeopleVehicleHourFlow.java +++ b/gather-app/src/main/java/com/ruoyi/database/domain/PeopleVehicleHourFlow.java @@ -9,6 +9,8 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; +import java.time.LocalDateTime; + @Data @EqualsAndHashCode(callSuper = false) @TableName(value = "statistics_user_vehicle_hour_info") @@ -41,5 +43,10 @@ public class PeopleVehicleHourFlow { @ApiModelProperty("日期") @TableField(value = "statistic_time") private String statisticTime; + // 瞬时字段,不映射到数据库 + @TableField(exist = false) + private LocalDateTime startTimeRange; + @TableField(exist = false) + private LocalDateTime endTimeRange; }