zhanghua
2025-02-06 55793861746f0a8dd74b84d444a60c43f982b255
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
package com.ycl.task;
 
import com.ycl.common.constant.GlobalQueue;
import com.ycl.entity.video.VideoAlarmReport;
import com.ycl.entity.video.VideoPoint;
import com.ycl.service.caseHandler.IViolationsService;
import com.ycl.service.oss.OssService;
import com.ycl.service.video.IVideoAlarmReportService;
import com.ycl.service.video.impl.IVideoPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
 
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
 
@Component
public class SynchronizeDHAlarm {
 
    @Autowired
    private OssService ossService;
 
    @Autowired
    private IVideoPointService videoPointService;
 
    @Autowired
    private IVideoAlarmReportService videoAlarmReportService;
 
    @Autowired
    private IViolationsService violationsService;
 
    @Scheduled(cron = "0 */1 * * * ?")
    @Transactional(rollbackFor = Exception.class)
    public void scheduledTask() {
 
        while (GlobalQueue.size() > 0) {
            try {
                VideoAlarmReport videoAlarmReport = GlobalQueue.dequeue();
 
                List<VideoAlarmReport> list = videoAlarmReportService.findByChannelAndAlarmNameAndTime(videoAlarmReport.getChannel(), videoAlarmReport.getAlarmName(), videoAlarmReport.getAlarmTime());
                if (list.size() == 0) {
                    System.out.println("----------------开始保存报警信息:" + videoAlarmReport.getAlarmName());
                    VideoPoint videoPoint = videoPointService.getByChannelId(Integer.parseInt(videoAlarmReport.getChannel()));
 
                    if (videoPoint != null) {
                        videoAlarmReport.setPlatResourceId(videoPoint.getPlatResourceId());
                    }
                    if (videoAlarmReport.getPicByte() != null) {
                        String extension = "jpg";
                        InputStream inputStream = new ByteArrayInputStream(videoAlarmReport.getPicByte());
                        String picData = ossService.uploadImages(inputStream, extension,0);
 
                        videoAlarmReport.setPicData(picData);
                    }
                    videoAlarmReportService.save(videoAlarmReport);
 
                    List<VideoAlarmReport> videoAlarmReports = new ArrayList<>();
                    videoAlarmReports.add(videoAlarmReport);
                    violationsService.saveFromVideo(videoAlarmReports);
 
                }
            } catch (Exception ex) {
                System.out.println("------------保存报警信息异常:");
 
            }
        }
    }
}