From 016aa105789fca71e86cdbb0d26a181812f200f9 Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: 星期三, 10 七月 2024 15:33:36 +0800
Subject: [PATCH] 优化:流媒体同步任务

---
 ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java |  211 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 206 insertions(+), 5 deletions(-)

diff --git a/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java b/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java
index 1b7b893..aea448b 100644
--- a/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java
@@ -1,11 +1,17 @@
 package com.ruoyi.device.camera.service.impl;
 
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
 
+import com.ruoyi.alarm.global.domain.GuidePoint;
 import com.ruoyi.alarmpoints.well.domain.ArdAlarmpointsWell;
+import com.ruoyi.common.config.ARDConfig;
 import com.ruoyi.common.constant.CacheConstants;
 import com.ruoyi.common.constant.CameraConstants;
+import com.ruoyi.common.constant.Constants;
 import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.core.redis.RedisCache;
@@ -14,6 +20,7 @@
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.bean.BeanValidators;
+import com.ruoyi.common.utils.file.FileUtils;
 import com.ruoyi.common.utils.spring.SpringUtils;
 import com.ruoyi.common.utils.uuid.IdUtils;
 import com.ruoyi.device.camera.domain.CameraCmd;
@@ -33,6 +40,7 @@
 import com.ruoyi.utils.gis.Point;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.PostConstruct;
@@ -54,18 +62,21 @@
     private SysDeptMapper sysDeptMapper;
     @Resource
     private RedisCache redisCache;
-    @Autowired
+    @Resource
     private ISysDeptService deptService;
     @Resource
     private ArdChannelMapper ardChannelMapper;
     @Resource
     private IVtduService vtduService;
-    @Autowired
+    @Resource
     protected Validator validator;
 
     @PostConstruct
     public void loadCameras() {
 
+        //娓呯悊鏈湴褰曞儚缂撳瓨鏂囦欢
+        String tempPath = ARDConfig.getProfile() + Constants.LOCAL_RECORD_TEMP_PREFIX;
+        FileUtils.deleteFolder(tempPath);
         //娓呯┖鐩告満缂撳瓨
         Collection<String> cacheKeys = redisCache.keys(getCacheKey("*"));
         redisCache.deleteObject(cacheKeys);
@@ -74,7 +85,24 @@
         for (ArdCameras ardCamera : ardCameras) {
             redisCache.setCacheObject(getCacheKey(ardCamera.getId()), ardCamera);
         }
+        //娓呯┖娴佸獟浣�
+        vtduService.clearVtdu();
+    }
 
