zhaowenyu
2025-12-06 f3de8ac216bfc05348222e2b963ef3629358ae62
2025-12-06 zwy 修改设备属性设置方法,不抛异常,返回错误号与错误提示。
3 files modified
34 ■■■■■ changed files
ard-admin/src/main/java/com/ard/web/controller/sample/DeviceController.java 10 ●●●●● patch | view | raw | blame | history
ard-sample/src/main/java/com/ard/sample/manage/service/IDeviceService.java 2 ●●●●● patch | view | raw | blame | history
ard-sample/src/main/java/com/ard/sample/manage/service/impl/DeviceServiceImpl.java 22 ●●●●● patch | view | raw | blame | history
ard-admin/src/main/java/com/ard/web/controller/sample/DeviceController.java
@@ -218,15 +218,17 @@
    public ResponseResult devicePropertySet(@PathVariable("device_sn") String dockSn,
                                            @RequestBody JsonNode param) {
        if (param.size() != 1) {
            return ResponseResult.error(CommonErrorEnum.ILLEGAL_ARGUMENT);
            //return ResponseResult.error(CommonErrorEnum.ILLEGAL_ARGUMENT);
            return ResponseResult.error(999,"参数不合法");
        }
        String property = param.fieldNames().next();
        Optional<DeviceSetPropertyEnum> propertyEnumOpt = DeviceSetPropertyEnum.find(property);
        if (propertyEnumOpt.isEmpty()) {
            return ResponseResult.error(CommonErrorEnum.ILLEGAL_ARGUMENT);
            //return ResponseResult.error(CommonErrorEnum.ILLEGAL_ARGUMENT);
            return ResponseResult.error(999,"参数无效");
        }
        deviceService.devicePropertySet(dockSn, propertyEnumOpt.get(), param);
        return ResponseResult.success();
        return deviceService.devicePropertySet(dockSn, propertyEnumOpt.get(), param);
//        return ResponseResult.success();
    }
    //.get(property)
ard-sample/src/main/java/com/ard/sample/manage/service/IDeviceService.java
@@ -241,7 +241,7 @@
     * @param propertyEnum
     * @param param
     */
    void devicePropertySet(String dockSn, DeviceSetPropertyEnum propertyEnum, JsonNode param);
    ResponseResult devicePropertySet(String dockSn, DeviceSetPropertyEnum propertyEnum, JsonNode param);
    /**
     * 更改静音模型
ard-sample/src/main/java/com/ard/sample/manage/service/impl/DeviceServiceImpl.java
@@ -1196,23 +1196,29 @@
        return ResponseResult.success();
    }
    /**
     * 属性设置
     * */
    @Override
    public void devicePropertySet(String dockSn, DeviceSetPropertyEnum propertyEnum, JsonNode param) {
    public ResponseResult devicePropertySet(String dockSn, DeviceSetPropertyEnum propertyEnum, JsonNode param) {
        boolean dockOnline = this.checkDeviceOnline(dockSn);
        if (!dockOnline) {
            throw new RuntimeException(CommonErrorEnum.DEVICE_OFFLINE.getErrorMsg());
            return ResponseResult.error(CommonErrorEnum.DEVICE_OFFLINE.getErrorCode(),"机场" + CommonErrorEnum.DEVICE_OFFLINE.getErrorMsg());
            //throw new RuntimeException(CommonErrorEnum.DEVICE_OFFLINE.getErrorMsg());
        }
        DeviceDTO deviceDTO = (DeviceDTO) RedisOpsUtils.get(RedisConst.DEVICE_ONLINE_PREFIX + dockSn);
        boolean deviceOnline = this.checkDeviceOnline(deviceDTO.getChildDeviceSn());
        if (!deviceOnline) {
            throw new RuntimeException("Device is offline.");
            return ResponseResult.error(CommonErrorEnum.DEVICE_OFFLINE.getErrorCode(),"无人机" + CommonErrorEnum.DEVICE_OFFLINE.getErrorMsg());
            //throw new RuntimeException("Device is offline.");
        }
        // Make sure the data is valid.
        BasicDeviceProperty basicDeviceProperty = objectMapper.convertValue(param, propertyEnum.getClazz());
        boolean valid = basicDeviceProperty.valid();
        if (!valid) {
            throw new IllegalArgumentException(CommonErrorEnum.ILLEGAL_ARGUMENT.getErrorMsg());
            return ResponseResult.error(CommonErrorEnum.ILLEGAL_ARGUMENT.getErrorMsg());
            // throw new IllegalArgumentException(CommonErrorEnum.ILLEGAL_ARGUMENT.getErrorMsg());
        }
        String topic = THING_MODEL_PRE + PRODUCT + dockSn + PROPERTY_SUF + SET_SUF;
@@ -1220,12 +1226,14 @@
                (OsdSubDeviceReceiver) RedisOpsUtils.get(RedisConst.OSD_PREFIX + deviceDTO.getChildDeviceSn());
        if (!param.isObject()) {
            this.deviceOnePropertySet(topic, propertyEnum, Map.entry(propertyEnum.getProperty(), param));
            return;
            return ResponseResult.success();
//            return;
        }
        if(param.size()==1){
            this.deviceOnePropertySetSilent(topic,propertyEnum,param);
            return;
            return ResponseResult.success();
//            return;
        }
//        if(Objects.equals(param.fieldNames().next(), "silent_mode"))
//        {
@@ -1242,7 +1250,7 @@
            this.deviceOnePropertySet(topic, propertyEnum, Map.entry(propertyEnum.getProperty(), node));
        }
        return ResponseResult.success();
    }
    /**