按当前时间减1天,留7天

develop
Angel 10 months ago
parent a302afe668
commit c6338da9d1

@ -77,8 +77,8 @@ public class PerceptionDeviceController extends BaseController {
LocalDate currentDate = LocalDate.now();
// 创建一个 TreeMap 用于存储每天的数据量
Map<LocalDate, Long> dailyCountsMap = new TreeMap<>();
// 循环迭代前7
for (int i = 0; i < 7; i++) {
// 循环迭代前6
for (int i = 1; i <=7 ; i++) {
LocalDate date = currentDate.minusDays(i);
// 构造查询条件
QueryWrapper<TransitUserRecord> userQueryWrapper = new QueryWrapper<>(transitUserRecord);
@ -88,7 +88,6 @@ public class PerceptionDeviceController extends BaseController {
// 存储结果到 TreeMap 中
dailyCountsMap.put(date, userCount);
}
return AjaxResult.success(dailyCountsMap);
} catch (Exception e) {
logger.info(StringKit.toString(e));
@ -105,7 +104,7 @@ public class PerceptionDeviceController extends BaseController {
// 创建一个 TreeMap 用于存储每天的数据量
Map<LocalDate, Long> dailyCountsMap = new TreeMap<>();
// 循环迭代前7天
for (int i = 0; i < 7; i++) {
for (int i = 0; i <7; i++) {
LocalDate date = currentDate.minusDays(i);
// 构造查询条件
QueryWrapper<TransitImpVehicleRecord> vehicleQueryWrapper = new QueryWrapper<>();
@ -132,7 +131,7 @@ public class PerceptionDeviceController extends BaseController {
// 创建一个 TreeMap 用于存储每天的数据量
Map<LocalDate, Long> dailyCountsMap = new TreeMap<>();
// 循环迭代前7天
for (int i = 0; i < 7; i++) {
for (int i = 0; i <7; i++) {
LocalDate date = currentDate.minusDays(i);
// 构造查询条件
QueryWrapper<TransitImpUserRecord> userQueryWrapper = new QueryWrapper<>();
@ -159,7 +158,7 @@ public class PerceptionDeviceController extends BaseController {
// 创建一个 TreeMap 用于存储每天的数据量
Map<LocalDate, Long> dailyCountsMap = new TreeMap<>();
// 循环迭代前7天
for (int i = 0; i < 7; i++) {
for (int i = 1; i <= 7; i++) {
LocalDate date = currentDate.minusDays(i);
// 构造查询条件
QueryWrapper<TransitVehicleRecord> vehicleQueryWrapper = new QueryWrapper<>(transitVehicleRecord);
@ -183,23 +182,39 @@ public class PerceptionDeviceController extends BaseController {
try {
// 获取当前日期
LocalDateTime currentDateTime = LocalDateTime.now();
LocalDateTime startOfDay = currentDateTime.withHour(0).withMinute(0).withSecond(0);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedDateTime = startOfDay.format(formatter);
// 获取当前小时数
int currentHour = currentDateTime.getHour();
// 将分钟和秒数置为零,表示当前时间点的小时的开始
LocalDateTime startOfCurrentHour = currentDateTime.withMinute(0).withSecond(0);
// 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<String, Long> dailyCountsMap = new TreeMap<>();
Map<String, Long> hourlyCountsMap = new TreeMap<>();
// 循环迭代前7天
for (int i = 0; i < 24; i++) {
for (int i = 0; i < currentHour; i++) {
// 构造查询条件
LocalDateTime startOfHour = startOfCurrentHour.minusHours(currentHour - i);
LocalDateTime endOfHour = startOfHour.plusHours(1);
QueryWrapper<TransitUserRecord> userQueryWrapper = new QueryWrapper<>(transitUserRecord);
userQueryWrapper.between("partition_field", startOfDay.plusHours(i).format(formatter), startOfDay.plusHours(i+1).format(formatter));
// 查询当前日期的记录数据总数
userQueryWrapper.between("partition_field", startOfHour.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),
endOfHour.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
// 查询当前小时的记录数据总数
long userCount = transitUserRecordService.count(userQueryWrapper);
// 存储结果到 TreeMap 中
dailyCountsMap.put(startOfDay.plusHours(i+1).format(formatter), userCount);
hourlyCountsMap.put(endOfHour.format(DateTimeFormatter.ofPattern("HH:mm")), userCount);
// // 构造查询条件
// QueryWrapper<TransitUserRecord> userQueryWrapper = new QueryWrapper<>(transitUserRecord);
// 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(i+1).format(formatter), userCount);
}
return AjaxResult.success(dailyCountsMap);
return AjaxResult.success(hourlyCountsMap);
} catch (Exception e) {
logger.info(StringKit.toString(e));
return AjaxResult.error("请求失败,请联系管理员");
@ -217,7 +232,7 @@ public class PerceptionDeviceController extends BaseController {
String formattedDateTime = startOfDay.format(formatter);
// 创建一个 TreeMap 用于存储每天的数据量
Map<String, Long> dailyCountsMap = new TreeMap<>();
// 循环迭代前7天
// 循环迭代前24小时
for (int i = 0; i < 24; i++) {
// 构造查询条件
QueryWrapper<TransitVehicleRecord> vehicleQueryWrapper = new QueryWrapper<>(transitVehicleRecord);

@ -67,7 +67,9 @@ public class DevopsDeviceInfoController extends BaseController {
List<DevopsDeviceInfo> list = devopsDeviceInfoService.list(new QueryWrapper<>(devopsDeviceInfo));
return getDataTable(list);
}
// LambdaQueryWrapper<DevopsDeviceInfo> devopsDeviceInfoQueryWrapper = new LambdaQueryWrapper<>(devopsDeviceInfo);
// devopsDeviceInfoQueryWrapper.in(DevopsDeviceInfo::getGbsChannelNo,strings);
// List<DevopsDeviceInfo> list = devopsDeviceInfoService.list(devopsDeviceInfoQueryWrapper);
@PostMapping
@ApiOperation("新增智能设备信息表")
@Log(title = "智能设备信息表", businessType = BusinessType.INSERT)

@ -35,8 +35,8 @@ public class PeopleVehicleFlowController extends BaseController {
// 获取当前日期和计算日期范围
LocalDate currentDate = LocalDate.now();
LocalDate startDate = currentDate.minusDays(6); // 包括今天在内的前6
LocalDate endDate = currentDate;
LocalDate startDate = currentDate.minusDays(7); // 包括今天在内的前7
LocalDate endDate = currentDate.minusDays(1);
// 处理查询结果

@ -9,6 +9,7 @@ import com.ruoyi.database.service.PeopleVehicleHourFlowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.auditing.CurrentDateTimeProvider;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@ -33,22 +34,22 @@ public class PeopleVehicleHourFlowController extends BaseController {
@ApiOperation("查询人车记录表")
public AjaxResult list(@RequestParam int statistictype) {
try {
// 获取当前日期
LocalDate currentDate = LocalDate.now();
// 获取当前日期和时间
LocalDateTime currentDateTime = LocalDateTime.now();
// 将分钟和秒数置为零,表示当前时间点的小时的开始
LocalDateTime startDateTime = currentDateTime.withMinute(0).withSecond(0);
// 构建日期时间范围从当天的00:00到23:59:59
LocalDateTime startDateTime = currentDate.atStartOfDay();
LocalDateTime endDateTime = currentDate.plusDays(1).atStartOfDay().minusSeconds(1);
// 构建查询条件
PeopleVehicleHourFlow queryFlow = new PeopleVehicleHourFlow();
queryFlow.setStartTimeRange(startDateTime);
queryFlow.setEndTimeRange(endDateTime);
queryFlow.setEndTimeRange(currentDateTime);
queryFlow.setStatisticType(statistictype);
// 查询数据库
List<PeopleVehicleHourFlow> list = peopleVehicleHourFlowService.list(new QueryWrapper<>(queryFlow)
.between("statistic_time", startDateTime, endDateTime).eq("statistic_type", statistictype)); // 添加日期范围条件
.between("statistic_time", startDateTime, currentDateTime).eq("statistic_type", statistictype)); // 添加日期范围条件
// 处理查询结果
Map<String, Long> hourlyCountsMap = new TreeMap<>();
@ -65,26 +66,4 @@ public class PeopleVehicleHourFlowController extends BaseController {
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("请求失败,请联系管理员");
// }
// }
}

@ -29,6 +29,7 @@ public class DevopsDeviceInfoServiceImpl extends ServiceImpl<DevopsDeviceInfoMap
public Object importData(List<DevopsDeviceInfo> list) {
int successNum = 0;
int failureNum = 0;
StringBuilder successMsg = new StringBuilder();
StringBuilder failureMsg = new StringBuilder();

Loading…
Cancel
Save