Explorar o código

智慧灯杆,摄像头列表模块

crazycat %!s(int64=2) %!d(string=hai) anos
pai
achega
ef25b797bc

+ 135 - 3
src/main/java/com/welampiot/controller/VideoController.java

@@ -1,14 +1,21 @@
 package com.welampiot.controller;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.welampiot.common.BaseResult;
+import com.welampiot.common.Constant;
 import com.welampiot.common.InterfaceResultEnum;
 import com.welampiot.common.ResultEnum;
 import com.welampiot.dto.UserDTO;
 import com.welampiot.dto.VideoMonitorDTO;
 import com.welampiot.dto.WaterImmersionDevInfoDTO;
+import com.welampiot.service.SystemConfigService;
 import com.welampiot.service.VideoMonitorService;
 import com.welampiot.utils.MD5Utils;
 import com.welampiot.utils.ToolUtils;
+import com.welampiot.utils.VideoUtil;
+import com.welampiot.utils.WebUtils;
 import com.welampiot.vo.LoginVO;
 import com.welampiot.vo.VideoMonitorVO;
 import org.slf4j.Logger;
@@ -34,6 +41,9 @@ public class VideoController {
 
     @Autowired
     private VideoMonitorService videoMonitorService;
+
+    @Autowired
+    private SystemConfigService systemConfigService;
     /**
      * 设置AI开关状态
      * @param request
@@ -58,7 +68,6 @@ public class VideoController {
     @RequestMapping(value = "/getRecordList", method = RequestMethod.POST)
     public BaseResult getRecordList(VideoMonitorDTO videoMonitorDTO){
         int version = videoMonitorDTO.getVersion();
-//        Integer id = videoMonitorDTO.getId();
         long startTime = System.currentTimeMillis() - 24 * 3600 * 1000;
         ArrayList<VideoMonitorDTO> videoMonitorDTOS = new ArrayList<>();
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -76,14 +85,71 @@ public class VideoController {
 
 
     /**
-     * 获取摄像头回放列表
+     * 获取回放播放地址
      * @param videoMonitorDTO
      * @return
      */
     @RequestMapping(value = "/getRecordPlay", method = RequestMethod.POST)
     public BaseResult getRecordPlay(VideoMonitorDTO videoMonitorDTO){
         int version = videoMonitorDTO.getVersion();
-//        Integer id = videoMonitorDTO.getId();
+        Integer id = videoMonitorDTO.getId();
+        String startTime = videoMonitorDTO.getStartTime();
+        String endTime = videoMonitorDTO.getEndTime();
+        if (startTime == null || endTime == null) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
+        VideoMonitorDTO oneById = videoMonitorService.getOneById(id);
+        String gbAddress = oneById.getGbAddress();
+        String gbPlayBackAddress = VideoUtil.getGbPlayBackAddress(videoMonitorService, systemConfigService, gbAddress, startTime, endTime);
+        VideoMonitorDTO videoMonitorDTO1 = new VideoMonitorDTO();
+        videoMonitorDTO1.setAddress(gbPlayBackAddress);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,videoMonitorDTO1);
+    }
+
+    /**
+     * 获取NVR通道值信息
+     * @param videoMonitorDTO
+     * @return
+     */
+    @RequestMapping(value = "/getChannelValue", method = RequestMethod.POST)
+    public BaseResult getChannelValue(VideoMonitorDTO videoMonitorDTO){
+        int version = videoMonitorDTO.getVersion();
+        Integer id = videoMonitorDTO.getId();
+        if (id == null || id == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
+        VideoMonitorDTO oneById = videoMonitorService.getOneById(id);
+
+        String url = Constant.GB_HOST_ADDRESS+"/api/devices";
+        String s = WebUtils.requestGet(url);
+        JSONArray jsonArray = JSON.parseArray(s);
+        JSONObject data = null;
+        if (jsonArray != null){
+            for (Object j: jsonArray) {
+                JSONObject j1 = (JSONObject) j;
+                String deviceId = (String) j1.get("deviceId");
+                if (deviceId.equalsIgnoreCase(oneById.getGbAddress())){
+                    data = j1;
+                }
+            }
+        }
+        ArrayList<Object> objects = new ArrayList<>();
+        if (data != null){
+            for (Object channelMap : (JSONArray) data.get("channelMap")) {
+                JSONObject channelMap1 = (JSONObject) channelMap;
+                VideoMonitorDTO videoMonitorDTO1 = new VideoMonitorDTO();
+                videoMonitorDTO1.setName((String) channelMap1.get("name"));
+                videoMonitorDTO1.setChannelId((String) channelMap1.get("channelId"));
+                objects.add(videoMonitorDTO1);
+            }
+        }
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,objects);
+    }
+
+    /**
+     * NVR获取回放列表
+     * @param videoMonitorDTO
+     * @return
+     */
+    @RequestMapping(value = "/getNvrRecordList", method = RequestMethod.POST)
+    public BaseResult getNvrRecordList(VideoMonitorDTO videoMonitorDTO){
+        int version = videoMonitorDTO.getVersion();
         long startTime = System.currentTimeMillis() - 24 * 3600 * 1000;
         ArrayList<VideoMonitorDTO> videoMonitorDTOS = new ArrayList<>();
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -98,4 +164,70 @@ public class VideoController {
         videoMonitorVO.setList(videoMonitorDTOS);
         return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,videoMonitorVO);
     }
