|  |  |  | 
|---|
|  |  |  | import com.ruoyi.alarm.radar.service.IArdAlarmRadarPumpService; | 
|---|
|  |  |  | import com.ruoyi.alarm.tube.domain.ArdAlarmTube; | 
|---|
|  |  |  | import com.ruoyi.alarm.tube.service.IArdAlarmTubeService; | 
|---|
|  |  |  | import com.ruoyi.common.constant.CacheConstants; | 
|---|
|  |  |  | import com.ruoyi.common.core.redis.RedisCache; | 
|---|
|  |  |  | import com.ruoyi.common.utils.StringUtils; | 
|---|
|  |  |  | import com.ruoyi.common.utils.spring.SpringUtils; | 
|---|
|  |  |  | import com.ruoyi.device.camera.domain.ArdCameras; | 
|---|
|  |  |  | import com.ruoyi.device.camera.domain.CameraCmd; | 
|---|
|  |  |  | import com.ruoyi.device.camera.service.ICameraSdkService; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.scheduling.annotation.Async; | 
|---|
|  |  |  | import org.springframework.stereotype.Component; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import java.time.Duration; | 
|---|
|  |  |  | import java.time.Instant; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Slf4j(topic = "guideQueue") | 
|---|
|  |  |  | @Component | 
|---|
|  |  |  | public class QueueHandler { | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private RedisCache redisCache; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 引导任务入队 | 
|---|
|  |  |  | * 刘苏义 | 
|---|
|  |  |  | 
|---|
|  |  |  | /*通过相机ID获取引导队列,并将引导任务加入队列*/ | 
|---|
|  |  |  | PriorityBlockingQueue<GuideTask> guideTaskQueue = GuidePriorityQueue.cameraQueueMap.get(cameraId); | 
|---|
|  |  |  | if (StringUtils.isNull(guideTaskQueue)) { | 
|---|
|  |  |  | log.info("相机未登录,没有队列,无法入队引导"); | 
|---|
|  |  |  | log.debug("相机未登录,没有队列,无法入队引导"); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | log.debug("新任务入队:" + task.getAlarmId()); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void processTask(GuideTask guideTask) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | if (!IsEnableGuide(guideTask.getCameraId())) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String url = ""; | 
|---|
|  |  |  | CameraCmd cmd = new CameraCmd(); | 
|---|
|  |  |  | cmd.setCameraId(guideTask.getCameraId()); | 
|---|
|  |  |  | 
|---|
|  |  |  | Instant currentTime = Instant.now(); | 
|---|
|  |  |  | long elapsedSeconds = Duration.between(startTime, currentTime).getSeconds(); | 
|---|
|  |  |  | if (elapsedSeconds >= 30) { | 
|---|
|  |  |  | recordFlag = false; | 
|---|
|  |  |  | recordFlag = false;//达到30秒录像停止 | 
|---|
|  |  |  | url = cameraSdkService.recordStopToMinio(cmd);//停止录像返回url | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!IsEnableGuide(guideTask.getCameraId())) { | 
|---|
|  |  |  | recordFlag = false;//相机关闭引导录像停止 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //判断队列中第一条数据的优先级是否大于当前数据的优先级 | 
|---|
|  |  |  | PriorityBlockingQueue<GuideTask> guideTasks = GuidePriorityQueue.cameraQueueMap.get(guideTask.getCameraId()); | 
|---|
|  |  |  | 
|---|
|  |  |  | log.info("线程任务异常:" + ex.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 光电是否开启报警引导功能 | 
|---|
|  |  |  | * 刘苏义 | 
|---|
|  |  |  | * 2023/7/7 14:03 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Boolean IsEnableGuide(String cameraId) { | 
|---|
|  |  |  | boolean enabled = false; | 
|---|
|  |  |  | ArdCameras ardCameras = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId); | 
|---|
|  |  |  | if (ardCameras != null) { | 
|---|
|  |  |  | if (ardCameras.getCamAlarmGuideEnable().equals(1)) { | 
|---|
|  |  |  | enabled = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return enabled; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|