From cddda74b41f5790938a24b5fe80cb4e2e5e99856 Mon Sep 17 00:00:00 2001 From: hanrenchun Date: Wed, 3 Jan 2024 14:45:14 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=A6=E8=BE=86=E6=A1=A3=E6=A1=88=E4=B8=8E?= =?UTF-8?q?=E4=BA=BA,=E8=BD=A6=E6=B5=81=E9=87=8F=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PerceptionDeviceController.java | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/gather-app/src/main/java/com/ruoyi/business/controller/PerceptionDeviceController.java b/gather-app/src/main/java/com/ruoyi/business/controller/PerceptionDeviceController.java index 7f2d338..5cc0e5c 100644 --- a/gather-app/src/main/java/com/ruoyi/business/controller/PerceptionDeviceController.java +++ b/gather-app/src/main/java/com/ruoyi/business/controller/PerceptionDeviceController.java @@ -18,10 +18,7 @@ import com.ruoyi.database.service.TransitVehicleRecordService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.time.LocalDate; import java.time.LocalDateTime; @@ -72,9 +69,9 @@ public class PerceptionDeviceController extends BaseController { } } - @PostMapping("/allHumanTrafficStatistics") + @GetMapping("/allHumanTrafficStatistics") @ApiOperation("人流量统计(前7天)(全数)") - public AjaxResult allHumanTrafficStatistics(@RequestBody TransitUserRecord transitUserRecord) { + public AjaxResult allHumanTrafficStatistics(TransitUserRecord transitUserRecord) { try { // 获取当前日期 LocalDate currentDate = LocalDate.now(); @@ -153,9 +150,9 @@ public class PerceptionDeviceController extends BaseController { } } - @PostMapping("/allVehicleTrafficStatistics") + @GetMapping("/allVehicleTrafficStatistics") @ApiOperation("车流量统计(前7天)(全数)") - public AjaxResult allVehicleTrafficStatistics(@RequestBody TransitVehicleRecord transitVehicleRecord) { + public AjaxResult allVehicleTrafficStatistics(TransitVehicleRecord transitVehicleRecord) { try { // 获取当前日期 LocalDate currentDate = LocalDate.now(); @@ -180,14 +177,14 @@ public class PerceptionDeviceController extends BaseController { } } - @PostMapping("/allHumanTrafficStatisticsHour") + @GetMapping("/allHumanTrafficStatisticsHour") @ApiOperation("人流量统计(当天)(全数)") - public AjaxResult allHumanTrafficStatisticsHour(@RequestBody TransitUserRecord transitUserRecord) { + public AjaxResult allHumanTrafficStatisticsHour(TransitUserRecord transitUserRecord) { try { // 获取当前日期 LocalDateTime currentDateTime = LocalDateTime.now(); - LocalDateTime startOfDay = currentDateTime.withHour(0).withMinute(0).withSecond(0).withNano(0); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); + LocalDateTime startOfDay = currentDateTime.withHour(0).withMinute(0).withSecond(0); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); String formattedDateTime = startOfDay.format(formatter); // 创建一个 TreeMap 用于存储每天的数据量 Map dailyCountsMap = new TreeMap<>(); @@ -195,11 +192,11 @@ public class PerceptionDeviceController extends BaseController { for (int i = 0; i < 24; i++) { // 构造查询条件 QueryWrapper userQueryWrapper = new QueryWrapper<>(transitUserRecord); - userQueryWrapper.between("partition_field", formattedDateTime, startOfDay.plusHours(1).format(formatter)); + userQueryWrapper.between("partition_field", startOfDay.plusHours(i).format(formatter), startOfDay.plusHours(i+1).format(formatter)); // 查询当前日期的记录数据总数 long userCount = transitUserRecordService.count(userQueryWrapper); // 存储结果到 TreeMap 中 - dailyCountsMap.put(startOfDay.plusHours(1).format(formatter), userCount); + dailyCountsMap.put(startOfDay.plusHours(i+1).format(formatter), userCount); } return AjaxResult.success(dailyCountsMap); @@ -209,14 +206,14 @@ public class PerceptionDeviceController extends BaseController { } } - @PostMapping("/allVehicleTrafficStatisticsHour") + @GetMapping("/allVehicleTrafficStatisticsHour") @ApiOperation("车流量统计(当天)(全数)") - public AjaxResult allVehicleTrafficStatisticsHour(@RequestBody TransitVehicleRecord transitVehicleRecord) { + public AjaxResult allVehicleTrafficStatisticsHour(TransitVehicleRecord transitVehicleRecord) { try { // 获取当前日期 LocalDateTime currentDateTime = LocalDateTime.now(); - LocalDateTime startOfDay = currentDateTime.withHour(0).withMinute(0).withSecond(0).withNano(0); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); + LocalDateTime startOfDay = currentDateTime.withHour(0).withMinute(0).withSecond(0); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); String formattedDateTime = startOfDay.format(formatter); // 创建一个 TreeMap 用于存储每天的数据量 Map dailyCountsMap = new TreeMap<>(); @@ -224,11 +221,11 @@ public class PerceptionDeviceController extends BaseController { for (int i = 0; i < 24; i++) { // 构造查询条件 QueryWrapper vehicleQueryWrapper = new QueryWrapper<>(transitVehicleRecord); - vehicleQueryWrapper.between("partition_field", formattedDateTime, startOfDay.plusHours(1).format(formatter)); + vehicleQueryWrapper.between("partition_field", startOfDay.plusHours(i).format(formatter), startOfDay.plusHours(i+1).format(formatter)); // 查询当前日期的记录数据总数 long vehicleCount = transitVehicleRecordService.count(vehicleQueryWrapper); // 存储结果到 TreeMap 中 - dailyCountsMap.put(startOfDay.plusHours(1).format(formatter), vehicleCount); + dailyCountsMap.put(startOfDay.plusHours(i+1).format(formatter), vehicleCount); } return AjaxResult.success(dailyCountsMap);