develop
Angel 10 months ago
parent 41e54f557b
commit c595bcc90d

@ -3,21 +3,26 @@ package com.ruoyi.business.controller;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.ruoyi.business.domain.vo.HumanVehicleStatisticsVo; import com.ruoyi.business.domain.vo.HumanVehicleStatisticsVo;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.StringKit; import com.ruoyi.common.utils.StringKit;
import com.ruoyi.database.domain.*; import com.ruoyi.database.domain.*;
import com.ruoyi.database.service.*; import com.ruoyi.database.service.*;
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.aspectj.weaver.loadtime.Aj;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.lang.reflect.Field;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
@ -44,27 +49,11 @@ public class PerceptionDeviceController extends BaseController {
@ApiOperation("人车统计") @ApiOperation("人车统计")
public AjaxResult overviewResources() { public AjaxResult overviewResources() {
try { try {
// // 人流量统计
// String todayDateString = DateUtil.today();
// QueryWrapper<TransitImpUserRecord> userQueryWrapper = new QueryWrapper<>();
// userQueryWrapper.eq("DATE(partition_field)", todayDateString);
// int userCount = userRecordService.count(userQueryWrapper);
// //车流量统计
// QueryWrapper<TransitImpVehicleRecord> vehicleQueryWrapper = new QueryWrapper<>();
// vehicleQueryWrapper.eq("DATE(partition_field)", todayDateString);
// int vehicleCount = vehicleRecordService.count(vehicleQueryWrapper);
//
// HumanVehicleStatisticsVo bean = new HumanVehicleStatisticsVo();
// bean.setUserCount(StringKit.toString(userCount));
// bean.setVehicleCount(StringKit.toString(vehicleCount));
//
// return AjaxResult.success(bean);
Integer userCount = devopsDeviceInfoService.lambdaQuery().eq(DevopsDeviceInfo::getDeviceType, 1).count(); Integer userCount = devopsDeviceInfoService.lambdaQuery().eq(DevopsDeviceInfo::getDeviceType, 1).count();
Integer vehicleCount = devopsDeviceInfoService.lambdaQuery().eq(DevopsDeviceInfo::getDeviceType, 2).count(); Integer vehicleCount = devopsDeviceInfoService.lambdaQuery().eq(DevopsDeviceInfo::getDeviceType, 2).count();
Map<String, Integer> map = new HashMap<>(); Map<String, Integer> map = new HashMap<>();
map.put("userCount",userCount); map.put("userCount", userCount);
map.put("vehicleCount",vehicleCount); map.put("vehicleCount", vehicleCount);
return AjaxResult.success(map); return AjaxResult.success(map);
} catch (Exception e) { } catch (Exception e) {
logger.info(StringKit.toString(e)); logger.info(StringKit.toString(e));
@ -72,6 +61,51 @@ public class PerceptionDeviceController extends BaseController {
} }
} }
@GetMapping("/peoplelist")
@ApiOperation("人设备列表")
public TableDataInfo<DevopsDeviceInfo> PeopleList() {
startPage();
List<DevopsDeviceInfo> list = devopsDeviceInfoService.lambdaQuery().eq(DevopsDeviceInfo::getDeviceType, 1).list();
return getDataTable(list);
}
@GetMapping("/vehiclelist")
@ApiOperation("车设备列表")
public TableDataInfo<DevopsDeviceInfo> VehicleList() {
startPage();
List<DevopsDeviceInfo> list = devopsDeviceInfoService.lambdaQuery().eq(DevopsDeviceInfo::getDeviceType, 2).list();
return getDataTable(list);
}
@GetMapping("/PeopleOrVehiclelist")
@ApiOperation("人车设备列表")
public TableDataInfo<DevopsDeviceInfo> OVehicleList(DevopsDeviceInfo devopsDeviceInfo) {
startPage();
DevopsDeviceInfo filteredDeviceInfo = removeEmptyFields(devopsDeviceInfo);
LambdaQueryChainWrapper<DevopsDeviceInfo> lambdaQueryWrapper = devopsDeviceInfoService.lambdaQuery()
.eq(DevopsDeviceInfo::getDeviceType, filteredDeviceInfo.getDeviceType());
List<DevopsDeviceInfo> list = lambdaQueryWrapper
.eq(DevopsDeviceInfo::getDeviceType, filteredDeviceInfo.getDeviceType())
.list();
return getDataTable(list);
}
private DevopsDeviceInfo removeEmptyFields(DevopsDeviceInfo deviceInfo) {
DevopsDeviceInfo modifiedDeviceInfo = new DevopsDeviceInfo();
Field[] fields = DevopsDeviceInfo.class.getDeclaredFields();
for (Field field : fields) {
try {
field.setAccessible(true);
Object value = field.get(deviceInfo);
if (value != null && !(value instanceof String && ((String) value).isEmpty())) {
field.set(modifiedDeviceInfo, value);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
return modifiedDeviceInfo;
}
@GetMapping("/allHumanTrafficStatistics") @GetMapping("/allHumanTrafficStatistics")
@ApiOperation("人流量统计前7天(全数)") @ApiOperation("人流量统计前7天(全数)")
public AjaxResult allHumanTrafficStatistics(TransitUserRecord transitUserRecord) { public AjaxResult allHumanTrafficStatistics(TransitUserRecord transitUserRecord) {
@ -81,7 +115,7 @@ public class PerceptionDeviceController extends BaseController {
// 创建一个 TreeMap 用于存储每天的数据量 // 创建一个 TreeMap 用于存储每天的数据量
Map<LocalDate, Long> dailyCountsMap = new TreeMap<>(); Map<LocalDate, Long> dailyCountsMap = new TreeMap<>();
// 循环迭代前6天 // 循环迭代前6天
for (int i = 1; i <=7 ; i++) { for (int i = 1; i <= 7; i++) {
LocalDate date = currentDate.minusDays(i); LocalDate date = currentDate.minusDays(i);
// 构造查询条件 // 构造查询条件
QueryWrapper<TransitUserRecord> userQueryWrapper = new QueryWrapper<>(transitUserRecord); QueryWrapper<TransitUserRecord> userQueryWrapper = new QueryWrapper<>(transitUserRecord);
@ -107,7 +141,7 @@ public class PerceptionDeviceController extends BaseController {
// 创建一个 TreeMap 用于存储每天的数据量 // 创建一个 TreeMap 用于存储每天的数据量
Map<LocalDate, Long> dailyCountsMap = new TreeMap<>(); Map<LocalDate, Long> dailyCountsMap = new TreeMap<>();
// 循环迭代前7天 // 循环迭代前7天
for (int i = 0; i <7; i++) { for (int i = 0; i < 7; i++) {
LocalDate date = currentDate.minusDays(i); LocalDate date = currentDate.minusDays(i);
// 构造查询条件 // 构造查询条件
QueryWrapper<TransitImpVehicleRecord> vehicleQueryWrapper = new QueryWrapper<>(); QueryWrapper<TransitImpVehicleRecord> vehicleQueryWrapper = new QueryWrapper<>();
@ -134,7 +168,7 @@ public class PerceptionDeviceController extends BaseController {
// 创建一个 TreeMap 用于存储每天的数据量 // 创建一个 TreeMap 用于存储每天的数据量
Map<LocalDate, Long> dailyCountsMap = new TreeMap<>(); Map<LocalDate, Long> dailyCountsMap = new TreeMap<>();
// 循环迭代前7天 // 循环迭代前7天
for (int i = 0; i <7; i++) { for (int i = 0; i < 7; i++) {
LocalDate date = currentDate.minusDays(i); LocalDate date = currentDate.minusDays(i);
// 构造查询条件 // 构造查询条件
QueryWrapper<TransitImpUserRecord> userQueryWrapper = new QueryWrapper<>(); QueryWrapper<TransitImpUserRecord> userQueryWrapper = new QueryWrapper<>();
@ -194,7 +228,7 @@ public class PerceptionDeviceController extends BaseController {
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); // 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> hourlyCountsMap = new TreeMap<>(); Map<String, Long> hourlyCountsMap = new TreeMap<>();
// 循环迭代前7天 // 循环迭代前7天
for (int i = 0; i < currentHour; i++) { for (int i = 0; i < currentHour; i++) {
// 构造查询条件 // 构造查询条件
@ -239,11 +273,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", startOfDay.plusHours(i).format(formatter), startOfDay.plusHours(i+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(i+1).format(formatter), vehicleCount); dailyCountsMap.put(startOfDay.plusHours(i + 1).format(formatter), vehicleCount);
} }
return AjaxResult.success(dailyCountsMap); return AjaxResult.success(dailyCountsMap);

@ -1,7 +1,6 @@
package com.ruoyi.database.controller; package com.ruoyi.database.controller;
import cn.hutool.core.util.PageUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.PageUtils; import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.common.utils.StringKit; import com.ruoyi.common.utils.StringKit;

@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
@ -37,19 +38,21 @@ public class PeopleVehicleHourFlowController extends BaseController {
// 获取当前日期和时间 // 获取当前日期和时间
LocalDateTime currentDateTime = LocalDateTime.now(); LocalDateTime currentDateTime = LocalDateTime.now();
// 将分钟和秒数置为零,表示当前时间点的小时的开始 // 构建日期时间范围从当天的00:00到当前小时
LocalDateTime startDateTime = currentDateTime.withMinute(0).withSecond(0); LocalDateTime startDateTime = currentDateTime.toLocalDate().atStartOfDay();
LocalDateTime endDateTime = currentDateTime.truncatedTo(ChronoUnit.HOURS);
// 构建查询条件 // 构建查询条件
PeopleVehicleHourFlow queryFlow = new PeopleVehicleHourFlow(); PeopleVehicleHourFlow queryFlow = new PeopleVehicleHourFlow();
queryFlow.setStartTimeRange(startDateTime); queryFlow.setStartTimeRange(startDateTime);
queryFlow.setEndTimeRange(currentDateTime); queryFlow.setEndTimeRange(endDateTime);
queryFlow.setStatisticType(statistictype); queryFlow.setStatisticType(statistictype);
// 查询数据库 // 查询数据库
List<PeopleVehicleHourFlow> list = peopleVehicleHourFlowService.list(new QueryWrapper<>(queryFlow) List<PeopleVehicleHourFlow> list = peopleVehicleHourFlowService.list(new QueryWrapper<>(queryFlow)
.between("statistic_time", startDateTime, currentDateTime).eq("statistic_type", statistictype)); // 添加日期范围条件 .between("statistic_time", startDateTime, endDateTime)
.eq("statistic_type", statistictype)); // 添加日期范围条件
// 处理查询结果 // 处理查询结果
Map<String, Long> hourlyCountsMap = new TreeMap<>(); Map<String, Long> hourlyCountsMap = new TreeMap<>();

Loading…
Cancel
Save