| | |
| | | import com.ard.common.core.domain.R; |
| | | import com.ard.common.core.domain.RtpServerParam; |
| | | import com.ard.common.core.exception.ServiceException; |
| | | import com.ard.gb28181.api.domain.Device; |
| | | import com.ard.gb28181.api.domain.DeviceChannel; |
| | | import com.ard.gb28181.api.domain.GbChannelDTO; |
| | | import com.ard.gb28181.api.domain.GbDeviceDTO; |
| | | import com.ard.gb28181.api.domain.*; |
| | | import com.ard.gb28181.config.UserSetting; |
| | | import com.ard.gb28181.domain.GbChannel; |
| | | import com.ard.gb28181.domain.GbDevice; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.Assert; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.context.request.async.DeferredResult; |
| | | |
| | | import javax.sip.ResponseEvent; |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.concurrent.CompletableFuture; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 根据主键ID获取GbChannel |
| | | */ |
| | | @GetMapping("/getGbChannelById/{id}") |
| | | public R<GbChannelDTO> getGbChannelById(@PathVariable Long id) { |
| | | GbChannel gbChannel = gbChannelService.selectGbChannelById(id); |
| | | if (gbChannel == null) { |
| | | return R.fail("GbChannel不存在 id:" + id); |
| | | } |
| | | return R.ok(toGbChannelDTO(gbChannel)); |
| | | } |
| | | |
| | | /** |
| | | * 根据国标设备ID和通道ID获取GbChannel |
| | | */ |
| | | @GetMapping("/getGbChannel/{gbDeviceId}/{gbChannelId}") |
| | |
| | | dto.setGbDeviceId(d.getGbDeviceId()); |
| | | dto.setDeviceName(d.getDeviceName()); |
| | | dto.setDeviceCode(d.getDeviceCode()); |
| | | dto.setStreamMode(d.getStreamMode()); |
| | | dto.setEnableMp4(d.getEnableMp4()); |
| | | dto.setStreamStatus(d.getStreamStatus()); |
| | | dto.setMediaServerId(d.getMediaServerId()); |
| | | dto.setStreamKey(d.getStreamKey()); |
| | | dto.setSnap(d.getSnap()); |
| | | dto.setIp(d.getIp()); |
| | | dto.setPort(d.getPort()); |
| | | dto.setManufacturer(d.getManufacturer()); |
| | | dto.setModel(d.getModel()); |
| | | dto.setFirmware(d.getFirmware()); |
| | | dto.setOnLine(d.getOnLine()); |
| | | return dto; |
| | | } |
| | | |
| | |
| | | dto.setStreamKey(c.getStreamKey()); |
| | | dto.setSnap(c.getSnap()); |
| | | return dto; |
| | | } |
| | | |
| | | /** |
| | | * 一键迁移:将 Redis 中已注册的国标设备同步到 MySQL(供首次执行 SQL 后使用) |
| | | */ |
| | | @Operation(summary = "迁移Redis国标设备到MySQL") |
| | | @PostMapping("/migrateGbDevices") |
| | | public R<String> migrateGbDevices() { |
| | | List<Device> allDevices = deviceService.getAllDevices(); |
| | | int deviceCount = 0; |
| | | int channelCount = 0; |
| | | |
| | | for (Device device : allDevices) { |
| | | 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); |
| | | deviceCount++; |
| | | log.info("[迁移] 创建设备: {}", device.getDeviceId()); |
| | | } |
| | | |
| | | // 创建默认通道(设备自身) |
| | | GbChannel existingDefaultChannel = gbChannelService.selectByGbDeviceIdAndGbChannelId( |
| | | device.getDeviceId(), device.getDeviceId()); |
| | | if (existingDefaultChannel == null) { |
| | | 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); |
| | | channelCount++; |
| | | } |
| | | |
| | | // 创建所有通道 |
| | | List<DeviceChannel> channels = deviceService.getChannelsByDeviceId(device.getDeviceId()); |
| | | if (channels != null) { |
| | | for (DeviceChannel channel : channels) { |
| | | String channelId = channel.getDeviceId(); |
| | | if (channelId == null || channelId.length() <= 8) { |
| | | continue; |
| | | } |
| | | if (channelId.length() == 20) { |
| | | try { |
| | | com.ard.gb28181.api.domain.GbCode gbCode = com.ard.gb28181.api.domain.GbCode.decode(channelId); |
| | | if (gbCode != null && ("215".equals(gbCode.getTypeCode()) || "216".equals(gbCode.getTypeCode()))) { |
| | | continue; |
| | | } |
| | | } catch (Exception ignored) {} |
| | | } |
| | | GbChannel existing = gbChannelService.selectByGbDeviceIdAndGbChannelId(device.getDeviceId(), channelId); |
| | | if (existing == null) { |
| | | GbChannel gbChannel = new GbChannel(); |
| | | gbChannel.setGbDeviceId(device.getDeviceId()); |
| | | gbChannel.setGbChannelId(channelId); |
| | | gbChannel.setChannelName(channel.getName() != null ? channel.getName() : channelId); |
| | | gbChannel.setDeviceCode(channelId); |
| | | gbChannel.setStreamMode(device.getStreamMode() != null ? device.getStreamMode() : "TCP-PASSIVE"); |
| | | gbChannel.setEnableMp4("0"); |
| | | gbChannelService.insertGbChannel(gbChannel); |
| | | channelCount++; |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("[迁移] 处理设备失败: {}", device.getDeviceId(), e); |
| | | } |
| | | } |
| | | |
| | | return R.ok("迁移完成: 设备 " + deviceCount + " 条, 通道 " + channelCount + " 条"); |
| | | } |
| | | } |