车辆档案与人,车流量接口更新

develop
hanrenchun 11 months ago
parent ca7acf1191
commit cddda74b41

@ -18,10 +18,7 @@ import com.ruoyi.database.service.TransitVehicleRecordService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -72,9 +69,9 @@ public class PerceptionDeviceController extends BaseController {
} }
} }
@PostMapping("/allHumanTrafficStatistics") @GetMapping("/allHumanTrafficStatistics")
@ApiOperation("人流量统计前7天(全数)") @ApiOperation("人流量统计前7天(全数)")
public AjaxResult allHumanTrafficStatistics(@RequestBody TransitUserRecord transitUserRecord) { public AjaxResult allHumanTrafficStatistics(TransitUserRecord transitUserRecord) {
try { try {
// 获取当前日期 // 获取当前日期
LocalDate currentDate = LocalDate.now(); LocalDate currentDate = LocalDate.now();
@ -153,9 +150,9 @@ public class PerceptionDeviceController extends BaseController {
} }
} }
@PostMapping("/allVehicleTrafficStatistics") @GetMapping("/allVehicleTrafficStatistics")
@ApiOperation("车流量统计前7天(全数)") @ApiOperation("车流量统计前7天(全数)")
public AjaxResult allVehicleTrafficStatistics(@RequestBody TransitVehicleRecord transitVehicleRecord) { public AjaxResult allVehicleTrafficStatistics(TransitVehicleRecord transitVehicleRecord) {
try { try {
// 获取当前日期 // 获取当前日期
LocalDate currentDate = LocalDate.now(); LocalDate currentDate = LocalDate.now();
@ -180,14 +177,14 @@ public class PerceptionDeviceController extends BaseController {
} }
} }
@PostMapping("/allHumanTrafficStatisticsHour") @GetMapping("/allHumanTrafficStatisticsHour")
@ApiOperation("人流量统计(当天)(全数)") @ApiOperation("人流量统计(当天)(全数)")
public AjaxResult allHumanTrafficStatisticsHour(@RequestBody TransitUserRecord transitUserRecord) { public AjaxResult allHumanTrafficStatisticsHour(TransitUserRecord transitUserRecord) {
try { try {
// 获取当前日期 // 获取当前日期
LocalDateTime currentDateTime = LocalDateTime.now(); LocalDateTime currentDateTime = LocalDateTime.now();
LocalDateTime startOfDay = currentDateTime.withHour(0).withMinute(0).withSecond(0).withNano(0); LocalDateTime startOfDay = currentDateTime.withHour(0).withMinute(0).withSecond(0);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedDateTime = startOfDay.format(formatter); String formattedDateTime = startOfDay.format(formatter);
// 创建一个 TreeMap 用于存储每天的数据量 // 创建一个 TreeMap 用于存储每天的数据量
Map<String, Long> dailyCountsMap = new TreeMap<>(); Map<String, Long> dailyCountsMap = new TreeMap<>();
@ -195,11 +192,11 @@ public class PerceptionDeviceController extends BaseController {
for (int i = 0; i < 24; i++) { for (int i = 0; i < 24; i++) {
// 构造查询条件 // 构造查询条件
QueryWrapper<TransitUserRecord> userQueryWrapper = new QueryWrapper<>(transitUserRecord); QueryWrapper<TransitUserRecord> 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); long userCount = transitUserRecordService.count(userQueryWrapper);
// 存储结果到 TreeMap 中 // 存储结果到 TreeMap 中
dailyCountsMap.put(startOfDay.plusHours(1).format(formatter), userCount); dailyCountsMap.put(startOfDay.plusHours(i+1).format(formatter), userCount);
} }
return AjaxResult.success(dailyCountsMap); return AjaxResult.success(dailyCountsMap);
@ -209,14 +206,14 @@ public class PerceptionDeviceController extends BaseController {
} }
} }
@PostMapping("/allVehicleTrafficStatisticsHour") @GetMapping("/allVehicleTrafficStatisticsHour")
@ApiOperation("车流量统计(当天)(全数)") @ApiOperation("车流量统计(当天)(全数)")
public AjaxResult allVehicleTrafficStatisticsHour(@RequestBody TransitVehicleRecord transitVehicleRecord) { public AjaxResult allVehicleTrafficStatisticsHour(TransitVehicleRecord transitVehicleRecord) {
try { try {
// 获取当前日期 // 获取当前日期
LocalDateTime currentDateTime = LocalDateTime.now(); LocalDateTime currentDateTime = LocalDateTime.now();
LocalDateTime startOfDay = currentDateTime.withHour(0).withMinute(0).withSecond(0).withNano(0); LocalDateTime startOfDay = currentDateTime.withHour(0).withMinute(0).withSecond(0);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedDateTime = startOfDay.format(formatter); String formattedDateTime = startOfDay.format(formatter);
// 创建一个 TreeMap 用于存储每天的数据量 // 创建一个 TreeMap 用于存储每天的数据量
Map<String, Long> dailyCountsMap = new TreeMap<>(); Map<String, Long> dailyCountsMap = new TreeMap<>();
@ -224,11 +221,11 @@ public class PerceptionDeviceController extends BaseController {
for (int i = 0; i < 24; i++) { for (int i = 0; i < 24; i++) {
// 构造查询条件 // 构造查询条件
QueryWrapper<TransitVehicleRecord> vehicleQueryWrapper = new QueryWrapper<>(transitVehicleRecord); QueryWrapper<TransitVehicleRecord> 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); long vehicleCount = transitVehicleRecordService.count(vehicleQueryWrapper);
// 存储结果到 TreeMap 中 // 存储结果到 TreeMap 中
dailyCountsMap.put(startOfDay.plusHours(1).format(formatter), vehicleCount); dailyCountsMap.put(startOfDay.plusHours(i+1).format(formatter), vehicleCount);
} }
return AjaxResult.success(dailyCountsMap); return AjaxResult.success(dailyCountsMap);

Loading…
Cancel
Save