This commit is contained in:
2026-05-28 13:38:00 +08:00
parent 2a99b0bd5e
commit f02329b2d0
6 changed files with 195 additions and 14 deletions

View File

@@ -37,4 +37,5 @@ public class IotUAVDevice extends BaseDO {
@TableField(updateStrategy = FieldStrategy.IGNORED)
private Long tenantId; //配置可以设置null 不自动过滤
}

View File

@@ -4,6 +4,7 @@ package com.maibu.memory;
import com.maibu.core.business.Device;
import com.maibu.core.business.IoTCommonDevice;
import com.maibu.core.business.IoTCommonProduct;
import com.maibu.core.business.uav.IotUAVDevice;
import lombok.Data;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
@@ -28,7 +29,6 @@ public class GlobalMemory {
public static ConcurrentHashMap<String, Device> unRegisterDeviceMap = new ConcurrentHashMap<>();
// key:orgId - siteId
public static ConcurrentHashMap<Long, Map<Long, SiteMemory>> orgAttrs = new ConcurrentHashMap<>();

View File

@@ -0,0 +1,9 @@
package com.maibu.uav.common;
import io.netty.util.AttributeKey;
public class UAVConstant {
public static final String uavCameraKey = "uav_camera:";
}

View File

@@ -41,7 +41,7 @@ public class UAVController extends BaseController {
@GetMapping("/getUAVList")
public TableDataInfo getUAVList(@RequestParam(required = false) Integer status,
@RequestParam(required = false) String sn) {
@RequestParam(required = false) String sn) {
startPage();
Long roleId = getLoginUser().getRoleId();
Long orgId = getLoginUser().getOrgId();
@@ -57,9 +57,9 @@ public class UAVController extends BaseController {
return uavService.getDeviceHMS(deviceSn);
}
@GetMapping("/getDeviceState")
public String getDeviceState(@RequestParam String deviceSn) {
return uavService.getDeviceState(deviceSn);
@GetMapping("/getUAVState")
public AjaxResult getUAVState(@RequestParam String sn, @RequestParam String droneSn) {
return AjaxResult.success(uavService.getUAVState(sn, droneSn));
}
@GetMapping("/getWayline")

View File

@@ -1,10 +1,13 @@
package com.maibu.uav.scheduled;
import com.maibu.core.business.uav.IotUAVDevice;
import com.maibu.core.redis.RedisCache;
import com.maibu.mapper.UAVDeviceMapper;
import com.maibu.uav.common.UAVConstant;
import com.maibu.uav.dto.UavDeviceStateResponseDTO;
import com.maibu.uav.dto.UavDeviceStateResponseDetailDTO;
import com.maibu.uav.service.UAVService;
import com.maibu.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -14,6 +17,7 @@ import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Component
@@ -25,6 +29,9 @@ public class UAVScheduled {
@Autowired
private UAVDeviceMapper uavDeviceMapper;
@Autowired
private RedisCache redisCache;
//10分钟执行一次同步无人机设备
@Scheduled(cron = "0 */10 * * * ?")
@@ -47,6 +54,17 @@ public class UAVScheduled {
.map(UavDeviceStateResponseDetailDTO::getGateway_sn)
.collect(Collectors.toSet());
// detailList.forEach(y -> {
// if (!StringUtils.isEmpty(y.getGateway_sn())) {
// String snKey = UAVConstant.uavCameraKey + y.getGateway_sn();
// redisCache.setCacheObject(snKey, y.getGateway_camera_list(), 10, TimeUnit.MINUTES);
// }
// if (!StringUtils.isEmpty(y.getDevice_sn())) {
// String droneKey = UAVConstant.uavCameraKey + y.getDevice_sn();
// redisCache.setCacheObject(droneKey, y.getDrone_camera_list(), 10, TimeUnit.MINUTES);
// }
// });
// ========================
// 1. 获取新增设备
// 远程有,数据库没有

View File

@@ -5,8 +5,10 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.maibu.core.business.uav.IotUAVDevice;
import com.maibu.core.domain.entity.SysRole;
import com.maibu.core.redis.RedisCache;
import com.maibu.mapper.UAVDeviceMapper;
import com.maibu.service.ISysRoleService;
import com.maibu.uav.common.UAVConstant;
import com.maibu.uav.dto.*;
import com.maibu.uav.entity.UavDevice;
import com.maibu.uav.entity.UavDeviceState;
@@ -20,6 +22,7 @@ import io.minio.errors.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
@@ -51,6 +54,9 @@ public class UAVService {
@Autowired
private UAVDeviceMapper uavDeviceMapper;
@Autowired
private RedisCache redisCache;
public static final Map<String, Long> latestActiveTime = new ConcurrentHashMap<>();
@@ -75,9 +81,9 @@ public class UAVService {
queryWrapper.eq(IotUAVDevice::getOlineStatus, 1);
List<IotUAVDevice> list = uavDeviceMapper.selectList(queryWrapper);
List<UavDeviceStateResponseDetailDTO> res = transferData(list);
if (status!=null && !CollectionUtils.isEmpty(res)) {
return res.stream().filter(x->status.equals(x.getOnlineStatus())).collect(Collectors.toList());
}else {
if (status != null && !CollectionUtils.isEmpty(res)) {
return res.stream().filter(x -> status.equals(x.getOnlineStatus())).collect(Collectors.toList());
} else {
return res;
}
}
@@ -85,7 +91,7 @@ public class UAVService {
return new ArrayList<>();
}
public List<UavDeviceStateResponseDetailDTO> getUAVList(Long siteId, Long orgId, Long roleId, Long userId,Integer status, String sn) {
public List<UavDeviceStateResponseDetailDTO> getUAVList(Long siteId, Long orgId, Long roleId, Long userId, Integer status, String sn) {
SysRole sysRole = roleService.selectRoleById(roleId);
if (sysRole != null) {
String roleKey = sysRole.getRoleKey();
@@ -110,9 +116,9 @@ public class UAVService {
// }
list = uavDeviceMapper.selectList(queryWrapper);
List<UavDeviceStateResponseDetailDTO> res = transferData(list);
if (status!=null && !CollectionUtils.isEmpty(res)) {
return res.stream().filter(x->status.equals(x.getOnlineStatus())).collect(Collectors.toList());
}else {
if (status != null && !CollectionUtils.isEmpty(res)) {
return res.stream().filter(x -> status.equals(x.getOnlineStatus())).collect(Collectors.toList());
} else {
return res;
}
}
@@ -127,7 +133,7 @@ public class UAVService {
IotUAVDevice::getSn,
item -> item
));
UavDeviceStateResponseDTO dto = getProjectDeviceList();
UavDeviceStateResponseDTO dto = getAllDeviceList();
List<UavDeviceStateResponseDetailDTO> details = dto.getDetail();
if (!CollectionUtils.isEmpty(details)) {
List<UavDeviceStateResponseDetailDTO> fiList = details.stream().filter(x -> deviceMap.containsKey(x.getGateway_sn())).collect(Collectors.toList());
@@ -144,7 +150,99 @@ public class UAVService {
return fiList;
}
}
return null;
return new ArrayList<>();
}
@Cacheable(
value = "uav_all_state",
key = "'all'",
sync = true,
unless = "#result == null"
)
public UavDeviceStateResponseDTO getAllDeviceList() {
try {
String url = baseUrl + "/openapi/v0.1/project/device";
String result = httpService.doGet(url, null);
SK2ResultDTO resultDTO = JsonUtils.parseObject(result, SK2ResultDTO.class);
Map<String, Object> map = (Map<String, Object>) resultDTO.getData();
UavDeviceStateResponseDTO responseDTO = new UavDeviceStateResponseDTO();
if (!CollectionUtils.isEmpty(map)) {
List<Map<String, UavDevice>> l = (List<Map<String, UavDevice>>) map.get("list");
if (!CollectionUtils.isEmpty(l)) {
List<UavDeviceStateResponseDetailDTO> detail = new ArrayList<>();
responseDTO.setDetail(detail);
l.forEach(x -> {
// 方式1:如果droneObj是Map,用TypeReference反序列化(推荐)
UavProjectDeviceDTO up = JsonUtils.parseObject(
JsonUtils.toJsonString(x), // 先转JSON字符串
new TypeReference<UavProjectDeviceDTO>() {
}
);
UavDevice device = up.getDrone();
UavDevice getway = up.getGateway();
UavDeviceStateResponseDetailDTO dto = new UavDeviceStateResponseDetailDTO();
if (getway != null) {
dto.setGateway_sn(getway.getSn());
dto.setCallsign(getway.getCallsign());
dto.setOnlineStatus(getway.getDevice_online_status() ? 1 : 0);
dto.setGateway_camera_list(getway.getCamera_list());
if (device != null) {
dto.setDevice_sn(device.getSn());
dto.setDrone_callsign(device.getCallsign());
dto.setDrone_onlineStatus(device.getDevice_online_status() ? 1 : 0);
dto.setDrone_camera_list(device.getCamera_list());
}
detail.add(dto);
}
});
}
}
return responseDTO;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public List<UavDeviceStateResponseDetailDTO> getCurrentState() {
try {
String url = baseUrl + "/openapi/v0.1/project/device";
String result = httpService.doGet(url, null);
SK2ResultDTO resultDTO = JsonUtils.parseObject(result, SK2ResultDTO.class);
Map<String, Object> map = (Map<String, Object>) resultDTO.getData();
List<UavDeviceStateResponseDetailDTO> detail = new ArrayList<>();
if (!CollectionUtils.isEmpty(map)) {
List<Map<String, UavDevice>> l = (List<Map<String, UavDevice>>) map.get("list");
if (!CollectionUtils.isEmpty(l)) {
l.forEach(x -> {
// 方式1:如果droneObj是Map,用TypeReference反序列化(推荐)
UavProjectDeviceDTO up = JsonUtils.parseObject(
JsonUtils.toJsonString(x), // 先转JSON字符串
new TypeReference<UavProjectDeviceDTO>() {
}
);
UavDevice device = up.getDrone();
UavDevice getway = up.getGateway();
UavDeviceStateResponseDetailDTO dto = new UavDeviceStateResponseDetailDTO();
if (getway != null) {
dto.setGateway_sn(getway.getSn());
dto.setCallsign(getway.getCallsign());
dto.setOnlineStatus(getway.getDevice_online_status() ? 1 : 0);
dto.setGateway_camera_list(getway.getCamera_list());
if (device != null) {
dto.setDevice_sn(device.getSn());
dto.setDrone_callsign(device.getCallsign());
dto.setDrone_onlineStatus(device.getDevice_online_status() ? 1 : 0);
dto.setDrone_camera_list(device.getCamera_list());
}
detail.add(dto);
}
});
}
}
return detail;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@@ -261,6 +359,61 @@ public class UAVService {
return httpService.doGet(url, null);
}
public UavDeviceStateResponseDetailDTO getUAVState(String deviceSn, String droneSn) {
List<UavDeviceStateResponseDetailDTO> list = getCurrentState();
UavDeviceStateResponseDetailDTO dto = null;
if(!CollectionUtils.isEmpty(list)){
dto = list.stream().filter(x->x.getGateway_sn().equals(deviceSn)).findFirst().orElse(null);
if (!StringUtils.isEmpty(deviceSn)) {
String url = baseUrl + "/openapi/v0.1/device/" + deviceSn + "/state";
String deviceData = httpService.doGet(url, null);
SK2ResultDTO res = JsonUtils.parseObject(deviceData, SK2ResultDTO.class);
if (res != null && res.getData() != null) {
UavDeviceStateDTO stateDTO = JsonUtils.parseObject(
JsonUtils.toJsonString(res.getData()), // 先转JSON字符串
new TypeReference<UavDeviceStateDTO>() {
}
);
if (stateDTO != null && stateDTO.getDevice_state() != null) {
UavDeviceState deviceState = stateDTO.getDevice_state();
dto.setWind_speed(deviceState.getWind_speed());
dto.setEnvironment_temperature(deviceState.getEnvironment_temperature());
dto.setRainfall(deviceState.getRainfall());
// dto.setLatitude(deviceState.getLatitude());
// dto.setLongitude(deviceState.getLongitude());
}
}
}
if (!StringUtils.isEmpty(droneSn)) {
String droneUrl = baseUrl + "/openapi/v0.1/device/" + droneSn + "/state";
String droneData = httpService.doGet(droneUrl, null);
SK2ResultDTO res2 = JsonUtils.parseObject(droneData, SK2ResultDTO.class);
if (res2 != null && res2.getData() != null) {
UavDeviceStateDTO stateDTO = JsonUtils.parseObject(
JsonUtils.toJsonString(res2.getData()), // 先转JSON字符串
new TypeReference<UavDeviceStateDTO>() {
}
);
if (stateDTO != null && stateDTO.getDevice_state() != null) {
UavDeviceState deviceState = stateDTO.getDevice_state();
dto.setNetwork_state(deviceState.getNetwork_state());
dto.setPosition_state(deviceState.getPosition_state());
dto.setHome_distance(deviceState.getHome_distance());
dto.setHeight(deviceState.getHeight());
dto.setLatitude(deviceState.getLatitude());
dto.setLongitude(deviceState.getLongitude());
if (deviceState.getBattery() != null) {
dto.setCapacity_percent(deviceState.getBattery().getCapacity_percent());
}
}
}
}
}
return dto;
}
public String getWayline() {
String url = baseUrl + "/openapi/v0.1/wayline";
return httpService.doGet(url, null);