xiangpei
2024-08-28 c19666de02a21d62fb74c993a481141466111484
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
package com.ycl.task;
 
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.ycl.platform.domain.entity.DeviceInfo;
import com.ycl.platform.domain.vo.DeviceInfoVO;
import com.ycl.platform.mapper.DeviceInfoMapper;
import com.ycl.platform.service.WorkOrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
 
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
 
/**
 * 工单恢复图片获取
 *
 * @author:xp
 * @date:2024/8/21 11:56
 */
@Slf4j
@RequiredArgsConstructor
@Component("workOrderImgTask")
public class WorkOrderImgTask {
 
    private final WorkOrderService workOrderService;
    private final DeviceInfoMapper deviceInfoMapper;
 
    private static final ExecutorService executorService = new ThreadPoolExecutor(8,
            24,
            5000,
            TimeUnit.SECONDS,
            new ArrayBlockingQueue<>(10),
            new ThreadPoolExecutor.CallerRunsPolicy()
    );
 
    public void run() {
        // 查出故障的设备
        List<DeviceInfoVO> deviceList = workOrderService.hasErrorWorkOrderList();
        if (CollectionUtils.isEmpty(deviceList)) {
            return;
        }
        List<DeviceInfo> gbDevices = new LambdaQueryChainWrapper<>(deviceInfoMapper)
                .orderByDesc(DeviceInfo::getUpdateTime)
                .last("limit 1")
                .list();
        if (CollectionUtils.isEmpty(gbDevices)) {
            return;
        }
        for (DeviceInfoVO deviceInfo : deviceList) {
            executorService.submit(() -> {
                // 国标设备的编码就是取视频流的设备编码,国标设备就一个。国标设备的每一个通道代表一个摄像头,也就是设备id是取流的通道id
                String frameImg = null;
                try {
                    frameImg = workOrderService.getFrameImgByDevice(gbDevices.get(0).getDeviceId(), deviceInfo.getDeviceId());
                } catch (FFmpegFrameGrabber.Exception e) {
                    e.printStackTrace();
                }
                if (StringUtils.hasText(frameImg)) {
                    workOrderService.updateImgById(deviceInfo.getWorkOrderId(), frameImg);
                }
            });
        }
    }
 
}