admin
2024-02-21 2272213fea7ab9ea6250eefad55bb113ce2b1837
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
package com.ruoyi.utils;
 
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.activeMQ.vo.CameraCon;
import com.ruoyi.activeMQ.vo.CameraControlVO;
import com.ruoyi.activeMQ.vo.CameraRuleVO;
import com.ruoyi.activeMQ.vo.RuleAreaVO;
import com.ruoyi.aibrain.domain.AiCamera;
import com.ruoyi.aibrain.domain.AiCameraRule;
import com.ruoyi.aibrain.domain.Point;
import com.ruoyi.aibrain.service.IAiCameraService;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.Threads;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.framework.config.ActiveManager;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.apache.commons.lang3.ObjectUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
 
import javax.jms.Destination;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
public class CameraUtils {
 
    private static final Logger logger = LoggerFactory.getLogger(Threads.class);
 
    private static BeanCopier copier = BeanCopier.create(AiCamera.class, CameraControlVO.class, false);
 
    @Autowired
    private static ActiveManager activeManager;
 
    @Autowired
    private static IAiCameraService aiCameraService;
 
    @Autowired
    private static RedisCache redisCache;
 
 
    /**
     * 启动AI识别设备
     */
    public static void startCamera() {
        startCameraAll("1");
//        activeManager = SpringUtils.getBean(ActiveManager.class);
//        aiCameraService = SpringUtils.getBean(IAiCameraService.class);
//
//        Destination destination = new ActiveMQQueue("cameraControlQueue");//P2P模式单个消费者
//        List<AiCamera> cameraList = aiCameraService.queryCameraToStart();
//        for (AiCamera camera : cameraList){
//            CameraControlVO cameraVO = new CameraControlVO();
//            copier.copy(camera,cameraVO,null);
//            cameraVO.setTime(new Date().getTime());
//
//            List<CameraRuleVO> rules = new ArrayList<>();
//            for (AiCameraRule cameraRule : camera.getRules()){
//                CameraRuleVO ruleVO = new CameraRuleVO();
//                ruleVO.setrecordDuration(cameraRule.getrecordDuration());
//                ruleVO.setisRecord(cameraRule.getisRecord());
//                ruleVO.setCameraId(cameraRule.getCameraId());
//                ruleVO.setPeopleNumber(cameraRule.getPeopleNumber());
//                ruleVO.setRuleId(cameraRule.getRuleId());
//                ruleVO.setRuleName(cameraRule.getRuleName());
//                ruleVO.setRuleArea(cameraRule.getAreas());
//                rules.add(ruleVO);
//            }
//            cameraVO.setRules(rules);
//            camera.setRunStatus("1");
//            aiCameraService.updateAiCameraStatus(camera);
//            //传入队列以及值
//            activeManager.send(destination, JSON.toJSONString(cameraVO));
//            logger.info("cameraControlQueue队列:"+JSON.toJSONString(cameraVO));
//        }
    }
 
 
 
    /**
     * 启动AI识别设备
     */
    public static void startCamera(long id,String runStatus) {
        activeManager = SpringUtils.getBean(ActiveManager.class);
        aiCameraService = SpringUtils.getBean(IAiCameraService.class);
        redisCache = SpringUtils.getBean(RedisCache.class);
 
 
        Destination destination = new ActiveMQQueue("cameraControlQueue");//P2P模式单个消费者
        AiCamera camera = aiCameraService.selectAiCameraById(id);
        CameraCon cameraCon=new CameraCon();
        cameraCon.setState(Integer.valueOf(runStatus));
 
 
        List<CameraControlVO> cameraControlVOS=new ArrayList<>();
 
        CameraControlVO cameraVO = new CameraControlVO();
        cameraVO.setId(String.valueOf(camera.getId()));
        cameraVO.setRtspUrl(camera.getRtspUrl());
        cameraVO.setIp(camera.getCameraIp());
        cameraVO.setName(camera.getName());
        cameraVO.setRemp_h(camera.getRempH());
        cameraVO.setRemp_w(camera.getRempW());
        if(ObjectUtils.isNotEmpty(camera.getLeatherWidth())){
            cameraVO.setBeltWidth(String.valueOf(camera.getLeatherWidth()));//皮带宽度
        }
        if(ObjectUtils.isNotEmpty(camera.getToRtmp())){
            cameraVO.setToRtmp(camera.getToRtmp());
        }
        List<CameraRuleVO> rules = new ArrayList<>();
        for (AiCameraRule cameraRule : camera.getRules()){
            CameraRuleVO ruleVO = new CameraRuleVO();
            ruleVO.setId(String.valueOf(cameraRule.getRuleId()));
            if(ObjectUtils.isNotEmpty(cameraRule.getSecond())){
                ruleVO.setDelay(cameraRule.getSecond());//延时时间数
            }
            if(ObjectUtils.isNotEmpty(cameraRule.getThreshold())){
                ruleVO.setThreshold(cameraRule.getThreshold());//阈值
            }
            if(cameraRule.getIsRecord().equals("1")){
                ruleVO.setIsRecord(cameraRule.getIsRecord());//是否录像
                ruleVO.setRecordDuration(cameraRule.getRecordDuration());//录像时长
            }else{
                ruleVO.setIsRecord(cameraRule.getIsRecord());//是否录像
            }
            RuleAreaVO ruleAreaVO=new RuleAreaVO();
            ruleAreaVO.setB(cameraRule.getB());
            ruleAreaVO.setG(cameraRule.getG());
            ruleAreaVO.setR(cameraRule.getR());
            if(ObjectUtils.isNotEmpty(cameraRule.getPic_w())){
                ruleAreaVO.setPic_w(cameraRule.getPic_w());
            }
            if(ObjectUtils.isNotEmpty(cameraRule.getPic_h())){
                ruleAreaVO.setPic_h(cameraRule.getPic_h());
            }
            if(ObjectUtils.isNotEmpty(cameraRule.getRuleArea())){
                List<Point> objects = JSON.parseArray(cameraRule.getRuleArea(),Point.class);
                ruleAreaVO.setPoints(objects);
            }
            ruleVO.setRects(ruleAreaVO);
            rules.add(ruleVO);
        }
        cameraVO.setModels(rules);
        cameraControlVOS.add(cameraVO);
        cameraCon.setCameras(cameraControlVOS);
 
        //更新摄像头启动状态
        camera.setStatus(runStatus);
        aiCameraService.updateAiCameraStatus(camera);
        //传入队列以及值
        activeManager.send(destination, JSON.toJSONString(cameraCon).replace("\\", ""));
        logger.info("cameraControlQueue队列:"+JSON.toJSONString(cameraCon));
    }
 
