소스 검색

+ 新增uwb视频跟随socketserver

chen.cheng 6 달 전
부모
커밋
c3fefd9680

+ 1 - 1
bd-park/park-backend/park-application/src/main/java/com/huashe/park/application/BDApplication.java

@@ -17,7 +17,7 @@ import org.springframework.context.annotation.ComponentScan;
 @ComponentScan(basePackages = {"com.ruoyi", "com.huashe.park"})
 @MapperScan("com.huashe.park.core.mapper")
 @ForestScan(basePackages = {"com.huashe.park.infrastructure.uwb"})
-@EnableSocketServer(basePackages = {"com.huashe.park.application.socket.server"})
+@EnableSocketServer(basePackages = {"com.huashe.park.infrastructure.socket.server"})
 public class BDApplication {
     public static void main(String[] args) {
         // System.setProperty("spring.devtools.restart.enabled", "false");

+ 1 - 1
bd-park/park-backend/park-application/src/main/java/com/huashe/park/application/mybatis/interceptor/MybatisInterceptor.java → bd-park/park-backend/park-application/src/main/java/com/huashe/park/application/mybatis/MybatisInterceptor.java

@@ -1,4 +1,4 @@
-package com.huashe.park.application.mybatis.interceptor;
+package com.huashe.park.application.mybatis;
 
 
 import com.ruoyi.common.core.domain.model.LoginUser;

+ 1 - 1
bd-park/park-backend/park-application/src/main/java/com/huashe/park/application/mybatis/interceptor/RegisterCustomerInterceptor.java → bd-park/park-backend/park-application/src/main/java/com/huashe/park/application/mybatis/RegisterCustomerInterceptor.java

@@ -1,4 +1,4 @@
-package com.huashe.park.application.mybatis.interceptor;
+package com.huashe.park.application.mybatis;
 
 import org.apache.ibatis.session.SqlSessionFactory;
 import org.springframework.beans.factory.annotation.Autowired;

+ 44 - 11
bd-park/park-backend/park-application/src/main/java/com/huashe/park/application/web/controller/bd/BdDevcTrailUwbController.java

@@ -1,6 +1,28 @@
 package com.huashe.park.application.web.controller.bd;
 
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+
+import com.huashe.park.infrastructure.cfg.forest.UWBForestCfg;
+import com.huashe.park.infrastructure.uwb.HolidayWebService;
+import com.huashe.park.infrastructure.uwb.UWBWebService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
 import com.alibaba.fastjson2.JSON;
+import com.huashe.common.domain.AjaxResult;
 import com.huashe.park.common.DateTimeUtil;
 import com.huashe.park.common.consts.BDConst;
 import com.huashe.park.core.service.IBdDevcTrailUwbService;
@@ -8,18 +30,11 @@ import com.huashe.park.domain.entity.BdDevcTrailUwb;
 import com.ruoyi.common.annotation.Anonymous;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.core.controller.BaseController;
-import com.huashe.common.domain.AjaxResult;
 import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.common.enums.BusinessType;
 import com.ruoyi.common.utils.poi.ExcelUtil;
-import net.dreamlu.iot.mqtt.spring.client.MqttClientTemplate;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
 
-import javax.servlet.http.HttpServletResponse;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import net.dreamlu.iot.mqtt.spring.client.MqttClientTemplate;
 
 /**
  * 室内坐标定位Controller
@@ -30,6 +45,7 @@ import java.util.Map;
 @RestController
 @CrossOrigin
 @RequestMapping("/bd/devcTrailUwb")
+@Anonymous
 public class BdDevcTrailUwbController extends BaseController {
     @Autowired
     private IBdDevcTrailUwbService bdDevcTrailUwbService;
@@ -37,12 +53,30 @@ public class BdDevcTrailUwbController extends BaseController {
     @Autowired
     private MqttClientTemplate client;
 
+    @Autowired
+    private UWBForestCfg uwbForestCfg;
+
+    @Autowired
+    private HolidayWebService holidayWebService;
+
+    @Resource
+    private UWBWebService uwbWebService;
 
     /**
      * 查询室内坐标定位列表
      */
     @GetMapping("/list")
     public TableDataInfo list(BdDevcTrailUwb bdDevcTrailUwb) {
+//        Map map = uwbWebService.exchangeToken(new HashMap<String, Object>() {
+//            {
+//                {
+//                    put("username", uwbForestCfg.getUwbUsr());
+//                    put("password", uwbForestCfg.getUwbPwd());
+//                    put("isfresh", 1);
+//                }
+//            }
+//        });
+//        Map yearHoliday = holidayWebService.getYearHoliday("2025");
         startPage();
         List<BdDevcTrailUwb> list = bdDevcTrailUwbService.selectBdDevcTrailUwbList(bdDevcTrailUwb);
         return getDataTable(list);
@@ -71,10 +105,10 @@ public class BdDevcTrailUwbController extends BaseController {
                 put("deviceId", bdDevcTrailUwb.getDevcKey());
             }
         };
-        client.publish(String.format(BDConst.MQTT_TOPIC.DEVICE_LOCATION_TOPIC, bdDevcTrailUwb.getDevcKey()), JSON.toJSONBytes(map));
+        client.publish(String.format(BDConst.MQTT_TOPIC.DEVICE_LOCATION_TOPIC, bdDevcTrailUwb.getDevcKey()),
+            JSON.toJSONBytes(map));
     }
 
-
     /**
      * 获取室内坐标定位详细信息
      */
@@ -117,5 +151,4 @@ public class BdDevcTrailUwbController extends BaseController {
         return toAjax(bdDevcTrailUwbService.deleteBdDevcTrailUwbByIds(ids));
     }
 
-
 }

