Переглянути джерело

修复设备初次注册无通道

panlinlin 1 рік тому
батько
коміт
d201be2f88

+ 1 - 0
src/main/java/com/genersoft/iot/vmp/gb28181/dao/DeviceChannelMapper.java

@@ -26,6 +26,7 @@ public interface DeviceChannelMapper {
             "#{ipAddress}, #{port}, #{password}, #{status}, #{longitude}, #{latitude}, #{ptzType}, #{positionType}, #{roomType}, #{useType}, " +
             "#{supplyLightType}, #{directionType}, #{resolution}, #{businessGroupId}, #{downloadSpeed}, #{svcSpaceSupportMod}," +
             " #{svcTimeSupportMode}, #{createTime}, #{updateTime}, #{subCount}, #{streamId}, #{hasAudio}, #{gpsTime}, #{streamIdentification})")
+    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
     int add(DeviceChannel channel);
 
     @Update(value = {" <script>" +

+ 1 - 0
src/main/java/com/genersoft/iot/vmp/gb28181/dao/DeviceMapper.java

@@ -110,6 +110,7 @@ public interface DeviceMapper {
                 "#{geoCoordSys}," +
                 "#{onLine}" +
             ")")
+    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
     int add(Device device);
 
     @Update(value = {" <script>" +

+ 7 - 18
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java

@@ -35,6 +35,7 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.TransactionDefinition;
 import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.ObjectUtils;
 
 import javax.sip.InvalidArgumentException;
@@ -537,29 +538,17 @@ public class DeviceServiceImpl implements IDeviceService {
     }
 
     @Override
+    @Transactional
     public boolean delete(String deviceId) {
         Device device = deviceMapper.getDeviceByDeviceId(deviceId);
         if (device == null) {
             throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到设备:" + deviceId);
         }
-        TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
-        boolean result = false;
-        try {
-            platformChannelMapper.delChannelForDeviceId(deviceId);
-            deviceChannelMapper.cleanChannelsByDeviceId(device.getId());
-            if ( deviceMapper.del(deviceId) < 0 ) {
-                //事务回滚
-                dataSourceTransactionManager.rollback(transactionStatus);
-            }
-            result = true;
-            dataSourceTransactionManager.commit(transactionStatus);     //手动提交
-        }catch (Exception e) {
-            dataSourceTransactionManager.rollback(transactionStatus);
-        }
-        if (result) {
-            redisCatchStorage.removeDevice(deviceId);
-        }
-        return result;
+        platformChannelMapper.delChannelForDeviceId(deviceId);
+        deviceChannelMapper.cleanChannelsByDeviceId(device.getId());
+        deviceMapper.del(deviceId);
+        redisCatchStorage.removeDevice(deviceId);
+        return true;
     }
 
     @Override