+
+    /**
+     * NVR获取回放地址
+     * @param videoMonitorDTO
+     * @return
+     */
+    @RequestMapping(value = "/getPlayBackAddressByChannel", method = RequestMethod.POST)
+    public BaseResult getPlayBackAddressByChannel(VideoMonitorDTO videoMonitorDTO){
+        int version = videoMonitorDTO.getVersion();
+        if (videoMonitorDTO.getId() == null || videoMonitorDTO.getChannel() == null || videoMonitorDTO.getStartTime() == null || videoMonitorDTO.getEndTime() == null) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
+        VideoMonitorDTO oneById = videoMonitorService.getOneById(videoMonitorDTO.getId());
+        String nvrGbPlayBackAddress = VideoUtil.getNvrGbPlayBackAddress(videoMonitorService, systemConfigService, oneById.getGbAddress(), videoMonitorDTO.getStartTime(), videoMonitorDTO.getEndTime(), videoMonitorDTO.getChannel());
+        VideoMonitorDTO videoMonitorDTO1 = new VideoMonitorDTO();
+        videoMonitorDTO1.setAddress(nvrGbPlayBackAddress);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,videoMonitorDTO1);
+    }
+
+    /**
+     * NVR获取通道播放地址
+     * @param videoMonitorDTO
+     * @return
+     */
+    @RequestMapping(value = "/getPlayAddressByChannel", method = RequestMethod.POST)
+    public BaseResult getPlayAddressByChannel(VideoMonitorDTO videoMonitorDTO){
+        int version = videoMonitorDTO.getVersion();
+        if (videoMonitorDTO.getId() == null || videoMonitorDTO.getChannel() == null || videoMonitorDTO.getStartTime() == null || videoMonitorDTO.getEndTime() == null) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
+        VideoMonitorDTO oneById = videoMonitorService.getOneById(videoMonitorDTO.getId());
+        String nvrGbPlayBackAddress = VideoUtil.getNvrGbPlayAddress(videoMonitorService, systemConfigService, oneById.getGbAddress(), videoMonitorDTO.getChannel());
+        VideoMonitorDTO videoMonitorDTO1 = new VideoMonitorDTO();
+        videoMonitorDTO1.setAddress(nvrGbPlayBackAddress);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,videoMonitorDTO1);
+    }
+
+    /**
+     * 设置报警位
+     * @param videoMonitorDTO
+     * @return
+     */
+    @RequestMapping(value = "/setEmergencyLocation", method = RequestMethod.POST)
+    public BaseResult setEmergencyLocation(VideoMonitorDTO videoMonitorDTO){
+        int version = videoMonitorDTO.getVersion();
+        if (videoMonitorDTO.getId() == null) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
+        VideoMonitorDTO oneById = videoMonitorService.getOneById(videoMonitorDTO.getId());
+
+        String url = Constant.GB_HOST_ADDRESS+"/api/postion/"+oneById.getGbAddress()+"/34020000001320000001";
+        String param = "{\"code\":1,\"postion\":1}";
+        WebUtils.requestPost(url, param);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
+    }
+
+    /**
+     * 查看报警位
+     * @param videoMonitorDTO
+     * @return
+     */
+    @RequestMapping(value = "/getEmergencyLocation", method = RequestMethod.POST)
+    public BaseResult getEmergencyLocation(VideoMonitorDTO videoMonitorDTO){
+        int version = videoMonitorDTO.getVersion();
+        if (videoMonitorDTO.getId() == null) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
+        VideoMonitorDTO oneById = videoMonitorService.getOneById(videoMonitorDTO.getId());
+
+        String url = Constant.GB_HOST_ADDRESS+"/api/postion/"+oneById.getGbAddress()+"/34020000001320000001";
+        String param = "{\"code\":2,\"postion\":1}";
+        WebUtils.requestPost(url, param);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
+    }
 }

