| | |
| | | package com.ruoyi.alarm.global.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.ruoyi.alarm.access.domain.ArdAlarmAccess; |
| | | import com.ruoyi.alarm.access.service.IArdAlarmAccessService; |
| | | import com.ruoyi.alarm.external.domain.ArdAlarmExternal; |
| | |
| | | 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.domain.AjaxResult; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | 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 com.ruoyi.utils.websocket.util.WebSocketUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.concurrent.*; |
| | | |
| | | import static com.ruoyi.utils.websocket.util.WebSocketUtils.ONLINE_USER_SESSIONS; |
| | | |
| | | /** |
| | | * @Description: 队列处理器 |
| | |
| | | } |
| | | log.debug("新任务入队:" + task.getAlarmId()); |
| | | guideTaskQueue.add(task); |
| | | /*获取该相机的当前执行线程-----弃用*/ |
| | | //TaskThread currentTaskThread = threadMap.get(cameraId); |
| | | ////如果队列当前线程正在运行,若入队任务优先级大于当前任务优先级,则终止当前线程 |
| | | //if (currentTaskThread != null){ |
| | | // if (task.getPriority() > currentTaskThread.getCurrentTask().getPriority()) { |
| | | // currentTaskThread.getThread().interrupt(); |
| | | // } |
| | | // if (!currentTaskThread.getThread().isAlive()) { |
| | | // Thread newThread = createThread(cameraId, guideTaskQueue); |
| | | // threadMap.put(cameraId, new TaskThread(newThread, task)); |
| | | // newThread.start(); |
| | | // } |
| | | //} |
| | | ////如果队列当前没有线程正在运行,则启动新线程 |
| | | //else { |
| | | // Thread newThread = createThread(cameraId, guideTaskQueue); |
| | | // threadMap.put(cameraId, new TaskThread(newThread, task)); |
| | | // newThread.start(); |
| | | //} |
| | | } |
| | | |
| | | @Async("guideExecutor") |
| | |
| | | } |
| | | log.debug("执行新任务:【" + newTask.getAlarmId() + "】"); |
| | | log.debug("剩余任务数:【" + guideTasks.size() + "】"); |
| | | // 异步处理任务,并获取Future |
| | | // 处理任务 |
| | | processTask(newTask); |
| | | } |
| | | try { |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | //异步处理任务 |
| | | public void processTask(GuideTask guideTask) { |
| | | try { |
| | | if (!IsEnableGuide(guideTask.getCameraId())) { |
| | |
| | | CameraCmd cmd = new CameraCmd(); |
| | | cmd.setCameraId(guideTask.getCameraId()); |
| | | cmd.setChanNo(guideTask.getChanNo()); |
| | | cmd.setTargetPosition(guideTask.getTargetPosition()); |
| | | cmd.setOperator(guideTask.getAlarmType()); |
| | | cmd.setExpired(30); |
| | | cmd.setRecordBucketName("record"); |
| | | Map<String, Double> ptzMap = new HashMap<>(); |
| | | switch (guideTask.getChanNo()) { |
| | | case 1: |
| | | ptzMap.put("p", guideTask.getGuidePTZ().getP1()); |
| | | ptzMap.put("t", guideTask.getGuidePTZ().getT1()); |
| | | ptzMap.put("z", guideTask.getGuidePTZ().getZ1()); |
| | | break; |
| | | case 2: |
| | | ptzMap.put("p", guideTask.getGuidePTZ().getP2()); |
| | | ptzMap.put("t", guideTask.getGuidePTZ().getT2()); |
| | | ptzMap.put("z", guideTask.getGuidePTZ().getZ2()); |
| | | break; |
| | | } |
| | | cmd.setPtzMap(ptzMap); |
| | | cmd.setRecordObjectName("alarm_" + guideTask.getAlarmId()); |
| | | cmd.setTargetPosition(guideTask.getTargetPosition()); |
| | | cmd.setRecordObjectName("alarmGuide/"+ DateUtils.getDateYYYYMMDD()+"/"+guideTask.getAlarmType()+"/"+guideTask.getAlarmId()); |
| | | ICameraSdkService cameraSdkService = SpringUtils.getBean(ICameraSdkService.class); |
| | | log.debug("开始引导"); |
| | | boolean guideRes = false; |
| | | boolean recordFlag = false; |
| | | if (cmd.getPtzMap().get("p") != null) { |
| | | //p值存在 优先引导ptz |
| | | guideRes = cameraSdkService.setPtz(cmd); |
| | | } else { |
| | | guideRes = cameraSdkService.guideTargetPosition(cmd); |
| | | } |
| | | boolean guideRes = cameraSdkService.guideTargetPosition(cmd); |
| | | if (guideRes) { |
| | | log.debug("引导成功"); |
| | | //region 通知前端 |
| | | Map<String,Object> message = new HashMap<>(); |
| | | Map<String,String> data = new HashMap<>(); |
| | | data.put("cameraId",cmd.getCameraId()); |
| | | data.put("chanNo",cmd.getChanNo().toString()); |
| | | data.put("alarmType",cmd.getOperator()); |
| | | data.put("alarmId", guideTask.getAlarmId()); |
| | | data.put("wellId",guideTask.getWellId()); |
| | | message.put("70000",data); |
| | | WebSocketUtils.sendMessageAll(message); |
| | | //endregion |
| | | cameraSdkService.controlLock(cmd);//上锁 |
| | | cameraSdkService.recordStart(cmd);//开始录像 |
| | | recordFlag = true; |
| | |
| | | } |
| | | return enabled; |
| | | } |
| | | } |
| | | } |