liusuyi
2026-05-30 f4f4fc53260eb67483dce406a963628273786a61
ard-modules/ard-modules-gb28181/src/main/java/com/ard/gb28181/service/impl/DeviceServiceImpl.java
@@ -13,7 +13,11 @@
import com.ard.gb28181.api.utils.DateUtil;
import com.ard.gb28181.common.ErrorCode;
import com.ard.gb28181.config.UserSetting;
import com.ard.gb28181.domain.GbChannel;
import com.ard.gb28181.domain.GbDevice;
import com.ard.gb28181.service.IDeviceService;
import com.ard.gb28181.service.IGbChannelService;
import com.ard.gb28181.service.IGbDeviceService;
import com.ard.gb28181.service.IRedisCatchStorage;
import com.ard.gb28181.service.ISIPCommander;
import com.ard.gb28181.session.SipInviteSessionManager;
@@ -71,6 +75,12 @@
    @Autowired
    private RemoteQsDeviceService remoteQsDeviceService;
    @Autowired
    private IGbDeviceService gbDeviceService;
    @Autowired
    private IGbChannelService gbChannelService;
    /**
     * 查询设备信息
@@ -176,6 +186,35 @@
        } catch (Exception e) {
            log.error("[同步设备状态] 设备上线,同步到 QS 模块失败:{}", device.getDeviceId(), e);
        }
        // 设备注册成功时,自动在 ard_gb_device 表中创建设备记录(若不存在)
        try {
            GbDevice existingDevice = gbDeviceService.selectGbDeviceByGbDeviceId(device.getDeviceId());
            if (existingDevice == null) {
                GbDevice gbDevice = new GbDevice();
                gbDevice.setGbDeviceId(device.getDeviceId());
                gbDevice.setDeviceName(device.getName() != null ? device.getName() : device.getDeviceId());
                gbDevice.setDeviceCode(device.getDeviceId());
                gbDevice.setStreamMode(device.getStreamMode() != null ? device.getStreamMode() : "TCP-PASSIVE");
                gbDevice.setEnableMp4("0");
                gbDeviceService.insertGbDevice(gbDevice);
                log.info("[GbDevice自动创建] deviceId: {}, id: {}", device.getDeviceId(), gbDevice.getId());
                // 同时创建默认通道(设备自身)
                GbChannel gbChannel = new GbChannel();
                gbChannel.setGbDeviceId(device.getDeviceId());
                gbChannel.setGbChannelId(device.getDeviceId());
                gbChannel.setChannelName(device.getName() != null ? device.getName() : device.getDeviceId());
                gbChannel.setDeviceCode(device.getDeviceId());
                gbChannel.setStreamMode(device.getStreamMode() != null ? device.getStreamMode() : "TCP-PASSIVE");
                gbChannel.setEnableMp4("0");
                gbChannelService.insertGbChannel(gbChannel);
                log.info("[GbChannel默认创建] deviceId: {}, channelId: {}, id: {}",
                        device.getDeviceId(), device.getDeviceId(), gbChannel.getId());
            }
        } catch (Exception e) {
            log.error("[GbDevice自动创建] 设备上线,自动创建失败:{}", device.getDeviceId(), e);
        }
    }
    @Override