From bf34444f482223d291830c13cb147392298d99ee Mon Sep 17 00:00:00 2001
From: vince <757871790@qq.com>
Date: 星期五, 15 三月 2024 09:39:25 +0800
Subject: [PATCH] 粮情协议优化
---
src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java | 48 +++++++++++++++++++++++++++++++++---------------
1 files changed, 33 insertions(+), 15 deletions(-)
diff --git a/src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java b/src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java
index 1af6419..ea1fca7 100644
--- a/src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java
+++ b/src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java
@@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSONObject;
import com.fzzy.api.Constant;
import com.fzzy.api.data.ApiCommonDevice;
+import com.fzzy.api.data.DepotType;
import com.fzzy.api.data.GatewayDeviceType;
import com.fzzy.api.utils.BytesUtil;
import com.fzzy.api.utils.NumberUtil;
@@ -107,19 +108,19 @@
private void analysisGrain(IoMessage message) {
try {
//鏍规嵁鍒嗘満SN鑾峰彇璁惧閰嶇疆淇℃伅
- GatewayDevice gatewayDevice = GatewayUtils.getCacheByDeviceSn(message.getAddr());
+ GatewayDevice gatewayDevice = BhznGrainV0ServerUtils.contextOrder;
if (null == gatewayDevice) {
replayGrain(message);
log.error("涓绘満-------->>骞冲彴锛岃В鏋愮伯鎯呭け璐ワ紝鏈幏鍙栧埌绯荤粺璁惧閰嶇疆淇℃伅锛�" + message.getAddr());
return;
}
//鏍规嵁鍒嗘満鍦板潃鑾峰彇鍒嗘満淇℃伅
- ApiCommonDevice commonDevice = Constant.getCommonDeviceCache(message.getIp());
- if (commonDevice == null) {
- replayGrain(message);
- log.error("涓绘満-------->>骞冲彴锛岃В鏋愮伯鎯呭け璐ワ紝鏈幏鍙栧埌绯荤粺绮儏涓绘満閰嶇疆锛�" + message.getAddr());
- return;
- }
+// ApiCommonDevice commonDevice = Constant.getCommonDeviceCache(message.getIp());
+// if (commonDevice == null) {
+// replayGrain(message);
+// log.error("涓绘満-------->>骞冲彴锛岃В鏋愮伯鎯呭け璐ワ紝鏈幏鍙栧埌绯荤粺绮儏涓绘満閰嶇疆锛�" + message.getAddr());
+// return;
+// }
//鑾峰彇璇锋眰淇℃伅
BaseReqData reqData = ProtocolUtils.getSyncReq(gatewayDevice.getDepotIdSys());
@@ -187,7 +188,7 @@
String hexStr = CommandBuild.getMsgGrainReply(message.getAddr());
log.info("骞冲彴--------->>>涓绘満锛岃繑鍥炵伯鎯呮姤鏂囨敹鍒颁俊鎭紝鎶ユ枃={}", hexStr);
- BhznGrainV0ServerEngine.push(message.getIp(), message.getPort(), BytesUtil.hexStrToBytes(hexStr));
+ BhznGrainV0ServerEngine.pushByMin(hexStr);
}
/**
@@ -239,22 +240,39 @@
contextMapGrain.put(key, null);
- if (cableData.isCir()) {
+
+ if(DepotType.TYPE_03.getCode().equals(device.getDepotType())){
//绛掍粨
+ analysisAndPush3(temps, reqData, thDto, cableData);
+ }else if(DepotType.TYPE_02.getCode().equals(device.getDepotType())){
analysisAndPush2(temps, reqData, thDto, cableData);
- } else {
+ }else if(DepotType.TYPE_04.getCode().equals(device.getDepotType())){
+ analysisAndPush2(temps, reqData, thDto, cableData);
+ }else {
//骞虫埧浠�
analysisAndPush1(temps, reqData, thDto, cableData);
}
}
/**
- * 绛掍粨瑙f瀽锛岃В鏋愮浜屾锛岃В鏋愬埌鍧愭爣鏁版嵁
+ * 绛掍粨锛岃В鏋愮浜屾锛岃В鏋愬埌鍧愭爣鏁版嵁
+ * @param temps
+ * @param reqData
+ * @param thDto
+ * @param cableData
+ */
+ private void analysisAndPush2(List<Double> temps, BaseReqData reqData, THDto thDto, GrainCableData cableData) {
+ //TODO
+ log.info("-------------------------鏆傛湭瀹炵幇----------------");
+ }
+
+ /**
+ * 娌圭綈浠擄紝瑙f瀽绗簩姝ワ紝瑙f瀽鍒板潗鏍囨暟鎹�
*
* @param temps
* @throws Exception
*/
- private void analysisAndPush2(List<Double> temps, BaseReqData reqData, THDto thDto, GrainCableData cableData) {
+ private void analysisAndPush3(List<Double> temps, BaseReqData reqData, THDto thDto, GrainCableData cableData) {
GatewayDevice device = reqData.getDevice();
@@ -335,14 +353,14 @@
JSONObject properties = new JSONObject();
- properties.put("data", JSONObject.toJSONString(outPut));
+ properties.put("data", outPut);
properties.put("timestamp", grain.getTimestamp());
String height = this.getCacheHeight(device);
if (StringUtils.isEmpty(height)) height = "0.0";
properties.put("liquidHeight", height);
- grain.setProperties(properties.toJSONString());
+ grain.setProperties(properties);
//灏佽濂界殑鏁版嵁
log.info("---娴呭渾浠撳皝瑁呭畬鎴�----寮�濮嬫墽琛屾帹閫�");
@@ -544,7 +562,7 @@
} finally {
String hexStr = CommandBuild.getMsgTHReply(message.getAddr());
log.info("骞冲彴--------->>>涓绘満锛岃繑鍥炰粨娓╀粨婀挎敹鍒颁俊鎭紝鎶ユ枃={}", hexStr);
- BhznGrainV0ServerEngine.push(message.getIp(), message.getPort(), BytesUtil.hexStrToBytes(hexStr));
+ BhznGrainV0ServerEngine.pushByMin(hexStr);
}
}
--
Gitblit v1.9.3