liusuyi
2026-06-02 f652169cc5d6501511eece5df57b7b396fd7a7ab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package com.ard.zlm.service;
 
import com.ard.common.core.constant.SecurityConstants;
import com.ard.common.core.domain.R;
import com.ard.gb28181.api.RemoteGb28181Service;
import com.ard.gb28181.api.domain.GbChannelDTO;
import com.ard.zlm.domain.StreamChannel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
/**
 * ZLM流媒体本地服务(统一管理国标通道和普通相机通道的流状态)
 */
@Slf4j
@Service
public class ZlmStreamService {
 
    @Autowired
    private RemoteGb28181Service remoteGb28181Service;
 
    /**
     * 根据ID获取通道信息
     */
    public R<StreamChannel> getQsDeviceInfo(Long id, String inner) {
        try {
            R<GbChannelDTO> r = remoteGb28181Service.getGbChannelById(id, SecurityConstants.INNER);
            if (r != null && r.getData() != null && r.getData().getId() != null) {
                return R.ok(toStreamChannel(r.getData()));
            }
        } catch (Exception e) {
            log.error("[ZlmStream] 查询通道信息失败 id={}", id, e);
        }
        return R.ok(new StreamChannel());
    }
 
    /**
     * 根据流标识获取通道
     */
    public R<StreamChannel> getQsDeviceStream(String stream, String inner) {
        log.debug("[ZlmStream] 查找流: stream={}", stream);
        return R.ok(new StreamChannel());
    }
 
    /**
     * 更新通道流信息
     */
    public R<Boolean> updateQsDevice(StreamChannel streamChannel, String inner) {
        try {
            if (streamChannel.getId() != null && streamChannel.getId() > 0) {
                GbChannelDTO dto = new GbChannelDTO();
                dto.setId(streamChannel.getId());
                dto.setStreamKey(streamChannel.getStreamKey());
                dto.setMediaServerId(streamChannel.getMediaServerId());
                dto.setStreamStatus(streamChannel.getStreamStatus());
                dto.setSnap(streamChannel.getSnap());
                R<Boolean> r = remoteGb28181Service.updateGbChannelStream(dto, SecurityConstants.INNER);
                if (r != null && r.getData() != null) {
                    return r;
                }
            }
        } catch (Exception e) {
            log.error("[ZlmStream] 更新流信息失败 id={}", streamChannel.getId(), e);
        }
        return R.ok(false);
    }
 
    /**
     * 新增通道
     */
    public R<Boolean> addQsDevice(StreamChannel streamChannel, String inner) {
        log.info("[ZlmStream] 新增通道请求: channelName={}, channelType={}",
                streamChannel.getChannelName(), streamChannel.getChannelType());
        return R.ok(true);
    }
 
    /**
     * 根据计划ID统计设备数量
     */
    public R<Integer> countRecordPlanDevice(Long planId, String inner) {
        return R.ok(0);
    }
 
    /**
     * 清理设备计划ID
     */
    public R<Void> cleanRecordPlanId(Long planId, String inner) {
        return R.ok();
    }
 
    public static StreamChannel toStreamChannel(GbChannelDTO c) {
        StreamChannel sc = new StreamChannel();
        sc.setId(c.getId());
        sc.setChannelName(c.getChannelName());
        sc.setDeviceCode(c.getDeviceCode());
        sc.setStreamKey(c.getStreamKey());
        sc.setMediaServerId(c.getMediaServerId());
        sc.setStreamStatus(c.getStreamStatus());
        sc.setSnap(c.getSnap());
        sc.setEnableMp4(c.getEnableMp4());
        sc.setGbDeviceId(c.getGbDeviceId());
        sc.setGbChannelId(c.getGbChannelId());
        sc.setStreamMode(c.getStreamMode());
        sc.setChannelType("gb28181");
        return sc;
    }
}