【功能完善】IoT: 产品物模型属性相关
This commit is contained in:
parent
c5894765b5
commit
f930f31fab
|
@ -1,13 +1,13 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction;
|
||||
package cn.iocoder.yudao.module.iot.controller.admin.productthingmodel;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionPageReqVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionRespVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionSaveReqVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.vo.IotThinkModelFunctionPageReqVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.vo.IotThinkModelFunctionRespVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.vo.IotThinkModelFunctionSaveReqVO;
|
||||
import cn.iocoder.yudao.module.iot.convert.thinkmodelfunction.IotThinkModelFunctionConvert;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.productthingmodel.IotProductThingModelDO;
|
||||
import cn.iocoder.yudao.module.iot.service.thinkmodelfunction.IotThinkModelFunctionService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
|
@ -26,7 +26,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|||
@RestController
|
||||
@RequestMapping("/iot/think-model-function")
|
||||
@Validated
|
||||
public class IotThinkModelFunctionController {
|
||||
public class IotProductThingModelController {
|
||||
|
||||
@Resource
|
||||
private IotThinkModelFunctionService thinkModelFunctionService;
|
||||
|
@ -60,7 +60,7 @@ public class IotThinkModelFunctionController {
|
|||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('iot:think-model-function:query')")
|
||||
public CommonResult<IotThinkModelFunctionRespVO> getThinkModelFunction(@RequestParam("id") Long id) {
|
||||
IotThinkModelFunctionDO function = thinkModelFunctionService.getThinkModelFunction(id);
|
||||
IotProductThingModelDO function = thinkModelFunctionService.getThinkModelFunction(id);
|
||||
return success(IotThinkModelFunctionConvert.INSTANCE.convert(function));
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ public class IotThinkModelFunctionController {
|
|||
@Parameter(name = "productId", description = "产品ID", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('iot:think-model-function:query')")
|
||||
public CommonResult<List<IotThinkModelFunctionRespVO>> getThinkModelFunctionListByProductId(@RequestParam("productId") Long productId) {
|
||||
List<IotThinkModelFunctionDO> list = thinkModelFunctionService.getThinkModelFunctionListByProductId(productId);
|
||||
List<IotProductThingModelDO> list = thinkModelFunctionService.getThinkModelFunctionListByProductId(productId);
|
||||
return success(IotThinkModelFunctionConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class IotThinkModelFunctionController {
|
|||
@Operation(summary = "获得产品物模型分页")
|
||||
@PreAuthorize("@ss.hasPermission('iot:think-model-function:query')")
|
||||
public CommonResult<PageResult<IotThinkModelFunctionRespVO>> getThinkModelFunctionPage(@Valid IotThinkModelFunctionPageReqVO pageReqVO) {
|
||||
PageResult<IotThinkModelFunctionDO> pageResult = thinkModelFunctionService.getThinkModelFunctionPage(pageReqVO);
|
||||
PageResult<IotProductThingModelDO> pageResult = thinkModelFunctionService.getThinkModelFunctionPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, IotThinkModelFunctionRespVO.class));
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel;
|
||||
package cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType.ThingModelArgument;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.dataType.ThingModelArgument;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.dataType.ThingModelDataSpecs;
|
||||
import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelAccessModeEnum;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 物模型中的属性
|
||||
*
|
||||
* dataSpecs 和 dataSpecsList 之中必须传入且只能传入一个
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@Data
|
||||
public class ThingModelProperty {
|
||||
|
||||
/**
|
||||
* 属性标识符
|
||||
*/
|
||||
private String identifier;
|
||||
/**
|
||||
* 属性名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 属性描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 云端可以对该属性进行的操作类型
|
||||
* 关联枚举 {@link IotProductThingModelAccessModeEnum}
|
||||
*/
|
||||
private String accessMode;
|
||||
/**
|
||||
* 是否是标准品类的必选服务。
|
||||
*
|
||||
* - true:是
|
||||
* - false:否
|
||||
*/
|
||||
private Boolean required;
|
||||
/**
|
||||
* 数据类型,与 dataSpecs 的 dataType 保持一致
|
||||
*/
|
||||
private String dataType;
|
||||
/**
|
||||
* 数据类型(dataType)为非列表型(int、float、double、text、date、array)的数据规范存储在 dataSpecs 中
|
||||
*/
|
||||
private ThingModelDataSpecs dataSpecs;
|
||||
/**
|
||||
* 数据类型(dataType)为列表型(enum、bool、struct)的数据规范存储在 dataSpecsList 中
|
||||
*/
|
||||
private List<ThingModelDataSpecs> dataSpecsList;
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel;
|
||||
package cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel;
|
||||
|
||||
import lombok.*;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel;
|
||||
package cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType.ThingModelArgument;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.dataType.ThingModelArgument;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType;
|
||||
package cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.dataType;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
|
@ -7,7 +7,7 @@ public class ThingModelArgument {
|
|||
|
||||
private String identifier;
|
||||
private String name;
|
||||
private ThingModelDataType dataType;
|
||||
private ThingModelDataSpecs dataType;
|
||||
/**
|
||||
* 用于区分输入或输出参数,"input" 或 "output"
|
||||
*/
|
|
@ -0,0 +1,35 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.dataType;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 物模型数据类型为数组的 DataSpec 定义
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@Data
|
||||
public class ThingModelArrayDataSpecs extends ThingModelDataSpecs {
|
||||
|
||||
/**
|
||||
* 数组中的元素个数。
|
||||
*/
|
||||
private Long size;
|
||||
/**
|
||||
* 数组中的元素的数据类型。可选值:struct、int、float、double 或 text。
|
||||
*/
|
||||
private String childDataType;
|
||||
/**
|
||||
* 数据类型(dataType)为非列表型(int、float、double、text、date、array)的数据规范存储在 dataSpecs 中。
|
||||
* 仅当 dataType 不是列表型时,才传入此字段。
|
||||
*/
|
||||
private ThingModelDataSpecs dataSpecs;
|
||||
/**
|
||||
* 数据类型(dataType)为列表型(enum、bool、struct)的数据规范存储在 dataSpecsList 中。
|
||||
* 仅当 dataType 是列表型时,才传入此字段。
|
||||
*/
|
||||
private List<ThingModelDataSpecs> dataSpecsList;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.dataType;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 物模型数据类型为布尔型或枚举型的 DataSpec 定义
|
||||
*
|
||||
* 数据类型,取值为 bool 或 enum。
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ThingModelBoolOrEnumDataSpecs extends ThingModelDataSpecs {
|
||||
|
||||
/**
|
||||
* 枚举项的名称。
|
||||
* 可包含中文、大小写英文字母、数字、下划线(_)和短划线(-)。
|
||||
* 必须以中文、英文字母或数字开头,长度不超过 20 个字符。
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 枚举值。
|
||||
*/
|
||||
private Integer value;
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.dataType;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 抽象类 ThingModelDataSpecs
|
||||
*
|
||||
* 用于表示物模型数据的通用类型,根据具体的 "dataType" 字段动态映射到对应的子类。
|
||||
* 提供多态支持,适用于不同类型的数据结构序列化和反序列化场景。
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@Data
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "dataType", visible = true)
|
||||
@JsonSubTypes({
|
||||
@JsonSubTypes.Type(value = ThingModelNumericDataSpec.class, name = "int"),
|
||||
@JsonSubTypes.Type(value = ThingModelNumericDataSpec.class, name = "float"),
|
||||
@JsonSubTypes.Type(value = ThingModelNumericDataSpec.class, name = "double"),
|
||||
@JsonSubTypes.Type(value = ThingModelDateOrTextDataSpecs.class, name = "text"),
|
||||
@JsonSubTypes.Type(value = ThingModelDateOrTextDataSpecs.class, name = "date"),
|
||||
@JsonSubTypes.Type(value = ThingModelBoolOrEnumDataSpecs.class, name = "bool"),
|
||||
@JsonSubTypes.Type(value = ThingModelBoolOrEnumDataSpecs.class, name = "enum"),
|
||||
@JsonSubTypes.Type(value = ThingModelArrayDataSpecs.class, name = "array")
|
||||
})
|
||||
public abstract class ThingModelDataSpecs {
|
||||
|
||||
/**
|
||||
* 数据类型
|
||||
*/
|
||||
private String dataType;
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.dataType;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 物模型数据类型为时间型或文本型的 DataSpec 定义
|
||||
*
|
||||
* 数据类型,取值为 date 或 text。
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@Data
|
||||
public class ThingModelDateOrTextDataSpecs extends ThingModelDataSpecs {
|
||||
|
||||
/**
|
||||
* 数据长度,单位为字节。取值不能超过 2048。
|
||||
* 当 dataType 为 text 时,需传入该参数。
|
||||
*/
|
||||
private Long length;
|
||||
/**
|
||||
* 默认值,可选参数,用于存储默认值。
|
||||
*/
|
||||
private String defaultValue;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.dataType;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 物模型数据类型为数值的 DataSpec 定义
|
||||
*
|
||||
* 数据类型,取值为 int、float 或 double。
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@Data
|
||||
public class ThingModelNumericDataSpec extends ThingModelDataSpecs {
|
||||
|
||||
/**
|
||||
* 最大值,需转为字符串类型。值必须与 dataType 类型一致。
|
||||
* 例如,当 dataType 为 int 时,取值为 "200",而不是 200。
|
||||
*/
|
||||
private String max;
|
||||
/**
|
||||
* 最小值,需转为字符串类型。值必须与 dataType 类型一致。
|
||||
* 例如,当 dataType 为 int 时,取值为 "0",而不是 0。
|
||||
*/
|
||||
private String min;
|
||||
/**
|
||||
* 步长,需转为字符串类型。值必须与 dataType 类型一致。
|
||||
* 例如,当 dataType 为 int 时,取值为 "10",而不是 10。
|
||||
*/
|
||||
private String step;
|
||||
/**
|
||||
* 精度。当 dataType 为 float 或 double 时可选传入。
|
||||
*/
|
||||
private String precise;
|
||||
/**
|
||||
* 默认值,可传入用于存储的默认值。
|
||||
*/
|
||||
private String defaultValue;
|
||||
/**
|
||||
* 单位的符号。
|
||||
*/
|
||||
private String unit;
|
||||
/**
|
||||
* 单位的名称。
|
||||
*/
|
||||
private String unitName;
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo;
|
||||
package cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
|
@ -1,8 +1,8 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo;
|
||||
package cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.vo;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelEvent;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelProperty;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelService;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.ThingModelEvent;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.ThingModelProperty;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.ThingModelService;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
@ -1,9 +1,9 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo;
|
||||
package cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelEvent;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelProperty;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelService;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.ThingModelEvent;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.ThingModelProperty;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.ThingModelService;
|
||||
import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelTypeEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
|
@ -1,29 +0,0 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType.ThingModelDataType;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ThingModelProperty {
|
||||
|
||||
/**
|
||||
* 属性标识符
|
||||
*/
|
||||
private String identifier;
|
||||
/**
|
||||
* 属性名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 属性描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
private String accessMode; // "rw"、"r"、"w"
|
||||
private Boolean required;
|
||||
private ThingModelDataType dataSpecs;
|
||||
private List<ThingModelDataType> dataSpecsList;
|
||||
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ThingModelArraySpecs {
|
||||
|
||||
/**
|
||||
* 数组长度
|
||||
*/
|
||||
private int size;
|
||||
/**
|
||||
* 数组元素的类型
|
||||
*/
|
||||
private ThingModelDataType item;
|
||||
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
// TODO @haohao:这个是不是和别的类,不太统一哈
|
||||
@Data
|
||||
public class ThingModelArrayType extends ThingModelDataType {
|
||||
|
||||
private ThingModelArraySpecs specs;
|
||||
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ThingModelBoolType extends ThingModelDataType {
|
||||
|
||||
// Bool 类型一般不需要额外的 specs
|
||||
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "dataType", visible = true)
|
||||
@JsonSubTypes({
|
||||
@JsonSubTypes.Type(value = ThingModelIntType.class, name = "int"),
|
||||
@JsonSubTypes.Type(value = ThingModelFloatType.class, name = "float"),
|
||||
@JsonSubTypes.Type(value = ThingModelDoubleType.class, name = "double"),
|
||||
@JsonSubTypes.Type(value = ThingModelTextType.class, name = "text"),
|
||||
@JsonSubTypes.Type(value = ThingModelDateType.class, name = "date"),
|
||||
@JsonSubTypes.Type(value = ThingModelBoolType.class, name = "bool"),
|
||||
@JsonSubTypes.Type(value = ThingModelEnumType.class, name = "enum"),
|
||||
@JsonSubTypes.Type(value = ThingModelStructType.class, name = "struct"),
|
||||
@JsonSubTypes.Type(value = ThingModelArrayType.class, name = "array")
|
||||
})
|
||||
public abstract class ThingModelDataType {
|
||||
|
||||
private String dataType;
|
||||
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ThingModelDateType extends ThingModelDataType {
|
||||
|
||||
// Date 类型一般不需要额外的 specs
|
||||
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ThingModelDoubleType extends ThingModelDataType {
|
||||
private ThingModelDoubleSpecs specs;
|
||||
}
|
||||
|
||||
@Data
|
||||
class ThingModelDoubleSpecs {
|
||||
|
||||
private Double min;
|
||||
private Double max;
|
||||
private Double step;
|
||||
private String unit;
|
||||
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class ThingModelEnumType extends ThingModelDataType {
|
||||
|
||||
/**
|
||||
* 枚举值和描述的键值对
|
||||
*/
|
||||
private Map<String, String> specs;
|
||||
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ThingModelFloatType extends ThingModelDataType {
|
||||
private ThingModelFloatSpecs specs;
|
||||
}
|
||||
|
||||
@Data
|
||||
class ThingModelFloatSpecs {
|
||||
|
||||
private Float min;
|
||||
private Float max;
|
||||
private Float step;
|
||||
private String unit;
|
||||
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ThingModelIntType extends ThingModelDataType {
|
||||
private ThingModelIntSpecs specs;
|
||||
}
|
||||
|
||||
@Data
|
||||
class ThingModelIntSpecs {
|
||||
|
||||
private Integer min;
|
||||
private Integer max;
|
||||
private Integer step;
|
||||
private String unit;
|
||||
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ThingModelStructField {
|
||||
|
||||
private String identifier;
|
||||
private String name;
|
||||
private ThingModelDataType dataType;
|
||||
private String description;
|
||||
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ThingModelStructType extends ThingModelDataType {
|
||||
|
||||
private List<ThingModelStructField> specs;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ThingModelTextType extends ThingModelDataType {
|
||||
|
||||
private ThingModelTextSpecs specs;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
class ThingModelTextSpecs {
|
||||
|
||||
/**
|
||||
* 最大长度
|
||||
*/
|
||||
private Integer length;
|
||||
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
package cn.iocoder.yudao.module.iot.convert.thinkmodelfunction;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelEvent;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelProperty;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelService;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionRespVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionSaveReqVO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.ThingModelEvent;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.ThingModelProperty;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.ThingModelService;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.vo.IotThinkModelFunctionRespVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.vo.IotThinkModelFunctionSaveReqVO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.productthingmodel.IotProductThingModelDO;
|
||||
import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelTypeEnum;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
|
@ -23,7 +23,7 @@ public interface IotThinkModelFunctionConvert {
|
|||
@Mapping(target = "property", expression = "java(convertToProperty(bean))")
|
||||
@Mapping(target = "event", expression = "java(convertToEvent(bean))")
|
||||
@Mapping(target = "service", expression = "java(convertToService(bean))")
|
||||
IotThinkModelFunctionDO convert(IotThinkModelFunctionSaveReqVO bean);
|
||||
IotProductThingModelDO convert(IotThinkModelFunctionSaveReqVO bean);
|
||||
|
||||
default ThingModelProperty convertToProperty(IotThinkModelFunctionSaveReqVO bean) {
|
||||
if (Objects.equals(bean.getType(), IotProductThingModelTypeEnum.PROPERTY.getType())) {
|
||||
|
@ -50,8 +50,8 @@ public interface IotThinkModelFunctionConvert {
|
|||
@Mapping(target = "property", source = "property")
|
||||
@Mapping(target = "event", source = "event")
|
||||
@Mapping(target = "service", source = "service")
|
||||
IotThinkModelFunctionRespVO convert(IotThinkModelFunctionDO bean);
|
||||
IotThinkModelFunctionRespVO convert(IotProductThingModelDO bean);
|
||||
|
||||
// 批量转换
|
||||
List<IotThinkModelFunctionRespVO> convertList(List<IotThinkModelFunctionDO> list);
|
||||
List<IotThinkModelFunctionRespVO> convertList(List<IotProductThingModelDO> list);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package cn.iocoder.yudao.module.iot.dal.dataobject.device;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.productthingmodel.IotProductThingModelDO;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
@ -30,7 +30,7 @@ public class IotDeviceDataDO {
|
|||
/**
|
||||
* 物模型编号
|
||||
* <p>
|
||||
* 关联 {@link IotThinkModelFunctionDO#getId()}
|
||||
* 关联 {@link IotProductThingModelDO#getId()}
|
||||
*/
|
||||
private Long thinkModelFunctionId;
|
||||
|
||||
|
@ -51,21 +51,21 @@ public class IotDeviceDataDO {
|
|||
/**
|
||||
* 属性标识符
|
||||
* <p>
|
||||
* 关联 {@link IotThinkModelFunctionDO#getIdentifier()}
|
||||
* 关联 {@link IotProductThingModelDO#getIdentifier()}
|
||||
*/
|
||||
private String identifier;
|
||||
|
||||
/**
|
||||
* 属性名称
|
||||
* <p>
|
||||
* 关联 {@link IotThinkModelFunctionDO#getName()}
|
||||
* 关联 {@link IotProductThingModelDO#getName()}
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 数据类型
|
||||
* <p>
|
||||
* 关联 {@link IotThinkModelFunctionDO#getProperty()#getDataType()}
|
||||
* 关联 {@link IotProductThingModelDO#getProperty()#getDataType()}
|
||||
*/
|
||||
private String dataType;
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction;
|
||||
package cn.iocoder.yudao.module.iot.dal.dataobject.productthingmodel;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelEvent;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelProperty;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelService;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.ThingModelEvent;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.ThingModelProperty;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.ThingModelService;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
|
||||
import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelTypeEnum;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
|
@ -19,7 +19,7 @@ import lombok.NoArgsConstructor;
|
|||
/**
|
||||
* IoT 产品物模型功能 DO
|
||||
* <p>
|
||||
* 每个 {@link IotProductDO} 和 {@link IotThinkModelFunctionDO} 是“一对多”的关系,它的每个属性、事件、服务都对应一条记录
|
||||
* 每个 {@link IotProductDO} 和 {@link IotProductThingModelDO} 是“一对多”的关系,它的每个属性、事件、服务都对应一条记录
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
|
@ -29,7 +29,7 @@ import lombok.NoArgsConstructor;
|
|||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class IotThinkModelFunctionDO extends BaseDO {
|
||||
public class IotProductThingModelDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 物模型功能编号
|
|
@ -1,8 +1,8 @@
|
|||
package cn.iocoder.yudao.module.iot.dal.dataobject.tdengine;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelProperty;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelRespVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType.ThingModelDataType;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.ThingModelProperty;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.ThingModelRespVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.dataType.ThingModelDataSpecs;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -36,17 +36,19 @@ public class FieldParser {
|
|||
*/
|
||||
public static TdFieldDO parse(ThingModelProperty property) {
|
||||
String fieldName = property.getIdentifier().toLowerCase();
|
||||
ThingModelDataType type = property.getDataType();
|
||||
|
||||
// 将物模型字段类型映射为td字段类型
|
||||
String fType = TYPE_MAPPING.get(type.getDataType().toUpperCase());
|
||||
|
||||
// 如果字段类型为NCHAR,默认长度为64
|
||||
int dataLength = 0;
|
||||
if ("NCHAR".equals(fType)) {
|
||||
dataLength = 64;
|
||||
}
|
||||
return new TdFieldDO(fieldName, fType, dataLength);
|
||||
//// TODO @puhui999: 需要重构
|
||||
//ThingModelDataSpecs type = property.getDataType();
|
||||
//
|
||||
//// 将物模型字段类型映射为td字段类型
|
||||
//String fType = TYPE_MAPPING.get(type.getDataType().toUpperCase());
|
||||
//
|
||||
//// 如果字段类型为NCHAR,默认长度为64
|
||||
//int dataLength = 0;
|
||||
//if ("NCHAR".equals(fType)) {
|
||||
// dataLength = 64;
|
||||
//}
|
||||
//return new TdFieldDO(fieldName, fType, dataLength);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,8 +3,8 @@ package cn.iocoder.yudao.module.iot.dal.mysql.thinkmodelfunction;
|
|||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionPageReqVO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.vo.IotThinkModelFunctionPageReqVO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.productthingmodel.IotProductThingModelDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -15,48 +15,48 @@ import java.util.List;
|
|||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface IotThinkModelFunctionMapper extends BaseMapperX<IotThinkModelFunctionDO> {
|
||||
public interface IotThinkModelFunctionMapper extends BaseMapperX<IotProductThingModelDO> {
|
||||
|
||||
default PageResult<IotThinkModelFunctionDO> selectPage(IotThinkModelFunctionPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<IotThinkModelFunctionDO>()
|
||||
.eqIfPresent(IotThinkModelFunctionDO::getIdentifier, reqVO.getIdentifier())
|
||||
.likeIfPresent(IotThinkModelFunctionDO::getName, reqVO.getName())
|
||||
.eqIfPresent(IotThinkModelFunctionDO::getType, reqVO.getType())
|
||||
.eqIfPresent(IotThinkModelFunctionDO::getProductId, reqVO.getProductId())
|
||||
.notIn(IotThinkModelFunctionDO::getIdentifier, "get", "set", "post")
|
||||
.orderByDesc(IotThinkModelFunctionDO::getId));
|
||||
default PageResult<IotProductThingModelDO> selectPage(IotThinkModelFunctionPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<IotProductThingModelDO>()
|
||||
.eqIfPresent(IotProductThingModelDO::getIdentifier, reqVO.getIdentifier())
|
||||
.likeIfPresent(IotProductThingModelDO::getName, reqVO.getName())
|
||||
.eqIfPresent(IotProductThingModelDO::getType, reqVO.getType())
|
||||
.eqIfPresent(IotProductThingModelDO::getProductId, reqVO.getProductId())
|
||||
.notIn(IotProductThingModelDO::getIdentifier, "get", "set", "post")
|
||||
.orderByDesc(IotProductThingModelDO::getId));
|
||||
}
|
||||
|
||||
default IotThinkModelFunctionDO selectByProductIdAndIdentifier(Long productId, String identifier) {
|
||||
return selectOne(IotThinkModelFunctionDO::getProductId, productId,
|
||||
IotThinkModelFunctionDO::getIdentifier, identifier);
|
||||
default IotProductThingModelDO selectByProductIdAndIdentifier(Long productId, String identifier) {
|
||||
return selectOne(IotProductThingModelDO::getProductId, productId,
|
||||
IotProductThingModelDO::getIdentifier, identifier);
|
||||
}
|
||||
|
||||
default List<IotThinkModelFunctionDO> selectListByProductId(Long productId) {
|
||||
return selectList(IotThinkModelFunctionDO::getProductId, productId);
|
||||
default List<IotProductThingModelDO> selectListByProductId(Long productId) {
|
||||
return selectList(IotProductThingModelDO::getProductId, productId);
|
||||
}
|
||||
|
||||
default List<IotThinkModelFunctionDO> selectListByProductIdAndType(Long productId, Integer type) {
|
||||
return selectList(IotThinkModelFunctionDO::getProductId, productId,
|
||||
IotThinkModelFunctionDO::getType, type);
|
||||
default List<IotProductThingModelDO> selectListByProductIdAndType(Long productId, Integer type) {
|
||||
return selectList(IotProductThingModelDO::getProductId, productId,
|
||||
IotProductThingModelDO::getType, type);
|
||||
}
|
||||
|
||||
default List<IotThinkModelFunctionDO> selectListByProductIdAndIdentifiersAndTypes(Long productId,
|
||||
List<String> identifiers,
|
||||
List<Integer> types) {
|
||||
return selectList(new LambdaQueryWrapperX<IotThinkModelFunctionDO>()
|
||||
.eq(IotThinkModelFunctionDO::getProductId, productId)
|
||||
.in(IotThinkModelFunctionDO::getIdentifier, identifiers)
|
||||
.in(IotThinkModelFunctionDO::getType, types));
|
||||
default List<IotProductThingModelDO> selectListByProductIdAndIdentifiersAndTypes(Long productId,
|
||||
List<String> identifiers,
|
||||
List<Integer> types) {
|
||||
return selectList(new LambdaQueryWrapperX<IotProductThingModelDO>()
|
||||
.eq(IotProductThingModelDO::getProductId, productId)
|
||||
.in(IotProductThingModelDO::getIdentifier, identifiers)
|
||||
.in(IotProductThingModelDO::getType, types));
|
||||
}
|
||||
|
||||
default IotThinkModelFunctionDO selectByProductIdAndName(Long productId, String name) {
|
||||
return selectOne(IotThinkModelFunctionDO::getProductId, productId,
|
||||
IotThinkModelFunctionDO::getName, name);
|
||||
default IotProductThingModelDO selectByProductIdAndName(Long productId, String name) {
|
||||
return selectOne(IotProductThingModelDO::getProductId, productId,
|
||||
IotProductThingModelDO::getName, name);
|
||||
}
|
||||
|
||||
default List<IotThinkModelFunctionDO> selectListByProductKey(String productKey) {
|
||||
return selectList(IotThinkModelFunctionDO::getProductKey, productKey);
|
||||
default List<IotProductThingModelDO> selectListByProductKey(String productKey) {
|
||||
return selectList(IotProductThingModelDO::getProductKey, productKey);
|
||||
}
|
||||
|
||||
}
|
|
@ -7,9 +7,9 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|||
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataPageReqVO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDataDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.productthingmodel.IotProductThingModelDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.SelectVisualDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessage;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.redis.deviceData.DeviceDataRedisDAO;
|
||||
import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDMLMapper;
|
||||
import cn.iocoder.yudao.module.iot.enums.IotConstants;
|
||||
|
@ -73,7 +73,7 @@ public class IotDeviceDataServiceImpl implements IotDeviceDataService {
|
|||
// 1. 获取设备信息
|
||||
IotDeviceDO device = deviceService.getDevice(deviceDataReqVO.getDeviceId());
|
||||
// 2. 获取设备属性最新数据
|
||||
List<IotThinkModelFunctionDO> thinkModelFunctionList = thinkModelFunctionService.getThinkModelFunctionListByProductKey(device.getProductKey());
|
||||
List<IotProductThingModelDO> thinkModelFunctionList = thinkModelFunctionService.getThinkModelFunctionListByProductKey(device.getProductKey());
|
||||
thinkModelFunctionList = thinkModelFunctionList.stream()
|
||||
.filter(function -> IotProductThingModelTypeEnum.PROPERTY.getType()
|
||||
.equals(function.getType())).toList();
|
||||
|
@ -90,6 +90,7 @@ public class IotDeviceDataServiceImpl implements IotDeviceDataService {
|
|||
.toList();
|
||||
}
|
||||
// 4. 获取设备属性最新数据
|
||||
// TODO @puhui999: 需要重构
|
||||
thinkModelFunctionList.forEach(function -> {
|
||||
IotDeviceDataDO deviceData = deviceDataRedisDAO.get(device.getProductKey(), device.getDeviceName(), function.getIdentifier());
|
||||
if (deviceData == null) {
|
||||
|
@ -100,7 +101,7 @@ public class IotDeviceDataServiceImpl implements IotDeviceDataService {
|
|||
deviceData.setDeviceId(deviceDataReqVO.getDeviceId());
|
||||
deviceData.setThinkModelFunctionId(function.getId());
|
||||
deviceData.setName(function.getName());
|
||||
deviceData.setDataType(function.getProperty().getDataType().getDataType());
|
||||
//deviceData.setDataType(function.getProperty().getDataType().getDataType());
|
||||
}
|
||||
list.add(deviceData);
|
||||
});
|
||||
|
|
|
@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.iot.service.tdengine;
|
|||
|
||||
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.productthingmodel.IotProductThingModelDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -14,5 +14,5 @@ public interface IotSuperTableService {
|
|||
/**
|
||||
* 创建超级表数据模型
|
||||
*/
|
||||
void createSuperTableDataModel(IotProductDO product, List<IotThinkModelFunctionDO> functionList);
|
||||
void createSuperTableDataModel(IotProductDO product, List<IotProductThingModelDO> functionList);
|
||||
}
|
|
@ -2,13 +2,13 @@ package cn.iocoder.yudao.module.iot.service.tdengine;
|
|||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelProperty;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelRespVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.ThingModelProperty;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.ThingModelRespVO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.FieldParser;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TdFieldDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TdTableDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.productthingmodel.IotProductThingModelDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDDLMapper;
|
||||
import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelTypeEnum;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -33,7 +33,7 @@ public class IotSuperTableServiceImpl implements IotSuperTableService {
|
|||
private String url;
|
||||
|
||||
@Override
|
||||
public void createSuperTableDataModel(IotProductDO product, List<IotThinkModelFunctionDO> functionList) {
|
||||
public void createSuperTableDataModel(IotProductDO product, List<IotProductThingModelDO> functionList) {
|
||||
ThingModelRespVO thingModel = buildThingModel(product, functionList);
|
||||
|
||||
if (thingModel.getModel() == null || CollUtil.isEmpty(thingModel.getModel().getProperties())) {
|
||||
|
@ -210,7 +210,7 @@ public class IotSuperTableServiceImpl implements IotSuperTableService {
|
|||
/**
|
||||
* 构建物模型
|
||||
*/
|
||||
private ThingModelRespVO buildThingModel(IotProductDO product, List<IotThinkModelFunctionDO> functionList) {
|
||||
private ThingModelRespVO buildThingModel(IotProductDO product, List<IotProductThingModelDO> functionList) {
|
||||
ThingModelRespVO thingModel = new ThingModelRespVO();
|
||||
thingModel.setId(product.getId());
|
||||
thingModel.setProductKey(product.getProductKey());
|
||||
|
@ -231,7 +231,7 @@ public class IotSuperTableServiceImpl implements IotSuperTableService {
|
|||
/**
|
||||
* 构建物模型属性
|
||||
*/
|
||||
private ThingModelProperty buildThingModelProperty(IotThinkModelFunctionDO function) {
|
||||
private ThingModelProperty buildThingModelProperty(IotProductThingModelDO function) {
|
||||
ThingModelProperty property = BeanUtil.copyProperties(function, ThingModelProperty.class);
|
||||
property.setDataType(function.getProperty().getDataType());
|
||||
return property;
|
||||
|
|
|
@ -11,7 +11,7 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.FieldParser;
|
|||
import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TdFieldDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TdTableDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessage;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.productthingmodel.IotProductThingModelDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.redis.deviceData.DeviceDataRedisDAO;
|
||||
import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDDLMapper;
|
||||
import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDMLMapper;
|
||||
|
@ -71,7 +71,7 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
|
|||
|
||||
// 2. 获取设备属性并进行物模型校验,过滤非物模型属性
|
||||
Map<String, Object> params = thingModelMessage.dataToMap();
|
||||
List<IotThinkModelFunctionDO> functionList = getValidFunctionList(thingModelMessage.getProductKey());
|
||||
List<IotProductThingModelDO> functionList = getValidFunctionList(thingModelMessage.getProductKey());
|
||||
if (functionList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
|
|||
.build());
|
||||
}
|
||||
|
||||
private List<IotThinkModelFunctionDO> getValidFunctionList(String productKey) {
|
||||
private List<IotProductThingModelDO> getValidFunctionList(String productKey) {
|
||||
return iotThinkModelFunctionService
|
||||
.getThinkModelFunctionListByProductKey(productKey)
|
||||
.stream()
|
||||
|
@ -98,13 +98,13 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
|
|||
.toList();
|
||||
}
|
||||
|
||||
private List<TdFieldDO> filterAndCollectValidFields(Map<String, Object> params, List<IotThinkModelFunctionDO> functionList, IotDeviceDO device, Long time) {
|
||||
private List<TdFieldDO> filterAndCollectValidFields(Map<String, Object> params, List<IotProductThingModelDO> functionList, IotDeviceDO device, Long time) {
|
||||
// 1. 获取属性标识符集合
|
||||
Set<String> propertyIdentifiers = CollectionUtils.convertSet(functionList, IotThinkModelFunctionDO::getIdentifier);
|
||||
Set<String> propertyIdentifiers = CollectionUtils.convertSet(functionList, IotProductThingModelDO::getIdentifier);
|
||||
|
||||
// 2. 构建属性标识符和属性的映射
|
||||
Map<String, IotThinkModelFunctionDO> functionMap = functionList.stream()
|
||||
.collect(Collectors.toMap(IotThinkModelFunctionDO::getIdentifier, function -> function));
|
||||
Map<String, IotProductThingModelDO> functionMap = functionList.stream()
|
||||
.collect(Collectors.toMap(IotProductThingModelDO::getIdentifier, function -> function));
|
||||
|
||||
// 3. 过滤并收集有效的属性字段
|
||||
List<TdFieldDO> schemaFieldValues = new ArrayList<>();
|
||||
|
@ -124,21 +124,22 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
|
|||
* 缓存设备属性
|
||||
*
|
||||
* @param device 设备信息
|
||||
* @param iotThinkModelFunctionDO 物模型属性
|
||||
* @param iotProductThingModelDO 物模型属性
|
||||
* @param val 属性值
|
||||
* @param time 时间
|
||||
*/
|
||||
private void setDeviceDataCache(IotDeviceDO device, IotThinkModelFunctionDO iotThinkModelFunctionDO, Object val, Long time) {
|
||||
private void setDeviceDataCache(IotDeviceDO device, IotProductThingModelDO iotProductThingModelDO, Object val, Long time) {
|
||||
// TODO @puhui999: 需要重构
|
||||
IotDeviceDataDO deviceData = IotDeviceDataDO.builder()
|
||||
.productKey(device.getProductKey())
|
||||
.deviceName(device.getDeviceName())
|
||||
.identifier(iotThinkModelFunctionDO.getIdentifier())
|
||||
.identifier(iotProductThingModelDO.getIdentifier())
|
||||
.value(val != null ? val.toString() : null)
|
||||
.updateTime(DateUtil.toLocalDateTime(new Date(time)))
|
||||
.deviceId(device.getId())
|
||||
.thinkModelFunctionId(iotThinkModelFunctionDO.getId())
|
||||
.name(iotThinkModelFunctionDO.getName())
|
||||
.dataType(iotThinkModelFunctionDO.getProperty().getDataType().getDataType())
|
||||
.thinkModelFunctionId(iotProductThingModelDO.getId())
|
||||
.name(iotProductThingModelDO.getName())
|
||||
//.dataType(iotProductThingModelDO.getProperty().getDataType().getDataType())
|
||||
.build();
|
||||
deviceDataRedisDAO.set(deviceData);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package cn.iocoder.yudao.module.iot.service.thinkmodelfunction;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionPageReqVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionSaveReqVO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.vo.IotThinkModelFunctionPageReqVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.vo.IotThinkModelFunctionSaveReqVO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.productthingmodel.IotProductThingModelDO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -44,7 +44,7 @@ public interface IotThinkModelFunctionService {
|
|||
* @param id 编号
|
||||
* @return 产品物模型
|
||||
*/
|
||||
IotThinkModelFunctionDO getThinkModelFunction(Long id);
|
||||
IotProductThingModelDO getThinkModelFunction(Long id);
|
||||
|
||||
/**
|
||||
* 获得产品物模型列表
|
||||
|
@ -52,7 +52,7 @@ public interface IotThinkModelFunctionService {
|
|||
* @param productId 产品编号
|
||||
* @return 产品物模型列表
|
||||
*/
|
||||
List<IotThinkModelFunctionDO> getThinkModelFunctionListByProductId(Long productId);
|
||||
List<IotProductThingModelDO> getThinkModelFunctionListByProductId(Long productId);
|
||||
|
||||
/**
|
||||
* 获得产品物模型分页
|
||||
|
@ -60,7 +60,7 @@ public interface IotThinkModelFunctionService {
|
|||
* @param pageReqVO 分页查询
|
||||
* @return 产品物模型分页
|
||||
*/
|
||||
PageResult<IotThinkModelFunctionDO> getThinkModelFunctionPage(IotThinkModelFunctionPageReqVO pageReqVO);
|
||||
PageResult<IotProductThingModelDO> getThinkModelFunctionPage(IotThinkModelFunctionPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 创建超级表数据模型
|
||||
|
@ -75,5 +75,5 @@ public interface IotThinkModelFunctionService {
|
|||
* @param productKey 产品 Key
|
||||
* @return 产品物模型列表
|
||||
*/
|
||||
List<IotThinkModelFunctionDO> getThinkModelFunctionListByProductKey(String productKey);
|
||||
List<IotProductThingModelDO> getThinkModelFunctionListByProductKey(String productKey);
|
||||
}
|
|
@ -4,23 +4,20 @@ import cn.hutool.core.collection.CollUtil;
|
|||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelEvent;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelProperty;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelService;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType.ThingModelArgument;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType.ThingModelArraySpecs;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType.ThingModelArrayType;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType.ThingModelTextType;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionPageReqVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionSaveReqVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.ThingModelEvent;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.ThingModelProperty;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.ThingModelService;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.dataType.ThingModelArgument;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.dataType.ThingModelArrayDataSpecs;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.dataType.ThingModelDateOrTextDataSpecs;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.vo.IotThinkModelFunctionPageReqVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.vo.IotThinkModelFunctionSaveReqVO;
|
||||
import cn.iocoder.yudao.module.iot.convert.thinkmodelfunction.IotThinkModelFunctionConvert;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.productthingmodel.IotProductThingModelDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.mysql.thinkmodelfunction.IotThinkModelFunctionMapper;
|
||||
import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelAccessModeEnum;
|
||||
import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelTypeEnum;
|
||||
import cn.iocoder.yudao.module.iot.enums.product.IotProductStatusEnum;
|
||||
import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelTypeEnum;
|
||||
import cn.iocoder.yudao.module.iot.service.product.IotProductService;
|
||||
import cn.iocoder.yudao.module.iot.service.tdengine.IotSuperTableService;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -70,7 +67,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
|
|||
validateProductStatus(createReqVO.getProductId());
|
||||
|
||||
// 5. 插入数据库
|
||||
IotThinkModelFunctionDO function = IotThinkModelFunctionConvert.INSTANCE.convert(createReqVO);
|
||||
IotProductThingModelDO function = IotThinkModelFunctionConvert.INSTANCE.convert(createReqVO);
|
||||
thinkModelFunctionMapper.insert(function);
|
||||
|
||||
// 6. 如果创建的是属性,需要更新默认的事件和服务
|
||||
|
@ -98,14 +95,14 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
|
|||
}
|
||||
|
||||
private void validateNameUnique(Long productId, String name) {
|
||||
IotThinkModelFunctionDO function = thinkModelFunctionMapper.selectByProductIdAndName(productId, name);
|
||||
IotProductThingModelDO function = thinkModelFunctionMapper.selectByProductIdAndName(productId, name);
|
||||
if (function != null) {
|
||||
throw exception(THINK_MODEL_FUNCTION_NAME_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateIdentifierUnique(Long productId, String identifier) {
|
||||
IotThinkModelFunctionDO function = thinkModelFunctionMapper.selectByProductIdAndIdentifier(productId, identifier);
|
||||
IotProductThingModelDO function = thinkModelFunctionMapper.selectByProductIdAndIdentifier(productId, identifier);
|
||||
if (function != null) {
|
||||
throw exception(THINK_MODEL_FUNCTION_IDENTIFIER_EXISTS);
|
||||
}
|
||||
|
@ -124,7 +121,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
|
|||
validateProductStatus(updateReqVO.getProductId());
|
||||
|
||||
// 4. 更新数据库
|
||||
IotThinkModelFunctionDO thinkModelFunction = IotThinkModelFunctionConvert.INSTANCE.convert(updateReqVO);
|
||||
IotProductThingModelDO thinkModelFunction = IotThinkModelFunctionConvert.INSTANCE.convert(updateReqVO);
|
||||
thinkModelFunctionMapper.updateById(thinkModelFunction);
|
||||
|
||||
// 5. 如果更新的是属性,需要更新默认的事件和服务
|
||||
|
@ -134,7 +131,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
|
|||
}
|
||||
|
||||
private void validateIdentifierUniqueForUpdate(Long id, Long productId, String identifier) {
|
||||
IotThinkModelFunctionDO function = thinkModelFunctionMapper.selectByProductIdAndIdentifier(productId, identifier);
|
||||
IotProductThingModelDO function = thinkModelFunctionMapper.selectByProductIdAndIdentifier(productId, identifier);
|
||||
if (function != null && ObjectUtil.notEqual(function.getId(), id)) {
|
||||
throw exception(THINK_MODEL_FUNCTION_IDENTIFIER_EXISTS);
|
||||
}
|
||||
|
@ -144,7 +141,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
|
|||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteThinkModelFunction(Long id) {
|
||||
// 1. 校验功能是否存在
|
||||
IotThinkModelFunctionDO functionDO = thinkModelFunctionMapper.selectById(id);
|
||||
IotProductThingModelDO functionDO = thinkModelFunctionMapper.selectById(id);
|
||||
if (functionDO == null) {
|
||||
throw exception(THINK_MODEL_FUNCTION_NOT_EXISTS);
|
||||
}
|
||||
|
@ -173,17 +170,17 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
|
|||
}
|
||||
|
||||
@Override
|
||||
public IotThinkModelFunctionDO getThinkModelFunction(Long id) {
|
||||
public IotProductThingModelDO getThinkModelFunction(Long id) {
|
||||
return thinkModelFunctionMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IotThinkModelFunctionDO> getThinkModelFunctionListByProductId(Long productId) {
|
||||
public List<IotProductThingModelDO> getThinkModelFunctionListByProductId(Long productId) {
|
||||
return thinkModelFunctionMapper.selectListByProductId(productId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<IotThinkModelFunctionDO> getThinkModelFunctionPage(IotThinkModelFunctionPageReqVO pageReqVO) {
|
||||
public PageResult<IotProductThingModelDO> getThinkModelFunctionPage(IotThinkModelFunctionPageReqVO pageReqVO) {
|
||||
return thinkModelFunctionMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
|
@ -193,14 +190,14 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
|
|||
IotProductDO product = productService.getProduct(productId);
|
||||
|
||||
// 2. 查询产品的物模型功能列表
|
||||
List<IotThinkModelFunctionDO> functionList = thinkModelFunctionMapper.selectListByProductId(productId);
|
||||
List<IotProductThingModelDO> functionList = thinkModelFunctionMapper.selectListByProductId(productId);
|
||||
|
||||
// 3. 生成 TDengine 的数据模型
|
||||
dbStructureDataService.createSuperTableDataModel(product, functionList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IotThinkModelFunctionDO> getThinkModelFunctionListByProductKey(String productKey) {
|
||||
public List<IotProductThingModelDO> getThinkModelFunctionListByProductKey(String productKey) {
|
||||
return thinkModelFunctionMapper.selectListByProductKey(productKey);
|
||||
}
|
||||
|
||||
|
@ -209,45 +206,45 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
|
|||
*/
|
||||
public void createDefaultEventsAndServices(Long productId, String productKey) {
|
||||
// 1. 获取当前属性列表
|
||||
List<IotThinkModelFunctionDO> propertyList = thinkModelFunctionMapper
|
||||
List<IotProductThingModelDO> propertyList = thinkModelFunctionMapper
|
||||
.selectListByProductIdAndType(productId, IotProductThingModelTypeEnum.PROPERTY.getType());
|
||||
|
||||
// 2. 生成新的事件和服务列表
|
||||
List<IotThinkModelFunctionDO> newFunctionList = new ArrayList<>();
|
||||
List<IotProductThingModelDO> newFunctionList = new ArrayList<>();
|
||||
// 生成属性上报事件
|
||||
ThingModelEvent propertyPostEvent = generatePropertyPostEvent(propertyList);
|
||||
if (propertyPostEvent != null) {
|
||||
IotThinkModelFunctionDO eventFunction = buildEventFunctionDO(productId, productKey, propertyPostEvent);
|
||||
IotProductThingModelDO eventFunction = buildEventFunctionDO(productId, productKey, propertyPostEvent);
|
||||
newFunctionList.add(eventFunction);
|
||||
}
|
||||
// 生成属性设置服务
|
||||
ThingModelService propertySetService = generatePropertySetService(propertyList);
|
||||
if (propertySetService != null) {
|
||||
IotThinkModelFunctionDO setServiceFunction = buildServiceFunctionDO(productId, productKey, propertySetService);
|
||||
IotProductThingModelDO setServiceFunction = buildServiceFunctionDO(productId, productKey, propertySetService);
|
||||
newFunctionList.add(setServiceFunction);
|
||||
}
|
||||
// 生成属性获取服务
|
||||
ThingModelService propertyGetService = generatePropertyGetService(propertyList);
|
||||
if (propertyGetService != null) {
|
||||
IotThinkModelFunctionDO getServiceFunction = buildServiceFunctionDO(productId, productKey, propertyGetService);
|
||||
IotProductThingModelDO getServiceFunction = buildServiceFunctionDO(productId, productKey, propertyGetService);
|
||||
newFunctionList.add(getServiceFunction);
|
||||
}
|
||||
|
||||
// 3. 获取数据库中的默认的旧事件和服务列表
|
||||
List<IotThinkModelFunctionDO> oldFunctionList = thinkModelFunctionMapper.selectListByProductIdAndIdentifiersAndTypes(
|
||||
List<IotProductThingModelDO> oldFunctionList = thinkModelFunctionMapper.selectListByProductIdAndIdentifiersAndTypes(
|
||||
productId,
|
||||
Arrays.asList("post", "set", "get"),
|
||||
Arrays.asList(IotProductThingModelTypeEnum.EVENT.getType(), IotProductThingModelTypeEnum.SERVICE.getType())
|
||||
);
|
||||
|
||||
// 3.1 使用 diffList 方法比较新旧列表
|
||||
List<List<IotThinkModelFunctionDO>> diffResult = diffList(oldFunctionList, newFunctionList,
|
||||
List<List<IotProductThingModelDO>> diffResult = diffList(oldFunctionList, newFunctionList,
|
||||
// 继续使用 identifier 和 type 进行比较:这样可以准确地匹配对应的功能对象。
|
||||
(oldFunc, newFunc) -> Objects.equals(oldFunc.getIdentifier(), newFunc.getIdentifier())
|
||||
&& Objects.equals(oldFunc.getType(), newFunc.getType()));
|
||||
List<IotThinkModelFunctionDO> createList = diffResult.get(0); // 需要新增的
|
||||
List<IotThinkModelFunctionDO> updateList = diffResult.get(1); // 需要更新的
|
||||
List<IotThinkModelFunctionDO> deleteList = diffResult.get(2); // 需要删除的
|
||||
List<IotProductThingModelDO> createList = diffResult.get(0); // 需要新增的
|
||||
List<IotProductThingModelDO> updateList = diffResult.get(1); // 需要更新的
|
||||
List<IotProductThingModelDO> deleteList = diffResult.get(2); // 需要删除的
|
||||
|
||||
// 3.2 批量执行数据库操作
|
||||
// 新增数据库中的新事件和服务列表
|
||||
|
@ -258,14 +255,14 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
|
|||
if (CollUtil.isNotEmpty(updateList)) {
|
||||
// 首先,为每个需要更新的对象设置其对应的 ID
|
||||
updateList.forEach(updateFunc -> {
|
||||
IotThinkModelFunctionDO oldFunc = findFunctionByIdentifierAndType(
|
||||
IotProductThingModelDO oldFunc = findFunctionByIdentifierAndType(
|
||||
oldFunctionList, updateFunc.getIdentifier(), updateFunc.getType());
|
||||
if (oldFunc != null) {
|
||||
updateFunc.setId(oldFunc.getId());
|
||||
}
|
||||
});
|
||||
// 过滤掉没有设置 ID 的对象
|
||||
List<IotThinkModelFunctionDO> validUpdateList = updateList.stream()
|
||||
List<IotProductThingModelDO> validUpdateList = updateList.stream()
|
||||
.filter(func -> func.getId() != null)
|
||||
.collect(Collectors.toList());
|
||||
// 执行批量更新
|
||||
|
@ -276,7 +273,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
|
|||
|
||||
// 删除数据库中的旧事件和服务列表
|
||||
if (CollUtil.isNotEmpty(deleteList)) {
|
||||
Set<Long> idsToDelete = CollectionUtils.convertSet(deleteList, IotThinkModelFunctionDO::getId);
|
||||
Set<Long> idsToDelete = CollectionUtils.convertSet(deleteList, IotProductThingModelDO::getId);
|
||||
thinkModelFunctionMapper.deleteByIds(idsToDelete);
|
||||
}
|
||||
}
|
||||
|
@ -284,8 +281,8 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
|
|||
/**
|
||||
* 根据标识符和类型查找功能对象
|
||||
*/
|
||||
private IotThinkModelFunctionDO findFunctionByIdentifierAndType(List<IotThinkModelFunctionDO> functionList,
|
||||
String identifier, Integer type) {
|
||||
private IotProductThingModelDO findFunctionByIdentifierAndType(List<IotProductThingModelDO> functionList,
|
||||
String identifier, Integer type) {
|
||||
return CollUtil.findOne(functionList, func ->
|
||||
Objects.equals(func.getIdentifier(), identifier) && Objects.equals(func.getType(), type));
|
||||
}
|
||||
|
@ -293,8 +290,8 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
|
|||
/**
|
||||
* 构建事件功能对象
|
||||
*/
|
||||
private IotThinkModelFunctionDO buildEventFunctionDO(Long productId, String productKey, ThingModelEvent event) {
|
||||
return new IotThinkModelFunctionDO()
|
||||
private IotProductThingModelDO buildEventFunctionDO(Long productId, String productKey, ThingModelEvent event) {
|
||||
return new IotProductThingModelDO()
|
||||
.setProductId(productId)
|
||||
.setProductKey(productKey)
|
||||
.setIdentifier(event.getIdentifier())
|
||||
|
@ -307,8 +304,8 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
|
|||
/**
|
||||
* 构建服务功能对象
|
||||
*/
|
||||
private IotThinkModelFunctionDO buildServiceFunctionDO(Long productId, String productKey, ThingModelService service) {
|
||||
return new IotThinkModelFunctionDO()
|
||||
private IotProductThingModelDO buildServiceFunctionDO(Long productId, String productKey, ThingModelService service) {
|
||||
return new IotProductThingModelDO()
|
||||
.setProductId(productId)
|
||||
.setProductKey(productKey)
|
||||
.setIdentifier(service.getIdentifier())
|
||||
|
@ -321,7 +318,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
|
|||
/**
|
||||
* 生成属性上报事件
|
||||
*/
|
||||
private ThingModelEvent generatePropertyPostEvent(List<IotThinkModelFunctionDO> propertyList) {
|
||||
private ThingModelEvent generatePropertyPostEvent(List<IotProductThingModelDO> propertyList) {
|
||||
if (CollUtil.isEmpty(propertyList)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -335,12 +332,13 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
|
|||
|
||||
// 将属性列表转换为事件的输出参数
|
||||
List<ThingModelArgument> outputData = new ArrayList<>();
|
||||
for (IotThinkModelFunctionDO functionDO : propertyList) {
|
||||
// TODO @puhui999: 需要重构
|
||||
for (IotProductThingModelDO functionDO : propertyList) {
|
||||
ThingModelProperty property = functionDO.getProperty();
|
||||
ThingModelArgument arg = new ThingModelArgument()
|
||||
.setIdentifier(property.getIdentifier())
|
||||
.setName(property.getName())
|
||||
.setDataType(property.getDataType())
|
||||
//.setDataType(property.getDataType())
|
||||
.setDescription(property.getDescription())
|
||||
.setDirection("output"); // 设置为输出参数
|
||||
outputData.add(arg);
|
||||
|
@ -352,24 +350,24 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
|
|||
/**
|
||||
* 生成属性设置服务
|
||||
*/
|
||||
private ThingModelService generatePropertySetService(List<IotThinkModelFunctionDO> propertyList) {
|
||||
private ThingModelService generatePropertySetService(List<IotProductThingModelDO> propertyList) {
|
||||
if (propertyList == null || propertyList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<ThingModelArgument> inputData = new ArrayList<>();
|
||||
// TODO @puhui999: 需要重构
|
||||
for (IotThinkModelFunctionDO functionDO : propertyList) {
|
||||
for (IotProductThingModelDO functionDO : propertyList) {
|
||||
ThingModelProperty property = functionDO.getProperty();
|
||||
if (IotProductThingModelAccessModeEnum.WRITE.getMode().equals(property.getAccessMode()) || IotProductThingModelAccessModeEnum.READ_WRITE.getMode().equals(property.getAccessMode())) {
|
||||
ThingModelArgument arg = new ThingModelArgument()
|
||||
.setIdentifier(property.getIdentifier())
|
||||
.setName(property.getName())
|
||||
.setDataType(property.getDataType())
|
||||
.setDescription(property.getDescription())
|
||||
.setDirection("input"); // 设置为输入参数
|
||||
inputData.add(arg);
|
||||
}
|
||||
//if (IotProductThingModelAccessModeEnum.WRITE.getMode().equals(property.getAccessMode()) || IotProductThingModelAccessModeEnum.READ_WRITE.getMode().equals(property.getAccessMode())) {
|
||||
// ThingModelArgument arg = new ThingModelArgument()
|
||||
// .setIdentifier(property.getIdentifier())
|
||||
// .setName(property.getName())
|
||||
// .setDataType(property.getDataType())
|
||||
// .setDescription(property.getDescription())
|
||||
// .setDirection("input"); // 设置为输入参数
|
||||
// inputData.add(arg);
|
||||
//}
|
||||
}
|
||||
if (inputData.isEmpty()) {
|
||||
// 如果没有可写属性,不生成属性设置服务
|
||||
|
@ -391,24 +389,24 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
|
|||
/**
|
||||
* 生成属性获取服务
|
||||
*/
|
||||
private ThingModelService generatePropertyGetService(List<IotThinkModelFunctionDO> propertyList) {
|
||||
private ThingModelService generatePropertyGetService(List<IotProductThingModelDO> propertyList) {
|
||||
if (propertyList == null || propertyList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO @puhui999: 需要重构
|
||||
List<ThingModelArgument> outputData = new ArrayList<>();
|
||||
for (IotThinkModelFunctionDO functionDO : propertyList) {
|
||||
for (IotProductThingModelDO functionDO : propertyList) {
|
||||
ThingModelProperty property = functionDO.getProperty();
|
||||
if (ObjectUtils.equalsAny(property.getAccessMode(),
|
||||
IotProductThingModelAccessModeEnum.READ.getMode(), IotProductThingModelAccessModeEnum.READ_WRITE.getMode())) {
|
||||
ThingModelArgument arg = new ThingModelArgument()
|
||||
.setIdentifier(property.getIdentifier())
|
||||
.setName(property.getName())
|
||||
.setDataType(property.getDataType())
|
||||
.setDescription(property.getDescription())
|
||||
.setDirection("output"); // 设置为输出参数
|
||||
outputData.add(arg);
|
||||
}
|
||||
//if (ObjectUtils.equalsAny(property.getAccessMode(),
|
||||
// IotProductThingModelAccessModeEnum.READ.getMode(), IotProductThingModelAccessModeEnum.READ_WRITE.getMode())) {
|
||||
// ThingModelArgument arg = new ThingModelArgument()
|
||||
// .setIdentifier(property.getIdentifier())
|
||||
// .setName(property.getName())
|
||||
// .setDataType(property.getDataType())
|
||||
// .setDescription(property.getDescription())
|
||||
// .setDirection("output"); // 设置为输出参数
|
||||
// outputData.add(arg);
|
||||
//}
|
||||
}
|
||||
if (outputData.isEmpty()) {
|
||||
// 如果没有可读属性,不生成属性获取服务
|
||||
|
@ -430,13 +428,13 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
|
|||
.setDirection("input"); // 设置为输入参数
|
||||
|
||||
// 创建数组类型,元素类型为文本类型(字符串)
|
||||
ThingModelArrayType arrayType = new ThingModelArrayType();
|
||||
ThingModelArrayDataSpecs arrayType = new ThingModelArrayDataSpecs();
|
||||
arrayType.setDataType("array");
|
||||
ThingModelArraySpecs arraySpecs = new ThingModelArraySpecs();
|
||||
ThingModelTextType textType = new ThingModelTextType();
|
||||
//ThingModelArraySpecs arraySpecs = new ThingModelArraySpecs();
|
||||
ThingModelDateOrTextDataSpecs textType = new ThingModelDateOrTextDataSpecs();
|
||||
textType.setDataType("text");
|
||||
arraySpecs.setItem(textType);
|
||||
arrayType.setSpecs(arraySpecs);
|
||||
//arraySpecs.setItem(textType);
|
||||
//arrayType.setSpecs(arraySpecs);
|
||||
inputArg.setDataType(arrayType);
|
||||
|
||||
service.setInputData(Collections.singletonList(inputArg));
|
||||
|
|
Loading…
Reference in New Issue