|
@@ -5,8 +5,10 @@ import cn.hutool.json.JSON;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.huimv.env.common.entity.BaseFarm;
|
|
|
+import com.huimv.env.common.entity.EnergyEnvDevice;
|
|
|
import com.huimv.env.common.entity.Gateway;
|
|
|
import com.huimv.env.common.entity.vo.AllData;
|
|
|
+import com.huimv.env.common.mapper.EnergyEnvDeviceMapper;
|
|
|
import com.huimv.env.common.service.IBaseFarmService;
|
|
|
import com.huimv.env.common.service.IGatewayService;
|
|
|
import com.huimv.env.common.utils.Const;
|
|
@@ -14,6 +16,7 @@ import com.huimv.env.common.utils.MathUtil2;
|
|
|
import com.huimv.env.common.utils.SendSMS;
|
|
|
import com.huimv.env.device.service.DataService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.checkerframework.checker.units.qual.A;
|
|
|
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
|
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -33,6 +36,8 @@ public class DeviceListener {
|
|
|
private IGatewayService gatewayService;
|
|
|
@Autowired
|
|
|
private IBaseFarmService farmService;
|
|
|
+ @Autowired
|
|
|
+ private EnergyEnvDeviceMapper deviceMapper;
|
|
|
|
|
|
|
|
|
@RabbitListener(queues = Const.QUEUE_ENV_SHUI_HUIMV_DATA)
|
|
@@ -52,6 +57,15 @@ public class DeviceListener {
|
|
|
//数据
|
|
|
String payload = allData.getContent().getNodeUplinkPacket().getNode().getPayload();
|
|
|
dataService.saveData(payload, timestamp, nodeEui);
|
|
|
+ QueryWrapper<EnergyEnvDevice> queryWrapper = new QueryWrapper<>();
|
|
|
+ nodeEui = nodeEui.substring(nodeEui.length() - 8);
|
|
|
+ queryWrapper.eq("device_code", nodeEui);
|
|
|
+ EnergyEnvDevice envDevice = deviceMapper.selectOne(queryWrapper);
|
|
|
+ if (ObjectUtil.isNotEmpty(envDevice)) {
|
|
|
+ envDevice.setDeviceStatus(1);
|
|
|
+ deviceMapper.updateById(envDevice);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
if ("NODE_ONLINE".equals(event)) {
|
|
@@ -63,6 +77,14 @@ public class DeviceListener {
|
|
|
//离线通知
|
|
|
String payload = allData.getContent().getNodeUplinkPacket().getNode().getPayload();
|
|
|
dataService.saveOffInfo(payload, timestamp, nodeEui);
|
|
|
+ QueryWrapper<EnergyEnvDevice> queryWrapper = new QueryWrapper<>();
|
|
|
+ nodeEui = nodeEui.substring(nodeEui.length() - 8);
|
|
|
+ queryWrapper.eq("device_code", nodeEui);
|
|
|
+ EnergyEnvDevice envDevice = deviceMapper.selectOne(queryWrapper);
|
|
|
+ if (ObjectUtil.isNotEmpty(envDevice)) {
|
|
|
+ envDevice.setDeviceStatus(0);
|
|
|
+ deviceMapper.updateById(envDevice);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if ("GATEWAY_ONLINE".equals(event)) {
|