From facc0ea3fa37091a98aa1e0a0d1081fd32fba28e Mon Sep 17 00:00:00 2001
From: vince <757871790@qq.com>
Date: 星期六, 27 一月 2024 11:38:29 +0800
Subject: [PATCH] 优化协议
---
src/main/java/com/fzzy/protocol/youxian0/client/ClientHandler.java | 2
src/main/java/com/fzzy/gateway/service/GatewayDeviceTestPR.java | 13 +-
src/main/java/com/fzzy/protocol/bhzn/v0/cmd/CommandBuild.java | 42 +++---
src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0MessageConsumer.java | 5
src/main/java/com/fzzy/protocol/bhzn/v0/service/Bhzn0GatewayGrainService.java | 43 +++---
src/main/resources/application-pro5308.yml | 64 +++++++++-
src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0HeartbeatImpl.java | 7
src/main/java/com/fzzy/protocol/ProtocolRunner.java | 4
src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerEngine.java | 34 ++---
src/main/resources/application-proGateway.yml | 2
src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java | 1
src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java | 18 +-
src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerUtils.java | 17 ++
src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java | 50 +++++++
src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0SessionListener.java | 28 ++++
src/main/java/com/fzzy/protocol/youxian0/client/ClientEngine.java | 2
16 files changed, 229 insertions(+), 103 deletions(-)
diff --git a/src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java b/src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java
index bae9cd8..8b4c3a3 100644
--- a/src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java
+++ b/src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java
@@ -34,6 +34,7 @@
List<ApiTrigger> list = new ArrayList<>();
list.add(new ApiTrigger(TCP_FZZY_V3.getCode(), TCP_FZZY_V3.getName()));
list.add(new ApiTrigger(GRAIN_FZZY_IGDS_V40.getCode(), GRAIN_FZZY_IGDS_V40.getName()));
+ list.add(new ApiTrigger(GRAIN_BHZN_V0_WEB.getCode(), GRAIN_BHZN_V0_WEB.getName()));
list.add(new ApiTrigger(GRAIN_FZZY_BHZN_WEB.getCode(), GRAIN_FZZY_BHZN_WEB.getName()));
list.add(new ApiTrigger(GRAIN_FZZY_ZLDZ_WEB.getCode(), GRAIN_FZZY_ZLDZ_WEB.getName()));
list.add(new ApiTrigger(GRAIN_YOUXIAN0_2023.getCode(), GRAIN_YOUXIAN0_2023.getName()));
diff --git a/src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java b/src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java
index 302fc5e..53a6984 100644
--- a/src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java
+++ b/src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java
@@ -2,13 +2,17 @@
import com.alibaba.fastjson.JSON;
import com.fzzy.api.data.GatewayDeviceProtocol;
+import com.fzzy.api.data.GatewayDeviceType;
+import com.fzzy.api.utils.DateUtil;
import com.fzzy.data.ConfigData;
import com.fzzy.gateway.api.GatewayRemoteManager;
import com.fzzy.gateway.data.BaseReqData;
+import com.fzzy.gateway.data.BaseResp;
import com.fzzy.gateway.data.WeatherWebDto;
import com.fzzy.gateway.entity.GatewayConf;
import com.fzzy.gateway.entity.GatewayDevice;
import com.fzzy.gateway.service.GatewayConfService;
+import com.fzzy.gateway.service.GatewayDeviceTestPR;
import com.fzzy.gateway.util.GatewayHttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
@@ -16,10 +20,7 @@
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
/**
* 缃戝叧鐩稿叧鐨勫畾鏃跺櫒
@@ -43,6 +44,8 @@
@Resource
private ConfigData configData;
+ @Resource
+ private GatewayDeviceTestPR gatewayDeviceTestPR;
/**
* <p>
@@ -55,7 +58,46 @@
doHeartbeat();
}
+ /**
+ * <p>
+ * 绮儏姣忓ぉ11鐐圭┛涓婂尯
+ */
+ @Scheduled(cron = "0 0 11 * * ?")
+ public void scheduledGrain() {
+ //鑾峰彇璁惧閰嶇疆锛屽彧閽堝绮儏璁惧杩涜鎵ц
+ log.info("瀹氭椂kafka绮儏鎺ㄩ��");
+ List<GatewayDevice> list = gatewayDeviceTestPR.listAll();
+ if (null == list || list.isEmpty()) {
+ log.error("涓鸿幏鍙栧埌绯荤粺涓澶囬厤缃紝鍙栨秷鎵ц\"");
+ return ;
+ }
+ BaseReqData reqData;
+ BaseResp resp;
+ for (GatewayDevice device : list) {
+
+ //濡傛灉涓嶆槸绮儏鍒嗘満璺宠繃
+ if (!GatewayDeviceType.TYPE_07.getCode().equals(device.getType())) {
+ continue;
+ }
+ reqData = new BaseReqData();
+ reqData.setProductId(device.getProductId());
+ reqData.setDeviceName(device.getDeviceName());
+ reqData.setDeviceId(device.getDeviceId());
+ reqData.setDayTime(new Date());
+ reqData.setDevice(device);
+
+ //鑾峰彇鍒�
+ resp = gatewayRemoteManager.getGatewayTestService(device.getPushProtocol()).testGrainKafka(reqData);
+ log.info("resp = "+resp.toString());
+ //鑷姩鎺ㄩ��
+ if (BaseResp.CODE_200 == resp.getCode()) {
+ reqData.setData(resp.getData());
+ gatewayRemoteManager.getDeviceReportService(device.getPushProtocol()).reportGrainDataByHand(reqData);
+ }
+ }
+
+ }
/**
* <p>
* 姣忛棿闅�3绉掓墽琛屼竴娆′簨浠�
diff --git a/src/main/java/com/fzzy/gateway/service/GatewayDeviceTestPR.java b/src/main/java/com/fzzy/gateway/service/GatewayDeviceTestPR.java
index 484a0e8..d6cbee4 100644
--- a/src/main/java/com/fzzy/gateway/service/GatewayDeviceTestPR.java
+++ b/src/main/java/com/fzzy/gateway/service/GatewayDeviceTestPR.java
@@ -4,6 +4,7 @@
import com.bstek.dorado.annotation.Expose;
import com.fzzy.api.data.GatewayDeviceType;
import com.fzzy.api.utils.DateUtil;
+import com.fzzy.async.fzzy40.Fzzy40CommonService;
import com.fzzy.async.fzzy40.entity.Fz40Grain;
import com.fzzy.gateway.api.GatewayDeviceReportService;
import com.fzzy.gateway.api.GatewayRemoteManager;
@@ -35,8 +36,8 @@
@Resource
private GatewayDeviceRep gatewayDeviceRep;
-// @Resource
-// private Fzzy40CommonService fzzy40CommonService;
+ @Resource
+ private Fzzy40CommonService fzzy40CommonService;
@Resource
private GatewayRemoteManager gatewayRemoteManager;
// @Resource
@@ -119,7 +120,7 @@
}
- private String pushByV40(List<GatewayDevice> list, Date start, Date end) {
+ public String pushByV40(List<GatewayDevice> list, Date start, Date end) {
String depotIdSys;
List<Fz40Grain> listGrain;
@@ -138,8 +139,8 @@
}
//TODO ----銆�
- // listGrain = fzzy40CommonService.listGrain(depotIdSys, start, end);
- listGrain = null;
+ listGrain = fzzy40CommonService.listGrain(depotIdSys, start, end);
+ //listGrain = null;
if (null == listGrain || listGrain.isEmpty()) {
log.info("---------璁惧---{}--鏈悓姝ュ埌绮儏淇℃伅锛岃纭褰撳墠鏉′欢涓嬫槸鍚︽湁鏁版嵁", device.getDeviceName());
continue;
@@ -157,7 +158,7 @@
}
- // deviceReportService.pushGrainData2Cloud(pushData);
+ // deviceReportService.reportGrainDataByHand(pushData);
}
diff --git a/src/main/java/com/fzzy/protocol/ProtocolRunner.java b/src/main/java/com/fzzy/protocol/ProtocolRunner.java
index c883fcc..bc8df1e 100644
--- a/src/main/java/com/fzzy/protocol/ProtocolRunner.java
+++ b/src/main/java/com/fzzy/protocol/ProtocolRunner.java
@@ -1,6 +1,7 @@
package com.fzzy.protocol;
import com.fzzy.protocol.bhzn.server.BhznGrainV2ServerEngine;
+import com.fzzy.protocol.bhzn.v0.server.BhznGrainV0ServerEngine;
import com.fzzy.protocol.fzzy.server.FzzyServerEngine;
import com.fzzy.protocol.weightyh.YhScaleServerEngine;
import com.fzzy.protocol.zldz.server.ZldzServerEngine;
@@ -34,7 +35,8 @@
//閭︽捣鏅鸿兘绾綉鍙h澶囧崗璁�
BhznGrainV2ServerEngine.start(null);
-
+ //閭︽捣鏅鸿兘鏃犵嚎涓绘満璁惧鍗忚
+ BhznGrainV0ServerEngine.start(null);
}
}
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 2f8cb56..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
@@ -108,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());
@@ -188,7 +188,7 @@
String hexStr = CommandBuild.getMsgGrainReply(message.getAddr());
log.info("骞冲彴--------->>>涓绘満锛岃繑鍥炵伯鎯呮姤鏂囨敹鍒颁俊鎭紝鎶ユ枃={}", hexStr);
- BhznGrainV0ServerEngine.push(message.getIp(), message.getPort(), BytesUtil.hexStrToBytes(hexStr));
+ BhznGrainV0ServerEngine.pushByMin(hexStr);
}
/**
@@ -562,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);
}
}
diff --git a/src/main/java/com/fzzy/protocol/bhzn/v0/cmd/CommandBuild.java b/src/main/java/com/fzzy/protocol/bhzn/v0/cmd/CommandBuild.java
index a93ef90..9b4e7d8 100644
--- a/src/main/java/com/fzzy/protocol/bhzn/v0/cmd/CommandBuild.java
+++ b/src/main/java/com/fzzy/protocol/bhzn/v0/cmd/CommandBuild.java
@@ -2,7 +2,7 @@
import com.fzzy.api.utils.BytesUtil;
-import com.fzzy.protocol.bhzn.server.BhznGrainV2ServerUtils;
+import com.fzzy.protocol.bhzn.v0.server.BhznGrainV0ServerUtils;
/**
* 鍛戒护鐢熸垚
@@ -31,8 +31,8 @@
StringBuffer sb = new StringBuffer();
//寮�濮嬬鍙�
- sb.append(BhznGrainV2ServerUtils.MSG_START);
- sb.append(BhznGrainV2ServerUtils.MSG_START2);
+ sb.append(BhznGrainV0ServerUtils.MSG_START);
+ sb.append(BhznGrainV0ServerUtils.MSG_START2);
//鍒嗘満鍦板潃
int i = Integer.parseInt(grainAddr);
@@ -42,7 +42,7 @@
sb.append("0001");
//鍛戒护ID
- sb.append(BhznGrainV2ServerUtils.FUNCTION_ID_F2);
+ sb.append(BhznGrainV0ServerUtils.FUNCTION_ID_F2);
//鏁版嵁闀垮害-01
sb.append("01");
@@ -51,10 +51,10 @@
sb.append("01");
//鑾峰彇鏍¢獙鐮�
- sb.append(BhznGrainV2ServerUtils.getCheck(sb.toString()));
+ sb.append(BhznGrainV0ServerUtils.getCheck(sb.toString()));
//缁撳熬绗�
- sb.append(BhznGrainV2ServerUtils.MSG_END_16);
+ sb.append(BhznGrainV0ServerUtils.MSG_END_16);
return sb.toString();
}
@@ -71,8 +71,8 @@
StringBuffer sb = new StringBuffer();
//寮�濮嬬鍙�
- sb.append(BhznGrainV2ServerUtils.MSG_START);
- sb.append(BhznGrainV2ServerUtils.MSG_START2);
+ sb.append(BhznGrainV0ServerUtils.MSG_START);
+ sb.append(BhznGrainV0ServerUtils.MSG_START2);
//鍒嗘満鍦板潃
int i = Integer.parseInt(grainAddr);
@@ -82,7 +82,7 @@
sb.append("0001");
//鍛戒护ID
- sb.append(BhznGrainV2ServerUtils.FUNCTION_ID_83);
+ sb.append(BhznGrainV0ServerUtils.FUNCTION_ID_83);
//鏁版嵁闀垮害-01
sb.append("01");
@@ -92,10 +92,10 @@
sb.append(BytesUtil.intToHexStr1(i));
//鑾峰彇鏍¢獙鐮�
- sb.append(BhznGrainV2ServerUtils.getCheck(sb.toString()));
+ sb.append(BhznGrainV0ServerUtils.getCheck(sb.toString()));
//缁撳熬绗�
- sb.append(BhznGrainV2ServerUtils.MSG_END_16);
+ sb.append(BhznGrainV0ServerUtils.MSG_END_16);
return sb.toString();
}
@@ -111,8 +111,8 @@
StringBuffer sb = new StringBuffer();
//寮�濮嬬鍙�
- sb.append(BhznGrainV2ServerUtils.MSG_START);
- sb.append(BhznGrainV2ServerUtils.MSG_START2);
+ // sb.append(BhznGrainV0ServerUtils.MSG_START);
+ sb.append(BhznGrainV0ServerUtils.MSG_START2);
//鍒嗘満鍦板潃
int i = Integer.parseInt(grainAddr);
@@ -122,7 +122,7 @@
sb.append("0001");
//鍛戒护ID
- sb.append(BhznGrainV2ServerUtils.FUNCTION_ID_93);
+ sb.append(BhznGrainV0ServerUtils.FUNCTION_ID_93);
//鏁版嵁闀垮害-01
sb.append("01");
@@ -131,10 +131,10 @@
sb.append("01");
//鑾峰彇鏍¢獙鐮�
- sb.append(BhznGrainV2ServerUtils.getCheck(sb.toString()));
+ sb.append(BhznGrainV0ServerUtils.getCheck(sb.toString()));
//缁撳熬绗�
- sb.append(BhznGrainV2ServerUtils.MSG_END_16);
+ sb.append(BhznGrainV0ServerUtils.MSG_END_16);
return sb.toString();
}
@@ -149,8 +149,8 @@
StringBuffer sb = new StringBuffer();
//寮�濮嬬鍙�
- sb.append(BhznGrainV2ServerUtils.MSG_START);
- sb.append(BhznGrainV2ServerUtils.MSG_START2);
+ sb.append(BhznGrainV0ServerUtils.MSG_START);
+ sb.append(BhznGrainV0ServerUtils.MSG_START2);
//鍒嗘満鍦板潃
int i = Integer.parseInt(grainAddr);
@@ -160,7 +160,7 @@
sb.append("0001");
//鍛戒护ID
- sb.append(BhznGrainV2ServerUtils.FUNCTION_ID_92);
+ sb.append(BhznGrainV0ServerUtils.FUNCTION_ID_92);
//鏁版嵁闀垮害-01
sb.append("01");
@@ -169,10 +169,10 @@
sb.append("01");
//鑾峰彇鏍¢獙鐮�
- sb.append(BhznGrainV2ServerUtils.getCheck(sb.toString()));
+ sb.append(BhznGrainV0ServerUtils.getCheck(sb.toString()));
//缁撳熬绗�
- sb.append(BhznGrainV2ServerUtils.MSG_END_16);
+ sb.append(BhznGrainV0ServerUtils.MSG_END_16);
return sb.toString();
}
diff --git a/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0HeartbeatImpl.java b/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0HeartbeatImpl.java
index fffb563..a3385dd 100644
--- a/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0HeartbeatImpl.java
+++ b/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0HeartbeatImpl.java
@@ -17,8 +17,10 @@
@Override
public byte[] provide(IoSession session) {
+ //鐩存帴鏍规嵁涓绘満SESSIOn鍒ゆ柇
+ IoSession session1 = BhznGrainV0ServerUtils.getSession();
- Long lastBeatTime = BhznGrainV0ServerUtils.getHearBeat(session);
+ Long lastBeatTime = BhznGrainV0ServerUtils.getHearBeat(session1);
if (null == lastBeatTime) {
return null;
@@ -29,7 +31,8 @@
if (deTime > (BhznGrainV0ServerUtils.HEART_BEAT_TIME * 3 * 1000)) {
log.info("-----------瓒呰繃{}绉掓湭鑾峰彇鍒板績璺充俊鎭紝鍒ゅ畾缁堢绂荤嚎锛岃涪鍑鸿繛鎺�------------{}-{}", deTime, session.getAddress(), session.getPort());
- session.destroy();
+
+ // session.destroy();
}
return null;
diff --git a/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0MessageConsumer.java b/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0MessageConsumer.java
index 84cee99..b359838 100644
--- a/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0MessageConsumer.java
+++ b/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0MessageConsumer.java
@@ -1,6 +1,7 @@
package com.fzzy.protocol.bhzn.v0.server;
import com.fzzy.api.utils.BytesUtil;
+import com.fzzy.api.utils.SpringUtil;
import com.fzzy.protocol.bhzn.v0.analysis.AnalysisService;
import com.fzzy.protocol.bhzn.v0.cmd.ReMessageBuilder;
import com.fzzy.protocol.bhzn.v0.data.IoMessage;
@@ -38,7 +39,7 @@
BhznGrainV0ServerUtils.addHeartBeat(ioSession);
//榛樿璁剧疆涓婚�氳鏈嶅姟
- //BhznGrainV2ServerUtils.addSession(ioSession);
+ BhznGrainV0ServerUtils.addSession(ioSession);
try {
String hexStr = BytesUtil.bytesToString(bytes);
@@ -48,7 +49,7 @@
IoMessage ioMessage = ReMessageBuilder.getInstance().buildMessage(hexStr);
ioMessage.setIp(ioSession.getAddress());
ioMessage.setPort(ioSession.getPort());
-
+ analysisService = SpringUtil.getBean(AnalysisService.class);
analysisService.analysis(ioSession.getBusinessKey(), ioMessage);
} catch (Exception e) {
log.error(e.getMessage(), e);
diff --git a/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerEngine.java b/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerEngine.java
index 45c43e6..29dc938 100644
--- a/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerEngine.java
+++ b/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerEngine.java
@@ -1,5 +1,7 @@
package com.fzzy.protocol.bhzn.v0.server;
+import com.fzzy.api.utils.BytesUtil;
+import com.fzzy.protocol.bhzn.server.BhznGrainV2ServerUtils;
import com.fzzy.protocol.fzzy.server.ServerUtils;
import com.ld.io.api.*;
import com.ld.io.netty.NettyServer;
@@ -15,7 +17,7 @@
public class BhznGrainV0ServerEngine {
- public static final Integer PORT = 19302;
+ public static final Integer PORT = 19303;
public static NettyServer ioServer = null;
@@ -39,8 +41,13 @@
}
//纭缁撳熬鏍囧織-娌℃湁鍥哄畾缁撴潫绗﹀彿
- ioServerOption.setSplitDecoderType(SplitByteDecoderType.NO_LIMIT);
+ //纭缁撳熬鏍囧織
+ //ioServerOption.setDelimiter(BhznGrainV2ServerUtils.MSG_END.getBytes());
+// ioServerOption.setSplitDecoderType(SplitByteDecoderType.NO_LIMIT);
+
+ ioServerOption.setDelimiter(BhznGrainV2ServerUtils.MSG_END.getBytes());
+ ioServerOption.setSplitDecoderType(SplitByteDecoderType.DELIMITER_SYMBOL);
// 閰嶇疆绯荤粺蹇冭烦闂撮殧
ioServerOption.setReaderIdleTime(5 * 60);
@@ -64,28 +71,17 @@
}
/**
- * 鍙戦�佷俊鎭�
- *
- * @param ip
- * @param port
- * @param msg
- * @return
+ * 鐩存帴浣跨敤鍐呭瓨鐨凷ession鎵ц
*/
- public static InvokeResult push(String ip, int port, byte[] msg) {
- IoSessionQuery sessionFactory = ioServer.getSessionQuery();
- List<IoSession> sessions = sessionFactory.getAllSession();
- IoSession session = null;
- for (IoSession ioSession : sessions) {
- if (ServerUtils.getServerKey(ip, port).equals(ioSession.getBusinessKey())) {
- session = ioSession;
- break;
- }
- }
+ public static InvokeResult pushByMin(String hexStr) {
+
+ IoSession session = BhznGrainV0ServerUtils.getSession();
+
if (null == session) {
return InvokeResult.CHANNEL_CLOSED;
}
+ byte[] msg = BytesUtil.hexStrToBytes(hexStr);
return session.invoke(msg);
}
-
}
\ No newline at end of file
diff --git a/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerUtils.java b/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerUtils.java
index ebd0b3e..ec8341a 100644
--- a/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerUtils.java
+++ b/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerUtils.java
@@ -2,7 +2,7 @@
import com.fzzy.api.utils.BytesUtil;
-import com.fzzy.protocol.bhzn.server.BhznGrainV2ServerUtils;
+import com.fzzy.gateway.entity.GatewayDevice;
import com.ld.io.api.IoSession;
import java.util.HashMap;
@@ -20,15 +20,16 @@
* 璁板綍姣忎釜杩炴帴鐨勬渶鍚庝竴娆′俊鎭椂闂� key = 杩炴帴鐨凨YE锛宒ata =褰撳墠鏃堕棿鎴�
*/
public static Map<String, Long> contextMapHeart = new HashMap<>();
+ public static Map<String, IoSession> contextIoSession = new HashMap<>();
-
+ public static GatewayDevice contextOrder = new GatewayDevice();
public static int HEART_BEAT_TIME = 30;//蹇冭烦闂撮殧鏃堕棿
public static String MSG_START = "3C42485A4E3E";//<BHZN>
public static String MSG_START2 = "AA";
public static String MSG_END = "<END>";//<END>
- public static String MSG_END_16 = "3C454E443E";//<END>
+ public static String MSG_END_16 = "3C454E443E";//<END>3C454E443E
public static final String CHARSET = "UTF-8";
@@ -78,7 +79,7 @@
* @return
*/
public static String getCheck(String content) {
- int start = BhznGrainV2ServerUtils.MSG_START.length() + BhznGrainV2ServerUtils.MSG_START2.length();
+ int start = BhznGrainV0ServerUtils.MSG_START.length() + BhznGrainV0ServerUtils.MSG_START2.length();
content = content.substring(start);
int sum = 0;
String hex;
@@ -91,4 +92,12 @@
return BytesUtil.intToHexStr(256 - check).substring(2);
}
+
+ public static void addSession(IoSession session) {
+ contextIoSession.put(DEFAULT_MAC_ID, session);
+ }
+
+ public static IoSession getSession() {
+ return contextIoSession.get(DEFAULT_MAC_ID);
+ }
}
diff --git a/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0SessionListener.java b/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0SessionListener.java
index 613ae98..73d8bfa 100644
--- a/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0SessionListener.java
+++ b/src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0SessionListener.java
@@ -2,11 +2,15 @@
import com.fzzy.api.Constant;
import com.fzzy.api.data.ApiCommonDevice;
+import com.fzzy.api.service.ApiCommonService;
import com.fzzy.api.utils.SpringUtil;
+import com.fzzy.gateway.entity.GatewayDevice;
import com.fzzy.gateway.service.GatewayDeviceService;
import com.ld.io.api.IoSession;
import com.ld.io.api.IoSessionListener;
import lombok.extern.slf4j.Slf4j;
+
+import java.util.List;
/**
*
@@ -23,13 +27,31 @@
*/
@Override
public void onCreate(IoSession session) {
-
+ //娣诲姞鍒板唴瀛�
+ BhznGrainV0ServerUtils.addSession(session);
log.info("++++鏂板缓杩炴帴++++-IP={}锛孭ORT={}", session.getAddress(), session.getPort());
// 娣诲姞鑷畾涔変笟鍔D
session.setBusinessKey(BhznGrainV0ServerUtils.getServerKey(session.getAddress(), session.getPort()));
-
- //鎵ц鍒嗘満涓婄嚎
+// GatewayDeviceService gatewayDeviceService = SpringUtil.getBean(GatewayDeviceService.class);
+// List<GatewayDevice> devices = gatewayDeviceService.listAll();
+// //鎵ц鍒嗘満涓婄嚎
+// if(devices!= null && devices.size()>0){
+// ApiCommonDevice device =null;
+// for (GatewayDevice d:devices) {
+// device = new ApiCommonDevice();
+// device.setIp(d.getIp());
+// device.setPort(d.getPort());
+// device.setStatus(Constant.YN_N);
+// device.setSn(d.getDeviceSn());
+// device.setCode("ERROR");
+// device.setMsg("璁惧绂荤嚎");
+// }
+//
+//
+// contextDeviceMap.put(device.getIp(), device);
+//
+// }
Constant.updateCacheOnline(session.getAddress(), session.getPort());
}
diff --git a/src/main/java/com/fzzy/protocol/bhzn/v0/service/Bhzn0GatewayGrainService.java b/src/main/java/com/fzzy/protocol/bhzn/v0/service/Bhzn0GatewayGrainService.java
index 3ec7257..fdd22dc 100644
--- a/src/main/java/com/fzzy/protocol/bhzn/v0/service/Bhzn0GatewayGrainService.java
+++ b/src/main/java/com/fzzy/protocol/bhzn/v0/service/Bhzn0GatewayGrainService.java
@@ -9,8 +9,9 @@
import com.fzzy.gateway.data.BaseResp;
import com.fzzy.gateway.entity.GatewayDevice;
import com.fzzy.protocol.ProtocolUtils;
-import com.fzzy.protocol.bhzn.cmd.CommandBuild;
-import com.fzzy.protocol.bhzn.server.BhznGrainV2ServerEngine;
+import com.fzzy.protocol.bhzn.v0.cmd.CommandBuild;
+import com.fzzy.protocol.bhzn.v0.server.BhznGrainV0ServerEngine;
+import com.fzzy.protocol.bhzn.v0.server.BhznGrainV0ServerUtils;
import com.ld.io.api.InvokeResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@@ -33,26 +34,26 @@
BaseResp resp = new BaseResp();
GatewayDevice device = reqData.getDevice();
-
+ BhznGrainV0ServerUtils.contextOrder = device;
//鑾峰彇杩炴帴涓殑璁惧淇℃伅
- ApiCommonDevice apiCommonDevice = Constant.getCommonDeviceCache(device.getIp());
+// ApiCommonDevice apiCommonDevice = Constant.getCommonDeviceCacheBySn(device.getDeviceSn());
+//
+// if (null == apiCommonDevice) {
+// resp.setCode(500);
+// resp.setMsg("绯荤粺鏈幏鍙栧埌涓嬭杩炴帴璁惧淇℃伅锛屾棤娉曟墽琛�");
+// log.error("----------------绯荤粺鏈幏鍙栧埌涓嬭杩炴帴璁惧淇℃伅,鏃犳硶鎵ц---------");
+// return resp;
+// }
+//
+// if (Constant.YN_N.equals(apiCommonDevice.getStatus())) {
+// resp.setCode(500);
+// resp.setMsg("涓嬭璁惧涓嶅湪绾�---鏃犳硶鎵ц----" + device.getDeviceName());
+// log.error("涓嬭璁惧涓嶅湪绾�---鏃犳硶鎵ц----" + device.getDeviceName());
+// return resp;
+// }
- if (null == apiCommonDevice) {
- resp.setCode(500);
- resp.setMsg("绯荤粺鏈幏鍙栧埌涓嬭杩炴帴璁惧淇℃伅锛屾棤娉曟墽琛�");
- log.error("----------------绯荤粺鏈幏鍙栧埌涓嬭杩炴帴璁惧淇℃伅,鏃犳硶鎵ц---------");
- return resp;
- }
-
- if (Constant.YN_N.equals(apiCommonDevice.getStatus())) {
- resp.setCode(500);
- resp.setMsg("涓嬭璁惧涓嶅湪绾�---鏃犳硶鎵ц----" + device.getDeviceName());
- log.error("涓嬭璁惧涓嶅湪绾�---鏃犳硶鎵ц----" + device.getDeviceName());
- return resp;
- }
-
- device.setIp(apiCommonDevice.getIp());
- device.setPort(apiCommonDevice.getPort());
+// device.setIp(apiCommonDevice.getIp());
+// device.setPort(apiCommonDevice.getPort());
reqData.setDevice(device);
@@ -63,7 +64,7 @@
// 鐢熸垚绮儏淇℃伅
String hexStr = CommandBuild.getInstance().getMsgCheck(device.getDeviceSn(), device.getDepotIdSys());
// 鍙戦�佸懡浠�
- InvokeResult message = BhznGrainV2ServerEngine.push(device.getIp(), device.getPort(), BytesUtil.hexStrToBytes(hexStr));
+ InvokeResult message = BhznGrainV0ServerEngine.pushByMin(hexStr);
log.error("骞冲彴------>>>>鎺у埗鏌滐細鍙戦�佺伯鎯呮娴嬪懡浠�-{}", message);
diff --git a/src/main/java/com/fzzy/protocol/youxian0/client/ClientEngine.java b/src/main/java/com/fzzy/protocol/youxian0/client/ClientEngine.java
index 3266acc..972ccf6 100644
--- a/src/main/java/com/fzzy/protocol/youxian0/client/ClientEngine.java
+++ b/src/main/java/com/fzzy/protocol/youxian0/client/ClientEngine.java
@@ -103,6 +103,7 @@
return InvokeResult.SOCKET_NOT_CREATE;
}
if (!defaultChannel.isActive()) {
+ defaultChannel = null;
return InvokeResult.CHANNEL_CLOSED;
}
@@ -143,6 +144,7 @@
return InvokeResult.SOCKET_NOT_CREATE;
}
if (!channel.isActive()) {
+ defaultChannel = null;
return InvokeResult.CHANNEL_CLOSED;
}
channel.writeAndFlush(Unpooled.copiedBuffer(BytesUtil.hexStrToBytes(hex))).sync();
diff --git a/src/main/java/com/fzzy/protocol/youxian0/client/ClientHandler.java b/src/main/java/com/fzzy/protocol/youxian0/client/ClientHandler.java
index 50521eb..b47e340 100644
--- a/src/main/java/com/fzzy/protocol/youxian0/client/ClientHandler.java
+++ b/src/main/java/com/fzzy/protocol/youxian0/client/ClientHandler.java
@@ -32,7 +32,7 @@
InetSocketAddress socketAddress = (InetSocketAddress) ctx.channel().remoteAddress();
log.info("杩炴帴缁堢鎺夌嚎锛孖P={},port={}", socketAddress.getAddress(), socketAddress.getPort());
- //ClientEngine.defaultChannel = null;
+ ClientEngine.defaultChannel = null;
}
diff --git a/src/main/resources/application-pro5308.yml b/src/main/resources/application-pro5308.yml
index dd1333b..e7c52ff 100644
--- a/src/main/resources/application-pro5308.yml
+++ b/src/main/resources/application-pro5308.yml
@@ -1,20 +1,18 @@
server:
- port: 8081
- jetty:
- max-http-post-size: 209715200
- tomcat:
- max-http-post-size: 209715200
+ port: 8090
+
spring:
datasource:
#涓绘暟鎹簮
primary:
- url: jdbc:mysql://127.0.0.1:3306/igds_api?useUnicode=true&characterEncoding=utf-8
+ url: jdbc:mysql://127.0.0.1:3306/igds_api_2023?useUnicode=true&useSSL=false&characterEncoding=utf-8
username: root
password: Abc123..
driver-class-name: com.mysql.jdbc.Driver
#娆℃暟鎹簮
secondary:
- url: jdbc:mysql://127.0.0.1:3306/igds_3.5?useUnicode=true&characterEncoding=utf-8
+ url: jdbc:mysql://127.0.0.1:3306/igds_3.5?useUnicode=true&useSSL=false&characterEncoding=utf-8
+
username: root
password: Abc123..
driver-class-name: com.mysql.jdbc.Driver
@@ -37,7 +35,7 @@
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
# Redis鐩稿叧閰嶇疆
redis:
- database: 0
+ database: 5
host: 127.0.0.1
port: 6379
password:
@@ -47,4 +45,52 @@
max-wait: -1
max-idle: 10
min-idle: 0
- timeout: 6000
\ No newline at end of file
+ timeout: 6000
+ kafka:
+ bootstrap-servers: 103.203.217.16:9092
+ producer:
+ retries: 0
+ acks: 1
+ batch-size: 16384
+ buffer-memory: 33554432
+ key-serializer: org.apache.kafka.common.serialization.StringSerializer
+ value-serializer: org.apache.kafka.common.serialization.StringSerializer
+ properties:
+ security.protocol: SASL_PLAINTEXT
+ sasl.mechanism: PLAIN
+ sasl.username: sc001
+ sasl.password: wCV0ISwmoKwbx1lpBKMW
+ sasl.jaas.config: org.apache.kafka.common.security.scram.ScramLoginModule required username='sc001' password='wCV0ISwmoKwbx1lpBKMW';
+ consumer:
+ group-id: fzzygroup
+ enable-auto-commit: true
+ auto-commit-interval: 100
+ auto-offset-reset: latest
+ key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
+ value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
+
+ mqtt:
+ host: tcp://127.0.0.1:1883
+ username: admin
+ password: admin123321
+ client-inId: fzzy_client_id_in_igds_api
+ client-outId: fzzy_client_id_out_igds_api
+ completionTimeout: 3000
+ keep-alive-interval: 2
+ max-connect-times: 5
+ qos: 0
+ isOpen: false
+ default-topic: mqtt/+/test1
+ topics: /device-message-sender/#
+license:
+ subject: ld_license
+ publicAlias: publicCert
+ storePass: PUBLICFZZYXXJSGFYXGS888888
+ licensePath: D:/IGDS/license/license.lic
+ publicKeysStorePath: D:/IGDS/license/publicCerts.keystore
+igds:
+ default:
+ companyId: 5308
+ file-path: D:/app/igds-api
+ img-path: D:/IGDS/FILE/
+ weather-url: https://v1.yiketianqi.com/api?unescape=1&version=v61&appid={appId}&appsecret={appsecret}&cityid={cityid}
diff --git a/src/main/resources/application-proGateway.yml b/src/main/resources/application-proGateway.yml
index e4905db..55e75e4 100644
--- a/src/main/resources/application-proGateway.yml
+++ b/src/main/resources/application-proGateway.yml
@@ -35,7 +35,7 @@
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
# Redis鐩稿叧閰嶇疆
redis:
- database: 0
+ database: 5
host: 127.0.0.1
port: 6379
password:
--
Gitblit v1.9.3