liuxiaolong
2019-05-06 0bc4f4c791437b39b8c30624f5c21f8c855dc61d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package com.cloud.retrieve.controller;
 
import com.alibaba.fastjson.JSONObject;
import com.cloud.model.common.Result;
import com.cloud.retrieve.service.AnalyDevService;
import com.cloud.retrieve.utils.EnumStr;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.Map;
 
/**
 *  查看大图 查看视频
 */
@Slf4j
@Api(value = "EsDataBaseController",description = " 查看大图 查看视频")
@RestController
@RequestMapping("/data/api-r/dev")
public class DevInfoController {
 
    @Autowired
    private AnalyDevService analyDevService;
    @Autowired
    private EnumStr enumStr;
 
    @ApiOperation(value = "getBigPic",notes =
            "查看大图 {\"videoNum\":\"DS-2CD2T46WDA2-I20180622AACHC30488278\",\"picDate\":\"2019-02-12 06:59:52:505\"," +
                    "\"videoIp\":\"192.168.1.182\",\"indeviceid\":\"DSVAD010120181115\",\"imgKey\":\"DS-2CD2T46WDA2-I20180622AACHC30488278$2019-02-12-06-59-52_22803272\"}",
            httpMethod = "POST",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @RequestMapping("/getBigPic")
    public Result getBigPic(@RequestBody Map reqMap, HttpServletRequest req) throws ParseException {
        String videoNum = (String) reqMap.get("videoNum");
        String picDate = (String) reqMap.get("picDate");
        String videoIp = (String) reqMap.get("videoIp");
        String imgKey = (String) reqMap.get("imgKey");
        Object indeviceid =  reqMap.get("indeviceid");
        if (videoNum == null ||videoNum.isEmpty()|| picDate == null|| picDate.isEmpty()||
                ((videoIp == null|| videoIp.isEmpty() ))){
            throw new RuntimeException("查看大图参数 videoNum:"+videoNum+",picDate:"+picDate+
                    ",videoIp:"+videoIp+"为空。");
        }
        log.info("查看大图参数videoNum:"+videoNum+",picDate:"+picDate+
                ",videoIp:"+videoIp+"indeviceid:"+indeviceid+"imgKey:"+imgKey);
        JSONObject respView = analyDevService.getBigPic(videoNum,picDate,videoIp,indeviceid != null?indeviceid.toString():null,imgKey);
        if ( respView.getString("img_url")!= null){
            String file_path =  respView.getString("img_url");
            file_path =  enumStr.getHttpImgUrl() +":"+enumStr.getHttpImgPort()+"/"+file_path;  // 80   44280
            log.info("查看大图;file_path:"+file_path);
            respView.put("imgurl",file_path);
            return  Result.ok("查看大图成功。",respView);
        }else {
            return  Result.error(new RuntimeException(respView.getString("error")));
        }
    }
 
    @ApiOperation(value = "getVideoByCServer",notes =
            "查看视频{\"videoNum\":\"DS-2CD2T46WDA2-I20180622AACHC30488278\",\"picDate\":\"2019-02-12 06:59:52:505\"," +
                    "\"videoIp\":\"192.168.1.182\",\"indeviceid\":\"DSVAD010120181115\",\"imgKey\":\"DS-2CD2T46WDA2-I20180622AACHC30488278$2019-02-12-06-59-52_22803272\"}",
            httpMethod = "POST",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @RequestMapping("/getVideoByCServer")
    public Result getUploadRtnVideo(@RequestBody Map reqMap, HttpServletRequest req) throws ParseException {
        String videoNum = (String) reqMap.get("videoNum");
        String picDate = (String) reqMap.get("picDate");
        String videoIp = (String) reqMap.get("videoIp");
        String imgKey = (String) reqMap.get("imgKey");
        String indeviceid = (String) reqMap.get("indeviceid");
        if (videoNum == null ||videoNum.isEmpty()|| picDate == null|| picDate.isEmpty()||
                ((videoIp == null|| videoIp.isEmpty() )&&( indeviceid == null||indeviceid.isEmpty() ))){
            throw new RuntimeException("查看视频参数 videoNum:"+videoNum+",picDate:"+picDate+
                    ",videoIp:"+videoIp+"indeviceid:"+indeviceid+"为空。");
        }
        log.info("查看视频参数videoNum:"+videoNum+",picDate:"+picDate+
                ",videoIp:"+videoIp+"indeviceid:"+indeviceid);
        JSONObject respView = analyDevService.getVideo(videoNum,picDate,videoIp,indeviceid,imgKey);
        if ( respView.getString("file_path")!= null && respView.getString("file_path").contains("/cut")){
            String file_path =  respView.getString("file_path");
            log.info("c返回数据:"+file_path);
//            String netPath = req.getScheme()+"://"+req.getServerName() /*"http://"+PropUtils.getProperty("cserver_web_host")*/ // req.getServerName()
//                    + respView.getString("filepath");;  //  nginxHttpPort
//            respView.put("filepath",netPath);
//            log.info("返回页面数据:"+netPath);
//            log.info("视频地址:"+file_path);
            return  Result.ok("查看视频成功。",respView);
        }else {
            return  Result.error(new RuntimeException(respView.getString("error")));
        }
    }
 
 
    @ApiOperation(value = "getDevSnapshot",notes =
            "获取实时流截图{\"devId\":\"DS-2CD2T46WDA2-I20180622AACHC30488278\"}",
            httpMethod = "POST",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @RequestMapping("/getDevSnapshot")
    public Result getDevSnapshot(@RequestBody Map reqMap, HttpServletRequest req) throws ParseException {
        String devId = (String) reqMap.get("devId");
        if (StringUtils.isBlank(devId)){
            throw new RuntimeException("获取实时流截图 devId:"+devId+"为空。");
        }
        log.info("获取实时流截图 devId:"+devId);
        Result respView = analyDevService.getDevSnapshot(devId);
            return  respView;
    }
}