|
@@ -5,13 +5,9 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.huimv.guowei.admin.entity.EnvWarningInfo;
|
|
|
-import com.huimv.guowei.admin.service.IEnvWarningInfoService;
|
|
|
+import com.huimv.guowei.admin.entity.*;
|
|
|
+import com.huimv.guowei.admin.service.*;
|
|
|
import com.huimv.guowei.admin.utils.SpringUtil;
|
|
|
-import com.huimv.guowei.admin.entity.EnvDevice;
|
|
|
-import com.huimv.guowei.admin.entity.EnvDeviceEquipment;
|
|
|
-import com.huimv.guowei.admin.service.IEnvDeviceEquipmentService;
|
|
|
-import com.huimv.guowei.admin.service.IEnvDeviceService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
|
|
|
import org.eclipse.paho.client.mqttv3.MqttCallbackExtended;
|
|
@@ -20,6 +16,7 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.time.ZonedDateTime;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -33,6 +30,7 @@ public class PushCallback implements MqttCallbackExtended {
|
|
|
System.out.println("重新订阅!");
|
|
|
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
public void connectionLost(Throwable cause) {
|
|
|
// 连接丢失后,一般在这里面进行重连
|
|
@@ -76,7 +74,7 @@ public class PushCallback implements MqttCallbackExtended {
|
|
|
} catch (Exception e) {
|
|
|
System.out.println(e);
|
|
|
}
|
|
|
- }else if ("alarm_cfg".equals(messages)) {
|
|
|
+ } else if ("alarm_cfg".equals(messages)) {
|
|
|
log.info("高低温报警不做处理!!");
|
|
|
} else if ("get_dev_ctrl".equals(messages)) {
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
@@ -101,7 +99,7 @@ public class PushCallback implements MqttCallbackExtended {
|
|
|
PublishMQTT publishMQTT = new PublishMQTT();
|
|
|
publishMQTT.start("tcp://115.238.57.190:1883", "GUOWEIpublish", "admin", "admin", "huimv_down_" + chip, jsonObject.toJSONString());
|
|
|
log.info("---设备控制发送完成---");
|
|
|
- } else if ("dev_ctrl_suc".equals(messages)) {
|
|
|
+ } else if ("dev_ctrl_suc".equals(messages)) {
|
|
|
QueryWrapper<EnvDevice> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.eq("device_code", chip);
|
|
|
IEnvDeviceService envDeviceService = SpringUtil.getBean(IEnvDeviceService.class);
|
|
@@ -114,7 +112,7 @@ public class PushCallback implements MqttCallbackExtended {
|
|
|
for (EnvDeviceEquipment equipment : list) {
|
|
|
equipment.setUpdateTime(new Date());
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- System.out.println("----这个是应答时间:"+sdf.format(new Date()));
|
|
|
+ System.out.println("----这个是应答时间:" + sdf.format(new Date()));
|
|
|
envDeviceEquipmentService.updateById(equipment);
|
|
|
System.out.println("-----收到控制响应后修改标识成功!!");
|
|
|
}
|
|
@@ -123,7 +121,7 @@ public class PushCallback implements MqttCallbackExtended {
|
|
|
} else {
|
|
|
JSONObject jsonObject = JSON.parseObject(messages);
|
|
|
System.out.println("这里是1111:" + jsonObject);
|
|
|
- if (ObjectUtil.isNotEmpty(jsonObject.get("alarm_event"))) {
|
|
|
+ if (ObjectUtil.isNotEmpty(jsonObject.get("alarm_event"))) {
|
|
|
log.info("----报警信息开始保存---");
|
|
|
JSONObject jsonObject1 = (JSONObject) jsonObject.get("alarm_event");
|
|
|
try {
|
|
@@ -141,9 +139,9 @@ public class PushCallback implements MqttCallbackExtended {
|
|
|
warningInfo.setFarmId(one.getFarmId());
|
|
|
Integer type = (Integer) jsonObject1.get("sta");
|
|
|
if (type == 1) {
|
|
|
- warningInfo.setWarningContent(one.getBuildLocation()+"的设备断电报警!");
|
|
|
+ warningInfo.setWarningContent(one.getBuildLocation() + "的设备断电报警!");
|
|
|
} else {
|
|
|
- warningInfo.setWarningContent(one.getBuildLocation()+"的设备恢复供电!");
|
|
|
+ warningInfo.setWarningContent(one.getBuildLocation() + "的设备恢复供电!");
|
|
|
}
|
|
|
envWarningInfoService.save(warningInfo);
|
|
|
} catch (Exception e) {
|
|
@@ -151,12 +149,86 @@ public class PushCallback implements MqttCallbackExtended {
|
|
|
}
|
|
|
|
|
|
log.info("----报警信息保存成功!----");
|
|
|
+ } else if (ObjectUtil.isNotEmpty(jsonObject.get("sensor"))) {
|
|
|
+ log.info("开始处理传感器数据!");
|
|
|
+ IEnvDeviceService deviceService = SpringUtil.getBean(IEnvDeviceService.class);
|
|
|
+ EnvDevice device = deviceService.getOne(new QueryWrapper<EnvDevice>().eq("device_type", 1).eq("device_code", chip));
|
|
|
+ BigDecimal big = BigDecimal.valueOf(10);
|
|
|
+ Map map = (Map) jsonObject.get("sensor");
|
|
|
+
|
|
|
+ Map temp = (Map) map.get("temp");
|
|
|
+ JSONArray jsonArray = (JSONArray) temp.get("data");
|
|
|
+ BigDecimal data = new BigDecimal(Integer.parseInt(jsonArray.get(0).toString()));
|
|
|
+ BigDecimal temp2 = data.divide(big);
|
|
|
+ Map humi = (Map) map.get("humi");
|
|
|
+ JSONArray jsonArray1 = (JSONArray) humi.get("data");
|
|
|
+ BigDecimal data1 = new BigDecimal(Integer.parseInt(jsonArray1.get(0).toString()));
|
|
|
+ BigDecimal humi2 = data1.divide(big);
|
|
|
+ EnvData envData = new EnvData();
|
|
|
+ envData.setCreateTime(new Date());
|
|
|
+ envData.setEnvTemp(temp2.toString());
|
|
|
+ envData.setEnvHum(humi2.toString());
|
|
|
+ envData.setUnitId(device.getUnitId());
|
|
|
+ envData.setFarmId(device.getFarmId());
|
|
|
+ IEnvDataService dataService = SpringUtil.getBean(IEnvDataService.class);
|
|
|
+ dataService.save(envData);
|
|
|
+ log.info("温湿度处理完成!");
|
|
|
+
|
|
|
+ //水表的值
|
|
|
+ Map waterMeter = (Map) map.get("water_meter");
|
|
|
+ JSONArray jsonArray2 = (JSONArray) waterMeter.get("data");
|
|
|
+ IEnergyWaterService waterService = SpringUtil.getBean(IEnergyWaterService.class);
|
|
|
+// IEnvDeviceChipService chipService = SpringUtil.getBean(IEnvDeviceChipService.class);
|
|
|
+ for (int i = 0; i < jsonArray2.size(); i++) {
|
|
|
+ BigDecimal data2 = new BigDecimal(Integer.parseInt(jsonArray2.get(i).toString()));
|
|
|
+ BigDecimal waterMeter2 = data2.divide(big);
|
|
|
+ EnergyWater water = new EnergyWater();
|
|
|
+ water.setWaterValue(waterMeter2.toString());
|
|
|
+ water.setCreateDate(new Date());
|
|
|
+ water.setFarmId(device.getFarmId());
|
|
|
+ water.setUnitId(device.getUnitId());
|
|
|
+ water.setChipCode(device.getDeviceCode());
|
|
|
+ waterService.save(water);
|
|
|
+ }
|
|
|
+ log.info("水表处理完成!");
|
|
|
+
|
|
|
+ //电表的值
|
|
|
+ Map elect = (Map) map.get("electr_meter");
|
|
|
+ JSONArray jsonArray3 = (JSONArray) elect.get("data");
|
|
|
+ BigDecimal data2 = new BigDecimal(Integer.parseInt(jsonArray3.get(0).toString()));
|
|
|
+ BigDecimal elect2 = data2.divide(big);
|
|
|
+ IEnergyElectricityService electricityService = SpringUtil.getBean(IEnergyElectricityService.class);
|
|
|
+ EnergyElectricity electricity = new EnergyElectricity();
|
|
|
+ electricity.setCreateDate(new Date());
|
|
|
+ electricity.setElectricityValue(elect2.toString());
|
|
|
+ electricity.setUnitId(device.getUnitId());
|
|
|
+ electricity.setFarmId(device.getFarmId());
|
|
|
+ electricityService.save(electricity);
|
|
|
+ log.info("电表处理完成!");
|
|
|
+
|
|
|
+ //水压的值
|
|
|
+ Map waterPress = (Map) map.get("water_press");
|
|
|
+ JSONArray jsonArray4 = (JSONArray) waterPress.get("data");
|
|
|
+ IEnergyWaterPressureService pressureService = SpringUtil.getBean(IEnergyWaterPressureService.class);
|
|
|
+ for (int i = 0; i < jsonArray4.size(); i++) {
|
|
|
+ BigDecimal data3 = new BigDecimal(Integer.parseInt(jsonArray4.get(i).toString()));
|
|
|
+ BigDecimal waterMeter2 = data3.divide(big);
|
|
|
+ EnergyWaterPressure waterPressure = new EnergyWaterPressure();
|
|
|
+ waterPressure.setWaterValue(waterMeter2.toString());
|
|
|
+ waterPressure.setFarmId(device.getFarmId());
|
|
|
+ waterPressure.setUnitId(device.getUnitId());
|
|
|
+ waterPressure.setChipCode(device.getDeviceCode());
|
|
|
+ waterPressure.setCreateDate(LocalDateTime.now());
|
|
|
+ pressureService.save(waterPressure);
|
|
|
+ }
|
|
|
+ log.info("水压处理完成!");
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
System.out.println("数据处理完成!");
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
}
|