liusuyi
2024-07-11 b1084891961232e3c697ea9fc52f127cdccffb6b
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
package com.ruoyi.device.channel.service.impl;
 
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.device.camera.domain.ArdCameras;
import com.ruoyi.device.camera.factory.CameraSDK;
import com.ruoyi.device.camera.factory.CameraSDKFactory;
import com.ruoyi.device.camera.mapper.ArdCamerasMapper;
import com.ruoyi.media.mapper.VtduMapper;
import com.ruoyi.media.service.IVtduService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.device.channel.mapper.ArdChannelMapper;
import com.ruoyi.device.channel.domain.ArdChannel;
import com.ruoyi.device.channel.service.IArdChannelService;
 
import javax.annotation.Resource;
 
/**
 * 通道管理Service业务层处理
 *
 * @author ard
 * @date 2023-08-19
 */
@Service
public class ArdChannelServiceImpl implements IArdChannelService {
    @Resource
    private ArdChannelMapper ardChannelMapper;
    @Resource
    private CameraSDKFactory cameraSDKFactory;
    @Resource
    private IVtduService vtduService;
    /**
     * 查询通道管理
     *
     * @param id 通道管理主键
     * @return 通道管理
     */
    @Override
    public ArdChannel selectArdChannelById(String id) {
        return ardChannelMapper.selectArdChannelById(id);
    }
 
    /**
     * 查询通道管理列表
     *
     * @param ardChannel 通道管理
     * @return 通道管理
     */
    @Override
    public List<ArdChannel> selectArdChannelList(ArdChannel ardChannel) {
        return ardChannelMapper.selectArdChannelList(ardChannel);
    }
 
    /**
     * 新增通道管理
     *
     * @param ardChannel 通道管理
     * @return 结果
     */
    @Override
    public int insertArdChannel(ArdChannel ardChannel) {
        ardChannel.setId(IdUtils.simpleUUID());
        return ardChannelMapper.insertArdChannel(ardChannel);
    }
 
    /**
     * 修改通道管理
     *
     * @param ardChannel 通道管理
     * @return 结果
     */
    @Override
    public int updateArdChannel(ArdChannel ardChannel) {
        return ardChannelMapper.updateArdChannel(ardChannel);
    }
 
    /**
     * 批量删除通道管理
     *
     * @param ids 需要删除的通道管理主键
     * @return 结果
     */
    @Override
    public int deleteArdChannelByIds(String[] ids) {
        return ardChannelMapper.deleteArdChannelByIds(ids);
    }
 
    /**
     * 删除通道管理信息
     *
     * @param id 通道管理主键
     * @return 结果
     */
    @Override
    public int deleteArdChannelById(String id) {
        return ardChannelMapper.deleteArdChannelById(id);
    }
 
    /**
     * 删除通道管理信息
     *
     * @param deviceId 所属设备ID
     * @return 结果
     */
    @Override
    public int deleteArdChannelByDeviceId(String deviceId) {
        return ardChannelMapper.deleteArdChannelByDeviceId(deviceId);
    }
 
    @Override
    public void asyncChannel(ArdCameras ardCameras,List<ArdChannel> oldArrayList, List<ArdChannel> newArrayList) {
        // 将列表转换为映射以提高性能
        Map<Integer, ArdChannel> oldMap = oldArrayList.stream()
                .collect(Collectors.toMap(ArdChannel::getChanNo, channel -> channel));
        Map<Integer, ArdChannel> newMap = newArrayList.stream()
                .collect(Collectors.toMap(ArdChannel::getChanNo, channel -> channel));
 
        // 需要更新的数据
        newArrayList.stream()
                .filter(channel -> {
                    ArdChannel oldChannel = oldMap.get(channel.getChanNo());
                    return oldChannel != null && !oldChannel.getName().equals(channel.getName());
                })
                .forEach(channel -> {
                    ArdChannel oldChannel = oldMap.get(channel.getChanNo());
                    channel.setId(oldChannel.getId());
                    updateArdChannel(channel);
                });
 
        // 需要删除的数据
        oldArrayList.stream()
                .filter(channel -> !newMap.containsKey(channel.getChanNo()))
                .forEach(channel -> {
                    deleteArdChannelById(channel.getId());
                    vtduService.deleteVtduByName(channel.getDeviceId() + "_" + channel.getChanNo());
                });
 
        // 需要新增的数据
        newArrayList.stream()
                .filter(channel -> !oldMap.containsKey(channel.getChanNo()))
                .forEach(channel -> {
                    insertArdChannel(channel);
                    vtduService.addChanToVtdu(ardCameras, channel);
                });
    }
}