出去上传前端,以及设备上下线状态修改

master
yangxiaozhong 1 month ago
parent fbbe447f79
commit df1cbe260c

@ -6,7 +6,10 @@ import org.dromara.common.json.utils.JsonUtils;
import org.dromara.common.mqtt.handler.MqttMessageHandler;
import org.dromara.common.mqtt.server.MqttGateway;
import org.dromara.common.sse.dto.SseMessageDto;
import org.dromara.common.sse.enums.SseEnums;
import org.dromara.common.sse.utils.SseMessageUtils;
import org.dromara.hazard.domain.IotDevice;
import org.dromara.hazard.domain.bo.IotDeviceBo;
import org.dromara.hazard.domain.bo.IotSensorDataBo;
import org.dromara.hazard.domain.dto.Payload;
import org.dromara.hazard.domain.dto.SensorData;
@ -18,6 +21,7 @@ import org.dromara.hazard.service.IIotSensorService;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -143,7 +147,8 @@ public class HazardMqttMessageHandler implements MqttMessageHandler {
messageData.setValue(dataBo.getValue());
messageData.setType(iotSensorVo.getType());
String jsonStr = JSONUtil.toJsonStr(messageData);
dto.setMessage(topic+jsonStr);
dto.setMessage(jsonStr);
dto.setEvent(SseEnums.Event.HAZARD.getEvent());
// 如果需要指定特定用户接收消息可以设置userIds
// dto.setUserIds(List.of(userId));
SseMessageUtils.publishMessage(dto);
@ -167,8 +172,26 @@ public class HazardMqttMessageHandler implements MqttMessageHandler {
String sign = strings.get(0);
if ("OFFLINE".equals(sign)) {
log.info("设备 {} 下线。", strings.get(1));
//修改设备状态为下线状态
IotDeviceVo deviceVo = iotDeviceService.queryByDeviceCode(strings.get(1));
if (deviceVo != null){
deviceVo.setStatus("0");
IotDevice iotDeviceBo = new IotDevice();
BeanUtils.copyProperties(deviceVo, iotDeviceBo);
iotDeviceService.updateStatusByBo(iotDeviceBo);
}
}else if ("ONLINE".equals(sign)) {
log.info("设备 {} 上线。", strings.get(1));
//修改设备状态为上线状态
IotDeviceVo deviceVo = iotDeviceService.queryByDeviceCode(strings.get(1));
if (deviceVo != null){
deviceVo.setStatus("1");
IotDevice iotDeviceBo = new IotDevice();
BeanUtils.copyProperties(deviceVo, iotDeviceBo);
iotDeviceService.updateStatusByBo(iotDeviceBo);
}
}
}
}

@ -1,5 +1,6 @@
package org.dromara.hazard.service;
import org.dromara.hazard.domain.IotDevice;
import org.dromara.hazard.domain.vo.IotDeviceVo;
import org.dromara.hazard.domain.bo.IotDeviceBo;
import org.dromara.common.mybatis.core.page.TableDataInfo;
@ -67,4 +68,6 @@ public interface IIotDeviceService {
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
IotDeviceVo queryByDeviceCode(String deviceCode);
void updateStatusByBo(IotDevice iotDeviceBo);
}

@ -221,4 +221,9 @@ public class IotDeviceServiceImpl implements IIotDeviceService {
public IotDeviceVo queryByDeviceCode(String deviceCode) {
return baseMapper.selectVoOne(new LambdaQueryWrapper<IotDevice>().eq(IotDevice::getDeviceCode, deviceCode));
}
@Override
public void updateStatusByBo(IotDevice iotDevice) {
baseMapper.updateById(iotDevice);
}
}

Loading…
Cancel
Save