+ 1 - 0
src/main/java/com/welampiot/dto/VideoMonitorDTO.java

@@ -67,4 +67,5 @@ public class VideoMonitorDTO {
     private String startTime;
     private String endTime;
     private Integer select;
+    private String channelId;
 }

+ 101 - 42
src/main/java/com/welampiot/utils/VideoUtil.java

@@ -101,46 +101,105 @@ public class VideoUtil {
         return Constant.GB_PLAY_HOST_ADDRESS+"/gb3/rtp/"+gbId.toUpperCase()+".live.mp4";
     }
 
-    // 获取国标摄像头回放地址
-//    public function get_gb_play_back_address($gb_address,$startTime,$endTime,$res = ''){
-//
-//        $back_info = $this->db->query('select back_address from video_monitor where `gb_address` = "'.$gb_address.'"')->row_array();
-//        $back = false;
-//        if (!empty($back_info) && !empty($back_info['back_address'])) {
-//            $url = 'http://'.$this->config->config['gb_host'].':8089/api/playback/'.$back_info['back_address'].'/stop';
-//            // $url = 'http://139.196.213.241:8050/api/playback/'.$back_info['back_address'].'/stop';
-//            request_post($url,[],1);
-//            sleep(1);
-//            $back = true;
-//        }
-//        $ssrc = $this->get_video_ssrc();
-//        if (empty($res)) $res = http_get('http://'.$this->config->config['gb_host'].':8060/index/api/getMediaList?secret=weclouds123');
-//        $res = json_decode($res,true);
-//
-//        $url = 'http://'.$this->config->config['gb_host'].':8089/api/playback/'.$gb_address.'/34020000001320000001/'.$ssrc;
-//        // $url = 'http://139.196.213.241:8050/api/playback/'.$gb_address.'/34020000001320000001/'.$ssrc;
-//        $this->db->query('update video_monitor set back_address = '.$ssrc.' where `gb_address` = "'.$gb_address.'"');
-//        $gb_id = substr('00000000'.base_convert($ssrc, 10, 16), -8);
-//        if ($res && isset($res['code']) && $res['code'] == 0) {
-//            $data = isset($res['data']) ? $res['data'] : array();
-//            $flag = 0;
-//            foreach ($data as $key => $value) {
-//                if (strtolower($value['stream']) == strtolower($gb_id)) {
-//                    $flag = 1;
-//                    break;
-//                }
-//            }
-//
-//            if ($flag) {
-//                $address = 'https://gb.lampmind.com:8087/gb3/rtp/'.strtoupper($gb_id).'.live.mp4';
-//            }else{
-//                $res = request_post($url,['startTime'=>$startTime,'endTime'=>$endTime],5);
-//                json_decode($res,true);
-//                $address = 'https://gb.lampmind.com:8087/gb3/rtp/'.strtoupper($gb_id).'.live.mp4';
-//                if ($back) sleep(7);
-//            }
-//            return $address;
-//        }
-//        return '';
-//    }
+    /**
+     * 获取nvr国标摄像头回放地址
+     * @param service 视频监控 service
+     * @param systemConfigService 系统设置 service
+     * @param gbAddress 摄像头国标地址
+     * @param startTime  回放开始时间
+     * @param endTime  回放结束时间
+     * @param channel  视频通道值
+     * @return 返回视频播放地址
+     */
+    public static String getNvrGbPlayBackAddress(VideoMonitorService service,SystemConfigService systemConfigService, String gbAddress, String startTime, String endTime,String channel){
+        VideoMonitorDTO oneByDbAddress = service.getOneByDbAddress(gbAddress);
+        Boolean back = false;
+        if (oneByDbAddress != null && oneByDbAddress.getBackAddress() != null && !oneByDbAddress.getBackAddress().isEmpty()){
+            String url = Constant.GB_HOST_ADDRESS+"/api/playback/"+oneByDbAddress.getBackAddress()+"/stop";
+            WebUtils.requestPost(url, "");
+            try {
+                Thread.sleep(1000);
+            } catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            }
+            back = true;
+        }
+        int videoSrc = getVideoSrc(systemConfigService);
+        String url = Constant.ZK_HOST_ADDRESS+"/index/api/getMediaList?secret=weclouds123";
+        String s = WebUtils.requestGet(url);
+
+        String s2 = "00000000" + Integer.toString(videoSrc);
+        String gbId = s2.substring(-8);
+
+        JSONObject jsonObject = JSON.parseObject(s);
+        JSONArray data = (JSONArray)jsonObject.get("data");
+        Boolean flag = true;
+        if (data != null){
+            for (Object j: data) {
+                JSONObject j1 = (JSONObject) j;
+                String stream = (String) j1.get("stream");
+                if (stream.equalsIgnoreCase(gbId)){
+                    flag = false;
+                }
+            }
+        }
+
+        VideoMonitorDTO videoMonitorDTO = new VideoMonitorDTO();
+        videoMonitorDTO.setBackAddress(String.valueOf(videoSrc));
+        videoMonitorDTO.setGbAddress(gbAddress);
+        service.updateBackAddress(videoMonitorDTO);
+        if (flag){
+            url = Constant.GB_HOST_ADDRESS+"/api/playback/"+gbAddress+"/"+channel+"/"+videoSrc;
+            String param = "{\"startTime\":\""+startTime+"\",\"endTime\":\""+endTime+"\"}";
+            WebUtils.requestPost(url, param);
+        }
+
+        if (back) {
+            try {
+                Thread.sleep(7000);
+            } catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            }
+        }
+
+        return Constant.GB_PLAY_HOST_ADDRESS+"/gb3/rtp/"+gbId.toUpperCase()+".live.mp4";
+    }
+
+    /**
+     * 获取nvr国标摄像头播放地址
+     * @param service 视频监控 service
+     * @param systemConfigService 系统设置 service
+     * @param gbAddress 摄像头国标地址
+     * @param channel  视频通道值
+     * @return 返回视频播放地址
+     */
+    public static String getNvrGbPlayAddress(VideoMonitorService service,SystemConfigService systemConfigService, String gbAddress,String channel){
+        Boolean back = false;
+        String url = Constant.ZK_HOST_ADDRESS+"/index/api/getMediaList?secret=weclouds123";
+        String s = WebUtils.requestGet(url);
+        String s4 = channel.substring(-3) + gbAddress.substring(-4);
+        String s2 = "00000000" + Integer.toHexString(Integer.parseInt(s4));
+        String gbId = s2.substring(-8);
+
+        JSONObject jsonObject = JSON.parseObject(s);
+        JSONArray data = (JSONArray)jsonObject.get("data");
+        Boolean flag = true;
+        if (data != null){
+            for (Object j: data) {
+                JSONObject j1 = (JSONObject) j;
+                String stream = (String) j1.get("stream");
+                if (stream.equalsIgnoreCase(gbId)){
+                    flag = false;
+                }
+            }
+        }
+
+        if (flag){
+            int i = Integer.parseInt(s4);
+            url = Constant.GB_HOST_ADDRESS+"/api/play/"+gbAddress+"/"+channel+"/"+i;
+            WebUtils.requestGet(url);
+        }
+
+        return Constant.GB_PLAY_HOST_ADDRESS+"/gb3/rtp/"+gbId.toUpperCase()+".live.mp4";
+    }
 }