大屏数据

This commit is contained in:
2025-09-27 15:30:12 +08:00
parent b7c81419a4
commit 2d59397de5
32 changed files with 1032 additions and 39 deletions

View File

@ -90,6 +90,8 @@ public class BjqAlarmRule implements MqttMessageRule {
deviceAlarmBo.setDurationTime(durationBetween);
// 0已处理1未处理
deviceAlarmBo.setTreatmentState(0);
// 告警状态0 解除告警, 1 告警中
deviceAlarmBo.setAlarmState(0);
deviceAlarmService.updateByBo(deviceAlarmBo);
}
}
@ -107,6 +109,8 @@ public class BjqAlarmRule implements MqttMessageRule {
deviceAlarmBo.setStartTime(new Date());
// 0已处理1未处理
deviceAlarmBo.setTreatmentState(1);
// 告警状态0 解除告警, 1 告警中
deviceAlarmBo.setAlarmState(1);
// LoginUser loginUser = LoginHelper.getLoginUser();
// deviceAlarmBo.setCreateBy(loginUser.getUserId());

View File

@ -5,6 +5,8 @@ import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.core.utils.StringUtils;
import com.fuyuanshen.common.json.utils.JsonUtils;
import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.equipment.mapper.DeviceMapper;
import com.fuyuanshen.equipment.service.DeviceService;
import com.fuyuanshen.equipment.utils.map.GetAddressFromLatUtil;
import com.fuyuanshen.equipment.utils.map.LngLonUtil;
import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
@ -36,8 +38,9 @@ import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVIC
@RequiredArgsConstructor
@Slf4j
public class BjqLocationDataRule implements MqttMessageRule {
private final MqttGateway mqttGateway;
private final DeviceService deviceService;
@Override
@ -56,6 +59,8 @@ public class BjqLocationDataRule implements MqttMessageRule {
// 异步发送经纬度到Redis
asyncSendLocationToRedisWithFuture(context.getDeviceImei(), latitude, longitude);
// 异步保存数据
asyncSaveLocationToMySQLWithFuture(context.getDeviceImei(), latitude, longitude);
Map<String, Object> map = buildLocationDataMap(latitude, longitude);
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + context.getDeviceImei(), 1, JsonUtils.toJsonString(map));
@ -114,13 +119,13 @@ public class BjqLocationDataRule implements MqttMessageRule {
public void asyncSendLocationToRedisWithFuture(String deviceImei, String latitude, String longitude) {
CompletableFuture.runAsync(() -> {
try {
if(StringUtils.isBlank(latitude) || StringUtils.isBlank(longitude)){
if (StringUtils.isBlank(latitude) || StringUtils.isBlank(longitude)) {
return;
}
// String[] latArr = latitude.split("\\.");
// String[] lonArr = longitude.split("\\.");
// // 将位置信息存储到Redis中
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DEVICE_LOCATION_KEY_PREFIX;
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + DEVICE_LOCATION_KEY_PREFIX;
// String redisObj = RedisUtils.getCacheObject(redisKey);
// JSONObject jsonOBj = JSONObject.parseObject(redisObj);
// if(jsonOBj != null){
@ -153,7 +158,6 @@ public class BjqLocationDataRule implements MqttMessageRule {
locationInfo.put("timestamp", System.currentTimeMillis());
String locationJson = JsonUtils.toJsonString(locationInfo);
// 存储到Redis
@ -171,12 +175,38 @@ public class BjqLocationDataRule implements MqttMessageRule {
});
}
/**
* 异步保存位置信息到MySQL数据库
*
* @param deviceImei 设备IMEI
* @param latitude 纬度
* @param longitude 经度
*/
public void asyncSaveLocationToMySQLWithFuture(String deviceImei, String latitude, String longitude) {
CompletableFuture.runAsync(() -> {
try {
if (StringUtils.isBlank(latitude) || StringUtils.isBlank(longitude)) {
return;
}
// 调用服务层方法更新设备位置信息
deviceService.updateDeviceLocationByImei(deviceImei, longitude, latitude);
log.info("位置信息已异步保存到MySQL: device={}, lat={}, lon={}", deviceImei, latitude, longitude);
} catch (Exception e) {
log.error("异步保存位置信息到MySQL时出错: device={}, error={}", deviceImei, e.getMessage(), e);
}
});
}
/**
* 存储设备30天历史轨迹到Redis (使用Sorted Set)
*/
public void storeDeviceTrajectoryWithSortedSet(String deviceImei, String locationJson) {
try {
String trajectoryKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + deviceImei + DeviceRedisKeyConstants.DEVICE_LOCATION_HISTORY_KEY_PREFIX;
String trajectoryKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + DeviceRedisKeyConstants.DEVICE_LOCATION_HISTORY_KEY_PREFIX;
// String trajectoryKey = "device:trajectory:zset:" + deviceImei;
// String locationJson = JsonUtils.toJsonString(locationInfo);
long timestamp = System.currentTimeMillis();
@ -194,20 +224,20 @@ public class BjqLocationDataRule implements MqttMessageRule {
log.error("存储设备轨迹到Redis(ZSet)失败: device={}, error={}", deviceImei, e.getMessage(), e);
}
}
private Map<String, Object> buildLocationDataMap(String latitude, String longitude) {
String[] latArr = latitude.split("\\.");
String[] lonArr = longitude.split("\\.");
ArrayList<Integer> intData = new ArrayList<>();
intData.add(11);
intData.add(Integer.parseInt(latArr[0]));
String str1 = latArr[1];
intData.add(Integer.parseInt(str1.substring(0,4)));
intData.add(Integer.parseInt(str1.substring(0, 4)));
String str2 = lonArr[1];
intData.add(Integer.parseInt(lonArr[0]));
intData.add(Integer.parseInt(str2.substring(0,4)));
intData.add(Integer.parseInt(str2.substring(0, 4)));
Map<String, Object> map = new HashMap<>();
map.put("instruct", intData);
return map;

View File

@ -0,0 +1,142 @@
package com.fuyuanshen.web.controller;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.equipment.domain.vo.*;
import com.fuyuanshen.equipment.service.IDeviceAlarmService;
import com.fuyuanshen.equipment.service.DeviceService;
import com.fuyuanshen.equipment.service.IWeatherService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
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.util.List;
/**
* 大屏数据
*
* @author: 默苍璃
* @date: 2025-09-27 08:42
*/
@Tag(name = "大屏数据", description = "大屏数据")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/largeScreen")
public class LargeScreenController {
private final IDeviceAlarmService deviceAlarmService;
private final DeviceService deviceService;
private final IWeatherService weatherService;
/**
* 获取设备总览信息
* 包含设备总数、在线设备数量、设备型号数量
*/
@GetMapping("/getDeviceOverview")
public R<DeviceOverviewVo> getDeviceOverview() {
return R.ok(deviceService.getDeviceOverview());
}
/**
* 获取 实时报警信息
* RealtimeAlarm
*/
@GetMapping("/getRealtimeAlarm")
public R<List<DeviceAlarmVo>> getRealtimeAlarm() {
return R.ok(deviceAlarmService.getRealtimeAlarm());
}
/**
* 获取报警统计数据
* 包括正在报警数量、报警总数、已处理报警数量
*/
@GetMapping("/getAlarmStatistics")
public R<AlarmStatisticsVo> getAlarmStatistics() {
return R.ok(deviceAlarmService.getAlarmStatistics());
}
/**
* 获取最近一年每月告警统计数据
*/
@GetMapping("/getMonthlyAlarmStatistics")
public R<MonthlyAlarmStatisticsVo> getMonthlyAlarmStatistics() {
return R.ok(deviceAlarmService.getMonthlyAlarmStatistics());
}
/**
* 获取设备通讯方式统计数据
* 包含通讯方式名称、设备总数、异常设备数
*/
@GetMapping("/getDeviceCommunicationModeStatistics")
public R<List<DeviceCommunicationModeStatisticsVo>> getDeviceCommunicationModeStatistics() {
return R.ok(deviceService.getDeviceCommunicationModeStatistics());
}
/**
* 获取设备使用频次统计数据
*
* @param days 天数近一个月传30近半年传180
*/
@GetMapping("/getDeviceUsageFrequency")
public R<List<DeviceUsageFrequencyVo>> getDeviceUsageFrequency(@RequestParam int days) {
return R.ok(deviceService.getDeviceUsageFrequency(days));
}
/**
* 根据条件查询设备位置信息
*
* @param groupId 设备分组ID
* @param deviceType 设备类型
* @param deviceImei 设备IMEI
* @return 设备位置信息列表
*/
@GetMapping("/getDeviceLocationInfo")
public R<List<DeviceLocationVo>> getDeviceLocationInfo(
@RequestParam(required = false) Long groupId,
@RequestParam(required = false) Long deviceType,
@RequestParam(required = false) String deviceImei) {
return R.ok(deviceService.getDeviceLocationInfo(groupId, deviceType, deviceImei));
}
/**
* 根据经纬度获取天气信息
*
* @param latitude 纬度
* @param longitude 经度
* @return 天气信息
*/
@GetMapping("/weather")
public R<WeatherInfoVo> getWeatherInfo(
@RequestParam Double latitude,
@RequestParam Double longitude) {
if (latitude == null || longitude == null) {
return R.fail("经纬度参数不能为空");
}
// 简单的经纬度范围校验
if (latitude < -90 || latitude > 90 || longitude < -180 || longitude > 180) {
return R.fail("经纬度参数范围不正确");
}
WeatherInfoVo weatherInfo = weatherService.getWeatherByCoordinates(latitude, longitude);
if (weatherInfo != null) {
return R.ok(weatherInfo);
} else {
return R.fail("获取天气信息失败");
}
}
}