|
@@ -14,6 +14,7 @@ import com.huimv.env.common.utils.Const;
|
|
import com.huimv.env.common.utils.DateUtil;
|
|
import com.huimv.env.common.utils.DateUtil;
|
|
import com.huimv.env.common.utils.MathUtil;
|
|
import com.huimv.env.common.utils.MathUtil;
|
|
import com.huimv.env.device.producer.Producer;
|
|
import com.huimv.env.device.producer.Producer;
|
|
|
|
+import com.huimv.env.device.service.IDeviceService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
|
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
@@ -41,28 +42,18 @@ import java.util.Map;
|
|
@Slf4j
|
|
@Slf4j
|
|
public class DeviceListener {
|
|
public class DeviceListener {
|
|
@Autowired
|
|
@Autowired
|
|
- private EnvTempEntityRepo envTempEntityRepo;
|
|
|
|
- @Autowired
|
|
|
|
- private EnvHumiEntityRepo envHumiEntityRepo;
|
|
|
|
- @Autowired
|
|
|
|
- private EnvAmmoniaEntityRepo envAmmoniaEntityRepo;
|
|
|
|
- @Autowired
|
|
|
|
private IDeviceRegisterService deviceRegisterService;
|
|
private IDeviceRegisterService deviceRegisterService;
|
|
@Autowired
|
|
@Autowired
|
|
- private ISensorRegisterService sensorRegisterService;
|
|
|
|
|
|
+ private IDeviceService deviceService;
|
|
@Autowired
|
|
@Autowired
|
|
private MathUtil mathUtil;
|
|
private MathUtil mathUtil;
|
|
- @Autowired
|
|
|
|
- private DateUtil dateUtil;
|
|
|
|
- @Autowired
|
|
|
|
- private Producer producer;
|
|
|
|
|
|
|
|
@RabbitListener(queues = Const.QUEUE_TEMP)
|
|
@RabbitListener(queues = Const.QUEUE_TEMP)
|
|
@RabbitHandler
|
|
@RabbitHandler
|
|
public void processTemp(Map RawMap) throws ParseException {
|
|
public void processTemp(Map RawMap) throws ParseException {
|
|
System.out.println(">>>>>>>>>>>>>>接收温度数据 RawMap>>" + RawMap.toString());
|
|
System.out.println(">>>>>>>>>>>>>>接收温度数据 RawMap>>" + RawMap.toString());
|
|
String askText = RawMap.get("askText").toString();
|
|
String askText = RawMap.get("askText").toString();
|
|
- JSONObject dataJo = handleAskText(askText);
|
|
|
|
|
|
+ JSONObject dataJo = deviceService.handleAskText(askText);
|
|
dataJo.put("dataUnit", "°");
|
|
dataJo.put("dataUnit", "°");
|
|
System.out.println("温度数据=" + dataJo);
|
|
System.out.println("温度数据=" + dataJo);
|
|
java.sql.Date todayDate = new java.sql.Date(new java.util.Date().getTime());
|
|
java.sql.Date todayDate = new java.sql.Date(new java.util.Date().getTime());
|
|
@@ -78,52 +69,11 @@ public class DeviceListener {
|
|
String temp = new BigDecimal(mathUtil.countTemp(dataJo.getIntValue("value"))).setScale(1, RoundingMode.UP) + dataJo.getString("dataUnit");
|
|
String temp = new BigDecimal(mathUtil.countTemp(dataJo.getIntValue("value"))).setScale(1, RoundingMode.UP) + dataJo.getString("dataUnit");
|
|
int sensorSort = 1;
|
|
int sensorSort = 1;
|
|
//更新传感器数据
|
|
//更新传感器数据
|
|
-// updateSensorRegister(deviceCode, dataJo.getInteger("sensorSn"), nowTimestamp, todayDate, temp, farmCode,sensorSort);
|
|
|
|
- sendSensorToMQ(deviceCode, dataJo.getInteger("sensorSn"), nowTimestamp, todayDate, temp, farmCode,sensorSort);
|
|
|
|
|
|
+// deviceService.updateSensorRegister(deviceCode, dataJo.getInteger("sensorSn"), nowTimestamp, todayDate, temp, farmCode,sensorSort);
|
|
|
|
+ deviceService.sendSensorToMQ(deviceCode, dataJo.getInteger("sensorSn"), nowTimestamp, todayDate, temp, farmCode,sensorSort);
|
|
|
|
|
|
//保存温度流水数据
|
|
//保存温度流水数据
|
|
- saveTempFlow(dataJo, envDeviceRegisterEntity, nowTimestamp, todayDate, farmCode);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void sendSensorToMQ(String deviceCode, Integer sensorSn, Timestamp nowTimestamp, Date todayDate, String value, String farmCode, int sensorSort) {
|
|
|
|
- JSONObject sensorJo = new JSONObject();
|
|
|
|
- sensorJo.put("deviceCode",deviceCode);
|
|
|
|
- sensorJo.put("sensorSn",sensorSn);
|
|
|
|
- sensorJo.put("timestamp",nowTimestamp);
|
|
|
|
- sensorJo.put("todayDate",todayDate);
|
|
|
|
- sensorJo.put("value",value);
|
|
|
|
- sensorJo.put("farmCode",farmCode);
|
|
|
|
- sensorJo.put("sensorSort",sensorSort);
|
|
|
|
- producer.sendSensorAskToMQ(sensorJo);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //更新传感器数据
|
|
|
|
- private void updateSensorRegister(String deviceCode, int sensorSn, Timestamp nowTimestamp, Date todayDate, String value, String farmCode, int sensorSort) {
|
|
|
|
- if (sensorRegisterService.isExistSensorRegister(deviceCode, sensorSn, farmCode,sensorSort)) {
|
|
|
|
- System.out.println("更新...");
|
|
|
|
- //{更新传感器注册信息}
|
|
|
|
- sensorRegisterService.updateSensorRegister(deviceCode, sensorSn, nowTimestamp, todayDate, value, farmCode,sensorSort);
|
|
|
|
- } else {
|
|
|
|
- System.out.println("新建...");
|
|
|
|
- //{保存传感器注册信息}
|
|
|
|
- sensorRegisterService.saveSensorRegister(deviceCode, sensorSn, nowTimestamp, todayDate, value, farmCode,sensorSort);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //保存温度流水数据
|
|
|
|
- private void saveTempFlow(JSONObject dataJo, EnvDeviceRegisterEntity envDeviceRegisterEntity, Timestamp nowTimestamp, Date todayDate, String farmCode) {
|
|
|
|
- EnvTempEntity envTempEntity = new EnvTempEntity();
|
|
|
|
- envTempEntity.setDeviceCode(dataJo.getString("deviceCode"));
|
|
|
|
- envTempEntity.setSensorSn(dataJo.getInteger("sensorSn"));
|
|
|
|
- envTempEntity.setTemp(new BigDecimal(mathUtil.countTemp(dataJo.getIntValue("value"))));
|
|
|
|
- envTempEntity.setAskTime(dateUtil.handleAskTime(dataJo.getString("askTime")));
|
|
|
|
- envTempEntity.setAddTime(nowTimestamp);
|
|
|
|
- envTempEntity.setAddDate(todayDate);
|
|
|
|
- envTempEntity.setFarmCode(farmCode);
|
|
|
|
- envTempEntity.setPigpenId(envDeviceRegisterEntity.getPigpenId());
|
|
|
|
- envTempEntity.setUnitId(envDeviceRegisterEntity.getUnitId());
|
|
|
|
- envTempEntity.setDataUnit(dataJo.getString("dataUnit"));
|
|
|
|
- envTempEntityRepo.saveAndFlush(envTempEntity);
|
|
|
|
|
|
+ deviceService.saveTempFlow(dataJo, envDeviceRegisterEntity, nowTimestamp, todayDate, farmCode);
|
|
}
|
|
}
|
|
|
|
|
|
@RabbitListener(queues = Const.QUEUE_HUMI)
|
|
@RabbitListener(queues = Const.QUEUE_HUMI)
|
|
@@ -131,7 +81,7 @@ public class DeviceListener {
|
|
public void processHumi(Map RawMap) throws ParseException {
|
|
public void processHumi(Map RawMap) throws ParseException {
|
|
System.out.println(">>>>>>>>>>>>>>接收湿度数据 RawMap>>" + RawMap.toString());
|
|
System.out.println(">>>>>>>>>>>>>>接收湿度数据 RawMap>>" + RawMap.toString());
|
|
String askText = RawMap.get("askText").toString();
|
|
String askText = RawMap.get("askText").toString();
|
|
- JSONObject dataJo = handleAskText(askText);
|
|
|
|
|
|
+ JSONObject dataJo = deviceService.handleAskText(askText);
|
|
dataJo.put("dataUnit", "%");
|
|
dataJo.put("dataUnit", "%");
|
|
System.out.println("湿度数据=" + dataJo);
|
|
System.out.println("湿度数据=" + dataJo);
|
|
String todayDateText = new DateUtil().getTodayDateText();
|
|
String todayDateText = new DateUtil().getTodayDateText();
|
|
@@ -148,26 +98,10 @@ public class DeviceListener {
|
|
String humi = new BigDecimal(mathUtil.countTemp(dataJo.getIntValue("value"))).setScale(1, RoundingMode.UP) + dataJo.getString("dataUnit");
|
|
String humi = new BigDecimal(mathUtil.countTemp(dataJo.getIntValue("value"))).setScale(1, RoundingMode.UP) + dataJo.getString("dataUnit");
|
|
int sensorSort = 2;
|
|
int sensorSort = 2;
|
|
//更新传感器数据
|
|
//更新传感器数据
|
|
-// updateSensorRegister(deviceCode, dataJo.getInteger("sensorSn"), nowTimestamp, todayDate, humi, farmCode, sensorSort);
|
|
|
|
- sendSensorToMQ(deviceCode, dataJo.getInteger("sensorSn"), nowTimestamp, todayDate, humi, farmCode, sensorSort);
|
|
|
|
|
|
+// deviceService.updateSensorRegister(deviceCode, dataJo.getInteger("sensorSn"), nowTimestamp, todayDate, humi, farmCode, sensorSort);
|
|
|
|
+ deviceService.sendSensorToMQ(deviceCode, dataJo.getInteger("sensorSn"), nowTimestamp, todayDate, humi, farmCode, sensorSort);
|
|
//保存湿度流水数据
|
|
//保存湿度流水数据
|
|
- saveHumiFlow(dataJo, envDeviceRegisterEntity, nowTimestamp, todayDate, farmCode);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //保存湿度流水数据
|
|
|
|
- private void saveHumiFlow(JSONObject dataJo, EnvDeviceRegisterEntity envDeviceRegisterEntity, Timestamp nowTimestamp, Date todayDate, String farmCode) {
|
|
|
|
- EnvHumiEntity envHumiEntity = new EnvHumiEntity();
|
|
|
|
- envHumiEntity.setDeviceCode(dataJo.getString("deviceCode"));
|
|
|
|
- envHumiEntity.setSensorSn(dataJo.getInteger("sensorSn"));
|
|
|
|
- envHumiEntity.setHumi(new BigDecimal(mathUtil.countHumi(dataJo.getIntValue("value"))));
|
|
|
|
- envHumiEntity.setAskTime(dateUtil.handleAskTime(dataJo.getString("askTime")));
|
|
|
|
- envHumiEntity.setAddTime(nowTimestamp);
|
|
|
|
- envHumiEntity.setAddDate(todayDate);
|
|
|
|
- envHumiEntity.setFarmCode(farmCode);
|
|
|
|
- envHumiEntity.setPigpenId(envDeviceRegisterEntity.getPigpenId());
|
|
|
|
- envHumiEntity.setUnitId(envDeviceRegisterEntity.getUnitId());
|
|
|
|
- envHumiEntity.setDataUnit(dataJo.getString("dataUnit"));
|
|
|
|
- envHumiEntityRepo.saveAndFlush(envHumiEntity);
|
|
|
|
|
|
+ deviceService.saveHumiFlow(dataJo, envDeviceRegisterEntity, nowTimestamp, todayDate, farmCode);
|
|
}
|
|
}
|
|
|
|
|
|
@RabbitListener(queues = Const.QUEUE_AMMONIA)
|
|
@RabbitListener(queues = Const.QUEUE_AMMONIA)
|
|
@@ -175,7 +109,7 @@ public class DeviceListener {
|
|
public void processAmmonia(Map RawMap) throws ParseException {
|
|
public void processAmmonia(Map RawMap) throws ParseException {
|
|
System.out.println(">>>>>>>>>>>>>>接收氨气数据 RawMap>>" + RawMap.toString());
|
|
System.out.println(">>>>>>>>>>>>>>接收氨气数据 RawMap>>" + RawMap.toString());
|
|
String askText = RawMap.get("askText").toString();
|
|
String askText = RawMap.get("askText").toString();
|
|
- JSONObject dataJo = handleAskText(askText);
|
|
|
|
|
|
+ JSONObject dataJo = deviceService.handleAskText(askText);
|
|
dataJo.put("dataUnit", "ppm");
|
|
dataJo.put("dataUnit", "ppm");
|
|
System.out.println("氨气数据=" + dataJo);
|
|
System.out.println("氨气数据=" + dataJo);
|
|
String todayDateText = new DateUtil().getTodayDateText();
|
|
String todayDateText = new DateUtil().getTodayDateText();
|
|
@@ -192,42 +126,35 @@ public class DeviceListener {
|
|
String anmonia = dataJo.getString("value") + dataJo.getString("dataUnit");
|
|
String anmonia = dataJo.getString("value") + dataJo.getString("dataUnit");
|
|
int sensorSort = 3;
|
|
int sensorSort = 3;
|
|
//更新传感器数据
|
|
//更新传感器数据
|
|
-// updateSensorRegister(deviceCode, dataJo.getInteger("sensorSn"), nowTimestamp, todayDate, anmonia, farmCode, sensorSort);
|
|
|
|
- sendSensorToMQ(deviceCode, dataJo.getInteger("sensorSn"), nowTimestamp, todayDate, anmonia, farmCode, sensorSort);
|
|
|
|
|
|
+// deviceService.updateSensorRegister(deviceCode, dataJo.getInteger("sensorSn"), nowTimestamp, todayDate, anmonia, farmCode, sensorSort);
|
|
|
|
+ deviceService.sendSensorToMQ(deviceCode, dataJo.getInteger("sensorSn"), nowTimestamp, todayDate, anmonia, farmCode, sensorSort);
|
|
//保存氨气流水数据
|
|
//保存氨气流水数据
|
|
- saveAmmoniaFlow(dataJo, envDeviceRegisterEntity, nowTimestamp, todayDate, farmCode);
|
|
|
|
|
|
+ deviceService.saveAmmoniaFlow(dataJo, envDeviceRegisterEntity, nowTimestamp, todayDate, farmCode);
|
|
}
|
|
}
|
|
|
|
|
|
- //保存氨气流水数据
|
|
|
|
- private void saveAmmoniaFlow(JSONObject dataJo, EnvDeviceRegisterEntity envDeviceRegisterEntity, Timestamp nowTimestamp, Date todayDate, String farmCode) {
|
|
|
|
- EnvAmmoniaEntity envAmmoniaEntity = new EnvAmmoniaEntity();
|
|
|
|
- envAmmoniaEntity.setDeviceCode(dataJo.getString("deviceCode"));
|
|
|
|
- envAmmoniaEntity.setSensorSn(dataJo.getInteger("sensorSn"));
|
|
|
|
- envAmmoniaEntity.setAmmonia(new BigDecimal(dataJo.getIntValue("value")));
|
|
|
|
- envAmmoniaEntity.setAskTime(dateUtil.handleAskTime(dataJo.getString("askTime")));
|
|
|
|
- envAmmoniaEntity.setAddTime(nowTimestamp);
|
|
|
|
- envAmmoniaEntity.setAddDate(todayDate);
|
|
|
|
- envAmmoniaEntity.setFarmCode(farmCode);
|
|
|
|
- envAmmoniaEntity.setPigpenId(envDeviceRegisterEntity.getPigpenId());
|
|
|
|
- envAmmoniaEntity.setUnitId(envDeviceRegisterEntity.getUnitId());
|
|
|
|
- envAmmoniaEntity.setDataUnit(dataJo.getString("dataUnit"));
|
|
|
|
- envAmmoniaEntityRepo.saveAndFlush(envAmmoniaEntity);
|
|
|
|
- }
|
|
|
|
|
|
+ @RabbitListener(queues = Const.QUEUE_DEVICE_STATUS)
|
|
|
|
+ @RabbitHandler
|
|
|
|
+ public void processDeviceStatus(Map RawMap) throws ParseException {
|
|
|
|
+ System.out.println(">>>>>>>>>>>>>>接收设备状态数据 RawMap>>" + RawMap.toString());
|
|
|
|
+ String askText = RawMap.get("askText").toString();
|
|
|
|
+ JSONObject dataJo = deviceService.handleAskText(askText);
|
|
|
|
+ System.out.println("设备状态=" + dataJo);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
- //
|
|
|
|
- private JSONObject handleAskText(String askText) {
|
|
|
|
- String[] dataArray = askText.split("\\+");
|
|
|
|
- return buildDataObj(dataArray);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- //
|
|
|
|
- public JSONObject buildDataObj(String[] dataArray) {
|
|
|
|
- JSONObject dataJo = new JSONObject();
|
|
|
|
- dataJo.put("deviceCode", dataArray[1]);
|
|
|
|
- dataJo.put("cmd", dataArray[2]);
|
|
|
|
- dataJo.put("sensorSn", dataArray[3]);
|
|
|
|
- dataJo.put("value", dataArray[4]);
|
|
|
|
- dataJo.put("askTime", dataArray[5]);
|
|
|
|
- return dataJo;
|
|
|
|
|
|
+
|
|
|
|
+ @RabbitListener(queues = Const.QUEUE_PUSH_MESSAGE)
|
|
|
|
+ @RabbitHandler
|
|
|
|
+ public void processPushMessage(Map RawMap) throws ParseException {
|
|
|
|
+ System.out.println(">>>>>>>>>>>>>>接收平台推送消息 RawMap>>" + RawMap.toString());
|
|
|
|
+ String askText = RawMap.get("askText").toString();
|
|
|
|
+ JSONObject dataJo = deviceService.handleAskText(askText);
|
|
|
|
+ System.out.println("平台推送消息=" + dataJo);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|