|
|
|
@ -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<LocalDate, Long> dailyCountsMap = new TreeMap<>();
|
|
|
|
|
List<PeopleVehicleHourFlow> 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<PeopleVehicleHourFlow> list = peopleVehicleHourFlowService.list(new QueryWrapper<>(queryFlow));
|
|
|
|
|
|
|
|
|
|
// 处理查询结果
|
|
|
|
|
Map<LocalDateTime, Long> 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<LocalDate, Long> dailyCountsMap = new TreeMap<>();
|
|
|
|
|
// List<PeopleVehicleHourFlow> 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("请求失败,请联系管理员");
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|