+ 1 - 1
bd-park/park-backend/park-application/src/main/resources/application-druid.yml

@@ -101,4 +101,4 @@ mqtt:
       enabled: false
 bd:
   mqtt:
-    enabled: true
+    enabled: false

+ 3 - 3
bd-park/park-backend/park-application/src/main/resources/application.yml

@@ -35,7 +35,7 @@ server:
 logging:
   level:
     com.ruoyi: debug
-    com.huashe: info
+    com.huashe: debug
     org.springframework: warn
 
 # 用户配置
@@ -84,10 +84,10 @@ forest:
   log-response-content: true
   custom:
     # 自定义配置
-    holiday: https://fastly.jsdelivr.net
+    holiday: https://raw.githubusercontent.com
     uwb:
       enabled: true
-      uwb-socket: ws://172.192.13.77:2223/socket/websocket/pollingArea
+      uwb-socket: ws://172.192.13.80:2223/socket/websocket/pollingArea
       uwb-usr: admin
       uwb-pwd: admin123
       uwb-host: http://172.192.13.80:2223

+ 13 - 2
bd-park/park-backend/park-infrastructure/src/main/java/com/huashe/park/infrastructure/cfg/forest/CustomForestCfg.java

@@ -1,16 +1,27 @@
 package com.huashe.park.infrastructure.cfg.forest;
 
-import com.dtflys.forest.annotation.BindingVar;
-import com.dtflys.forest.reflection.ForestMethod;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.stereotype.Component;
 
+import com.dtflys.forest.annotation.BindingVar;
+import com.dtflys.forest.reflection.ForestMethod;
+
 @Component
 @ConfigurationProperties(prefix = "forest.custom")
+@ConditionalOnBean(UWBForestCfg.class)
 public class CustomForestCfg {
     private String holiday;
 
+    public String getHoliday() {
+        return holiday;
+    }
+
+    public void setHoliday(String holiday) {
+        this.holiday = holiday;
+    }
+
     @Autowired
     private UWBForestCfg uwbForestCfg;
 

+ 23 - 56
bd-park/park-backend/park-infrastructure/src/main/java/com/huashe/park/infrastructure/socket/client/UWBCfg.java

@@ -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);
                 }
             }

+ 2 - 3
bd-park/park-backend/park-infrastructure/src/main/java/com/huashe/park/infrastructure/socket/server/UwbVideoTraceSocketServer.java

@@ -1,6 +1,5 @@
 package com.huashe.park.infrastructure.socket.server;
 
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -32,8 +31,8 @@ public class UwbVideoTraceSocketServer extends SocketHandle {
 
     @Override
     public List<WebSocketSession> filterSession(String sessionKey, Map<String, WebSocketSession> webSocketSessionMap) {
-        return webSocketSessionMap.entrySet().stream()
-            .filter(entry -> entry.getKey().contains(sessionKey)).map(Map.Entry::getValue).collect(Collectors.toList());
+        return webSocketSessionMap.entrySet().stream().filter(entry -> entry.getKey().contains(sessionKey))
+            .map(Map.Entry::getValue).collect(Collectors.toList());
     }
 
 }

+ 4 - 1
bd-park/park-backend/park-infrastructure/src/main/java/com/huashe/park/infrastructure/uwb/HolidayWebService.java

@@ -1,10 +1,13 @@
 package com.huashe.park.infrastructure.uwb;
 
+import com.dtflys.forest.annotation.BaseRequest;
+import com.dtflys.forest.annotation.BaseURL;
 import com.dtflys.forest.annotation.Get;
 import com.dtflys.forest.annotation.Var;
 
 import java.util.Map;
 
+@BaseRequest(baseURL = "{holidayBaseUrl}")
 public interface HolidayWebService {
 
     /**
@@ -187,6 +190,6 @@ public interface HolidayWebService {
      * @param year
      * @return
      */
-    @Get(url = "{uwbBaseUrl}/gh/NateScarlet/holiday-cn@master/{year}.json", dataType = "json")
+    @Get(url = "/NateScarlet/holiday-cn/master/{year}.json", dataType = "json")
     Map getYearHoliday(@Var("year") String year);
 }

+ 5 - 3
bd-park/park-backend/park-infrastructure/src/main/java/com/huashe/park/infrastructure/uwb/UWBWebService.java

@@ -1,11 +1,13 @@
 package com.huashe.park.infrastructure.uwb;
 
+import java.util.Map;
+
+import com.dtflys.forest.annotation.BaseRequest;
 import com.dtflys.forest.annotation.JSONBody;
 import com.dtflys.forest.annotation.Post;
 
-import java.util.Map;
-
+@BaseRequest(baseURL = "{uwbBaseUrl}")
 public interface UWBWebService {
-    @Post(url = "{uwbBaseUrl}/stage-api/auth/login", dataType = "json")
+    @Post(url = "/stage-api/auth/login", dataType = "json")
     Map exchangeToken(@JSONBody Map<String, Object> data);
 }

+ 1 - 1
bd-park/park-backend/pom.xml

@@ -42,7 +42,7 @@
         <poi.version>4.1.2</poi.version>
         <velocity.version>2.3</velocity.version>
         <jwt.version>0.9.1</jwt.version>
-        <forest.version>1.5.9</forest.version>
+        <forest.version>1.6.3</forest.version>
         <cffu.version>1.0.0-Alpha19</cffu.version>
         <jts.version>1.18.2</jts.version>
         <mqttstarter.version>2.3.7</mqttstarter.version>