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.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 deviceList = workOrderService.hasErrorWorkOrderList(); if (CollectionUtils.isEmpty(deviceList)) { return; } List 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 = workOrderService.getFrameImgByDevice(gbDevices.get(0).getDeviceId(), deviceInfo.getDeviceId()); if (StringUtils.hasText(frameImg)) { workOrderService.updateImgById(deviceInfo.getWorkOrderId(), frameImg); } }); } } }