【功能完善】IoT: 产品物模型

This commit is contained in:
puhui999 2024-12-16 10:50:48 +08:00
parent db9c485285
commit 741096e208
14 changed files with 48 additions and 62 deletions

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.iot.enums.product; package cn.iocoder.yudao.module.iot.enums.thingmodel;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
@ -10,10 +10,9 @@ import lombok.Getter;
*/ */
@AllArgsConstructor @AllArgsConstructor
@Getter @Getter
public enum IotAccessModeEnum { public enum IotProductThingModelAccessModeEnum {
READ("r"), READ_ONLY("r"),
WRITE("w"),
READ_WRITE("rw"); READ_WRITE("rw");
private final String mode; private final String mode;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.iot.enums.product; package cn.iocoder.yudao.module.iot.enums.thingmodel;
import cn.iocoder.yudao.framework.common.core.IntArrayValuable; import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@ -13,13 +13,13 @@ import java.util.Arrays;
*/ */
@AllArgsConstructor @AllArgsConstructor
@Getter @Getter
public enum IotProductFunctionTypeEnum implements IntArrayValuable { public enum IotProductThingModelTypeEnum implements IntArrayValuable {
PROPERTY(1, "属性"), PROPERTY(1, "属性"),
SERVICE(2, "服务"), SERVICE(2, "服务"),
EVENT(3, "事件"); EVENT(3, "事件");
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotProductFunctionTypeEnum::getType).toArray(); public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotProductThingModelTypeEnum::getType).toArray();
/** /**
* 类型 * 类型
@ -30,8 +30,8 @@ public enum IotProductFunctionTypeEnum implements IntArrayValuable {
*/ */
private final String description; private final String description;
public static IotProductFunctionTypeEnum valueOfType(Integer type) { public static IotProductThingModelTypeEnum valueOfType(Integer type) {
for (IotProductFunctionTypeEnum value : values()) { for (IotProductThingModelTypeEnum value : values()) {
if (value.getType().equals(type)) { if (value.getType().equals(type)) {
return value; return value;
} }

View File

@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingMod
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType.ThingModelDataType; import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.dataType.ThingModelDataType;
import lombok.Data; import lombok.Data;
import java.util.List;
@Data @Data
public class ThingModelProperty { public class ThingModelProperty {
@ -21,7 +23,7 @@ public class ThingModelProperty {
private String accessMode; // "rw""r""w" private String accessMode; // "rw""r""w"
private Boolean required; private Boolean required;
// TODO @haohao这个是不是 dataSpecs dataSpecsListhttps://help.aliyun.com/zh/iot/developer-reference/api-a99t11 private ThingModelDataType dataSpecs;
private ThingModelDataType dataType; private List<ThingModelDataType> dataSpecsList;
} }

View File

@ -5,7 +5,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.Data; import lombok.Data;
@Data @Data
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", visible = true) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "dataType", visible = true)
@JsonSubTypes({ @JsonSubTypes({
@JsonSubTypes.Type(value = ThingModelIntType.class, name = "int"), @JsonSubTypes.Type(value = ThingModelIntType.class, name = "int"),
@JsonSubTypes.Type(value = ThingModelFloatType.class, name = "float"), @JsonSubTypes.Type(value = ThingModelFloatType.class, name = "float"),
@ -19,6 +19,6 @@ import lombok.Data;
}) })
public abstract class ThingModelDataType { public abstract class ThingModelDataType {
private String type; private String dataType;
} }

View File

@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.iot.enums.product.IotProductFunctionTypeEnum; import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import lombok.Data; import lombok.Data;
@ -22,7 +22,7 @@ public class IotThinkModelFunctionPageReqVO extends PageParam {
private String name; private String name;
@Schema(description = "功能类型", example = "1") @Schema(description = "功能类型", example = "1")
@InEnum(IotProductFunctionTypeEnum.class) @InEnum(IotProductThingModelTypeEnum.class)
private Integer type; private Integer type;
@Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED)

View File

@ -4,7 +4,7 @@ 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.ThingModelEvent;
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelProperty; 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.ThingModelService;
import cn.iocoder.yudao.module.iot.enums.product.IotProductFunctionTypeEnum; import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
@ -38,7 +38,7 @@ public class IotThinkModelFunctionSaveReqVO {
@Schema(description = "功能类型", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "功能类型", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "功能类型不能为空") @NotNull(message = "功能类型不能为空")
@InEnum(IotProductFunctionTypeEnum.class) @InEnum(IotProductThingModelTypeEnum.class)
private Integer type; private Integer type;
@Schema(description = "属性", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "属性", requiredMode = Schema.RequiredMode.REQUIRED)

View File

@ -1,23 +1,8 @@
package cn.iocoder.yudao.module.iot.convert.device; package cn.iocoder.yudao.module.iot.convert.device;
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataRespVO;
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.device.IotDeviceDO;
import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO;
import cn.iocoder.yudao.module.iot.enums.product.IotProductFunctionTypeEnum;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Mapper @Mapper
public interface IotDeviceDataConvert { public interface IotDeviceDataConvert {

View File

@ -6,7 +6,7 @@ import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingMode
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionRespVO; 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.thinkmodelfunction.vo.IotThinkModelFunctionSaveReqVO;
import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO; import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO;
import cn.iocoder.yudao.module.iot.enums.product.IotProductFunctionTypeEnum; import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelTypeEnum;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
@ -26,21 +26,21 @@ public interface IotThinkModelFunctionConvert {
IotThinkModelFunctionDO convert(IotThinkModelFunctionSaveReqVO bean); IotThinkModelFunctionDO convert(IotThinkModelFunctionSaveReqVO bean);
default ThingModelProperty convertToProperty(IotThinkModelFunctionSaveReqVO bean) { default ThingModelProperty convertToProperty(IotThinkModelFunctionSaveReqVO bean) {
if (Objects.equals(bean.getType(), IotProductFunctionTypeEnum.PROPERTY.getType())) { if (Objects.equals(bean.getType(), IotProductThingModelTypeEnum.PROPERTY.getType())) {
return bean.getProperty(); return bean.getProperty();
} }
return null; return null;
} }
default ThingModelEvent convertToEvent(IotThinkModelFunctionSaveReqVO bean) { default ThingModelEvent convertToEvent(IotThinkModelFunctionSaveReqVO bean) {
if (Objects.equals(bean.getType(), IotProductFunctionTypeEnum.EVENT.getType())) { if (Objects.equals(bean.getType(), IotProductThingModelTypeEnum.EVENT.getType())) {
return bean.getEvent(); return bean.getEvent();
} }
return null; return null;
} }
default ThingModelService convertToService(IotThinkModelFunctionSaveReqVO bean) { default ThingModelService convertToService(IotThinkModelFunctionSaveReqVO bean) {
if (Objects.equals(bean.getType(), IotProductFunctionTypeEnum.SERVICE.getType())) { if (Objects.equals(bean.getType(), IotProductThingModelTypeEnum.SERVICE.getType())) {
return bean.getService(); return bean.getService();
} }
return null; return null;

View File

@ -39,7 +39,7 @@ public class FieldParser {
ThingModelDataType type = property.getDataType(); ThingModelDataType type = property.getDataType();
// 将物模型字段类型映射为td字段类型 // 将物模型字段类型映射为td字段类型
String fType = TYPE_MAPPING.get(type.getType().toUpperCase()); String fType = TYPE_MAPPING.get(type.getDataType().toUpperCase());
// 如果字段类型为NCHAR默认长度为64 // 如果字段类型为NCHAR默认长度为64
int dataLength = 0; int dataLength = 0;

View File

@ -5,7 +5,7 @@ import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingMode
import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.thingModel.ThingModelProperty; 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.ThingModelService;
import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
import cn.iocoder.yudao.module.iot.enums.product.IotProductFunctionTypeEnum; import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelTypeEnum;
import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
@ -66,7 +66,7 @@ public class IotThinkModelFunctionDO extends BaseDO {
/** /**
* 功能类型 * 功能类型
* <p> * <p>
* 枚举 {@link IotProductFunctionTypeEnum} * 枚举 {@link IotProductThingModelTypeEnum}
*/ */
private Integer type; private Integer type;

View File

@ -13,7 +13,7 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkMod
import cn.iocoder.yudao.module.iot.dal.redis.deviceData.DeviceDataRedisDAO; 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.dal.tdengine.TdEngineDMLMapper;
import cn.iocoder.yudao.module.iot.enums.IotConstants; import cn.iocoder.yudao.module.iot.enums.IotConstants;
import cn.iocoder.yudao.module.iot.enums.product.IotProductFunctionTypeEnum; import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelTypeEnum;
import cn.iocoder.yudao.module.iot.service.tdengine.IotThingModelMessageService; import cn.iocoder.yudao.module.iot.service.tdengine.IotThingModelMessageService;
import cn.iocoder.yudao.module.iot.service.thinkmodelfunction.IotThinkModelFunctionService; import cn.iocoder.yudao.module.iot.service.thinkmodelfunction.IotThinkModelFunctionService;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
@ -75,7 +75,7 @@ public class IotDeviceDataServiceImpl implements IotDeviceDataService {
// 2. 获取设备属性最新数据 // 2. 获取设备属性最新数据
List<IotThinkModelFunctionDO> thinkModelFunctionList = thinkModelFunctionService.getThinkModelFunctionListByProductKey(device.getProductKey()); List<IotThinkModelFunctionDO> thinkModelFunctionList = thinkModelFunctionService.getThinkModelFunctionListByProductKey(device.getProductKey());
thinkModelFunctionList = thinkModelFunctionList.stream() thinkModelFunctionList = thinkModelFunctionList.stream()
.filter(function -> IotProductFunctionTypeEnum.PROPERTY.getType() .filter(function -> IotProductThingModelTypeEnum.PROPERTY.getType()
.equals(function.getType())).toList(); .equals(function.getType())).toList();
// 3. 过滤标识符和属性名称 // 3. 过滤标识符和属性名称
@ -100,7 +100,7 @@ public class IotDeviceDataServiceImpl implements IotDeviceDataService {
deviceData.setDeviceId(deviceDataReqVO.getDeviceId()); deviceData.setDeviceId(deviceDataReqVO.getDeviceId());
deviceData.setThinkModelFunctionId(function.getId()); deviceData.setThinkModelFunctionId(function.getId());
deviceData.setName(function.getName()); deviceData.setName(function.getName());
deviceData.setDataType(function.getProperty().getDataType().getType()); deviceData.setDataType(function.getProperty().getDataType().getDataType());
} }
list.add(deviceData); list.add(deviceData);
}); });

View File

@ -10,8 +10,7 @@ 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.TdTableDO;
import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO; import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO;
import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDDLMapper; import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDDLMapper;
import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDMLMapper; import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelTypeEnum;
import cn.iocoder.yudao.module.iot.enums.product.IotProductFunctionTypeEnum;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
@ -217,8 +216,8 @@ public class IotSuperTableServiceImpl implements IotSuperTableService {
thingModel.setProductKey(product.getProductKey()); thingModel.setProductKey(product.getProductKey());
List<ThingModelProperty> properties = functionList.stream() List<ThingModelProperty> properties = functionList.stream()
.filter(function -> IotProductFunctionTypeEnum.PROPERTY.equals( .filter(function -> IotProductThingModelTypeEnum.PROPERTY.equals(
IotProductFunctionTypeEnum.valueOfType(function.getType()))) IotProductThingModelTypeEnum.valueOfType(function.getType())))
.map(this::buildThingModelProperty) .map(this::buildThingModelProperty)
.collect(Collectors.toList()); .collect(Collectors.toList());

View File

@ -17,7 +17,7 @@ import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDDLMapper;
import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDMLMapper; import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDMLMapper;
import cn.iocoder.yudao.module.iot.enums.IotConstants; import cn.iocoder.yudao.module.iot.enums.IotConstants;
import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStatusEnum; import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStatusEnum;
import cn.iocoder.yudao.module.iot.enums.product.IotProductFunctionTypeEnum; import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelTypeEnum;
import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; import cn.iocoder.yudao.module.iot.service.device.IotDeviceService;
import cn.iocoder.yudao.module.iot.service.thinkmodelfunction.IotThinkModelFunctionService; import cn.iocoder.yudao.module.iot.service.thinkmodelfunction.IotThinkModelFunctionService;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
@ -94,7 +94,7 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
return iotThinkModelFunctionService return iotThinkModelFunctionService
.getThinkModelFunctionListByProductKey(productKey) .getThinkModelFunctionListByProductKey(productKey)
.stream() .stream()
.filter(function -> IotProductFunctionTypeEnum.PROPERTY.getType().equals(function.getType())) .filter(function -> IotProductThingModelTypeEnum.PROPERTY.getType().equals(function.getType()))
.toList(); .toList();
} }
@ -138,7 +138,7 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
.deviceId(device.getId()) .deviceId(device.getId())
.thinkModelFunctionId(iotThinkModelFunctionDO.getId()) .thinkModelFunctionId(iotThinkModelFunctionDO.getId())
.name(iotThinkModelFunctionDO.getName()) .name(iotThinkModelFunctionDO.getName())
.dataType(iotThinkModelFunctionDO.getProperty().getDataType().getType()) .dataType(iotThinkModelFunctionDO.getProperty().getDataType().getDataType())
.build(); .build();
deviceDataRedisDAO.set(deviceData); deviceDataRedisDAO.set(deviceData);
} }

View File

@ -18,8 +18,8 @@ import cn.iocoder.yudao.module.iot.convert.thinkmodelfunction.IotThinkModelFunct
import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; 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.thinkmodelfunction.IotThinkModelFunctionDO;
import cn.iocoder.yudao.module.iot.dal.mysql.thinkmodelfunction.IotThinkModelFunctionMapper; import cn.iocoder.yudao.module.iot.dal.mysql.thinkmodelfunction.IotThinkModelFunctionMapper;
import cn.iocoder.yudao.module.iot.enums.product.IotAccessModeEnum; import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelAccessModeEnum;
import cn.iocoder.yudao.module.iot.enums.product.IotProductFunctionTypeEnum; 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.product.IotProductStatusEnum;
import cn.iocoder.yudao.module.iot.service.product.IotProductService; import cn.iocoder.yudao.module.iot.service.product.IotProductService;
import cn.iocoder.yudao.module.iot.service.tdengine.IotSuperTableService; import cn.iocoder.yudao.module.iot.service.tdengine.IotSuperTableService;
@ -74,7 +74,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
thinkModelFunctionMapper.insert(function); thinkModelFunctionMapper.insert(function);
// 6. 如果创建的是属性需要更新默认的事件和服务 // 6. 如果创建的是属性需要更新默认的事件和服务
if (Objects.equals(createReqVO.getType(), IotProductFunctionTypeEnum.PROPERTY.getType())) { if (Objects.equals(createReqVO.getType(), IotProductThingModelTypeEnum.PROPERTY.getType())) {
createDefaultEventsAndServices(createReqVO.getProductId(), createReqVO.getProductKey()); createDefaultEventsAndServices(createReqVO.getProductId(), createReqVO.getProductKey());
} }
return function.getId(); return function.getId();
@ -128,7 +128,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
thinkModelFunctionMapper.updateById(thinkModelFunction); thinkModelFunctionMapper.updateById(thinkModelFunction);
// 5. 如果更新的是属性需要更新默认的事件和服务 // 5. 如果更新的是属性需要更新默认的事件和服务
if (Objects.equals(updateReqVO.getType(), IotProductFunctionTypeEnum.PROPERTY.getType())) { if (Objects.equals(updateReqVO.getType(), IotProductThingModelTypeEnum.PROPERTY.getType())) {
createDefaultEventsAndServices(updateReqVO.getProductId(), updateReqVO.getProductKey()); createDefaultEventsAndServices(updateReqVO.getProductId(), updateReqVO.getProductKey());
} }
} }
@ -156,7 +156,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
thinkModelFunctionMapper.deleteById(id); thinkModelFunctionMapper.deleteById(id);
// 3. 如果删除的是属性需要更新默认的事件和服务 // 3. 如果删除的是属性需要更新默认的事件和服务
if (Objects.equals(functionDO.getType(), IotProductFunctionTypeEnum.PROPERTY.getType())) { if (Objects.equals(functionDO.getType(), IotProductThingModelTypeEnum.PROPERTY.getType())) {
createDefaultEventsAndServices(functionDO.getProductId(), functionDO.getProductKey()); createDefaultEventsAndServices(functionDO.getProductId(), functionDO.getProductKey());
} }
} }
@ -210,7 +210,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
public void createDefaultEventsAndServices(Long productId, String productKey) { public void createDefaultEventsAndServices(Long productId, String productKey) {
// 1. 获取当前属性列表 // 1. 获取当前属性列表
List<IotThinkModelFunctionDO> propertyList = thinkModelFunctionMapper List<IotThinkModelFunctionDO> propertyList = thinkModelFunctionMapper
.selectListByProductIdAndType(productId, IotProductFunctionTypeEnum.PROPERTY.getType()); .selectListByProductIdAndType(productId, IotProductThingModelTypeEnum.PROPERTY.getType());
// 2. 生成新的事件和服务列表 // 2. 生成新的事件和服务列表
List<IotThinkModelFunctionDO> newFunctionList = new ArrayList<>(); List<IotThinkModelFunctionDO> newFunctionList = new ArrayList<>();
@ -237,7 +237,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
List<IotThinkModelFunctionDO> oldFunctionList = thinkModelFunctionMapper.selectListByProductIdAndIdentifiersAndTypes( List<IotThinkModelFunctionDO> oldFunctionList = thinkModelFunctionMapper.selectListByProductIdAndIdentifiersAndTypes(
productId, productId,
Arrays.asList("post", "set", "get"), Arrays.asList("post", "set", "get"),
Arrays.asList(IotProductFunctionTypeEnum.EVENT.getType(), IotProductFunctionTypeEnum.SERVICE.getType()) Arrays.asList(IotProductThingModelTypeEnum.EVENT.getType(), IotProductThingModelTypeEnum.SERVICE.getType())
); );
// 3.1 使用 diffList 方法比较新旧列表 // 3.1 使用 diffList 方法比较新旧列表
@ -300,7 +300,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
.setIdentifier(event.getIdentifier()) .setIdentifier(event.getIdentifier())
.setName(event.getName()) .setName(event.getName())
.setDescription(event.getDescription()) .setDescription(event.getDescription())
.setType(IotProductFunctionTypeEnum.EVENT.getType()) .setType(IotProductThingModelTypeEnum.EVENT.getType())
.setEvent(event); .setEvent(event);
} }
@ -314,7 +314,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
.setIdentifier(service.getIdentifier()) .setIdentifier(service.getIdentifier())
.setName(service.getName()) .setName(service.getName())
.setDescription(service.getDescription()) .setDescription(service.getDescription())
.setType(IotProductFunctionTypeEnum.SERVICE.getType()) .setType(IotProductThingModelTypeEnum.SERVICE.getType())
.setService(service); .setService(service);
} }
@ -358,9 +358,10 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
} }
List<ThingModelArgument> inputData = new ArrayList<>(); List<ThingModelArgument> inputData = new ArrayList<>();
// TODO @puhui999: 需要重构
for (IotThinkModelFunctionDO functionDO : propertyList) { for (IotThinkModelFunctionDO functionDO : propertyList) {
ThingModelProperty property = functionDO.getProperty(); ThingModelProperty property = functionDO.getProperty();
if (IotAccessModeEnum.WRITE.getMode().equals(property.getAccessMode()) || IotAccessModeEnum.READ_WRITE.getMode().equals(property.getAccessMode())) { if (IotProductThingModelAccessModeEnum.WRITE.getMode().equals(property.getAccessMode()) || IotProductThingModelAccessModeEnum.READ_WRITE.getMode().equals(property.getAccessMode())) {
ThingModelArgument arg = new ThingModelArgument() ThingModelArgument arg = new ThingModelArgument()
.setIdentifier(property.getIdentifier()) .setIdentifier(property.getIdentifier())
.setName(property.getName()) .setName(property.getName())
@ -399,7 +400,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
for (IotThinkModelFunctionDO functionDO : propertyList) { for (IotThinkModelFunctionDO functionDO : propertyList) {
ThingModelProperty property = functionDO.getProperty(); ThingModelProperty property = functionDO.getProperty();
if (ObjectUtils.equalsAny(property.getAccessMode(), if (ObjectUtils.equalsAny(property.getAccessMode(),
IotAccessModeEnum.READ.getMode(), IotAccessModeEnum.READ_WRITE.getMode())) { IotProductThingModelAccessModeEnum.READ.getMode(), IotProductThingModelAccessModeEnum.READ_WRITE.getMode())) {
ThingModelArgument arg = new ThingModelArgument() ThingModelArgument arg = new ThingModelArgument()
.setIdentifier(property.getIdentifier()) .setIdentifier(property.getIdentifier())
.setName(property.getName()) .setName(property.getName())
@ -430,10 +431,10 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
// 创建数组类型元素类型为文本类型字符串 // 创建数组类型元素类型为文本类型字符串
ThingModelArrayType arrayType = new ThingModelArrayType(); ThingModelArrayType arrayType = new ThingModelArrayType();
arrayType.setType("array"); arrayType.setDataType("array");
ThingModelArraySpecs arraySpecs = new ThingModelArraySpecs(); ThingModelArraySpecs arraySpecs = new ThingModelArraySpecs();
ThingModelTextType textType = new ThingModelTextType(); ThingModelTextType textType = new ThingModelTextType();
textType.setType("text"); textType.setDataType("text");
arraySpecs.setItem(textType); arraySpecs.setItem(textType);
arrayType.setSpecs(arraySpecs); arrayType.setSpecs(arraySpecs);
inputArg.setDataType(arrayType); inputArg.setDataType(arrayType);