czt
昨天 bc3e9b68c66fdeeb7c49155ff46ed68d3650cc18
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
package com.fzzy.igds.camera.impl;
 
import com.fzzy.igds.camera.AbstractApiCameraService;
import com.fzzy.igds.camera.data.ApiCameraData;
import com.fzzy.igds.camera.data.ApiCameraResp;
import com.fzzy.igds.constant.CameraPtzType;
import com.ld.onvif.OnvifService;
import com.ld.onvif.data.OnvifResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
 
/**
 * ONVIF播放接口实现,只负责实现PTZ接口
 */
@Component
public class ApiPtzOnvifService extends AbstractApiCameraService {
 
    @Resource
    private OnvifService onvifService;
 
    @Override
    public String getType() {
        return CameraPtzType.PTZ_TYPE_FZZY_ONVIF.getCode();
    }
 
    @Override
    public ApiCameraResp ptzMedia(ApiCameraData apiData) {
 
        if (StringUtils.isEmpty(apiData.getIp())
                || null == apiData.getWebPort()
                || StringUtils.isEmpty(apiData.getLoginId())
                || StringUtils.isEmpty(apiData.getPwd())) {
 
            return new ApiCameraResp(ApiCameraResp.CODE_ERROR, "参数不全,不支持云台控制");
        }
        try {
            OnvifResult result = onvifService.ptz(apiData.getIp(),
                    apiData.getWebPort(),
                    apiData.getLoginId(),
                    apiData.getPwd(),
                    apiData.getCommand(), 0.5);
 
            String code = result.get("code") + "";
            if ("0".equals(code) || "200".equals(code)) {
                code = ApiCameraResp.CODE_SUCCESS;
            }else {
                code = ApiCameraResp.CODE_ERROR;
            }
            return new ApiCameraResp(code, (String) result.get("msg"));
        } catch (Exception e) {
            return new ApiCameraResp(ApiCameraResp.CODE_ERROR, "后端执行异常" + e.getMessage());
        }
    }
 
    @Override
    public ApiCameraResp ptzPreset(ApiCameraData apiData) {
        try {
            if (StringUtils.isEmpty(apiData.getIp()) || null == apiData.getWebPort()
                    || StringUtils.isEmpty(apiData.getLoginId())
                    || StringUtils.isEmpty(apiData.getPwd())) {
                return new ApiCameraResp(ApiCameraResp.CODE_ERROR, "没有获取到当前摄像机信息,不支持云台控制");
            }
 
            OnvifResult result = onvifService.preset(apiData.getIp(), apiData.getWebPort(),
                    apiData.getLoginId(), apiData.getPwd(), apiData.getPreset());
 
 
            String code = result.get("code") + "";
            if ("0".equals(code) || "200".equals(code)) {
                code = ApiCameraResp.CODE_SUCCESS;
            }else {
                code = ApiCameraResp.CODE_ERROR;
            }
 
            return new ApiCameraResp(code, (String) result.get("msg"));
 
        } catch (Exception e) {
            return new ApiCameraResp(ApiCameraResp.CODE_ERROR, "后端执行异常" + e.getMessage());
        }
    }
}