liusuyi
2026-05-14 9958bc1501d0daee954d9bba383475e55e24ebab
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package com.ard.work.carousel.service.impl;
 
import com.ard.common.core.constant.SecurityConstants;
import com.ard.common.core.domain.R;
import com.ard.common.core.utils.DateUtils;
import com.ard.common.core.utils.uuid.IdUtils;
import com.ard.common.datascope.annotation.DataScope;
import com.ard.vtdu.api.RemoteArdVtduService;
import com.ard.vtdu.api.domian.ArdVtdu;
import com.ard.work.api.domian.ArdChannel;
import com.ard.work.carousel.domain.ArdCarouselPlans;
import com.ard.work.carousel.domain.ArdCarouselWindow;
import com.ard.work.carousel.domain.ArdCarouselWindowChannel;
import com.ard.work.carousel.mapper.ArdCarouselPlansMapper;
import com.ard.work.carousel.mapper.ArdCarouselWindowChannelMapper;
import com.ard.work.carousel.mapper.ArdCarouselWindowMapper;
import com.ard.work.carousel.service.IArdCarouselPlansService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * 视频轮播方案Service业务层处理
 *
 * @author ruoyi
 * @date 2024-09-03
 */
@Service
public class ArdCarouselPlansServiceImpl implements IArdCarouselPlansService {
    @Resource
    private ArdCarouselPlansMapper ardCarouselPlansMapper;
    @Resource
    private ArdCarouselWindowMapper ardCarouselWindowMapper;
    @Resource
    private ArdCarouselWindowChannelMapper ardCarouselWindowChannelMapper;
    @Resource
    private RemoteArdVtduService remoteArdVtduService;
 
    /**
     * 查询视频轮播方案
     *
     * @param id 视频轮播方案主键
     * @return 视频轮播方案
     */
    @Override
    public ArdCarouselPlans selectArdCarouselPlansById(String id) {
        ArdCarouselPlans ardCarouselPlans = ardCarouselPlansMapper.selectArdCarouselPlansById(id);
        if (ardCarouselPlans == null) {
            return new ArdCarouselPlans();
        }
        ArdCarouselWindow ardCarouselWindow = new ArdCarouselWindow();
        ardCarouselWindow.setPlanId(id);
        List<ArdCarouselWindow> ardCarouselWindows = ardCarouselWindowMapper.selectArdCarouselWindowList(ardCarouselWindow);
        ardCarouselWindows.stream().forEach(ardCarouselWindow1 -> {
            //获取窗口关联的通道
            List<ArdChannel> ardChannels = ardCarouselWindowChannelMapper.selectChannelIdsByWindowId(ardCarouselWindow1.getId());
            ardCarouselWindow1.setArdChannels(ardChannels);
 
            //获取通道关联的流媒体
            List<ArdVtdu> ardVtduList = ardChannels.stream().map(channel -> {
                        // 拼接名称
                        String name = channel.getDeviceId() + "_" + channel.getChanNo();
                        // 从 流媒体微服务 中获取对应的 ArdVtdu 对象
                        R<ArdVtdu> ArdVtduR = remoteArdVtduService.getInfo(name, SecurityConstants.INNER);
                        if (ArdVtduR.getCode() != R.SUCCESS) {
                            return null; // 如果不成功,返回 null
                        }
                        return ArdVtduR.getData();
                    }).filter(vtdu -> vtdu != null) // 过滤掉 null 值
                    .collect(Collectors.toList());
            ardCarouselWindow1.setArdVtdus(ardVtduList);
        });
        ardCarouselPlans.setArdCarouselWindows(ardCarouselWindows);
        return ardCarouselPlans;
    }
 
    /**
     * 查询视频轮播方案列表
     *
     * @param ardCarouselPlans 视频轮播方案
     * @return 视频轮播方案
     */
    @Override
    @DataScope(deptAlias = "d", userAlias = "u")
    public List<ArdCarouselPlans> selectArdCarouselPlansList(ArdCarouselPlans ardCarouselPlans) {
        return ardCarouselPlansMapper.selectArdCarouselPlansList(ardCarouselPlans);
    }
 
