Commit f320569f2c46ebca8ea88c4bbbe23d9b63539e94

Authored by puhui999
1 parent 44838510

perf:【iot】优化 IotTcpClient 代码

yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/data/action/IotTcpDataRuleAction.java
@@ -43,7 +43,6 @@ public class IotTcpDataRuleAction extends @@ -43,7 +43,6 @@ public class IotTcpDataRuleAction extends
43 config.getConnectTimeoutMs(), 43 config.getConnectTimeoutMs(),
44 config.getReadTimeoutMs(), 44 config.getReadTimeoutMs(),
45 config.getSsl(), 45 config.getSsl(),
46 - config.getSslCertPath(),  
47 config.getDataFormat() 46 config.getDataFormat()
48 ); 47 );
49 // 2.2 连接服务器 48 // 2.2 连接服务器
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/data/action/tcp/IotTcpClient.java
1 package cn.iocoder.yudao.module.iot.service.rule.data.action.tcp; 1 package cn.iocoder.yudao.module.iot.service.rule.data.action.tcp;
2 2
  3 +import cn.hutool.core.util.ObjUtil;
3 import cn.iocoder.yudao.framework.common.util.json.JsonUtils; 4 import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
4 import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; 5 import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
5 import cn.iocoder.yudao.module.iot.dal.dataobject.rule.config.IotDataSinkTcpConfig; 6 import cn.iocoder.yudao.module.iot.dal.dataobject.rule.config.IotDataSinkTcpConfig;
@@ -31,8 +32,6 @@ public class IotTcpClient { @@ -31,8 +32,6 @@ public class IotTcpClient {
31 private final Integer connectTimeoutMs; 32 private final Integer connectTimeoutMs;
32 private final Integer readTimeoutMs; 33 private final Integer readTimeoutMs;
33 private final Boolean ssl; 34 private final Boolean ssl;
34 - // TODO @puhui999:sslCertPath 是不是没在用?  
35 - private final String sslCertPath;  
36 private final String dataFormat; 35 private final String dataFormat;
37 36
38 private Socket socket; 37 private Socket socket;
@@ -41,15 +40,13 @@ public class IotTcpClient { @@ -41,15 +40,13 @@ public class IotTcpClient {
41 private final AtomicBoolean connected = new AtomicBoolean(false); 40 private final AtomicBoolean connected = new AtomicBoolean(false);
42 41
43 public IotTcpClient(String host, Integer port, Integer connectTimeoutMs, Integer readTimeoutMs, 42 public IotTcpClient(String host, Integer port, Integer connectTimeoutMs, Integer readTimeoutMs,
44 - Boolean ssl, String sslCertPath, String dataFormat) { 43 + Boolean ssl, String dataFormat) {
45 this.host = host; 44 this.host = host;
46 this.port = port; 45 this.port = port;
47 this.connectTimeoutMs = connectTimeoutMs != null ? connectTimeoutMs : IotDataSinkTcpConfig.DEFAULT_CONNECT_TIMEOUT_MS; 46 this.connectTimeoutMs = connectTimeoutMs != null ? connectTimeoutMs : IotDataSinkTcpConfig.DEFAULT_CONNECT_TIMEOUT_MS;
48 this.readTimeoutMs = readTimeoutMs != null ? readTimeoutMs : IotDataSinkTcpConfig.DEFAULT_READ_TIMEOUT_MS; 47 this.readTimeoutMs = readTimeoutMs != null ? readTimeoutMs : IotDataSinkTcpConfig.DEFAULT_READ_TIMEOUT_MS;
49 this.ssl = ssl != null ? ssl : IotDataSinkTcpConfig.DEFAULT_SSL; 48 this.ssl = ssl != null ? ssl : IotDataSinkTcpConfig.DEFAULT_SSL;
50 - this.sslCertPath = sslCertPath;  
51 - // TODO @puhui999:可以使用 StrUtil.defaultIfBlank 方法简化  
52 - this.dataFormat = dataFormat != null ? dataFormat : IotDataSinkTcpConfig.DEFAULT_DATA_FORMAT; 49 + this.dataFormat = ObjUtil.defaultIfBlank(dataFormat, IotDataSinkTcpConfig.DEFAULT_DATA_FORMAT);
53 } 50 }
54 51
55 /** 52 /**