liujie
2026-07-23 1fddea4f3d4e9415fe1f553c064d2daf953f3684
监控
5个文件已修改
115 ■■■■■ 已修改文件
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/TDevice.java 4 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TDeviceController.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/VideoMonitorController.java 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/util/EzvizOpenApiUtils.java 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/resources/mapper/other/TDeviceMapper.xml 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/TDevice.java
@@ -43,6 +43,10 @@
    @TableField("validate_code")
    private String validateCode;
    @ApiModelProperty(value = "视频通道号")
    @TableField("channel_no")
    private Integer channelNo;
    @ApiModelProperty(value = "合作商类型")
    @TableField("partner_type")
    private Integer partnerType;
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TDeviceController.java
@@ -108,6 +108,9 @@
        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("合作商不能为空");
        }
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/VideoMonitorController.java
@@ -90,6 +90,7 @@
        JSONObject result = ezvizOpenApiUtils.ptzControl(
                device.getDeviceSerial(),
                defaultChannelNo(request.getChannelNo(), device),
                StringUtils.hasText(request.getAction()) ? request.getAction() : "start",
                request.getCommand(),
                request.getSpeed()
@@ -108,7 +109,7 @@
        JSONObject result = ezvizOpenApiUtils.setSceneSwitch(
                device.getDeviceSerial(),
                defaultChannelNo(request.getChannelNo()),
                defaultChannelNo(request.getChannelNo(), device),
                request.getEnable()
        );
        return buildEzvizResult(result, "摄像头开关控制失败");
@@ -125,12 +126,19 @@
        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, "焦距控制失败");
    }
@@ -149,7 +157,7 @@
            result = ezvizOpenApiUtils.getLocalPlaybackAddress(
                    device.getDeviceSerial(),
                    device.getValidateCode(),
                    defaultChannelNo(request.getChannelNo()),
                    defaultChannelNo(request.getChannelNo(), device),
                    request.getStartTime(),
                    request.getStopTime()
            );
@@ -157,7 +165,7 @@
            result = ezvizOpenApiUtils.getCloudPlaybackAddress(
                    device.getDeviceSerial(),
                    device.getValidateCode(),
                    defaultChannelNo(request.getChannelNo()),
                    defaultChannelNo(request.getChannelNo(), device),
                    request.getStartTime(),
                    request.getStopTime()
            );
@@ -213,7 +221,7 @@
    }
    private void fillLiveAddress(VideoMonitorDeviceVO vo, TDevice device) {
        int channelNo = 1;
        int channelNo = defaultChannelNo(null, device);
        try {
            vo.setAccessToken(ezvizOpenApiUtils.getAccessToken());
            vo.setChannelNo(channelNo);
@@ -247,7 +255,11 @@
            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) {
@@ -262,7 +274,13 @@
        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;
    }
}
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/util/EzvizOpenApiUtils.java
@@ -103,24 +103,67 @@
     * @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);
    }
    /**
ruoyi-service/ruoyi-other/src/main/resources/mapper/other/TDeviceMapper.xml
@@ -8,6 +8,7 @@
        <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" />
@@ -19,7 +20,7 @@
    </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">