    /**
     * 新增视频轮播方案
     *
     * @param ardCarouselPlans 视频轮播方案
     * @return 结果
     */
    @Override
    @Transactional
    public int insertArdCarouselPlans(ArdCarouselPlans ardCarouselPlans) {
        ardCarouselPlans.setId(IdUtils.fastSimpleUUID());
        insertWindowChannel(ardCarouselPlans);
        ardCarouselPlans.setCreateTime(DateUtils.getNowDate());
        return ardCarouselPlansMapper.insertArdCarouselPlans(ardCarouselPlans);
    }
 
    /**
     * 修改视频轮播方案
     *
     * @param ardCarouselPlans 视频轮播方案
     * @return 结果
     */
    @Override
    @Transactional
    public int updateArdCarouselPlans(ArdCarouselPlans ardCarouselPlans) {
        ardCarouselPlans.setUpdateTime(DateUtils.getNowDate());
        //先删除当前计划ID关联的所有窗口和通道数据
        deleteWindowChannel(ardCarouselPlans.getId());
        //后插入ID关联的所有窗口和通道数据
        insertWindowChannel(ardCarouselPlans);
        return ardCarouselPlansMapper.updateArdCarouselPlans(ardCarouselPlans);
    }
 
    /**
     * 批量删除视频轮播方案
     *
     * @param ids 需要删除的视频轮播方案主键
     * @return 结果
     */
    @Override
    public int deleteArdCarouselPlansByIds(String[] ids) {
        Arrays.stream(ids).forEach(id -> {
            //先删除当前计划ID关联的所有窗口和通道数据
            deleteWindowChannel(id);
        });
        return ardCarouselPlansMapper.deleteArdCarouselPlansByIds(ids);
    }
 
    /**
     * 删除视频轮播方案信息
     *
     * @param id 视频轮播方案主键
     * @return 结果
     */
    @Override
    public int deleteArdCarouselPlansById(String id) {
        //先删除当前计划ID关联的所有窗口和通道数据
        deleteWindowChannel(id);
        return ardCarouselPlansMapper.deleteArdCarouselPlansById(id);
    }
 
    /**
     * 添加轮播方案和窗口和通道的关系
     *
     * @param ardCarouselPlans 巡检方案
     * @return
     * @author 刘苏义
     * @date 2024/9/4 10:57
     */
    public void insertWindowChannel(ArdCarouselPlans ardCarouselPlans) {
        ardCarouselPlans.getArdCarouselWindows().forEach(ardCarouselWindow -> {
            ardCarouselWindow.setId(IdUtils.fastSimpleUUID());
            List<ArdCarouselWindowChannel> windowChannelList = ardCarouselWindow.getArdChannels().stream()
                    .map(ardChannel -> {
                        ArdCarouselWindowChannel ardCarouselWindowChannel = new ArdCarouselWindowChannel();
                        ardCarouselWindowChannel.setCameraId(ardChannel.getDeviceId());
                        ardCarouselWindowChannel.setChanNo(ardChannel.getChanNo());
                        ardCarouselWindowChannel.setWindowId(ardCarouselWindow.getId());
                        return ardCarouselWindowChannel;
                    })
                    .collect(Collectors.toList());
 
            ardCarouselWindow.setCreateTime(DateUtils.getNowDate());
            ardCarouselWindow.setPlanId(ardCarouselPlans.getId());
            ardCarouselWindowMapper.insertArdCarouselWindow(ardCarouselWindow);
            if (!windowChannelList.isEmpty()) {
                ardCarouselWindowChannelMapper.batchWindowChannel(windowChannelList);
            }
        });
    }
 
    /**
     * 删除轮播方案和窗口和通道的关系
     *
     * @param id 巡检方案ID
     * @return
     * @author 刘苏义
     * @date 2024/9/4 10:57
     */
    public void deleteWindowChannel(String id) {
        //先删除当前计划ID关联的所有窗口和通道数据
        ArdCarouselWindow ardCarouselWindow = new ArdCarouselWindow();
        ardCarouselWindow.setPlanId(id);
        List<ArdCarouselWindow> windows = ardCarouselWindowMapper.selectArdCarouselWindowList(ardCarouselWindow);
        if (!windows.isEmpty()) {
            List<String> windowIds = windows.stream().map(ArdCarouselWindow::getId).collect(Collectors.toList());
            ardCarouselWindowChannelMapper.deleteWindowChannel(windowIds.toArray(new String[0]));
            ardCarouselWindowMapper.deleteArdCarouselWindowByIds(windowIds.toArray(new String[0]));
        }
    }
}