+    /**
+     * @Author 鍒樿嫃涔�
+     * @Description 瀹氭椂娓呯悊鏈湴褰曞儚缂撳瓨鏂囦欢锛堣秴杩�1澶╋級
+     * @Date   2024/6/21 8:13
+     * @Param
+     * @return
+     */
+    //@Scheduled(cron = "0 0/10 * * * ?")
+    public void clearRecordTemp()
+    {
+        log.debug("瀹氭椂娓呯悊鏈湴褰曞儚缂撳瓨鏂囦欢锛堣秴杩�1澶╋級");
+        String tempPath = ARDConfig.getProfile() + Constants.LOCAL_RECORD_TEMP_PREFIX;
+        Path folderPath = Paths.get(tempPath);
+        FileUtils.deleteNonTodayFiles(folderPath);
     }
 
     /**
@@ -290,7 +318,15 @@
     }
 
     public List findOptions(ArdCameras ardCameras) {
-        List<ArdCameras> options = ardCamerasMapper.findOptions(ardCameras);
+        //List<ArdCameras> options = ardCamerasMapper.findOptions(ardCameras);
+        List<Long> subDeptIdList = sysDeptMapper.selectDeptIdBySub(SecurityUtils.getDeptId());//涓嬪睘鍙婃湰鏉冮檺
+        List<Long> ownDeptIdList= sysDeptMapper.selectRoleDeptIdByUsersId(SecurityUtils.getUserId());//鑷畾涔夋潈闄�
+        HashSet<Long> deptIdSet = new HashSet();//鍘婚噸
+        deptIdSet.addAll(subDeptIdList);
+        deptIdSet.addAll(ownDeptIdList);
+        List<Long> deptIdList = new ArrayList();
+        deptIdList.addAll(deptIdSet);//绗﹀悎鏉′欢鐨勫叏閮ㄦ潈闄�
+        List<ArdCameras> options = ardCamerasMapper.findTowerCamerasBySubAndOwnDeptIds(deptIdList);
         for (ArdCameras camera :
                 options) {
             ArdChannel ardChannel = new ArdChannel();
@@ -315,6 +351,28 @@
         SysDept sysDept = sysDeptMapper.selectDeptById(deptId);
         Map<String, Object> map = fetchChildDepartments(sysDept, disabled);
         return map;
+    }
+
+    @Override
+    public List<Map<String, Object>> getChildDeptAndCameraOwn(Boolean disabled) {
+        Long deptId = SecurityUtils.getDeptId();
+        SysDept sysDept = sysDeptMapper.selectDeptById(deptId);
+        List<Long> ownDeptIdList = sysDeptMapper.selectRoleDeptIdByUsersId(SecurityUtils.getUserId());//鑷畾涔夋潈闄愪富閿煡璇�
+        ownDeptIdList.remove(SecurityUtils.getDeptId());//鑻ヨ嚜瀹氫箟鏉冮檺鍖呭惈鏈骇鏉冮檺锛屽垯绉婚櫎
+        Map<String, Object> map = fetchChildDepartments(sysDept, disabled, ownDeptIdList);//鏌ヨ鏈潈闄愬強涓嬪睘鏉冮檺璁惧骞跺湪鑷畾涔夋潈闄愪腑绉婚櫎涓嬪睘閮ㄩ棬涓婚敭
+        Set<Long> pIdSet = new HashSet();//鑷畾涔夋潈闄愪富閿殑鏈�璇ユ潈闄�
+        for(Long deptIdn : ownDeptIdList){
+            List<SysDept> pSysDeptList = sysDeptMapper.getParentsDeptListByDeptId(deptIdn);
+            pIdSet.add(pSysDeptList.get(pSysDeptList.size() - 1).getDeptId());//鑾峰彇
+        }
+        List<Map<String, Object>> result = new ArrayList();
+        result.add(map);
+        for(Long pId : pIdSet){
+            SysDept pSysDept = sysDeptMapper.selectDeptById(pId);
+            Map<String, Object> mapO = fetchChildDepartments(ownDeptIdList, pSysDept, disabled);
+            result.add(mapO);
+        }
+        return result;
     }
 
     @Override
@@ -353,6 +411,85 @@
                 ardChannel.setDeviceId(camera.getId());
                 List<ArdChannel> ardChannels = ardChannelMapper.selectArdChannelList(ardChannel);
                 if (ardChannels != null) {
+                    ardChannels.stream().sorted();
+                    camera.setChannelList(ardChannels);
+                }
+                Map<String, Object> cameraMap = ArdTool.convertEntityToMap(camera);
+                childList.add(cameraMap);
+            }
+        }
+        map.put("children", childList);
+        return map;
+    }
+
+    /**
+    * zns
+    *
+    * */
+    public Map<String, Object> fetchChildDepartments(SysDept sysDept, Boolean disabled, List<Long> ownDeptIdList) {
+        Map<String, Object> map = new HashMap<>();
+        map.put("name", sysDept.getDeptName());
+        map.put("deptId", sysDept.getDeptId());
+        map.put("disabled", disabled);
+        List<SysDept> sysDepts = sysDeptMapper.selectNextChildrenDeptById(sysDept.getDeptId());
+        for(SysDept sysDeptC : sysDepts){//鑻ヨ嚜瀹氫箟鏉冮檺鍖呭惈涓嬬骇鏉冮檺锛屽垯绉婚櫎
+            if(ownDeptIdList.contains(sysDeptC.getDeptId())){
+                ownDeptIdList.remove(sysDeptC.getDeptId());
+            }
+        }
+        List<ArdCameras> ardCameras = ardCamerasMapper.selectArdCamerasByDeptId(sysDept.getDeptId());
+        List<Object> childList = new ArrayList<>();
+        for (SysDept childDept : sysDepts) {
+            Map<String, Object> childMap = new HashMap<>();
+            childMap.put("name", childDept.getDeptName());
+            childMap.put("deptId", childDept.getDeptId());
+            childMap.put("disabled", disabled);
+            Map<String, Object> map1 = fetchChildDepartments(childDept, disabled);
+            childMap.putAll(map1);
+            childList.add(childMap);
+        }
+        if (ardCameras.size() > 0) {
+            for (ArdCameras camera : ardCameras) {
+                ArdChannel ardChannel = new ArdChannel();
+                ardChannel.setDeviceId(camera.getId());
+                List<ArdChannel> ardChannels = ardChannelMapper.selectArdChannelList(ardChannel);
+                if (ardChannels != null) {
+                    ardChannels.stream().sorted();
+                    camera.setChannelList(ardChannels);
+                }
+                Map<String, Object> cameraMap = ArdTool.convertEntityToMap(camera);
+                childList.add(cameraMap);
+            }
+        }
+        map.put("children", childList);
+        return map;
+    }
+
+    public Map<String, Object> fetchChildDepartments(List<Long> ownDeptIdList, SysDept sysDept, Boolean disabled) {
+        Map<String, Object> map = new HashMap<>();
+        map.put("name", sysDept.getDeptName());
+        map.put("deptId", sysDept.getDeptId());
+        map.put("disabled", disabled);
+        List<SysDept> sysDepts = sysDeptMapper.selectNextChildrenDeptByIdAndInList(sysDept.getDeptId(),ownDeptIdList);
+        List<ArdCameras> ardCameras = ardCamerasMapper.selectArdCamerasByDeptId(sysDept.getDeptId());
+        List<Object> childList = new ArrayList<>();
+        for (SysDept childDept : sysDepts) {
+            Map<String, Object> childMap = new HashMap<>();
+            childMap.put("name", childDept.getDeptName());
+            childMap.put("deptId", childDept.getDeptId());
+            childMap.put("disabled", disabled);
+            //Map<String, Object> map1 = fetchChildDepartments(childDept, disabled);
+            Map<String, Object> map1 = fetchChildDepartments(ownDeptIdList,childDept, disabled);
+            childMap.putAll(map1);
+            childList.add(childMap);
+        }
+        if (ardCameras.size() > 0) {
+            for (ArdCameras camera : ardCameras) {
+                ArdChannel ardChannel = new ArdChannel();
+                ardChannel.setDeviceId(camera.getId());
+                List<ArdChannel> ardChannels = ardChannelMapper.selectArdChannelList(ardChannel);
+                if (ardChannels != null) {
+                    ardChannels.stream().sorted();
                     camera.setChannelList(ardChannels);
                 }
                 Map<String, Object> cameraMap = ArdTool.convertEntityToMap(camera);
@@ -403,7 +540,7 @@
     public TreeMap getNearCamerasBycoordinate(CameraCmd cmd) {
         try {
             double[] targetPosition = cmd.getTargetPosition();
-            if (targetPosition == null || (targetPosition != null && targetPosition.length == 0)) {
+            if (targetPosition == null) {
                 log.debug("鐩爣浣嶇疆涓虹┖");
                 return new TreeMap<>();
             }
@@ -418,7 +555,7 @@
                     continue;
                 }
                 double[] camPosition = new double[]{camera.getLongitude(), camera.getLatitude()};
-                double distance = GisUtil.getDistance(cmd.getTargetPosition(), camPosition);
+                double distance = GisUtil.getDistance(targetPosition, camPosition);
                 if (camera.getCamMaxVisibleDistance() == null) {
                     continue;
                 }
@@ -559,4 +696,68 @@
         }
         return CameraConstants.UNIQUE;
     }
+
+    @Override
+    public List<Map<String, Object>> getCamerasByDeptId(Long deptId,String userId) {
+        List<Long> deptIdList = new ArrayList();
+        deptIdList.add(deptId);
+        deptIdList = getOwnAndChildrenDeptIdList(deptIdList,new ArrayList());//閫掑綊鏌ヨ涓嬪睘閮ㄩ棬涓婚敭
+        //List<Map<String, Object>> result = ardCamerasMapper.getCamerasByDeptId(deptId,userId);
+        List<Map<String, Object>> result = ardCamerasMapper.getCamerasByDeptId(deptIdList,userId);
+        return result;
+    }
+
+    public List<Long> getOwnAndChildrenDeptIdList(List<Long> deptIdList,List<Long> deptIdListr){
+        deptIdListr.addAll(deptIdList);
+        List<Long> result = sysDeptMapper.getChildrenDeptIdList(deptIdList);
+        if(result.size() != 0){
+            deptIdListr.addAll(result);
+            result = getOwnAndChildrenDeptIdList(result,deptIdListr);
+        }
+        deptIdListr = deptIdListr.stream().distinct().collect(Collectors.toList());
+        return deptIdListr;
+    }
+
+    @Override
+    public Boolean getCameraOperationByCameraId(String id, String userId) {
+        Boolean result = ardCamerasMapper.getCameraOperationByCameraId(id,userId);
+        return result;
+    }
+
+    @Override
+    public Map<String, Object> getChannelByCameraId(String id) {
+        List<Map<String,Object>> result = ardCamerasMapper.getChannelByCameraId(id);
+        Map<String,Object> resultMap = new HashMap();
+        if(result.size() == 1){
+            resultMap.put("chanNo", result.get(0).get("chan_no"));
+            return resultMap;
+        }else{
+            String configValue = (String) result.get(0).get("config_value");
+            String beginTime = configValue.split("-")[0];
+            String endTime = configValue.split("-")[1];
+            Date now = new Date();
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            String nowDay = sdf.format(now);
+            try{
+                Long beginDate = sdf.parse(nowDay).getTime()
+                        + Integer.parseInt(beginTime.split(":")[0]) * 60 * 60 *1000
+                        + Integer.parseInt(beginTime.split(":")[1]) * 60 *1000;
+                Long endDate = sdf.parse(nowDay).getTime()
+                        + Integer.parseInt(endTime.split(":")[0]) * 60 * 60 *1000
+                        + Integer.parseInt(endTime.split(":")[1]) * 60 *1000;
+                if(now.getTime() >= beginDate && now.getTime() <= endDate){
+                    result = result.stream().filter(map -> ((Integer)map.get("chan_no")) == 1).collect(Collectors.toList());
+                    resultMap.put("chanNo", result.get(0).get("chan_no"));
+                    return resultMap;
+                }else{
+                    result = result.stream().filter(map -> ((Integer)map.get("chan_no")) == 2).collect(Collectors.toList());
+                    resultMap.put("chanNo", result.get(0).get("chan_no"));
+                    return resultMap;
+                }
+            }catch (Exception e){
+                e.printStackTrace();
+                return resultMap;
+            }
+        }
+    }
 }

--
Gitblit v1.9.3