【功能完善】IoT: 产品物模型 CRUD 接口测试

This commit is contained in:
puhui999 2024-12-16 16:41:28 +08:00
parent f930f31fab
commit 9e98768022
20 changed files with 382 additions and 231 deletions

View File

@ -0,0 +1,187 @@
### 请求 /iot/product-thing-model/create 接口 => 成功
POST {{baseUrl}}/iot/product-thing-model/create
Content-Type: application/json
tenant-id: {{adminTenentId}}
Authorization: Bearer {{token}}
{
"productId": 12,
"productKey": "CJVS54fObwZJ9Qe5CJVS54fObwZJ9Qe5",
"identifier": "Temperature",
"name": "温度",
"description": "当前温度值",
"type": 1,
"property": {
"identifier": "Temperature",
"name": "温度",
"accessMode": "r",
"required": true,
"dataType": "int",
"dataSpecs": {
"dataType": "int",
"max": "200",
"min": "0",
"step": "10",
"defaultValue": "30",
"unit": "%",
"unitName": "百分比"
},
"description": "当前温度值"
}
}
### 请求 /iot/product-thing-model/create 接口 => 成功
POST {{baseUrl}}/iot/product-thing-model/create
Content-Type: application/json
tenant-id: {{adminTenentId}}
Authorization: Bearer {{token}}
{
"productId": 12,
"productKey": "CJVS54fObwZJ9Qe5CJVS54fObwZJ9Qe5",
"identifier": "switch",
"name": "开关",
"description": "温度计开关",
"type": 1,
"property": {
"identifier": "switch",
"name": "开关",
"description": "温度计开关",
"accessMode": "rw",
"required": true,
"dataType": "bool",
"dataSpecsList": [
{
"dataType": "bool",
"name": "关",
"value": 0
},
{
"dataType": "bool",
"name": "开",
"value": 1
}
]
}
}
### 请求 /iot/product-thing-model/create 接口 => 成功
POST {{baseUrl}}/iot/product-thing-model/create
Content-Type: application/json
tenant-id: {{adminTenentId}}
Authorization: Bearer {{token}}
{
"productId": 12,
"productKey": "CJVS54fObwZJ9Qe5CJVS54fObwZJ9Qe5",
"identifier": "argb",
"name": "温度计 argb 颜色",
"description": "温度计 argb 颜色",
"type": 1,
"property": {
"identifier": "argb",
"name": "温度计 argb 颜色",
"description": "温度计 argb 颜色",
"accessMode": "rw",
"required": true,
"dataType": "array",
"dataSpecs": {
"dataType": "array",
"size": 10,
"childDataType": "struct",
"dataSpecsList": [
{
"identifier": "switch",
"name": "开关",
"description": "温度计开关",
"accessMode": "rw",
"required": true,
"dataType": "struct",
"childDataType": "bool",
"dataSpecsList": [
{
"dataType": "bool",
"name": "关",
"value": 0
},
{
"dataType": "bool",
"name": "开",
"value": 1
}
]
},
{
"identifier": "Temperature",
"name": "温度",
"accessMode": "r",
"required": true,
"dataType": "struct",
"childDataType": "int",
"dataSpecs": {
"dataType": "int",
"max": "200",
"min": "0",
"step": "10",
"defaultValue": "30",
"unit": "%",
"unitName": "百分比"
},
"description": "当前温度值"
}
]
}
}
}
### 请求 /iot/product-thing-model/update 接口 => 成功
PUT {{baseUrl}}/iot/product-thing-model/update
Content-Type: application/json
tenant-id: {{adminTenentId}}
Authorization: Bearer {{token}}
{
"id": 33,
"productId": 12,
"productKey": "CJVS54fObwZJ9Qe5CJVS54fObwZJ9Qe5",
"identifier": "switch",
"name": "开关",
"description": "温度计开关",
"type": 1,
"property": {
"identifier": "switch",
"name": "开关",
"description": "温度计开关",
"accessMode": "r",
"required": true,
"dataType": "bool",
"dataSpecsList": [
{
"dataType": "bool",
"name": "关",
"value": 0
},
{
"dataType": "bool",
"name": "开",
"value": 1
}
]
}
}
### 请求 /iot/product-thing-model/delete 接口 => 成功
DELETE {{baseUrl}}/iot/product-thing-model/delete?id=36
tenant-id: {{adminTenentId}}
Authorization: Bearer {{token}}
### 请求 /iot/product-thing-model/get 接口 => 成功
GET {{baseUrl}}/iot/product-thing-model/get?id=40
tenant-id: {{adminTenentId}}
Authorization: Bearer {{token}}
### 请求 /iot/product-thing-model/list-by-product-id 接口 => 成功
GET {{baseUrl}}/iot/product-thing-model/list-by-product-id?productId=1001
tenant-id: {{adminTenentId}}
Authorization: Bearer {{token}}

