Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
smf-core
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 3610c118
由
LN
编写于
2025-03-28 09:37:14 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
韩华配置修改时自动重连
1 个父辈
6581cb82
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
107 行增加
和
35 行删除
src/main/java/com/neotel/smfcore/core/equipment/util/bean/EquipConfigInfo.java
src/main/java/com/neotel/smfcore/custom/hanwha/handler/TMSCommunicator.java
src/main/java/com/neotel/smfcore/core/equipment/util/bean/EquipConfigInfo.java
查看文件 @
3610c11
...
@@ -28,13 +28,17 @@ public class EquipConfigInfo {
...
@@ -28,13 +28,17 @@ public class EquipConfigInfo {
try
{
try
{
if
(
apiConfigMap
!=
null
)
{
if
(
apiConfigMap
!=
null
)
{
Object
result
=
apiConfigMap
.
get
(
key
);
Object
result
=
apiConfigMap
.
get
(
key
);
if
(
result
!=
null
)
{
if
(
result
instanceof
String
&&
defValue
instanceof
Integer
)
{
return
(
T
)
(
Integer
)
Integer
.
parseInt
((
String
)
result
);
}
else
if
(
result
!=
null
)
{
return
(
T
)
result
;
return
(
T
)
result
;
}
}
}
}
}
catch
(
Exception
exception
)
{
}
catch
(
Exception
exception
)
{
log
.
error
(
"GetConfigValue 出错: type="
+
equipType
+
",key="
+
key
+
", error ="
+
exception
.
toString
());
log
.
error
(
"GetConfigValue 出错: type="
+
equipType
+
",key="
+
key
+
", error ="
+
exception
.
toString
());
}
}
if
(
defValue
!=
null
)
{
if
(
defValue
!=
null
)
{
return
(
T
)
defValue
;
return
(
T
)
defValue
;
...
@@ -42,4 +46,5 @@ public class EquipConfigInfo {
...
@@ -42,4 +46,5 @@ public class EquipConfigInfo {
return
null
;
return
null
;
}
}
}
}
src/main/java/com/neotel/smfcore/custom/hanwha/handler/TMSCommunicator.java
查看文件 @
3610c11
...
@@ -98,41 +98,30 @@ public class TMSCommunicator implements WsMsgReceivedListener {
...
@@ -98,41 +98,30 @@ public class TMSCommunicator implements WsMsgReceivedListener {
@Autowired
@Autowired
private
IStoragePosManager
storagePosManager
;
private
IStoragePosManager
storagePosManager
;
// @Autowired
// private IDataLogManager dataLogManager;
// @Autowired
// private IComponentManager componentManager;
@Autowired
@Autowired
private
TMSUtil
tmsUtil
;
private
TMSUtil
tmsUtil
;
// private static int gRequestID = 1000;
// public static int GetRequestID()
// {
// return gRequestID++;
// }
private
boolean
needCheck
=
false
;
private
boolean
needCheck
=
false
;
@PostConstruct
@PostConstruct
public
void
init
()
{
public
void
init
()
{
EquipConfigInfo
equipConfigInfo
=
equipConfigUtil
.
getConfigCache
(
EquipmentType
.
HANWHA
.
name
());
EquipConfigInfo
equipConfigInfo
=
equipConfigUtil
.
getConfigCache
(
EquipmentType
.
HANWHA
.
name
());
// host = dataCache.getConfigCache("hanwha.host", host);
// host = dataCache.getConfigCache("hanwha.host", host);
// String webPortStr = dataCache.getConfigCache("hanwha.webPort", configWebPort);
// String webPortStr = dataCache.getConfigCache("hanwha.webPort", configWebPort);
// String apiPortStr = dataCache.getConfigCache("hanwha.apiPort", configApiPort);
// String apiPortStr = dataCache.getConfigCache("hanwha.apiPort", configApiPort);
host
=
equipConfigInfo
.
GetConfigValue
(
"host"
,
""
);
host
=
equipConfigInfo
.
GetConfigValue
(
"host"
,
""
);
webPort
=
equipConfigInfo
.
GetConfigValue
(
"webPort"
,
0
);
webPort
=
equipConfigInfo
.
GetConfigValue
(
"webPort"
,
0
);
apiPort
=
equipConfigInfo
.
GetConfigValue
(
"apiPort"
,
0
);
apiPort
=
equipConfigInfo
.
GetConfigValue
(
"apiPort"
,
0
);
enableApi
=
equipConfigInfo
.
isEnableApi
();
enableApi
=
equipConfigInfo
.
isEnableApi
();
apiName
=
dataCache
.
getConfigCache
(
"api.name"
,
apiName
);
apiName
=
dataCache
.
getConfigCache
(
"api.name"
,
apiName
);
boolean
enable
=
apiName
!=
null
&&
apiName
.
equalsIgnoreCase
(
"hanwha"
)
;
updateServerInfo
(
host
,
webPort
,
apiPort
,
enableApi
)
;
if
(!
enable
){
boolean
enable
=
apiName
!=
null
&&
apiName
.
equalsIgnoreCase
(
"hanwha"
);
log
.
info
(
"apiName="
+
apiName
+
",不需要连接"
);
if
(!
enable
)
{
}
else
if
(!
enableApi
){
log
.
info
(
"apiName="
+
apiName
+
",不需要连接"
);
log
.
info
(
"enableApi="
+
enableApi
+
",不需要连接"
);
}
else
if
(!
enableApi
)
{
}
log
.
info
(
"enableApi="
+
enableApi
+
",不需要连接"
);
else
if
(
ObjectUtil
.
isEmpty
(
host
)
||
webPort
==
0
||
apiPort
==
0
)
{
}
else
if
(
ObjectUtil
.
isEmpty
(
host
)
||
webPort
==
0
||
apiPort
==
0
)
{
// else if (ObjectUtil.isEmpty(host) || ObjectUtil.isEmpty(webPortStr) || ObjectUtil.isEmpty((apiPortStr))) {
// else if (ObjectUtil.isEmpty(host) || ObjectUtil.isEmpty(webPortStr) || ObjectUtil.isEmpty((apiPortStr))) {
log
.
info
(
"配置不完整,不需要连接"
);
log
.
info
(
"配置不完整,不需要连接"
);
}
else
{
}
else
{
...
@@ -140,7 +129,6 @@ public class TMSCommunicator implements WsMsgReceivedListener {
...
@@ -140,7 +129,6 @@ public class TMSCommunicator implements WsMsgReceivedListener {
// apiPort = Integer.parseInt(apiPortStr);
// apiPort = Integer.parseInt(apiPortStr);
String
apiName
=
dataCache
.
getConfigCache
(
"api.name"
,
""
);
String
apiName
=
dataCache
.
getConfigCache
(
"api.name"
,
""
);
if
(
apiName
!=
null
&&
apiName
.
equalsIgnoreCase
(
"hanwha"
))
{
if
(
apiName
!=
null
&&
apiName
.
equalsIgnoreCase
(
"hanwha"
))
{
updateServerInfo
(
host
,
webPort
,
apiPort
);
Thread
closeTask
=
new
Thread
(
new
Runnable
()
{
Thread
closeTask
=
new
Thread
(
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
...
@@ -148,39 +136,118 @@ public class TMSCommunicator implements WsMsgReceivedListener {
...
@@ -148,39 +136,118 @@ public class TMSCommunicator implements WsMsgReceivedListener {
Thread
.
sleep
(
20000
);
Thread
.
sleep
(
20000
);
start
();
start
();
Thread
.
sleep
(
5000
);
Thread
.
sleep
(
5000
);
needCheck
=
true
;
needCheck
=
true
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"开始连接webService出错:"
+
e
.
getMessage
());
log
.
error
(
"开始连接webService出错:"
+
e
.
getMessage
());
}
}
}
}
}
);
});
closeTask
.
start
();
closeTask
.
start
();
// StartCheckRun();
}
}
StartCheckRun
();
}
private
void
StartCheckRun
()
{
ExecutorService
executorService
=
Executors
.
newSingleThreadExecutor
();
ExecutorService
executorService
=
Executors
.
newSingleThreadExecutor
();
executorService
.
execute
(
new
Runnable
()
{
executorService
.
execute
(
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
log
.
info
(
"启动 webService 状态检查"
);
log
.
info
(
"启动 webService 状态检查"
);
while
(
true
)
{
while
(
true
)
{
try
{
try
{
if
(
waitSync
&&
System
.
currentTimeMillis
()>
syncTime
){
if
(
isEnable
()
&&
apiName
!=
null
&&
apiName
.
equalsIgnoreCase
(
"hanwha"
))
{
if
(
waitSync
&&
System
.
currentTimeMillis
()
>
syncTime
)
{
SyncData
();
SyncData
();
}
}
TimeUnit
.
SECONDS
.
sleep
(
6
);
TimeUnit
.
SECONDS
.
sleep
(
6
);
if
(
needCheck
)
{
if
(
needCheck
)
{
stateCheck
();
stateCheck
();
}
}
}
else
{
if
(
isConnected
())
{
//当前需要禁用webSocket连接
close
();
}
TimeUnit
.
SECONDS
.
sleep
(
6
);
}
EquipConfigInfo
equipConfigInfo
=
equipConfigUtil
.
getConfigCache
(
EquipmentType
.
HANWHA
.
name
());
ResetConfig
(
equipConfigInfo
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"webService"
+
e
.
getMessage
());
log
.
error
(
"webService"
+
e
.
getMessage
());
}
}
}
}
}
}
});
});
// start();
}
}
private
void
ResetConfig
(
EquipConfigInfo
nconfig
)
{
try
{
//重新设置韩华接口时调用
String
nhost
=
nconfig
.
GetConfigValue
(
"host"
,
""
);
int
nwebPort
=
nconfig
.
GetConfigValue
(
"webPort"
,
0
);
int
napiPort
=
nconfig
.
GetConfigValue
(
"apiPort"
,
0
);
if
(
enableApi
==
nconfig
.
enableApi
&&
nhost
==
host
&&
webPort
==
nwebPort
&&
napiPort
==
apiPort
)
{
return
;
}
if
(
nconfig
.
enableApi
)
{
//当前启用
if
(
enableApi
)
{
//如果ip端口不一致,需要关闭webSocket重新连接
String
nwsURL
=
String
.
format
(
"ws://%s:%d/"
,
nhost
,
nwebPort
);
if
(!
wsURL
.
equals
(
nwsURL
))
{
log
.
info
(
"更改韩华配置,wsURL = "
+
wsURL
+
",需要更改为:"
+
nwsURL
+
",关闭webSocket连接重新连接"
);
updateServerInfo
(
nhost
,
nwebPort
,
napiPort
,
nconfig
.
enableApi
);
close
();
}
else
{
updateServerInfo
(
nhost
,
nwebPort
,
napiPort
,
nconfig
.
enableApi
);
}
}
else
{
//当前禁用
updateServerInfo
(
nhost
,
nwebPort
,
napiPort
,
nconfig
.
enableApi
);
log
.
info
(
"更改韩华配置,之前禁用连接,现在启用连接,开始启动webSocket连接"
);
Thread
closeTask
=
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
if
(
isEnable
())
{
try
{
Thread
.
sleep
(
5000
);
start
();
Thread
.
sleep
(
5000
);
needCheck
=
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
"开始连接webService出错:"
+
e
.
getMessage
());
}
}
}
});
closeTask
.
start
();
}
}
else
{
//如果原来启用当前禁用
if
(
enableApi
)
{
log
.
info
(
"更改韩华配置,之前启用连接,现在禁用连接,关闭webSocket连接,更新配置"
);
updateServerInfo
(
nhost
,
nwebPort
,
napiPort
,
nconfig
.
enableApi
);
close
();
//关闭连接
}
}
}
}
}
catch
(
Exception
exception
)
{
log
.
error
(
"ResetConfig error :"
+
exception
.
toString
());
}
}
private
void
stateCheck
(){
private
void
stateCheck
(){
if
(
websocket
.
isOpen
()||
websocket
.
isConnecting
()){
if
(
websocket
.
isOpen
()||
websocket
.
isConnecting
()){
...
@@ -190,11 +257,11 @@ public class TMSCommunicator implements WsMsgReceivedListener {
...
@@ -190,11 +257,11 @@ public class TMSCommunicator implements WsMsgReceivedListener {
}
}
}
}
private
void
updateServerInfo
(
String
serverHost
,
int
wport
,
int
aport
)
{
private
void
updateServerInfo
(
String
serverHost
,
int
wport
,
int
aport
,
boolean
enableApiParam
)
{
host
=
serverHost
;
host
=
serverHost
;
webPort
=
wport
;
webPort
=
wport
;
apiPort
=
aport
;
apiPort
=
aport
;
enableApi
=
enableApiParam
;
wsURL
=
String
.
format
(
"ws://%s:%d/"
,
serverHost
,
wport
);
wsURL
=
String
.
format
(
"ws://%s:%d/"
,
serverHost
,
wport
);
apiURL
=
String
.
format
(
"http://%s:%d/"
,
serverHost
,
aport
);
apiURL
=
String
.
format
(
"http://%s:%d/"
,
serverHost
,
aport
);
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论