| | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.ard.common.core.redis.RedisConst; |
| | | import com.ard.common.core.redis.RedisOpsUtils; |
| | | import com.ard.ossdock.service.impl.OssDockServiceContext; |
| | | import com.ard.sample.component.websocket.enums.MessageType; |
| | | import com.ard.sample.component.websocket.handler.DockWebSocketHandler; |
| | | import com.ard.sample.manage.model.dto.DeviceDTO; |
| | | import com.ard.sample.manage.service.IDeviceService; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.net.URL; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class DockOnlineServiceImpl { |
| | | |
| | |
| | | |
| | | @Autowired |
| | | protected ObjectMapper _objectMapper; |
| | | |
| | | @Resource |
| | | private OssDockServiceContext _ossService; |
| | | |
| | | /** |
| | | * 定时任务,每5秒取一次机场设备的在线状态,如已离线更新状态 |
| | |
| | | if(!_deviceService.checkDeviceOnline(device.getDeviceSn())){ |
| | | _deviceService.updateWorkType(device.getDeviceSn(), 3L); |
| | | RedisOpsUtils.setWithExpire(RedisConst.OSD_STATUS_PREFIX + device.getDeviceSn(), 3, RedisConst.DEVICE_ALIVE_SECOND); |
| | | RedisOpsUtils.del(RedisConst.WEBSOCKET_VIDEO_ADDRESS_PREFIX + device.getDeviceSn()); |
| | | RedisOpsUtils.del(RedisConst.COVER_STATE_PREFIX + device.getDeviceSn()); |
| | | } |
| | | if(!_deviceService.checkDeviceOnline(device.getChildDeviceSn())){ |
| | | _deviceService.updateWorkType(device.getChildDeviceSn(), 6L); |
| | | RedisOpsUtils.del(RedisConst.WEBSOCKET_VIDEO_ADDRESS_PREFIX + device.getChildDeviceSn()); |
| | | RedisOpsUtils.del(RedisConst.COVER_STATE_PREFIX + device.getDeviceSn()); |
| | | } |
| | | } |
| | | } |
| | |
| | | * */ |
| | | @Scheduled(cron = "0/5 * * * * ?") |
| | | public void sendDeviceStatus(){ |
| | | // 测试 机场oss读取文件 |
| | | // URL url = _ossService.getObjectUrl("kmz","/2025/11/25/新建航点航线(1)_20251125161322A001.kmz"); |
| | | // log.info("机场任务航线文件url地址:{}", url.toString()); |
| | | // 发送设备状态到websocket客户端 |
| | | List<DeviceDTO> devicesList = _deviceService.getDevicesTopoForWeb(); |
| | | for (DeviceDTO device : devicesList) { |
| | |
| | | dockStatus = String.valueOf(RedisOpsUtils.get(RedisConst.OSD_STATUS_PREFIX + device.getDeviceSn())); |
| | | } |
| | | if(RedisOpsUtils.checkExist(RedisConst.OSD_STATUS_PREFIX + device.getChildDeviceSn())){ |
| | | droneStatus = String.valueOf(RedisOpsUtils.get(RedisConst.OSD_STATUS_PREFIX + device.getChildDeviceSn()));; |
| | | droneStatus = String.valueOf(RedisOpsUtils.get(RedisConst.OSD_STATUS_PREFIX + device.getChildDeviceSn())); |
| | | } |
| | | String json = getJSONString(device.getDeviceSn(), dockStatus, device.getChildDeviceSn(), droneStatus); |
| | | String json = getJSONString(MessageType.STATE.getType(), device.getDeviceSn(), dockStatus, droneStatus); |
| | | |
| | | // 发送给websocket客户端 |
| | | _dockWebSocketHandler.sendMessageToSubscribers(device.getDeviceSn(), MessageType.STATE.getType(), json); |
| | | } |
| | | } |
| | | |
| | | public String getJSONString(String dockSn, String dockStatus, String droneSn, String droneStatus){ |
| | | public String getJSONString(String messageType, String dockSn, String dockStatus, String droneStatus){ |
| | | Map<String, Object> json = new HashMap<>(); |
| | | json.put("code", 200); |
| | | json.put("type", MessageType.STATE.getType()); |
| | | json.put("gateway", dockSn); |
| | | json.put("type", messageType); |
| | | json.put("message", "success"); |
| | | |
| | | Map<String, String> data = new HashMap<>(); |
| | | data.put("docksn", dockSn); |
| | | data.put("state", dockStatus); |
| | | data.put("dockstate", dockStatus); |
| | | data.put("dronestate", droneStatus); |
| | | |
| | | Map<String, String> data1 = new HashMap<>(); |
| | | data1.put("droneSn", droneSn); |
| | | data1.put("state", droneStatus); |
| | | |
| | | List<Map<String, String>> lstMap = new ArrayList<>(); |
| | | lstMap.add(data); |
| | | lstMap.add(data1); |
| | | |
| | | json.put("data", lstMap); |
| | | json.put("data", data); |
| | | |
| | | // 将Map转换为JSON字符串 |
| | | String jsonString = ""; |