Merge remote-tracking branch 'yudao/feature/iot' into iot

This commit is contained in:
puhui999
2024-12-16 10:51:02 +08:00
58 changed files with 2533 additions and 265 deletions

View File

@@ -13,4 +13,7 @@ public class DictTypeConstants {
public static final String PROTOCOL_TYPE = "iot_protocol_type";
public static final String DATA_FORMAT = "iot_data_format";
public static final String VALIDATE_TYPE = "iot_validate_type";
public static final String DEVICE_STATUS = "iot_device_status";
}

View File

@@ -26,11 +26,26 @@ public interface ErrorCodeConstants {
ErrorCode DEVICE_NOT_EXISTS = new ErrorCode(1_050_003_000, "设备不存在");
ErrorCode DEVICE_NAME_EXISTS = new ErrorCode(1_050_003_001, "设备名称在同一产品下必须唯一");
ErrorCode DEVICE_HAS_CHILDREN = new ErrorCode(1_050_003_002, "有子设备,不允许删除");
ErrorCode DEVICE_NAME_CANNOT_BE_MODIFIED = new ErrorCode(1_050_003_003, "设备名称不能修改");
ErrorCode DEVICE_PRODUCT_CANNOT_BE_MODIFIED = new ErrorCode(1_050_003_004, "产品不能修改");
ErrorCode DEVICE_INVALID_DEVICE_STATUS = new ErrorCode(1_050_003_005, "无效的设备状态");
ErrorCode DEVICE_KEY_EXISTS = new ErrorCode(1_050_003_003, "设备标识已经存在");
ErrorCode DEVICE_GATEWAY_NOT_EXISTS = new ErrorCode(1_050_003_004, "网关设备不存在");
ErrorCode DEVICE_NOT_GATEWAY = new ErrorCode(1_050_003_005, "设备不是网关设备");
ErrorCode DEVICE_IMPORT_LIST_IS_EMPTY = new ErrorCode(1_050_003_006, "导入设备数据不能为空!");
// ========== 产品分类 1-050-004-000 ==========
ErrorCode PRODUCT_CATEGORY_NOT_EXISTS = new ErrorCode(1_050_004_000, "产品分类不存在");
}
// ========== 设备分组 1-050-005-000 ==========
ErrorCode DEVICE_GROUP_NOT_EXISTS = new ErrorCode(1_050_005_000, "设备分组不存在");
ErrorCode DEVICE_GROUP_DELETE_FAIL_DEVICE_EXISTS = new ErrorCode(1_050_005_001, "设备分组下存在设备,不允许删除");
// ========== 插件信息 1-050-006-000 ==========
ErrorCode PLUGIN_INFO_NOT_EXISTS = new ErrorCode(1_050_006_000, "插件信息不存在");
ErrorCode PLUGIN_INSTALL_FAILED = new ErrorCode(1_050_006_001, "插件安装失败");
ErrorCode PLUGIN_INSTALL_FAILED_FILE_NAME_NOT_MATCH = new ErrorCode(1_050_006_002, "插件安装失败文件名与原插件id不匹配");
ErrorCode PLUGIN_INFO_DELETE_FAILED_RUNNING = new ErrorCode(1_050_006_003, "请先停止插件");
ErrorCode PLUGIN_STATUS_INVALID = new ErrorCode(1_050_006_004, "插件状态无效");
// ========== 插件实例 1-050-007-000 ==========
ErrorCode PLUGIN_INSTANCE_NOT_EXISTS = new ErrorCode(1_050_007_000, "插件实例不存在");
}

View File

@@ -0,0 +1,53 @@
package cn.iocoder.yudao.module.iot.enums.plugin;
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
import lombok.Getter;
import java.util.Arrays;
/**
* IoT 部署方式枚举
*
* @author haohao
*/
@Getter
public enum IotPluginDeployTypeEnum implements IntArrayValuable {
UPLOAD(0, "上传 jar"), // TODO @haohaoUPLOAD 和 ALONE 感觉有点冲突,前者是部署方式,后者是运行方式。这个后续再讨论下哈
ALONE(1, "独立运行");
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotPluginDeployTypeEnum::getDeployType).toArray();
/**
* 部署方式
*/
private final Integer deployType;
/**
* 部署方式名
*/
private final String name;
IotPluginDeployTypeEnum(Integer deployType, String name) {
this.deployType = deployType;
this.name = name;
}
public static IotPluginDeployTypeEnum fromDeployType(Integer deployType) {
for (IotPluginDeployTypeEnum value : values()) {
if (value.getDeployType().equals(deployType)) {
return value;
}
}
return null;
}
public static boolean isValidDeployType(Integer deployType) {
return fromDeployType(deployType) != null;
}
@Override
public int[] array() {
return ARRAYS;
}
}

View File

@@ -0,0 +1,58 @@
package cn.iocoder.yudao.module.iot.enums.plugin;
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
import lombok.Getter;
import java.util.Arrays;
/**
* IoT 插件状态枚举
*
* @author haohao
*/
@Getter
public enum IotPluginStatusEnum implements IntArrayValuable {
STOPPED(0, "停止"),
RUNNING(1, "运行");
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotPluginStatusEnum::getStatus).toArray();
/**
* 状态
*/
private final Integer status;
/**
* 状态名
*/
private final String name;
IotPluginStatusEnum(Integer status, String name) {
this.status = status;
this.name = name;
}
public static IotPluginStatusEnum fromState(Integer state) {
for (IotPluginStatusEnum value : values()) {
if (value.getStatus().equals(state)) {
return value;
}
}
return null;
}
@Override
public int[] array() {
return ARRAYS;
}
public static boolean isValidState(Integer state) {
return fromState(state) != null;
}
public static boolean contains(Integer status) {
return Arrays.stream(values()).anyMatch(e -> e.getStatus().equals(status));
}
}

View File

@@ -0,0 +1,52 @@
package cn.iocoder.yudao.module.iot.enums.plugin;
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
/**
* IoT 插件类型枚举
*
* @author haohao
*/
@AllArgsConstructor
@Getter
public enum IotPluginTypeEnum implements IntArrayValuable {
NORMAL(0, "普通插件"),
DEVICE(1, "设备插件");
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotPluginTypeEnum::getType).toArray();
/**
* 类型
*/
private final Integer type;
/**
* 类型名
*/
private final String name;
@Override
public int[] array() {
return ARRAYS;
}
// TODO @haohao可以使用 hutool 简化
public static IotPluginTypeEnum fromType(Integer type) {
for (IotPluginTypeEnum value : values()) {
if (value.getType().equals(type)) {
return value;
}
}
return null;
}
public static boolean isValidType(Integer type) {
return fromType(type) != null;
}
}

View File

@@ -36,4 +36,14 @@ public enum IotProductDeviceTypeEnum implements IntArrayValuable {
return ARRAYS;
}
/**
* 判断是否是网关
*
* @param type 类型
* @return 是否是网关
*/
public static boolean isGateway(Integer type) {
return GATEWAY.getType().equals(type);
}
}