    /**
     * 批量启动设备
     */
    public static void startCameraAll(String runStatus) {
        activeManager = SpringUtils.getBean(ActiveManager.class);
        aiCameraService = SpringUtils.getBean(IAiCameraService.class);
        redisCache = SpringUtils.getBean(RedisCache.class);
 
 
        Destination destination = new ActiveMQQueue("cameraControlQueue");//P2P模式单个消费者
        List<AiCamera> list = aiCameraService.selectAllCamera();
        redisCache.setCacheObject("AI::AiCameraList",list);
 
 
 
        CameraCon cameraCon=new CameraCon();
        List<CameraControlVO> cameraControlVOS=new ArrayList<>();
        for (AiCamera camera : list) {
            redisCache.setCacheObject("AI::AiCameraObj"+camera.getCameraNum(),camera);
            cameraCon.setState(Integer.valueOf(runStatus));
            CameraControlVO cameraVO = new CameraControlVO();
            cameraVO.setId(String.valueOf(camera.getId()));
            cameraVO.setRtspUrl(camera.getRtspUrl());
            cameraVO.setIp(camera.getCameraIp());
            cameraVO.setName(camera.getName());
            cameraVO.setRemp_h(camera.getRempH());
            cameraVO.setRemp_w(camera.getRempW());
            if(ObjectUtils.isNotEmpty(camera.getLeatherWidth())){
                cameraVO.setBeltWidth(String.valueOf(camera.getLeatherWidth()));//皮带宽度
            }
            if(ObjectUtils.isNotEmpty(camera.getToRtmp())){
                cameraVO.setToRtmp(camera.getToRtmp());
            }
            List<CameraRuleVO> rules = new ArrayList<>();
            for (AiCameraRule cameraRule : camera.getRules()){
                CameraRuleVO ruleVO = new CameraRuleVO();
                ruleVO.setId(String.valueOf(cameraRule.getRuleId()));
                if(ObjectUtils.isNotEmpty(cameraRule.getSecond())){
                    ruleVO.setDelay(cameraRule.getSecond());//延时时间数
                }
                if(ObjectUtils.isNotEmpty(cameraRule.getThreshold())){
                    ruleVO.setThreshold(cameraRule.getThreshold());//阈值
                }
                RuleAreaVO ruleAreaVO=new RuleAreaVO();
                ruleAreaVO.setB(cameraRule.getB());
                ruleAreaVO.setG(cameraRule.getG());
                ruleAreaVO.setR(cameraRule.getR());
                if(ObjectUtils.isNotEmpty(cameraRule.getPic_w())){
                    ruleAreaVO.setPic_w(cameraRule.getPic_w());
                }
                if(ObjectUtils.isNotEmpty(cameraRule.getPic_h())){
                    ruleAreaVO.setPic_h(cameraRule.getPic_h());
                }
                if(ObjectUtils.isNotEmpty(cameraRule.getRuleArea())){
                    List<Point> objects = JSON.parseArray(cameraRule.getRuleArea(),Point.class);
                    ruleAreaVO.setPoints(objects);
                }
                ruleVO.setRects(ruleAreaVO);
                rules.add(ruleVO);
            }
            cameraVO.setModels(rules);
            cameraControlVOS.add(cameraVO);
            cameraCon.setCameras(cameraControlVOS);
 
            //更新摄像头启动状态
            camera.setStatus(runStatus);
            aiCameraService.updateAiCameraStatus(camera);
        }
 
 
 
        //传入队列以及值
        activeManager.send(destination, JSON.toJSONString(cameraCon).replace("\\", ""));
        logger.info("cameraControlQueue队列:"+JSON.toJSONString(cameraCon));
    }
}