|
@@ -9,104 +9,71 @@ import java.util.TimerTask;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
-import cn.hutool.core.map.MapUtil;
|
|
|
-import com.huashe.park.common.DateTimeUtil;
|
|
|
-import com.huashe.park.domain.dto.UWBAuth;
|
|
|
-import com.huashe.park.infrastructure.uwb.UWBWebService;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.java_websocket.client.WebSocketClient;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
-import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.huashe.park.common.DateTimeUtil;
|
|
|
+import com.huashe.park.domain.dto.UWBAuth;
|
|
|
+import com.huashe.park.infrastructure.cfg.forest.UWBForestCfg;
|
|
|
+import com.huashe.park.infrastructure.uwb.UWBWebService;
|
|
|
+
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
|
|
|
@Configuration
|
|
|
-@ConfigurationProperties(prefix = "bd.uwb")
|
|
|
-@ConditionalOnProperty(name = "bd.uwb.enabled", havingValue = "true")
|
|
|
+@ConditionalOnBean(UWBForestCfg.class)
|
|
|
public class UWBCfg {
|
|
|
private static final Logger log = LoggerFactory.getLogger(UWBCfg.class);
|
|
|
|
|
|
- private String uwbSocket;
|
|
|
-
|
|
|
- private String uwbUsr;
|
|
|
-
|
|
|
- private String uwbPwd;
|
|
|
-
|
|
|
- private String uwbHost;
|
|
|
-
|
|
|
- public String getUwbHost() {
|
|
|
- return uwbHost;
|
|
|
- }
|
|
|
-
|
|
|
- public void setUwbHost(String uwbHost) {
|
|
|
- this.uwbHost = uwbHost;
|
|
|
- }
|
|
|
+ @Autowired
|
|
|
+ private UWBForestCfg uwbForestCfg;
|
|
|
|
|
|
@Resource
|
|
|
private UWBWebService uwbWebService;
|
|
|
|
|
|
- public String getUwbSocket() {
|
|
|
- return uwbSocket;
|
|
|
- }
|
|
|
-
|
|
|
- public void setUwbSocket(String uwbSocket) {
|
|
|
- this.uwbSocket = uwbSocket;
|
|
|
- }
|
|
|
-
|
|
|
- public String getUwbUsr() {
|
|
|
- return uwbUsr;
|
|
|
- }
|
|
|
-
|
|
|
- public void setUwbUsr(String uwbUsr) {
|
|
|
- this.uwbUsr = uwbUsr;
|
|
|
- }
|
|
|
-
|
|
|
- public String getUwbPwd() {
|
|
|
- return uwbPwd;
|
|
|
- }
|
|
|
-
|
|
|
- public void setUwbPwd(String uwbPwd) {
|
|
|
- this.uwbPwd = uwbPwd;
|
|
|
+ @Bean
|
|
|
+ public UWBSocketClient uwbWebSocketClient() throws URISyntaxException {
|
|
|
+ return new UWBSocketClient(new URI(uwbForestCfg.getUwbSocket()));
|
|
|
}
|
|
|
|
|
|
@Bean
|
|
|
- public WebSocketClient webSocketClient() throws URISyntaxException {
|
|
|
- String ws = this.getUwbSocket();
|
|
|
- UWBSocketClient webSocketClient = new UWBSocketClient(new URI(ws));
|
|
|
+ public WebSocketClient webSocketClient(UWBSocketClient uwbWebSocketClient) {
|
|
|
UWBAuth uwbAuth = authUWB();
|
|
|
if (ObjectUtils.isEmpty(uwbAuth)) {
|
|
|
return null;
|
|
|
}
|
|
|
- webSocketClient.setAuthToken(uwbAuth);
|
|
|
- webSocketClient.connect();
|
|
|
+ uwbWebSocketClient.setAuthToken(uwbAuth);
|
|
|
+ uwbWebSocketClient.connect();
|
|
|
Timer t = new Timer();
|
|
|
t.scheduleAtFixedRate(new TimerTask() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- if (webSocketClient.isClosed()) {
|
|
|
+ if (uwbWebSocketClient.isClosed()) {
|
|
|
UWBAuth uwbAuth = authUWB();
|
|
|
if (ObjectUtils.isEmpty(uwbAuth)) {
|
|
|
return;
|
|
|
}
|
|
|
- webSocketClient.setAuthToken(uwbAuth);
|
|
|
- webSocketClient.reconnect();
|
|
|
+ uwbWebSocketClient.setAuthToken(uwbAuth);
|
|
|
+ uwbWebSocketClient.reconnect();
|
|
|
}
|
|
|
}
|
|
|
}, 1000, 5000);
|
|
|
- return webSocketClient;
|
|
|
+ return uwbWebSocketClient;
|
|
|
}
|
|
|
|
|
|
private UWBAuth authUWB() {
|
|
|
Map map = uwbWebService.exchangeToken(new HashMap<String, Object>() {
|
|
|
{
|
|
|
{
|
|
|
- put("username", uwbUsr);
|
|
|
- put("password", uwbPwd);
|
|
|
+ put("username", uwbForestCfg.getUwbUsr());
|
|
|
+ put("password", uwbForestCfg.getUwbPwd());
|
|
|
put("isfresh", 1);
|
|
|
}
|
|
|
}
|