View File

@ -3,12 +3,12 @@ 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.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.controller.admin.productthingmodel.vo.IotProductThingModelPageReqVO;
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.vo.IotProductThingModelRespVO;
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.vo.IotProductThingModelSaveReqVO;
import cn.iocoder.yudao.module.iot.convert.productthingmodel.IotProductThingModelConvert;
import cn.iocoder.yudao.module.iot.dal.dataobject.productthingmodel.IotProductThingModelDO;
import cn.iocoder.yudao.module.iot.service.thinkmodelfunction.IotThinkModelFunctionService;
import cn.iocoder.yudao.module.iot.service.productthingmodel.IotProductThingModelService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -24,61 +24,61 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - IoT 产品物模型")
@RestController
@RequestMapping("/iot/think-model-function")
@RequestMapping("/iot/product-thing-model")
@Validated
public class IotProductThingModelController {
@Resource
private IotThinkModelFunctionService thinkModelFunctionService;
private IotProductThingModelService thinkModelFunctionService;
@PostMapping("/create")
@Operation(summary = "创建产品物模型")
@PreAuthorize("@ss.hasPermission('iot:think-model-function:create')")
public CommonResult<Long> createThinkModelFunction(@Valid @RequestBody IotThinkModelFunctionSaveReqVO createReqVO) {
return success(thinkModelFunctionService.createThinkModelFunction(createReqVO));
@PreAuthorize("@ss.hasPermission('iot:product-thing-model:create')")
public CommonResult<Long> createProductThingModel(@Valid @RequestBody IotProductThingModelSaveReqVO createReqVO) {
return success(thinkModelFunctionService.createProductThingModel(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新产品物模型")
@PreAuthorize("@ss.hasPermission('iot:think-model-function:update')")
public CommonResult<Boolean> updateThinkModelFunction(@Valid @RequestBody IotThinkModelFunctionSaveReqVO updateReqVO) {
thinkModelFunctionService.updateThinkModelFunction(updateReqVO);
@PreAuthorize("@ss.hasPermission('iot:product-thing-model:update')")
public CommonResult<Boolean> updateProductThingModel(@Valid @RequestBody IotProductThingModelSaveReqVO updateReqVO) {
thinkModelFunctionService.updateProductThingModel(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除产品物模型")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('iot:think-model-function:delete')")
public CommonResult<Boolean> deleteThinkModelFunction(@RequestParam("id") Long id) {
thinkModelFunctionService.deleteThinkModelFunction(id);
@PreAuthorize("@ss.hasPermission('iot:product-thing-model:delete')")
public CommonResult<Boolean> deleteProductThingModel(@RequestParam("id") Long id) {
thinkModelFunctionService.deleteProductThingModel(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得产品物模型")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('iot:think-model-function:query')")
public CommonResult<IotThinkModelFunctionRespVO> getThinkModelFunction(@RequestParam("id") Long id) {
IotProductThingModelDO function = thinkModelFunctionService.getThinkModelFunction(id);
return success(IotThinkModelFunctionConvert.INSTANCE.convert(function));
@PreAuthorize("@ss.hasPermission('iot:product-thing-model:query')")
public CommonResult<IotProductThingModelRespVO> getProductThingModel(@RequestParam("id") Long id) {
IotProductThingModelDO function = thinkModelFunctionService.getProductThingModel(id);
return success(IotProductThingModelConvert.INSTANCE.convert(function));
}
@GetMapping("/list-by-product-id")
@Operation(summary = "获得产品物模型")
@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<IotProductThingModelDO> list = thinkModelFunctionService.getThinkModelFunctionListByProductId(productId);
return success(IotThinkModelFunctionConvert.INSTANCE.convertList(list));
@PreAuthorize("@ss.hasPermission('iot:product-thing-model:query')")
public CommonResult<List<IotProductThingModelRespVO>> getProductThingModelListByProductId(@RequestParam("productId") Long productId) {
List<IotProductThingModelDO> list = thinkModelFunctionService.getProductThingModelListByProductId(productId);
return success(IotProductThingModelConvert.INSTANCE.convertList(list));
}
@GetMapping("/page")
@Operation(summary = "获得产品物模型分页")
@PreAuthorize("@ss.hasPermission('iot:think-model-function:query')")
public CommonResult<PageResult<IotThinkModelFunctionRespVO>> getThinkModelFunctionPage(@Valid IotThinkModelFunctionPageReqVO pageReqVO) {
PageResult<IotProductThingModelDO> pageResult = thinkModelFunctionService.getThinkModelFunctionPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, IotThinkModelFunctionRespVO.class));
@PreAuthorize("@ss.hasPermission('iot:product-thing-model:query')")
public CommonResult<PageResult<IotProductThingModelRespVO>> getProductThingModelPage(@Valid IotProductThingModelPageReqVO pageReqVO) {
PageResult<IotProductThingModelDO> pageResult = thinkModelFunctionService.getProductThingModelPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, IotProductThingModelRespVO.class));
}
}

View File

@ -1,112 +0,0 @@
### 请求 /iot/think-model-function/create 接口 => 成功
POST {{baseUrl}}/iot/think-model-function/create
Content-Type: application/json
tenant-id: {{adminTenentId}}
Authorization: Bearer {{token}}
{
"productId": 1001,
"productKey": "smart-sensor-001",
"identifier": "Temperature",
"name": "温度",
"description": "当前温度值",
"type": 1,
"property": {
"identifier": "Temperature",
"name": "温度",
"accessMode": "r",
"required": true,
"dataType": {
"type": "float",
"specs": {
"min": -10.0,
"max": 100.0,
"step": 0.1,
"unit": "℃"
}
},
"description": "当前温度值"
}
}
### 请求 /iot/think-model-function/create 接口 => 成功
POST {{baseUrl}}/iot/think-model-function/create
Content-Type: application/json
tenant-id: {{adminTenentId}}
Authorization: Bearer {{token}}
{
"productId": 1001,
"productKey": "smart-sensor-001",
"identifier": "Humidity",
"name": "湿度",
"description": "当前湿度值",
"type": 1,
"property": {
"identifier": "Humidity",
"name": "湿度",
"accessMode": "r",
"required": true,
"dataType": {
"type": "float",
"specs": {
"min": 0.0,
"max": 100.0,
"step": 0.1,
"unit": "%"
}
},
"description": "当前湿度值"
}
}
### 请求 /iot/think-model-function/update 接口 => 成功
PUT {{baseUrl}}/iot/think-model-function/update
Content-Type: application/json
tenant-id: {{adminTenentId}}
Authorization: Bearer {{token}}
{
"id": 11,
"productId": 1001,
"productKey": "smart-sensor-001",
"identifier": "Temperature",
"name": "温度",
"description": "当前温度值",
"type": 1,
"property": {
"identifier": "Temperature",
"name": "温度",
"accessMode": "r",
"required": true,
"dataType": {
"type": "float",
"specs": {
"min": -111.0,
"max": 222.0,
"step": 0.1,
"unit": "℃"
}
},
"description": "当前温度值"
}
}
### 请求 /iot/think-model-function/delete 接口 => 成功
DELETE {{baseUrl}}/iot/think-model-function/delete?id=7
tenant-id: {{adminTenentId}}
Authorization: Bearer {{token}}
### 请求 /iot/think-model-function/get 接口 => 成功
GET {{baseUrl}}/iot/think-model-function/get?id=10
tenant-id: {{adminTenentId}}
Authorization: Bearer {{token}}
### 请求 /iot/think-model-function/list-by-product-id 接口 => 成功
GET {{baseUrl}}/iot/think-model-function/list-by-product-id?productId=1001
tenant-id: {{adminTenentId}}
Authorization: Bearer {{token}}

View File

@ -1,6 +1,9 @@
package cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.dataType;
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.ThingModelProperty;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
@ -10,24 +13,21 @@ import java.util.List;
* @author HUIHUI
*/
@Data
@EqualsAndHashCode(callSuper = true)
@JsonIgnoreProperties({"dataType"}) // 忽略子类中的 dataType 字段从而避免重复
public class ThingModelArrayDataSpecs extends ThingModelDataSpecs {
/**
* 数组中的元素个数
*/
private Long size;
private Integer size;
/**
* 数组中的元素的数据类型可选值structintfloatdouble text
*/
private String childDataType;
/**
* 数据类型dataType为非列表型intfloatdoubletextdatearray的数据规范存储在 dataSpecs
* 仅当 dataType 不是列表型时才传入此字段
*/
private ThingModelDataSpecs dataSpecs;
/**
* 数据类型dataType为列表型enumboolstruct的数据规范存储在 dataSpecsList
* 仅当 dataType 是列表型时才传入此字段
* 数据类型childDataType为列表型 struct 的数据规范存储在 dataSpecsList
* 此时 struct 取值范围为intfloatdoubletextdateenumbool
*/
private List<ThingModelDataSpecs> dataSpecsList;

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.dataType;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -12,6 +13,7 @@ import lombok.EqualsAndHashCode;
*/
@Data
@EqualsAndHashCode(callSuper = true)
@JsonIgnoreProperties({"dataType"}) // 忽略子类中的 dataType 字段从而避免重复
public class ThingModelBoolOrEnumDataSpecs extends ThingModelDataSpecs {
/**

View File

@ -22,7 +22,8 @@ import lombok.Data;
@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")
@JsonSubTypes.Type(value = ThingModelArrayDataSpecs.class, name = "array"),
@JsonSubTypes.Type(value = ThingModelStructDataSpecs.class, name = "struct")
})
public abstract class ThingModelDataSpecs {

View File

@ -1,6 +1,8 @@
package cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.dataType;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 物模型数据类型为时间型或文本型的 DataSpec 定义
@ -10,6 +12,8 @@ import lombok.Data;
* @author HUIHUI
*/
@Data
@EqualsAndHashCode(callSuper = true)
@JsonIgnoreProperties({"dataType"}) // 忽略子类中的 dataType 字段从而避免重复
public class ThingModelDateOrTextDataSpecs extends ThingModelDataSpecs {
/**

View File

@ -1,6 +1,8 @@
package cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.dataType;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 物模型数据类型为数值的 DataSpec 定义
@ -10,6 +12,8 @@ import lombok.Data;
* @author HUIHUI
*/
@Data
@EqualsAndHashCode(callSuper = true)
@JsonIgnoreProperties({"dataType"}) // 忽略子类中的 dataType 字段从而避免重复
public class ThingModelNumericDataSpec extends ThingModelDataSpecs {
/**

View File

@ -0,0 +1,58 @@
package cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel.dataType;
import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelAccessModeEnum;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
/**
* 物模型数据类型为 struct DataSpec 定义
*
* @author HUIHUI
*/
@Data
@EqualsAndHashCode(callSuper = true)
@JsonIgnoreProperties({"dataType"}) // 忽略子类中的 dataType 字段从而避免重复
public class ThingModelStructDataSpecs extends ThingModelDataSpecs {
/**
* 属性标识符
*/
private String identifier;
/**
* 属性名称
*/
private String name;
/**
* 属性描述
*/
private String description;
/**
* 云端可以对该属性进行的操作类型
* 关联枚举 {@link IotProductThingModelAccessModeEnum}
*/
private String accessMode;
/**
* 是否是标准品类的必选服务
*
* - true
* - false
*/
private Boolean required;
/**
* struct 数据的数据类型
*/
private String childDataType;
/**
* 数据类型dataType为非列表型intfloatdoubletextdatearray的数据规范存储在 dataSpecs
*/
private ThingModelDataSpecs dataSpecs;
/**
* 数据类型dataType为列表型enumboolstruct的数据规范存储在 dataSpecsList
*/
private List<ThingModelDataSpecs> dataSpecsList;
}

View File

@ -13,7 +13,7 @@ import lombok.ToString;
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class IotThinkModelFunctionPageReqVO extends PageParam {
public class IotProductThingModelPageReqVO extends PageParam {
@Schema(description = "功能标识")
private String identifier;

View File

@ -13,7 +13,7 @@ import java.time.LocalDateTime;
@Schema(description = "管理后台 - IoT 产品物模型 Response VO")
@Data
@ExcelIgnoreUnannotated
public class IotThinkModelFunctionRespVO {
public class IotProductThingModelRespVO {
@Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "21816")
@ExcelProperty("产品ID")

View File

@ -12,7 +12,7 @@ import lombok.Data;
@Schema(description = "管理后台 - IoT 产品物模型新增/修改 Request VO")
@Data
public class IotThinkModelFunctionSaveReqVO {
public class IotProductThingModelSaveReqVO {
@Schema(description = "编号", example = "1")
private Long id;

View File

@ -1,57 +1,62 @@
package cn.iocoder.yudao.module.iot.convert.thinkmodelfunction;
package cn.iocoder.yudao.module.iot.convert.productthingmodel;
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.controller.admin.productthingmodel.vo.IotProductThingModelRespVO;
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.vo.IotProductThingModelSaveReqVO;
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;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.Objects;
@Mapper
public interface IotThinkModelFunctionConvert {
public interface IotProductThingModelConvert {
IotThinkModelFunctionConvert INSTANCE = Mappers.getMapper(IotThinkModelFunctionConvert.class);
IotProductThingModelConvert INSTANCE = Mappers.getMapper(IotProductThingModelConvert.class);
// SaveReqVO 转换为 DO
@Mapping(target = "property", expression = "java(convertToProperty(bean))")
@Mapping(target = "event", expression = "java(convertToEvent(bean))")
@Mapping(target = "service", expression = "java(convertToService(bean))")
IotProductThingModelDO convert(IotThinkModelFunctionSaveReqVO bean);
IotProductThingModelDO convert(IotProductThingModelSaveReqVO bean);
default ThingModelProperty convertToProperty(IotThinkModelFunctionSaveReqVO bean) {
// DO 转换为 RespVO
@Mapping(target = "property", source = "property")
@Mapping(target = "event", source = "event")
@Mapping(target = "service", source = "service")
IotProductThingModelRespVO convert(IotProductThingModelDO bean);
// 批量转换
List<IotProductThingModelRespVO> convertList(List<IotProductThingModelDO> list);
@Named("convertToProperty")
default ThingModelProperty convertToProperty(IotProductThingModelSaveReqVO bean) {
if (Objects.equals(bean.getType(), IotProductThingModelTypeEnum.PROPERTY.getType())) {
return bean.getProperty();
}
return null;
}
default ThingModelEvent convertToEvent(IotThinkModelFunctionSaveReqVO bean) {
@Named("convertToEvent")
default ThingModelEvent convertToEvent(IotProductThingModelSaveReqVO bean) {
if (Objects.equals(bean.getType(), IotProductThingModelTypeEnum.EVENT.getType())) {
return bean.getEvent();
}
return null;
}
default ThingModelService convertToService(IotThinkModelFunctionSaveReqVO bean) {
@Named("convertToService")
default ThingModelService convertToService(IotProductThingModelSaveReqVO bean) {
if (Objects.equals(bean.getType(), IotProductThingModelTypeEnum.SERVICE.getType())) {
return bean.getService();
}
return null;
}
// DO 转换为 RespVO
@Mapping(target = "property", source = "property")
@Mapping(target = "event", source = "event")
@Mapping(target = "service", source = "service")
IotThinkModelFunctionRespVO convert(IotProductThingModelDO bean);
// 批量转换
List<IotThinkModelFunctionRespVO> convertList(List<IotProductThingModelDO> list);
}

View File

@ -23,8 +23,8 @@ import lombok.NoArgsConstructor;
*
* @author 芋道源码
*/
@TableName(value = "iot_think_model_function", autoResultMap = true)
@KeySequence("iot_think_model_function_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@TableName(value = "iot_product_thing_model", autoResultMap = true)
@KeySequence("iot_product_thing_model_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data
@Builder
@NoArgsConstructor

View File

@ -3,7 +3,7 @@ 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.productthingmodel.vo.IotThinkModelFunctionPageReqVO;
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.vo.IotProductThingModelPageReqVO;
import cn.iocoder.yudao.module.iot.dal.dataobject.productthingmodel.IotProductThingModelDO;
import org.apache.ibatis.annotations.Mapper;
@ -15,9 +15,9 @@ import java.util.List;
* @author 芋道源码
*/
@Mapper
public interface IotThinkModelFunctionMapper extends BaseMapperX<IotProductThingModelDO> {
public interface IotProductThingModelMapper extends BaseMapperX<IotProductThingModelDO> {
default PageResult<IotProductThingModelDO> selectPage(IotThinkModelFunctionPageReqVO reqVO) {
default PageResult<IotProductThingModelDO> selectPage(IotProductThingModelPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<IotProductThingModelDO>()
.eqIfPresent(IotProductThingModelDO::getIdentifier, reqVO.getIdentifier())
.likeIfPresent(IotProductThingModelDO::getName, reqVO.getName())

View File

@ -15,7 +15,7 @@ import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDMLMapper;
import cn.iocoder.yudao.module.iot.enums.IotConstants;
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.thinkmodelfunction.IotThinkModelFunctionService;
import cn.iocoder.yudao.module.iot.service.productthingmodel.IotProductThingModelService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
@ -40,7 +40,7 @@ public class IotDeviceDataServiceImpl implements IotDeviceDataService {
@Resource
private IotThingModelMessageService thingModelMessageService;
@Resource
private IotThinkModelFunctionService thinkModelFunctionService;
private IotProductThingModelService thinkModelFunctionService;
@Resource
private TdEngineDMLMapper tdEngineDMLMapper;
@ -73,7 +73,7 @@ public class IotDeviceDataServiceImpl implements IotDeviceDataService {
// 1. 获取设备信息
IotDeviceDO device = deviceService.getDevice(deviceDataReqVO.getDeviceId());
// 2. 获取设备属性最新数据
List<IotProductThingModelDO> thinkModelFunctionList = thinkModelFunctionService.getThinkModelFunctionListByProductKey(device.getProductKey());
List<IotProductThingModelDO> thinkModelFunctionList = thinkModelFunctionService.getProductThingModelListByProductKey(device.getProductKey());
thinkModelFunctionList = thinkModelFunctionList.stream()
.filter(function -> IotProductThingModelTypeEnum.PROPERTY.getType()
.equals(function.getType())).toList();

View File

@ -7,7 +7,7 @@ import cn.iocoder.yudao.module.iot.controller.admin.product.vo.product.IotProduc
import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
import cn.iocoder.yudao.module.iot.dal.mysql.product.IotProductMapper;
import cn.iocoder.yudao.module.iot.enums.product.IotProductStatusEnum;
import cn.iocoder.yudao.module.iot.service.thinkmodelfunction.IotThinkModelFunctionService;
import cn.iocoder.yudao.module.iot.service.productthingmodel.IotProductThingModelService;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Lazy;
@ -34,7 +34,7 @@ public class IotProductServiceImpl implements IotProductService {
@Resource
@Lazy
private IotThinkModelFunctionService thinkModelFunctionService;
private IotProductThingModelService thinkModelFunctionService;
@Override
public Long createProduct(IotProductSaveReqVO createReqVO) {

View File

@ -1,8 +1,8 @@
package cn.iocoder.yudao.module.iot.service.thinkmodelfunction;
package cn.iocoder.yudao.module.iot.service.productthingmodel;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
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.controller.admin.productthingmodel.vo.IotProductThingModelPageReqVO;
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.vo.IotProductThingModelSaveReqVO;
import cn.iocoder.yudao.module.iot.dal.dataobject.productthingmodel.IotProductThingModelDO;
import jakarta.validation.Valid;
@ -13,7 +13,7 @@ import java.util.List;
*
* @author 芋道源码
*/
public interface IotThinkModelFunctionService {
public interface IotProductThingModelService {
/**
* 创建产品物模型
@ -21,7 +21,7 @@ public interface IotThinkModelFunctionService {
* @param createReqVO 创建信息
* @return 编号
*/
Long createThinkModelFunction(@Valid IotThinkModelFunctionSaveReqVO createReqVO);
Long createProductThingModel(@Valid IotProductThingModelSaveReqVO createReqVO);
/**
@ -29,14 +29,14 @@ public interface IotThinkModelFunctionService {
*
* @param updateReqVO 更新信息
*/
void updateThinkModelFunction(@Valid IotThinkModelFunctionSaveReqVO updateReqVO);
void updateProductThingModel(@Valid IotProductThingModelSaveReqVO updateReqVO);
/**
* 删除产品物模型
*
* @param id 编号
*/
void deleteThinkModelFunction(Long id);
void deleteProductThingModel(Long id);
/**
* 获得产品物模型
@ -44,7 +44,7 @@ public interface IotThinkModelFunctionService {
* @param id 编号
* @return 产品物模型
*/
IotProductThingModelDO getThinkModelFunction(Long id);
IotProductThingModelDO getProductThingModel(Long id);
/**
* 获得产品物模型列表
@ -52,7 +52,7 @@ public interface IotThinkModelFunctionService {
* @param productId 产品编号
* @return 产品物模型列表
*/
List<IotProductThingModelDO> getThinkModelFunctionListByProductId(Long productId);
List<IotProductThingModelDO> getProductThingModelListByProductId(Long productId);
/**
* 获得产品物模型分页
@ -60,7 +60,7 @@ public interface IotThinkModelFunctionService {
* @param pageReqVO 分页查询
* @return 产品物模型分页
*/
PageResult<IotProductThingModelDO> getThinkModelFunctionPage(IotThinkModelFunctionPageReqVO pageReqVO);
PageResult<IotProductThingModelDO> getProductThingModelPage(IotProductThingModelPageReqVO pageReqVO);
/**
* 创建超级表数据模型
@ -75,5 +75,6 @@ public interface IotThinkModelFunctionService {
* @param productKey 产品 Key
* @return 产品物模型列表
*/
List<IotProductThingModelDO> getThinkModelFunctionListByProductKey(String productKey);
List<IotProductThingModelDO> getProductThingModelListByProductKey(String productKey);
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.iot.service.thinkmodelfunction;
package cn.iocoder.yudao.module.iot.service.productthingmodel;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
@ -10,12 +10,12 @@ import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.thingmodel
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.controller.admin.productthingmodel.vo.IotProductThingModelPageReqVO;
import cn.iocoder.yudao.module.iot.controller.admin.productthingmodel.vo.IotProductThingModelSaveReqVO;
import cn.iocoder.yudao.module.iot.convert.productthingmodel.IotProductThingModelConvert;
import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
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.dal.mysql.thinkmodelfunction.IotProductThingModelMapper;
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;
@ -41,10 +41,10 @@ import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
@Service
@Validated
@Slf4j
public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionService {
public class IotProductThingModelServiceImpl implements IotProductThingModelService {
@Resource
private IotThinkModelFunctionMapper thinkModelFunctionMapper;
private IotProductThingModelMapper productThingModelMapper;
@Resource
private IotProductService productService;
@ -53,7 +53,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
@Override
@Transactional(rollbackFor = Exception.class)
public Long createThinkModelFunction(IotThinkModelFunctionSaveReqVO createReqVO) {
public Long createProductThingModel(IotProductThingModelSaveReqVO createReqVO) {
// 1. 校验功能标识符在同一产品下是否唯一
validateIdentifierUnique(createReqVO.getProductId(), createReqVO.getIdentifier());
@ -67,12 +67,12 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
validateProductStatus(createReqVO.getProductId());
// 5. 插入数据库
IotProductThingModelDO function = IotThinkModelFunctionConvert.INSTANCE.convert(createReqVO);
thinkModelFunctionMapper.insert(function);
IotProductThingModelDO function = IotProductThingModelConvert.INSTANCE.convert(createReqVO);
productThingModelMapper.insert(function);
// 6. 如果创建的是属性需要更新默认的事件和服务
if (Objects.equals(createReqVO.getType(), IotProductThingModelTypeEnum.PROPERTY.getType())) {
createDefaultEventsAndServices(createReqVO.getProductId(), createReqVO.getProductKey());
//createDefaultEventsAndServices(createReqVO.getProductId(), createReqVO.getProductKey());
}
return function.getId();
}
@ -95,14 +95,14 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
}
private void validateNameUnique(Long productId, String name) {
IotProductThingModelDO function = thinkModelFunctionMapper.selectByProductIdAndName(productId, name);
IotProductThingModelDO function = productThingModelMapper.selectByProductIdAndName(productId, name);
if (function != null) {
throw exception(THINK_MODEL_FUNCTION_NAME_EXISTS);
}
}
private void validateIdentifierUnique(Long productId, String identifier) {
IotProductThingModelDO function = thinkModelFunctionMapper.selectByProductIdAndIdentifier(productId, identifier);
IotProductThingModelDO function = productThingModelMapper.selectByProductIdAndIdentifier(productId, identifier);
if (function != null) {
throw exception(THINK_MODEL_FUNCTION_IDENTIFIER_EXISTS);
}
@ -110,9 +110,9 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
@Override
@Transactional(rollbackFor = Exception.class)
public void updateThinkModelFunction(IotThinkModelFunctionSaveReqVO updateReqVO) {
public void updateProductThingModel(IotProductThingModelSaveReqVO updateReqVO) {
// 1. 校验功能是否存在
validateThinkModelFunctionExists(updateReqVO.getId());
validateproductThingModelMapperExists(updateReqVO.getId());
// 2. 校验功能标识符是否唯一
validateIdentifierUniqueForUpdate(updateReqVO.getId(), updateReqVO.getProductId(), updateReqVO.getIdentifier());
@ -121,8 +121,8 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
validateProductStatus(updateReqVO.getProductId());
// 4. 更新数据库
IotProductThingModelDO thinkModelFunction = IotThinkModelFunctionConvert.INSTANCE.convert(updateReqVO);
thinkModelFunctionMapper.updateById(thinkModelFunction);
IotProductThingModelDO productThingModelDO = IotProductThingModelConvert.INSTANCE.convert(updateReqVO);
productThingModelMapper.updateById(productThingModelDO);
// 5. 如果更新的是属性需要更新默认的事件和服务
if (Objects.equals(updateReqVO.getType(), IotProductThingModelTypeEnum.PROPERTY.getType())) {
@ -131,7 +131,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
}
private void validateIdentifierUniqueForUpdate(Long id, Long productId, String identifier) {
IotProductThingModelDO function = thinkModelFunctionMapper.selectByProductIdAndIdentifier(productId, identifier);
IotProductThingModelDO function = productThingModelMapper.selectByProductIdAndIdentifier(productId, identifier);
if (function != null && ObjectUtil.notEqual(function.getId(), id)) {
throw exception(THINK_MODEL_FUNCTION_IDENTIFIER_EXISTS);
}
@ -139,9 +139,9 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteThinkModelFunction(Long id) {
public void deleteProductThingModel(Long id) {
// 1. 校验功能是否存在
IotProductThingModelDO functionDO = thinkModelFunctionMapper.selectById(id);
IotProductThingModelDO functionDO = productThingModelMapper.selectById(id);
if (functionDO == null) {
throw exception(THINK_MODEL_FUNCTION_NOT_EXISTS);
}
@ -150,7 +150,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
validateProductStatus(functionDO.getProductId());
// 2. 删除功能
thinkModelFunctionMapper.deleteById(id);
productThingModelMapper.deleteById(id);
// 3. 如果删除的是属性需要更新默认的事件和服务
if (Objects.equals(functionDO.getType(), IotProductThingModelTypeEnum.PROPERTY.getType())) {
@ -163,25 +163,25 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
*
* @param id 功能编号
*/
private void validateThinkModelFunctionExists(Long id) {
if (thinkModelFunctionMapper.selectById(id) == null) {
private void validateproductThingModelMapperExists(Long id) {
if (productThingModelMapper.selectById(id) == null) {
throw exception(THINK_MODEL_FUNCTION_NOT_EXISTS);
}
}
@Override
public IotProductThingModelDO getThinkModelFunction(Long id) {
return thinkModelFunctionMapper.selectById(id);
public IotProductThingModelDO getProductThingModel(Long id) {
return productThingModelMapper.selectById(id);
}
@Override
public List<IotProductThingModelDO> getThinkModelFunctionListByProductId(Long productId) {
return thinkModelFunctionMapper.selectListByProductId(productId);
public List<IotProductThingModelDO> getProductThingModelListByProductId(Long productId) {
return productThingModelMapper.selectListByProductId(productId);
}
@Override
public PageResult<IotProductThingModelDO> getThinkModelFunctionPage(IotThinkModelFunctionPageReqVO pageReqVO) {
return thinkModelFunctionMapper.selectPage(pageReqVO);
public PageResult<IotProductThingModelDO> getProductThingModelPage(IotProductThingModelPageReqVO pageReqVO) {
return productThingModelMapper.selectPage(pageReqVO);
}
@Override
@ -190,23 +190,24 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
IotProductDO product = productService.getProduct(productId);
// 2. 查询产品的物模型功能列表
List<IotProductThingModelDO> functionList = thinkModelFunctionMapper.selectListByProductId(productId);
List<IotProductThingModelDO> functionList = productThingModelMapper.selectListByProductId(productId);
// 3. 生成 TDengine 的数据模型
dbStructureDataService.createSuperTableDataModel(product, functionList);
}
@Override
public List<IotProductThingModelDO> getThinkModelFunctionListByProductKey(String productKey) {
return thinkModelFunctionMapper.selectListByProductKey(productKey);
public List<IotProductThingModelDO> getProductThingModelListByProductKey(String productKey) {
return productThingModelMapper.selectListByProductKey(productKey);
}
// TODO @puhui999: 需要重构
/**
* 创建默认的事件和服务
*/
public void createDefaultEventsAndServices(Long productId, String productKey) {
// 1. 获取当前属性列表
List<IotProductThingModelDO> propertyList = thinkModelFunctionMapper
List<IotProductThingModelDO> propertyList = productThingModelMapper
.selectListByProductIdAndType(productId, IotProductThingModelTypeEnum.PROPERTY.getType());
// 2. 生成新的事件和服务列表
@ -231,7 +232,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
}
// 3. 获取数据库中的默认的旧事件和服务列表
List<IotProductThingModelDO> oldFunctionList = thinkModelFunctionMapper.selectListByProductIdAndIdentifiersAndTypes(
List<IotProductThingModelDO> oldFunctionList = productThingModelMapper.selectListByProductIdAndIdentifiersAndTypes(
productId,
Arrays.asList("post", "set", "get"),
Arrays.asList(IotProductThingModelTypeEnum.EVENT.getType(), IotProductThingModelTypeEnum.SERVICE.getType())
@ -249,7 +250,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
// 3.2 批量执行数据库操作
// 新增数据库中的新事件和服务列表
if (CollUtil.isNotEmpty(createList)) {
thinkModelFunctionMapper.insertBatch(createList);
productThingModelMapper.insertBatch(createList);
}
// 更新数据库中的事件和服务列表
if (CollUtil.isNotEmpty(updateList)) {
@ -267,14 +268,14 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
.collect(Collectors.toList());
// 执行批量更新
if (CollUtil.isNotEmpty(validUpdateList)) {
thinkModelFunctionMapper.updateBatch(validUpdateList);
productThingModelMapper.updateBatch(validUpdateList);
}
}
// 删除数据库中的旧事件和服务列表
if (CollUtil.isNotEmpty(deleteList)) {
Set<Long> idsToDelete = CollectionUtils.convertSet(deleteList, IotProductThingModelDO::getId);
thinkModelFunctionMapper.deleteByIds(idsToDelete);
productThingModelMapper.deleteByIds(idsToDelete);
}
}

View File

@ -19,7 +19,7 @@ import cn.iocoder.yudao.module.iot.enums.IotConstants;
import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStatusEnum;
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.thinkmodelfunction.IotThinkModelFunctionService;
import cn.iocoder.yudao.module.iot.service.productthingmodel.IotProductThingModelService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
@ -47,7 +47,7 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
private String url;
@Resource
private IotThinkModelFunctionService iotThinkModelFunctionService;
private IotProductThingModelService iotProductThingModelService;
@Resource
private IotDeviceService iotDeviceService;
@Resource
@ -91,8 +91,8 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
}
private List<IotProductThingModelDO> getValidFunctionList(String productKey) {
return iotThinkModelFunctionService
.getThinkModelFunctionListByProductKey(productKey)
return iotProductThingModelService
.getProductThingModelListByProductKey(productKey)
.stream()
.filter(function -> IotProductThingModelTypeEnum.PROPERTY.getType().equals(function.getType()))
.toList();