|
@@ -2,6 +2,7 @@ package com.huimv.eartag2.process.listener;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.huimv.eartag2.common.mq.Const;
|
|
import com.huimv.eartag2.common.mq.Const;
|
|
|
|
+//import com.huimv.eartag2.common.utils.MathUtil;
|
|
import com.huimv.eartag2.process.producer.ProcessProducer;
|
|
import com.huimv.eartag2.process.producer.ProcessProducer;
|
|
import com.huimv.eartag2.process.service.IDeviceService;
|
|
import com.huimv.eartag2.process.service.IDeviceService;
|
|
import com.huimv.eartag2.process.service.IEartagService;
|
|
import com.huimv.eartag2.process.service.IEartagService;
|
|
@@ -13,6 +14,7 @@ import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
@@ -29,7 +31,7 @@ import java.util.Map;
|
|
@Component
|
|
@Component
|
|
@Slf4j
|
|
@Slf4j
|
|
//@RabbitListener(queues = "topic.device")
|
|
//@RabbitListener(queues = "topic.device")
|
|
-public class DeviceListener {
|
|
|
|
|
|
+public class FlowListener {
|
|
@Autowired
|
|
@Autowired
|
|
private MathUtil mathUtil;
|
|
private MathUtil mathUtil;
|
|
@Autowired
|
|
@Autowired
|
|
@@ -53,58 +55,52 @@ public class DeviceListener {
|
|
}
|
|
}
|
|
|
|
|
|
// @RabbitListener(queues = "topic.askText.queue")
|
|
// @RabbitListener(queues = "topic.askText.queue")
|
|
- @RabbitListener(queues = Const.QUEUE_NAME_ASK)
|
|
|
|
|
|
+ @RabbitListener(queues = Const.QUEUE_ASK)
|
|
@RabbitHandler
|
|
@RabbitHandler
|
|
public void processRawdata(Map RawMap) throws ParseException {
|
|
public void processRawdata(Map RawMap) throws ParseException {
|
|
|
|
+ System.out.println("<<<<<<<<<<<<<<< RawMap>>"+RawMap.toString());
|
|
String askText = RawMap.get("askText").toString();
|
|
String askText = RawMap.get("askText").toString();
|
|
System.out.println("askText>>"+askText);
|
|
System.out.println("askText>>"+askText);
|
|
- //--保存原始数据
|
|
|
|
- //--保存设备心跳数据
|
|
|
|
- //--保存设备环境数据
|
|
|
|
- //--保存耳标数据
|
|
|
|
|
|
+ //本模块主要执行保存以下4类数据:(其他注册数据,在线数据,状态数据等都是由其他模块工程执行处理-process2模块工程)
|
|
|
|
+ //--保存原始流水数据(原始流水表)
|
|
|
|
+ //--保存设备心跳流水数据(设备心跳流水表)
|
|
|
|
+ //--保存设备环境流水数据(设备温度流水表)
|
|
|
|
+ //--保存耳标流水数据(耳标流水表)
|
|
|
|
|
|
- //--处理请求报文
|
|
|
|
|
|
+ //处理请求报文//
|
|
Map askMap = handleAskText(askText);
|
|
Map askMap = handleAskText(askText);
|
|
String type = askMap.get("type").toString();
|
|
String type = askMap.get("type").toString();
|
|
JSONObject dataJo = (JSONObject) askMap.get("data");
|
|
JSONObject dataJo = (JSONObject) askMap.get("data");
|
|
switch (type){
|
|
switch (type){
|
|
case "device-heartbeat":
|
|
case "device-heartbeat":
|
|
//--(1)处理心跳数据
|
|
//--(1)处理心跳数据
|
|
- //保存设备注册数据(MySQL,Redis)-processProducer
|
|
|
|
- //保存设备在线数据(MySQL,Redis)-processProducer
|
|
|
|
- //保存设备状态数据(MySQL,Redis)-processProducer
|
|
|
|
- //保存设备心跳流水数据(MySQL)
|
|
|
|
- //++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
- //
|
|
|
|
- deviceService.saveDeviceHartbeat(dataJo);
|
|
|
|
- //
|
|
|
|
- processProducer.sendDeviceMain(dataJo);
|
|
|
|
|
|
+ //--保存设备心跳流水数据(MySQL)
|
|
|
|
+
|
|
|
|
+ //保存心跳流水数据
|
|
|
|
+ deviceService.saveDeviceHeartbeat(dataJo);
|
|
|
|
+ //发送心跳数据到MQ
|
|
|
|
+ processProducer.sendHeartbeat(dataJo);
|
|
break;
|
|
break;
|
|
case "device-temp":
|
|
case "device-temp":
|
|
//--(2)处理环境数据
|
|
//--(2)处理环境数据
|
|
- //保存设备注册数据(MySQL,Redis)-processProducer
|
|
|
|
- //保存设备环境流水数据(MySQL)
|
|
|
|
- //++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
- //
|
|
|
|
|
|
+ //--保存设备环境流水数据(MySQL)
|
|
|
|
+
|
|
|
|
+ //保存设备环境温度流水数据
|
|
deviceService.saveDeviceTemp(dataJo);
|
|
deviceService.saveDeviceTemp(dataJo);
|
|
- //
|
|
|
|
- processProducer.sendRegisterMain(dataJo);
|
|
|
|
|
|
+ //发送设备环境温度数据到MQ
|
|
|
|
+ processProducer.sendDeviceTemp(dataJo);
|
|
break;
|
|
break;
|
|
case "eartag":
|
|
case "eartag":
|
|
//--(3)处理耳标数据
|
|
//--(3)处理耳标数据
|
|
- //保存耳标注册数据(MySQL,Redis)-processProducer
|
|
|
|
- //保存耳标在线数据(MySQL,Redis)-processProducer
|
|
|
|
- //保存耳标状态数据(MySQL,Redis)-processProducer
|
|
|
|
- //保存耳标流水数据(MySQL)
|
|
|
|
- //++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
- //
|
|
|
|
|
|
+ //--保存耳标流水数据(MySQL)
|
|
|
|
+
|
|
|
|
+ //保存耳标流水数据
|
|
eartagService.saveEartag(dataJo);
|
|
eartagService.saveEartag(dataJo);
|
|
- //
|
|
|
|
- processProducer.sendEartagMain(dataJo);
|
|
|
|
|
|
+ //发送耳标数据到MQ
|
|
|
|
+ processProducer.sendEartag(dataJo);
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
}
|
|
}
|
|
- System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
|
|
|
|
//保存原始数据//
|
|
//保存原始数据//
|
|
deviceService.saveRawdata(askText);
|
|
deviceService.saveRawdata(askText);
|
|
}
|
|
}
|
|
@@ -149,7 +145,7 @@ public class DeviceListener {
|
|
log.error("##当前数据为非法数据>>" + askText);
|
|
log.error("##当前数据为非法数据>>" + askText);
|
|
}
|
|
}
|
|
} else if (cmdHeader.trim().equalsIgnoreCase("zj")) {
|
|
} else if (cmdHeader.trim().equalsIgnoreCase("zj")) {
|
|
- String device = dataArray[1];
|
|
|
|
|
|
+// String device = dataArray[1];
|
|
//-- 耳标数据 --//
|
|
//-- 耳标数据 --//
|
|
//计算耳标温度
|
|
//计算耳标温度
|
|
Double earTemp = 0D;
|
|
Double earTemp = 0D;
|
|
@@ -157,8 +153,11 @@ public class DeviceListener {
|
|
if (other != null && other.trim().length() > 0) {
|
|
if (other != null && other.trim().length() > 0) {
|
|
String[] otherArray = other.split("#");
|
|
String[] otherArray = other.split("#");
|
|
String resi = otherArray[2];
|
|
String resi = otherArray[2];
|
|
- Double temp = MathUtil.ln(Integer.parseInt(resi));
|
|
|
|
- earTemp = new BigDecimal(temp).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
|
|
|
+ int resiInt = Integer.parseInt(resi);
|
|
|
|
+ if(resiInt != 0){
|
|
|
|
+ Double temp = MathUtil.ln(resiInt);
|
|
|
|
+ earTemp = new BigDecimal(temp).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
//计算运动量//
|
|
//计算运动量//
|
|
Integer act1Int = eartagService.countAct(dataArray[1], dataArray[6]);
|
|
Integer act1Int = eartagService.countAct(dataArray[1], dataArray[6]);
|