Преглед на файлове

fix: 修复设备绑定问题
1. 修复同一台设备能够绑定多个用户的问题
2. 修复普通用户页面访问问题

kindring преди 1 година
родител
ревизия
b9e97aa8aa

+ 8 - 4
src/main/java/com/genersoft/iot/vmp/service/impl/AccountServiceImpl.java

@@ -71,13 +71,17 @@ public class AccountServiceImpl implements IAccountService {
 
 
     public Boolean checkIsAllowBind(String bindCode) {
-        if (deviceMapper.getDeviceByBindCode(bindCode) == null) {
+
+        Device device = deviceMapper.getDeviceByBindCode(bindCode);
+        if (device == null) {
             logger.warn("not find device");
             return false;
         }
-        Device device = accountMapper.findDeviceByDevCode(bindCode);
-        logger.info("device: {}", device);
-        return device == null;
+
+        int bindNum = accountMapper.findDeviceByDevCode(bindCode, device.getId());
+        logger.info("bindNum: {}", bindNum);
+        // 该设备id 可能已经在
+        return bindNum < 1;
     }
 
 

+ 4 - 0
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java

@@ -140,6 +140,7 @@ public class PlayServiceImpl implements IPlayService {
             wvpResult.setMsg("点播失败, 无法找到zlm服务");
             msg.setData(wvpResult);
             resultHolder.invokeAllResult(msg);
+            redisCatchStorage.stopPlay(streamInfo);
             return;
         }
 
@@ -152,6 +153,8 @@ public class PlayServiceImpl implements IPlayService {
                 wvpResult.setMsg("点播失败, redis缓存streamId等于null");
                 msg.setData(wvpResult);
                 resultHolder.invokeAllResult(msg);
+                redisCatchStorage.stopPlay(streamInfo);
+                resultHolder.invokeAllResult(msg);
                 return;
             }
 
@@ -179,6 +182,7 @@ public class PlayServiceImpl implements IPlayService {
                         wvpResult.setCode(ErrorCode.ERROR100.getCode());
                         wvpResult.setMsg("点播已经在进行中,请稍候重试");
                         msg.setData(wvpResult);
+                        redisCatchStorage.stopPlay(streamInfo);
                         resultHolder.invokeAllResult(msg);
                         return;
                     } else {

+ 2 - 2
src/main/java/com/genersoft/iot/vmp/storager/dao/AccountMapper.java

@@ -32,8 +32,8 @@ public interface AccountMapper {
     @Delete("DELETE FROM device_bind WHERE userId=#{userId} AND devId=#{deviceId}")
     int unBindDevice(String userId, String deviceId);
 
-    @Select("SELECT * FROM device_bind where devCode = #{bindCode}")
-    Device findDeviceByDevCode(String devCode);
+    @Select("SELECT count(*) FROM device_bind where devCode = #{devCode} OR devId = #{deviceId}")
+    int findDeviceByDevCode(String devCode, String deviceId);
 
     // 查询用户设备
     //    SELECT * FROM `device_bind` as b LEFT JOIN `device` as d ON b.deviceId = d.id where b.userId = 1

+ 2 - 1
src/main/java/com/genersoft/iot/vmp/vmanager/account/AccountDeviceControl.java

@@ -54,12 +54,13 @@ public class AccountDeviceControl {
         if (device == null) {
             return WVPResult.fail(ErrorCode.ERROR404, "无法找到对应设备");
         }
-        // 判断设备是否已经绑定
+        // 判断设备是否已经绑定至用户
         if (!accountService.checkIsAllowBind(bindCode)) {
             return WVPResult.fail(
                     ErrorCode.ERROR403,
                     "设备已经绑定, 无法重新绑定");
         }
+
         if (accountService.bindDevice(
                 userId,
                 device.getId(),

+ 13 - 0
src/main/java/com/genersoft/iot/vmp/vmanager/pageController.java

@@ -12,4 +12,17 @@ public class pageController {
     public String share() {
         return "share.html";
     }
+
+    @Operation(summary = "普通用户登录")
+    @GetMapping("/account")
+    public String account() {
+        return "account.html";
+    }
+
+    @Operation(summary = "普通用户设备管理后台")
+    @GetMapping("/device")
+    public String device() {
+        return "device.html";
+    }
+
 }

+ 6 - 5
src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiStreamController.java

@@ -181,24 +181,25 @@ public class ApiStreamController {
         StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(serial, code);
         if (streamInfo == null) {
             JSONObject result = new JSONObject();
-            result.put("error","未找到流信息");
+            result.put("error", "未找到流信息");
             return result;
         }
         Device device = deviceService.getDevice(serial);
+        redisCatchStorage.stopPlay(streamInfo);
+        storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
         if (device == null) {
             JSONObject result = new JSONObject();
-            result.put("error","未找到设备");
+            result.put("error", "未找到设备");
             return result;
         }
         try {
             cmder.streamByeCmd(device, code, streamInfo.getStream(), null);
         } catch (InvalidArgumentException | ParseException | SipException | SsrcTransactionNotFoundException e) {
             JSONObject result = new JSONObject();
-            result.put("error","发送BYE失败:" + e.getMessage());
+            result.put("error", "发送BYE失败:" + e.getMessage());
             return result;
         }
-        redisCatchStorage.stopPlay(streamInfo);
-        storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
+
         return null;
     }