| | |
| | | @TableField("validate_code") |
| | | private String validateCode; |
| | | |
| | | @ApiModelProperty(value = "视频通道号") |
| | | @TableField("channel_no") |
| | | private Integer channelNo; |
| | | |
| | | @ApiModelProperty(value = "合作商类型") |
| | | @TableField("partner_type") |
| | | private Integer partnerType; |
| | |
| | | if (!StringUtils.hasText(device.getValidateCode())) { |
| | | return AjaxResult.error("设备验证码不能为空"); |
| | | } |
| | | if (device.getChannelNo() == null || device.getChannelNo() < 1) { |
| | | return AjaxResult.error("通道号不能为空"); |
| | | } |
| | | if (device.getPartnerId() == null) { |
| | | return AjaxResult.error("合作商不能为空"); |
| | | } |
| | |
| | | |
| | | JSONObject result = ezvizOpenApiUtils.ptzControl( |
| | | device.getDeviceSerial(), |
| | | defaultChannelNo(request.getChannelNo(), device), |
| | | StringUtils.hasText(request.getAction()) ? request.getAction() : "start", |
| | | request.getCommand(), |
| | | request.getSpeed() |
| | |
| | | |
| | | JSONObject result = ezvizOpenApiUtils.setSceneSwitch( |
| | | device.getDeviceSerial(), |
| | | defaultChannelNo(request.getChannelNo()), |
| | | defaultChannelNo(request.getChannelNo(), device), |
| | | request.getEnable() |
| | | ); |
| | | return buildEzvizResult(result, "摄像头开关控制失败"); |
| | |
| | | |
| | | JSONObject result = ezvizOpenApiUtils.ptzControl( |
| | | device.getDeviceSerial(), |
| | | defaultChannelNo(request.getChannelNo(), device), |
| | | "start", |
| | | request.getCommand(), |
| | | request.getSpeed() |
| | | ); |
| | | if (isEzvizSuccess(result)) { |
| | | ezvizOpenApiUtils.ptzControl(device.getDeviceSerial(), "stop", request.getCommand(), null); |
| | | ezvizOpenApiUtils.ptzControl( |
| | | device.getDeviceSerial(), |
| | | defaultChannelNo(request.getChannelNo(), device), |
| | | "stop", |
| | | request.getCommand(), |
| | | null |
| | | ); |
| | | } |
| | | return buildEzvizResult(result, "焦距控制失败"); |
| | | } |
| | |
| | | result = ezvizOpenApiUtils.getLocalPlaybackAddress( |
| | | device.getDeviceSerial(), |
| | | device.getValidateCode(), |
| | | defaultChannelNo(request.getChannelNo()), |
| | | defaultChannelNo(request.getChannelNo(), device), |
| | | request.getStartTime(), |
| | | request.getStopTime() |
| | | ); |
| | |
| | | result = ezvizOpenApiUtils.getCloudPlaybackAddress( |
| | | device.getDeviceSerial(), |
| | | device.getValidateCode(), |
| | | defaultChannelNo(request.getChannelNo()), |
| | | defaultChannelNo(request.getChannelNo(), device), |
| | | request.getStartTime(), |
| | | request.getStopTime() |
| | | ); |
| | |
| | | } |
| | | |
| | | private void fillLiveAddress(VideoMonitorDeviceVO vo, TDevice device) { |
| | | int channelNo = 1; |
| | | int channelNo = defaultChannelNo(null, device); |
| | | try { |
| | | vo.setAccessToken(ezvizOpenApiUtils.getAccessToken()); |
| | | vo.setChannelNo(channelNo); |
| | |
| | | return defaultMessage; |
| | | } |
| | | String message = result.getString("msg"); |
| | | return StringUtils.hasText(message) ? message : defaultMessage; |
| | | if (StringUtils.hasText(message)) { |
| | | return message; |
| | | } |
| | | String code = result.getString("code"); |
| | | return StringUtils.hasText(code) ? defaultMessage + ",错误码:" + code : defaultMessage; |
| | | } |
| | | |
| | | private String resolveVideoUrl(JSONObject result) { |
| | |
| | | return data.getString("ezopen"); |
| | | } |
| | | |
| | | private Integer defaultChannelNo(Integer channelNo) { |
| | | return channelNo == null ? 1 : channelNo; |
| | | private Integer defaultChannelNo(Integer channelNo, TDevice device) { |
| | | if (channelNo != null && channelNo > 0) { |
| | | return channelNo; |
| | | } |
| | | if (device != null && device.getChannelNo() != null && device.getChannelNo() > 0) { |
| | | return device.getChannelNo(); |
| | | } |
| | | return 1; |
| | | } |
| | | } |
| | |
| | | * @param speed 速度 1-7,为空时按萤石默认值 |
| | | */ |
| | | public JSONObject ptzControl(String deviceSerial, String action, String command, Integer speed) { |
| | | return ptzControl(deviceSerial, 1, action, command, speed); |
| | | } |
| | | |
| | | public JSONObject ptzControl(String deviceSerial, Integer channelNo, String action, String command, Integer speed) { |
| | | requireText(deviceSerial, "deviceSerial"); |
| | | requireText(action, "action"); |
| | | requireText(command, "command"); |
| | | |
| | | Map<String, Object> body = new LinkedHashMap<>(); |
| | | body.put("timeStamp", String.valueOf(System.currentTimeMillis())); |
| | | body.put("action", action); |
| | | body.put("control", "ptz"); |
| | | putIfNotNull(body, "command", command); |
| | | putIfNotNull(body, "speed", speed); |
| | | Map<String, Object> form = new LinkedHashMap<>(); |
| | | form.put("deviceSerial", deviceSerial); |
| | | form.put("channelNo", channelNo == null ? 1 : channelNo); |
| | | form.put("direction", resolvePtzDirection(command)); |
| | | if ("start".equalsIgnoreCase(action)) { |
| | | form.put("speed", normalizePtzSpeed(speed)); |
| | | return postFormWithToken("/api/lapp/device/ptz/start", form); |
| | | } |
| | | if ("stop".equalsIgnoreCase(action)) { |
| | | return postFormWithToken("/api/lapp/device/ptz/stop", form); |
| | | } |
| | | throw new IllegalArgumentException("action仅支持start/stop"); |
| | | } |
| | | |
| | | return otapAction( |
| | | deviceSerial, |
| | | "0", |
| | | "global", |
| | | "PTZManualCtrl", |
| | | "ModifyPTZCtrl", |
| | | body |
| | | ); |
| | | private Integer resolvePtzDirection(String command) { |
| | | switch (command) { |
| | | case "up": |
| | | return 0; |
| | | case "down": |
| | | return 1; |
| | | case "left": |
| | | return 2; |
| | | case "right": |
| | | return 3; |
| | | case "upleft": |
| | | return 4; |
| | | case "downleft": |
| | | return 5; |
| | | case "upright": |
| | | return 6; |
| | | case "downright": |
| | | return 7; |
| | | case "zoomin": |
| | | return 8; |
| | | case "zoomout": |
| | | return 9; |
| | | case "focusin": |
| | | return 10; |
| | | case "focusout": |
| | | return 11; |
| | | default: |
| | | throw new IllegalArgumentException("不支持的云台控制命令:" + command); |
| | | } |
| | | } |
| | | |
| | | private Integer normalizePtzSpeed(Integer speed) { |
| | | if (speed == null) { |
| | | return 1; |
| | | } |
| | | if (speed < 0) { |
| | | return 0; |
| | | } |
| | | return Math.min(speed, 2); |
| | | } |
| | | |
| | | /** |
| | |
| | | <result column="device_serial" property="deviceSerial" /> |
| | | <result column="device_brand" property="deviceBrand" /> |
| | | <result column="validate_code" property="validateCode" /> |
| | | <result column="channel_no" property="channelNo" /> |
| | | <result column="partner_type" property="partnerType" /> |
| | | <result column="partner_id" property="partnerId" /> |
| | | <result column="partner_name" property="partnerName" /> |
| | |
| | | </resultMap> |
| | | |
| | | <sql id="Base_Column_List"> |
| | | id, device_name, device_serial, device_brand, validate_code, partner_type, partner_id, partner_name, site_id, site_name, online_status, del_flag, create_time |
| | | id, device_name, device_serial, device_brand, validate_code, channel_no, partner_type, partner_id, partner_name, site_id, site_name, online_status, del_flag, create_time |
| | | </sql> |
| | | |
| | | <select id="pageList" resultMap="BaseResultMap"> |