debug:设备操作提示优化
This commit is contained in:
parent
76f2bb2150
commit
c778ca5abc
|
@ -2,7 +2,7 @@ package com.ruoyi.common.constant;
|
|||
|
||||
/**
|
||||
* 返回状态码
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class HttpStatus
|
||||
|
@ -92,119 +92,4 @@ public class HttpStatus
|
|||
*/
|
||||
public static final int WARN = 601;
|
||||
|
||||
/**----------------------------IOT错误码start----------------------------*/
|
||||
|
||||
/**
|
||||
* 成功
|
||||
*/
|
||||
public static final Integer IOT_SUCCESS = 0;
|
||||
/**
|
||||
* 错误码 新增设备失败:设备已存在
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_ALREADY_EXISTS = "10406";
|
||||
|
||||
/**
|
||||
* 错误码 设备不存在
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_NON_EXISTENT = "10410";
|
||||
/**
|
||||
* 错误码 设备属性设置失败
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_ATTRIBUTE_SET_FAIL = "10411";
|
||||
/**
|
||||
* 错误码 设备属性期望设置失败
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_ATTRIBUTE_DESIRE_SET_FAIL = "10412";
|
||||
/**
|
||||
* 错误码 设备属性期望查询失败
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_ATTRIBUTE_DESIRE_QUERY_FAIL = "10413";
|
||||
/**
|
||||
* 错误码 设备属性获取失败
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_ATTRIBUTE_DESIRE_GET_FAIL = "10414";
|
||||
/**
|
||||
* 错误码 设备服务调用失败
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_SERVICE_CALL_FAIL = "10415";
|
||||
/**
|
||||
* 错误码 设备属性期望删除失败
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_ATTRIBUTE_DESIRE_DALETE_FAIL = "10416";
|
||||
/**
|
||||
* 错误码 设备最新数据查询失败
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVIE_NEW_DATA_QUERY_FAIL = "10417";
|
||||
/**
|
||||
* 错误码 设备属性历史数据查询失败
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_ATTRIBUTE_HISTORY_QUERY_FAIL = "10418";
|
||||
/**
|
||||
* 错误码 设备事件历史数据查询失败
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_EVENT_HISTORY_DATA_QUERY_FAIL = "10419";
|
||||
/**
|
||||
* 错误码 设备操作记录查询失败
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_OPERATE_RECORD_QUERY_FAIL = "10420";
|
||||
/**
|
||||
* 错误码 设备不在线
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_NOT_ONLINE = "10421";
|
||||
|
||||
/**
|
||||
* 错误码 新增设备失败:设备已存在
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_ALREADY_EXISTS_MSG = "10406";
|
||||
|
||||
/**
|
||||
* 错误码 设备不存在
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_NON_EXISTENT_MSG = "设备不存在";
|
||||
/**
|
||||
* 错误码 设备属性设置失败
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_ATTRIBUTE_SET_FAIL_MSG = "设备属性设置失败";
|
||||
/**
|
||||
* 错误码 设备属性期望设置失败
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_ATTRIBUTE_DESIRE_SET_FAIL_MSG = "设备属性期望设置失败";
|
||||
/**
|
||||
* 错误码 设备属性期望查询失败
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_ATTRIBUTE_DESIRE_QUERY_FAIL_MSG = "设备属性期望查询失败";
|
||||
/**
|
||||
* 错误码 设备属性获取失败
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_ATTRIBUTE_DESIRE_GET_FAIL_MSG = "设备属性获取失败";
|
||||
/**
|
||||
* 错误码 设备服务调用失败
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_SERVICE_CALL_FAIL_MSG = "设备服务调用失败";
|
||||
/**
|
||||
* 错误码 设备属性期望删除失败
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_ATTRIBUTE_DESIRE_DALETE_FAIL_MSG = "设备属性期望删除失败";
|
||||
/**
|
||||
* 错误码 设备最新数据查询失败
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVIE_NEW_DATA_QUERY_FAIL_MSG = "设备最新数据查询失败";
|
||||
/**
|
||||
* 错误码 设备属性历史数据查询失败
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_ATTRIBUTE_HISTORY_QUERY_FAIL_MSG = "设备属性历史数据查询失败";
|
||||
/**
|
||||
* 错误码 设备事件历史数据查询失败
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_EVENT_HISTORY_DATA_QUERY_FAIL_MSG = "设备事件历史数据查询失败";
|
||||
/**
|
||||
* 错误码 设备操作记录查询失败
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_OPERATE_RECORD_QUERY_FAIL_MSG = "设备操作记录查询失败";
|
||||
/**
|
||||
* 错误码 设备不在线
|
||||
*/
|
||||
public static final String ERROR_CODE_DEVICE_NOT_ONLINE_MSG = "设备不在线";
|
||||
|
||||
/**----------------------------IOT错误码end----------------------------*/
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.ruoyi.iot.domain.response;
|
||||
|
||||
import com.ruoyi.common.constant.HttpStatus;
|
||||
import com.ruoyi.iot.enums.IotHttpStatus;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Objects;
|
||||
|
@ -17,7 +18,7 @@ public class CommandResponse extends BaseResponse {
|
|||
private String cmdResp;
|
||||
|
||||
public boolean isSuccess() {
|
||||
return Objects.equals(HttpStatus.IOT_SUCCESS, this.getCode());
|
||||
return Objects.equals(IotHttpStatus.SUCCESS.getCode(), this.getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,7 +12,20 @@ import lombok.Getter;
|
|||
public enum IotHttpStatus {
|
||||
|
||||
SUCCESS(0, "成功"),
|
||||
DEVICE_EXIST(10406, "设备已存在");
|
||||
DEVICE_EXIST(10406, "设备已存在"),
|
||||
DEVICE_NON_EXISTENT(10410, "设备不存在"),
|
||||
DEVICE_ATTRIBUTE_SET_FAIL(10411, "设备属性设置失败"),
|
||||
DEVICE_ATTRIBUTE_DESIRE_SET_FAIL(10412, "设备属性期望设置失败"),
|
||||
DEVICE_ATTRIBUTE_DESIRE_QUERY_FAIL(10413, "设备属性期望查询失败"),
|
||||
DEVICE_ATTRIBUTE_DESIRE_GET_FAIL(10414, "设备属性获取失败"),
|
||||
DEVICE_SERVICE_CALL_FAIL(10415, "设备服务调用失败"),
|
||||
DEVICE_ATTRIBUTE_DESIRE_DELETE_FAIL(10416, "设备属性期望删除失败"),
|
||||
DEVICE_NEW_DATA_QUERY_FAIL(10417, "设备最新数据查询失败"),
|
||||
DEVICE_ATTRIBUTE_HISTORY_QUERY_FAIL(10418, "设备属性历史数据查询失败"),
|
||||
DEVICE_EVENT_HISTORY_DATA_QUERY_FAIL(10419, "设备事件历史数据查询失败"),
|
||||
DEVICE_OPERATE_RECORD_QUERY_FAIL(10420, "设备操作记录查询失败"),
|
||||
DEVICE_NOT_ONLINE(10421, "设备不在线"),
|
||||
UNKNOWN_ERROR(null, "未知错误");
|
||||
|
||||
private final Integer code;
|
||||
private final String msg;
|
||||
|
@ -20,4 +33,14 @@ public enum IotHttpStatus {
|
|||
public boolean equalCode(int code) {
|
||||
return this.code == code;
|
||||
}
|
||||
|
||||
// 将code转换为枚举
|
||||
public static IotHttpStatus convertByCode(int code) {
|
||||
for (IotHttpStatus status : IotHttpStatus.values()) {
|
||||
if (status.getCode() == code) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.ruoyi.iot.domain.response.CommandResponse;
|
|||
import com.ruoyi.iot.domain.response.CurrentDataPointResponse;
|
||||
import com.ruoyi.iot.domain.response.DetailResponse;
|
||||
import com.ruoyi.iot.domain.response.HistoryDataPointResponse;
|
||||
import com.ruoyi.iot.enums.IotHttpStatus;
|
||||
import com.ruoyi.iot.util.CommandBuilder;
|
||||
import com.ruoyi.ss.device.domain.Device;
|
||||
import com.ruoyi.ss.device.domain.enums.DeviceOnlineStatus;
|
||||
|
@ -67,7 +68,7 @@ public class IotServiceImpl implements IotService {
|
|||
return DeviceOnlineStatus.OFFLINE;
|
||||
}
|
||||
// CommandResponse response = sendCommand(deviceName, "111");
|
||||
// return HttpStatus.IOT_SUCCESS.equals(response.getCode()) ? DeviceOnlineStatus.ONLINE : DeviceOnlineStatus.OFFLINE;
|
||||
// return IotHttpStatus.SUCCESS.getCode().equals(response.getCode()) ? DeviceOnlineStatus.ONLINE : DeviceOnlineStatus.OFFLINE;
|
||||
|
||||
IotDeviceDetail detail = this.getDeviceDetail(deviceName);
|
||||
if (detail == null) {
|
||||
|
@ -81,16 +82,22 @@ public class IotServiceImpl implements IotService {
|
|||
@Override
|
||||
public boolean open(String deviceName) {
|
||||
CommandResponse response = sendCommand(deviceName, IotConstants.COMMAND_OPEN);
|
||||
ServiceUtil.assertion(!HttpStatus.IOT_SUCCESS.equals(response.getCode()), "通电发生异常:" + response.getMsg());
|
||||
return HttpStatus.IOT_SUCCESS.equals(response.getCode());
|
||||
IotHttpStatus status = IotHttpStatus.convertByCode(response.getCode());
|
||||
if (!IotHttpStatus.SUCCESS.equals(status)) {
|
||||
throw new ServiceException("通电发生异常:" + status.getMsg());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 断电
|
||||
@Override
|
||||
public boolean close(String deviceName) {
|
||||
CommandResponse response = sendCommand(deviceName, IotConstants.COMMAND_CLOSE);
|
||||
ServiceUtil.assertion(!HttpStatus.IOT_SUCCESS.equals(response.getCode()), "断电发生异常:" + response.getMsg());
|
||||
return HttpStatus.IOT_SUCCESS.equals(response.getCode());
|
||||
IotHttpStatus status = IotHttpStatus.convertByCode(response.getCode());
|
||||
if (!IotHttpStatus.SUCCESS.equals(status)) {
|
||||
throw new ServiceException("断电发生异常:" + status.getMsg());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 获取历史设备数据点信息
|
||||
|
@ -109,7 +116,7 @@ public class IotServiceImpl implements IotService {
|
|||
return null;
|
||||
}
|
||||
HistoryDataPointResponse response = JSONObject.parseObject(result, HistoryDataPointResponse.class);
|
||||
if (!HttpStatus.IOT_SUCCESS.equals(response.getCode())) {
|
||||
if (!IotHttpStatus.SUCCESS.getCode().equals(response.getCode())) {
|
||||
log.error("获取历史设备数据点信息出错:" + response.getMsg());
|
||||
return null;
|
||||
}
|
||||
|
@ -130,7 +137,7 @@ public class IotServiceImpl implements IotService {
|
|||
return Collections.emptyList();
|
||||
}
|
||||
CurrentDataPointResponse response = JSONObject.parseObject(result, CurrentDataPointResponse.class);
|
||||
if (!HttpStatus.IOT_SUCCESS.equals(response.getCode())) {
|
||||
if (!IotHttpStatus.SUCCESS.getCode().equals(response.getCode())) {
|
||||
log.error("获取当前设备数据点信息出错:" + response.getMsg());
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
@ -162,7 +169,7 @@ public class IotServiceImpl implements IotService {
|
|||
return null;
|
||||
}
|
||||
DetailResponse response = JSONObject.parseObject(result, DetailResponse.class);
|
||||
if (!HttpStatus.IOT_SUCCESS.equals(response.getCode())) {
|
||||
if (!IotHttpStatus.SUCCESS.getCode().equals(response.getCode())) {
|
||||
log.error("获取当前设备数据点信息出错:{}", response.getMsg());
|
||||
return null;
|
||||
}
|
||||
|
@ -204,7 +211,7 @@ public class IotServiceImpl implements IotService {
|
|||
.setIfNull(IotConstants.COMMAND_OUTAGE_WAY, deviceOutageWay.getValue() , DeviceOutageWay.IMMEDIATE.getValue())
|
||||
.build();
|
||||
CommandResponse response = sendCommand(device.getMac(), command);
|
||||
ServiceUtil.assertion(!Objects.equals(HttpStatus.IOT_SUCCESS, response.getCode()), "修改设备设置发生异常:" + response.getMsg());
|
||||
ServiceUtil.assertion(!Objects.equals(IotHttpStatus.SUCCESS.getCode(), response.getCode()), "修改设备设置发生异常:" + response.getMsg());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user