zhanghua
2023-09-08 7ef4892f9f24f941aca37e6b3991b808a0aca619
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
package com.ycl.task;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ycl.dto.video.Camera;
import com.ycl.dto.video.PageResult;
import com.ycl.entity.video.VideoPoint;
import com.ycl.service.video.impl.IVideoPointService;
import com.ycl.util.VideoUtil;
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.util.ArrayList;
import java.util.List;
 
/**
 * 同步海康视频
 */
@Component
public class SynchronizeHKVideo {
 
    @Autowired
    private IVideoPointService videoPointService;
    @Autowired
    private VideoUtil videoUtil;
 
//    @Scheduled(cron = "0/9 * * * * ?")   // 每秒执行
//    @Scheduled(cron = "0 0/1 * ?")
    @Transactional(rollbackFor = Exception.class)
    public void scheduledTask() {
        System.out.println("海康:开始执行");
 
        findVideoList(1, 20);
 
    }
 
    private void findVideoList(Integer pageNo, Integer pageSize) {
        try {
            PageResult<Camera> pageResult = videoUtil.callPostCameras(pageNo, pageSize, "0");
            if (pageResult.getTotal() > 0) {
                if (pageResult.getList().size() > 0) {
                    saveVideoFromCamera(pageResult.getList());
 
                    if (pageResult.getList().size() >= pageSize) {
                        findVideoList(pageNo + 1, pageSize);
                    }
                }
            }
        } catch (Exception ex) {
            System.out.println("海康:" + ex.getMessage());
        }
    }
 
    private void saveVideoFromCamera(List<Camera> list) {
 
        for (Camera c : list) {
            LambdaQueryWrapper<VideoPoint> queryWrapper = new LambdaQueryWrapper<VideoPoint>()
                    .eq(VideoPoint::getPlatResourceId, c.getCameraIndexCode());
            List<VideoPoint> pointList = videoPointService.list(queryWrapper);
 
            if (pointList.size() == 0) {
                VideoPoint videoPoint = new VideoPoint();
                videoPoint.setType(1);
                videoPoint.setName(c.getName());
                videoPoint.setLatitude(Double.valueOf(c.getLatitude()));
                videoPoint.setLongitude(Double.valueOf(c.getLatitude()));
                videoPoint.setPlatResourceId(c.getCameraIndexCode());
                videoPoint.setCode(c.getDeviceIndexCode());
                videoPoint.setAddress(c.getInstallPlace());
                videoPoint.setEquipmentBrand("海康");
                videoPoint.setEquipmentModel(c.getCameraTypeName());
 
                videoPointService.save(videoPoint);
            }
        }
    }
}