Commit 18e789d4fb988dd4014a65fb4bda5ea90aa8307e
1 parent
1aef8515
新增:增加 IOT 物模型
Showing
13 changed files
with
588 additions
and
4 deletions
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java
| ... | ... | @@ -9,8 +9,11 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode; |
| 9 | 9 | */ |
| 10 | 10 | public interface ErrorCodeConstants { |
| 11 | 11 | |
| 12 | - // ========== 产品相关 1-050-001-000 ============ | |
| 12 | + // ========== IoT 产品相关 1-050-001-000 ============ | |
| 13 | 13 | ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_050_001_000, "产品不存在"); |
| 14 | 14 | ErrorCode PRODUCT_IDENTIFICATION_EXISTS = new ErrorCode(1_050_001_001, "产品标识已经存在"); |
| 15 | 15 | ErrorCode PRODUCT_STATUS_NOT_DELETE = new ErrorCode(1_050_001_002, "产品状是发布状态,不允许删除"); |
| 16 | + | |
| 17 | + // ========== IoT 产品物模型 1-050-002-000 ============ | |
| 18 | + ErrorCode THINK_MODEL_FUNCTION_NOT_EXISTS = new ErrorCode(1_050_002_000, "产品物模型不存在"); | |
| 16 | 19 | } | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodelfunction/IotThinkModelFunctionController.http
0 → 100644
| 1 | +### 请求 /iot/think-model-function/create 接口 => 成功 | |
| 2 | +POST {{baseUrl}}/iot/think-model-function/create | |
| 3 | +Content-Type: application/json | |
| 4 | +tenant-id: {{adminTenentId}} | |
| 5 | +Authorization: Bearer {{token}} | |
| 6 | + | |
| 7 | +{ | |
| 8 | + "productKey": "123456", | |
| 9 | + "properties": [ | |
| 10 | + { | |
| 11 | + "identifier": "CurrentTemperature", | |
| 12 | + "name": "当前温度", | |
| 13 | + "accessMode": "r", | |
| 14 | + "required": true, | |
| 15 | + "dataType": { | |
| 16 | + "type": "float", | |
| 17 | + "specs": { | |
| 18 | + "min": "-40", | |
| 19 | + "max": "120", | |
| 20 | + "unit": "°C", | |
| 21 | + "unitName": "摄氏度", | |
| 22 | + "step": "0.1" | |
| 23 | + } | |
| 24 | + } | |
| 25 | + }, | |
| 26 | + { | |
| 27 | + "identifier": "CurrentHumidity", | |
| 28 | + "name": "当前湿度", | |
| 29 | + "accessMode": "r", | |
| 30 | + "required": true, | |
| 31 | + "dataType": { | |
| 32 | + "type": "float", | |
| 33 | + "specs": { | |
| 34 | + "min": "0", | |
| 35 | + "max": "100", | |
| 36 | + "unit": "%", | |
| 37 | + "unitName": "百分比", | |
| 38 | + "step": "0.1" | |
| 39 | + } | |
| 40 | + } | |
| 41 | + } | |
| 42 | + ], | |
| 43 | + "services": "{}", | |
| 44 | + "events": "{}" | |
| 45 | +} | |
| 46 | + | |
| 47 | +### 请求 /iot/think-model-function/update 接口 => 成功 | |
| 48 | +PUT {{baseUrl}}/iot/think-model-function/update | |
| 49 | +Content-Type: application/json | |
| 50 | +tenant-id: {{adminTenentId}} | |
| 51 | +Authorization: Bearer {{token}} | |
| 52 | + | |
| 53 | +{ | |
| 54 | + "productKey": "123456", | |
| 55 | + "properties": [ | |
| 56 | + { | |
| 57 | + "identifier": "CurrentTemperature", | |
| 58 | + "name": "当前温度", | |
| 59 | + "accessMode": "r", | |
| 60 | + "required": true, | |
| 61 | + "dataType": { | |
| 62 | + "type": "float", | |
| 63 | + "specs": { | |
| 64 | + "min": "-40", | |
| 65 | + "max": "130", | |
| 66 | + "unit": "°C", | |
| 67 | + "unitName": "摄氏度", | |
| 68 | + "step": "0.1" | |
| 69 | + } | |
| 70 | + } | |
| 71 | + }, | |
| 72 | + { | |
| 73 | + "identifier": "CurrentHumidity", | |
| 74 | + "name": "当前湿度", | |
| 75 | + "accessMode": "r", | |
| 76 | + "required": true, | |
| 77 | + "dataType": { | |
| 78 | + "type": "float", | |
| 79 | + "specs": { | |
| 80 | + "min": "0", | |
| 81 | + "max": "100", | |
| 82 | + "unit": "%", | |
| 83 | + "unitName": "百分比", | |
| 84 | + "step": "0.1" | |
| 85 | + } | |
| 86 | + } | |
| 87 | + } | |
| 88 | + ], | |
| 89 | + "services": "{}", | |
| 90 | + "events": "{}" | |
| 91 | +} | |
| 92 | + | |
| 93 | +### 请求 /iot/think-model-function/get 接口 => 成功 | |
| 94 | +GET {{baseUrl}}/iot/think-model-function/get?productKey=123456 | |
| 95 | +tenant-id: {{adminTenentId}} | |
| 96 | +Authorization: Bearer {{token}} | |
| 0 | 97 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodelfunction/IotThinkModelFunctionController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction; | |
| 2 | + | |
| 3 | +import org.springframework.web.bind.annotation.*; | |
| 4 | +import jakarta.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 7 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 8 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 9 | +import io.swagger.v3.oas.annotations.Operation; | |
| 10 | + | |
| 11 | +import jakarta.validation.*; | |
| 12 | + | |
| 13 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 14 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 15 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 16 | + | |
| 17 | +import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.*; | |
| 18 | +import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO; | |
| 19 | +import cn.iocoder.yudao.module.iot.service.thinkmodelfunction.IotThinkModelFunctionService; | |
| 20 | + | |
| 21 | +@Tag(name = "管理后台 - IoT 产品物模型") | |
| 22 | +@RestController | |
| 23 | +@RequestMapping("/iot/think-model-function") | |
| 24 | +@Validated | |
| 25 | +public class IotThinkModelFunctionController { | |
| 26 | + | |
| 27 | + @Resource | |
| 28 | + private IotThinkModelFunctionService thinkModelFunctionService; | |
| 29 | + | |
| 30 | + @PostMapping("/create") | |
| 31 | + @Operation(summary = "创建IoT 产品物模型") | |
| 32 | + @PreAuthorize("@ss.hasPermission('iot:think-model-function:create')") | |
| 33 | + public CommonResult<Long> createThinkModelFunction(@Valid @RequestBody IotThinkModelFunctionSaveReqVO createReqVO) { | |
| 34 | + return success(thinkModelFunctionService.createThinkModelFunction(createReqVO)); | |
| 35 | + } | |
| 36 | + | |
| 37 | + @PutMapping("/update") | |
| 38 | + @Operation(summary = "更新IoT 产品物模型") | |
| 39 | + @PreAuthorize("@ss.hasPermission('iot:think-model-function:update')") | |
| 40 | + public CommonResult<Boolean> updateThinkModelFunction(@Valid @RequestBody IotThinkModelFunctionSaveReqVO updateReqVO) { | |
| 41 | + thinkModelFunctionService.updateThinkModelFunctionByProductKey(updateReqVO); | |
| 42 | + return success(true); | |
| 43 | + } | |
| 44 | + | |
| 45 | + @DeleteMapping("/delete") | |
| 46 | + @Operation(summary = "删除IoT 产品物模型") | |
| 47 | + @Parameter(name = "id", description = "编号", required = true) | |
| 48 | + @PreAuthorize("@ss.hasPermission('iot:think-model-function:delete')") | |
| 49 | + public CommonResult<Boolean> deleteThinkModelFunction(@RequestParam("id") Long id) { | |
| 50 | + thinkModelFunctionService.deleteThinkModelFunction(id); | |
| 51 | + return success(true); | |
| 52 | + } | |
| 53 | + | |
| 54 | + @GetMapping("/get") | |
| 55 | + @Operation(summary = "获得IoT 产品物模型") | |
| 56 | + @Parameter(name = "productKey", description = "产品Key", required = true, example = "1024") | |
| 57 | + @PreAuthorize("@ss.hasPermission('iot:think-model-function:query')") | |
| 58 | + public CommonResult<IotThinkModelFunctionRespVO> getThinkModelFunctionByProductKey(@RequestParam("productKey") String productKey) { | |
| 59 | + IotThinkModelFunctionDO thinkModelFunction = thinkModelFunctionService.getThinkModelFunctionByProductKey(productKey); | |
| 60 | + return success(BeanUtils.toBean(thinkModelFunction, IotThinkModelFunctionRespVO.class)); | |
| 61 | + } | |
| 62 | + | |
| 63 | +} | |
| 0 | 64 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodelfunction/vo/IotThingModelProperty.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | + | |
| 6 | +import java.util.List; | |
| 7 | + | |
| 8 | +@Schema(description = "管理后台 - IoT 产品物模型属性") | |
| 9 | +@Data | |
| 10 | +public class IotThingModelProperty { | |
| 11 | + | |
| 12 | + @Schema(description = "属性标识符") | |
| 13 | + private String identifier; | |
| 14 | + | |
| 15 | + @Schema(description = "属性名称") | |
| 16 | + private String name; | |
| 17 | + | |
| 18 | + @Schema(description = "访问模式 (r/rw)") | |
| 19 | + private String accessMode; | |
| 20 | + | |
| 21 | + @Schema(description = "是否必需") | |
| 22 | + private boolean required; | |
| 23 | + | |
| 24 | + @Schema(description = "数据类型") | |
| 25 | + private DataType dataType; | |
| 26 | + | |
| 27 | + @Schema(description = "数据类型") | |
| 28 | + @Data | |
| 29 | + public static class DataType { | |
| 30 | + | |
| 31 | + @Schema(description = "数据类型(float, double, struct, enum等)") | |
| 32 | + private String type; | |
| 33 | + | |
| 34 | + @Schema(description = "单一类型的规格(适用于float, double等)") | |
| 35 | + private Specs specs; | |
| 36 | + | |
| 37 | + @Schema(description = "结构体字段(适用于struct类型)") | |
| 38 | + private List<StructField> structSpecs; | |
| 39 | + | |
| 40 | + @Schema(description = "规格") | |
| 41 | + @Data | |
| 42 | + public static class Specs { | |
| 43 | + | |
| 44 | + @Schema(description = "最小值") | |
| 45 | + private String min; | |
| 46 | + | |
| 47 | + @Schema(description = "最大值") | |
| 48 | + private String max; | |
| 49 | + | |
| 50 | + @Schema(description = "单位符号") | |
| 51 | + private String unit; | |
| 52 | + | |
| 53 | + @Schema(description = "单位名称") | |
| 54 | + private String unitName; | |
| 55 | + | |
| 56 | + @Schema(description = "步进值") | |
| 57 | + private String step; | |
| 58 | + } | |
| 59 | + | |
| 60 | + @Schema(description = "结构体字段") | |
| 61 | + @Data | |
| 62 | + public static class StructField { | |
| 63 | + | |
| 64 | + @Schema(description = "字段标识符") | |
| 65 | + private String identifier; | |
| 66 | + | |
| 67 | + @Schema(description = "字段名称") | |
| 68 | + private String name; | |
| 69 | + | |
| 70 | + @Schema(description = "字段的数据类型") | |
| 71 | + private DataType dataType; | |
| 72 | + } | |
| 73 | + } | |
| 74 | + | |
| 75 | + @Schema(description = "枚举规格") | |
| 76 | + @Data | |
| 77 | + public static class EnumSpecs { | |
| 78 | + | |
| 79 | + @Schema(description = "枚举值") | |
| 80 | + private int value; | |
| 81 | + | |
| 82 | + @Schema(description = "枚举名称") | |
| 83 | + private String name; | |
| 84 | + | |
| 85 | + public EnumSpecs(int value, String name) { | |
| 86 | + this.value = value; | |
| 87 | + this.name = name; | |
| 88 | + } | |
| 89 | + } | |
| 90 | +} | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodelfunction/vo/IotThinkModelFunctionRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | + | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.alibaba.excel.annotation.*; | |
| 8 | + | |
| 9 | +@Schema(description = "管理后台 - IoT 产品物模型 Response VO") | |
| 10 | +@Data | |
| 11 | +@ExcelIgnoreUnannotated | |
| 12 | +public class IotThinkModelFunctionRespVO { | |
| 13 | + | |
| 14 | + @Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "21816") | |
| 15 | + @ExcelProperty("产品ID") | |
| 16 | + private Long id; | |
| 17 | + | |
| 18 | + @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 19 | + @ExcelProperty("产品标识") | |
| 20 | + private String productKey; | |
| 21 | + | |
| 22 | + @Schema(description = "属性列表", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 23 | + @ExcelProperty("属性列表") | |
| 24 | + private String properties; | |
| 25 | + | |
| 26 | + @Schema(description = "服务列表") | |
| 27 | + @ExcelProperty("服务列表") | |
| 28 | + private String services; | |
| 29 | + | |
| 30 | + @Schema(description = "事件列表") | |
| 31 | + @ExcelProperty("事件列表") | |
| 32 | + private String events; | |
| 33 | + | |
| 34 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 35 | + @ExcelProperty("创建时间") | |
| 36 | + private LocalDateTime createTime; | |
| 37 | + | |
| 38 | +} | |
| 0 | 39 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodelfunction/vo/IotThinkModelFunctionSaveReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import jakarta.validation.constraints.*; | |
| 7 | + | |
| 8 | +@Schema(description = "管理后台 - IoT 产品物模型新增/修改 Request VO") | |
| 9 | +@Data | |
| 10 | +public class IotThinkModelFunctionSaveReqVO { | |
| 11 | + | |
| 12 | + @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 13 | + @NotEmpty(message = "产品标识不能为空") | |
| 14 | + private String productKey; | |
| 15 | + | |
| 16 | + @Schema(description = "属性列表", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 17 | + @NotEmpty(message = "属性列表不能为空") | |
| 18 | + private List<IotThingModelProperty> properties; | |
| 19 | + | |
| 20 | + @Schema(description = "服务列表") | |
| 21 | + private String services; | |
| 22 | + | |
| 23 | + @Schema(description = "事件列表") | |
| 24 | + private String events; | |
| 25 | + | |
| 26 | +} | |
| 0 | 27 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/thinkmodelfunction/IotThinkModelFunctionDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import com.baomidou.mybatisplus.annotation.*; | |
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * IoT 产品物模型 DO | |
| 9 | + * | |
| 10 | + * @author 芋道源码 | |
| 11 | + */ | |
| 12 | +@TableName("iot_think_model_function") | |
| 13 | +@KeySequence("iot_think_model_function_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 14 | +@Data | |
| 15 | +@EqualsAndHashCode(callSuper = true) | |
| 16 | +@ToString(callSuper = true) | |
| 17 | +@Builder | |
| 18 | +@NoArgsConstructor | |
| 19 | +@AllArgsConstructor | |
| 20 | +public class IotThinkModelFunctionDO extends BaseDO { | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * 产品ID | |
| 24 | + */ | |
| 25 | + @TableId | |
| 26 | + private Long id; | |
| 27 | + /** | |
| 28 | + * 产品标识 | |
| 29 | + */ | |
| 30 | + private String productKey; | |
| 31 | + /** | |
| 32 | + * 属性列表 | |
| 33 | + */ | |
| 34 | + private String properties; | |
| 35 | + /** | |
| 36 | + * 服务列表 | |
| 37 | + */ | |
| 38 | + private String services; | |
| 39 | + /** | |
| 40 | + * 事件列表 | |
| 41 | + */ | |
| 42 | + private String events; | |
| 43 | + | |
| 44 | +} | |
| 0 | 45 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/thinkmodelfunction/IotThinkModelFunctionMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.dal.mysql.thinkmodelfunction; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 5 | +import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO; | |
| 6 | +import org.apache.ibatis.annotations.Mapper; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * IoT 产品物模型 Mapper | |
| 10 | + * | |
| 11 | + * @author 芋道源码 | |
| 12 | + */ | |
| 13 | +@Mapper | |
| 14 | +public interface IotThinkModelFunctionMapper extends BaseMapperX<IotThinkModelFunctionDO> { | |
| 15 | + | |
| 16 | + default IotThinkModelFunctionDO selectByProductKey(String productKey) { | |
| 17 | + return selectOne(new LambdaQueryWrapperX<IotThinkModelFunctionDO>().eq(IotThinkModelFunctionDO::getProductKey, productKey)); | |
| 18 | + } | |
| 19 | + | |
| 20 | + default int updateByProductKey(IotThinkModelFunctionDO thinkModelFunction) { | |
| 21 | + return update(thinkModelFunction, new LambdaQueryWrapperX<IotThinkModelFunctionDO>() | |
| 22 | + .eq(IotThinkModelFunctionDO::getProductKey, thinkModelFunction.getProductKey()) | |
| 23 | + ); | |
| 24 | + } | |
| 25 | +} | |
| 0 | 26 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductServiceImpl.java
| ... | ... | @@ -16,8 +16,7 @@ import java.util.Objects; |
| 16 | 16 | import java.util.UUID; |
| 17 | 17 | |
| 18 | 18 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 19 | -import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.PRODUCT_NOT_EXISTS; | |
| 20 | -import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.PRODUCT_STATUS_NOT_DELETE; | |
| 19 | +import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*; | |
| 21 | 20 | |
| 22 | 21 | /** |
| 23 | 22 | * IoT 产品 Service 实现类 |
| ... | ... | @@ -54,7 +53,7 @@ public class IotProductServiceImpl implements IotProductService { |
| 54 | 53 | } |
| 55 | 54 | // 2. 校验唯一性 |
| 56 | 55 | if (productMapper.selectByProductKey(productKey) != null) { |
| 57 | - throw exception(PRODUCT_NOT_EXISTS); | |
| 56 | + throw exception(PRODUCT_IDENTIFICATION_EXISTS); | |
| 58 | 57 | } |
| 59 | 58 | createReqVO.setProductKey(productKey); |
| 60 | 59 | } | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thinkmodelfunction/IotThinkModelFunctionService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.service.thinkmodelfunction; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionSaveReqVO; | |
| 4 | +import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO; | |
| 5 | +import jakarta.validation.Valid; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * IoT 产品物模型 Service 接口 | |
| 9 | + * | |
| 10 | + * @author 芋道源码 | |
| 11 | + */ | |
| 12 | +public interface IotThinkModelFunctionService { | |
| 13 | + | |
| 14 | + /** | |
| 15 | + * 创建IoT 产品物模型 | |
| 16 | + * | |
| 17 | + * @param createReqVO 创建信息 | |
| 18 | + * @return 编号 | |
| 19 | + */ | |
| 20 | + Long createThinkModelFunction(@Valid IotThinkModelFunctionSaveReqVO createReqVO); | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * 删除IoT 产品物模型 | |
| 24 | + * | |
| 25 | + * @param id 编号 | |
| 26 | + */ | |
| 27 | + void deleteThinkModelFunction(Long id); | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * 获得IoT 产品物模型 | |
| 31 | + * | |
| 32 | + * @param productKey 产品Key | |
| 33 | + * @return IoT 产品物模型 | |
| 34 | + */ | |
| 35 | + IotThinkModelFunctionDO getThinkModelFunctionByProductKey(String productKey); | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * 更新IoT 产品物模型 | |
| 39 | + * | |
| 40 | + * @param updateReqVO 更新信息 | |
| 41 | + */ | |
| 42 | + void updateThinkModelFunctionByProductKey(@Valid IotThinkModelFunctionSaveReqVO updateReqVO); | |
| 43 | +} | |
| 0 | 44 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thinkmodelfunction/IotThinkModelFunctionServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.service.thinkmodelfunction; | |
| 2 | + | |
| 3 | +import cn.hutool.json.JSONUtil; | |
| 4 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 5 | +import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.IotThinkModelFunctionSaveReqVO; | |
| 6 | +import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO; | |
| 7 | +import cn.iocoder.yudao.module.iot.dal.mysql.thinkmodelfunction.IotThinkModelFunctionMapper; | |
| 8 | +import jakarta.annotation.Resource; | |
| 9 | +import org.springframework.stereotype.Service; | |
| 10 | +import org.springframework.validation.annotation.Validated; | |
| 11 | + | |
| 12 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 13 | +import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.THINK_MODEL_FUNCTION_NOT_EXISTS; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * IoT 产品物模型 Service 实现类 | |
| 17 | + * | |
| 18 | + * @author 芋道源码 | |
| 19 | + */ | |
| 20 | +@Service | |
| 21 | +@Validated | |
| 22 | +public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionService { | |
| 23 | + | |
| 24 | + @Resource | |
| 25 | + private IotThinkModelFunctionMapper thinkModelFunctionMapper; | |
| 26 | + | |
| 27 | + @Override | |
| 28 | + public Long createThinkModelFunction(IotThinkModelFunctionSaveReqVO createReqVO) { | |
| 29 | + // 插入 | |
| 30 | + IotThinkModelFunctionDO thinkModelFunction = BeanUtils.toBean(createReqVO, IotThinkModelFunctionDO.class); | |
| 31 | + // properties 字段,需要转换成 JSON | |
| 32 | + thinkModelFunction.setProperties(JSONUtil.toJsonStr(createReqVO.getProperties())); | |
| 33 | + thinkModelFunctionMapper.insert(thinkModelFunction); | |
| 34 | + // 返回 | |
| 35 | + return thinkModelFunction.getId(); | |
| 36 | + } | |
| 37 | + | |
| 38 | + @Override | |
| 39 | + public void deleteThinkModelFunction(Long id) { | |
| 40 | + // 校验存在 | |
| 41 | + validateThinkModelFunctionExists(id); | |
| 42 | + // 删除 | |
| 43 | + thinkModelFunctionMapper.deleteById(id); | |
| 44 | + } | |
| 45 | + | |
| 46 | + private void validateThinkModelFunctionExists(Long id) { | |
| 47 | + if (thinkModelFunctionMapper.selectById(id) == null) { | |
| 48 | + throw exception(THINK_MODEL_FUNCTION_NOT_EXISTS); | |
| 49 | + } | |
| 50 | + } | |
| 51 | + | |
| 52 | + private void validateThinkModelFunctionExistsByProductKey(String productKey) { | |
| 53 | + if (thinkModelFunctionMapper.selectByProductKey(productKey) == null) { | |
| 54 | + throw exception(THINK_MODEL_FUNCTION_NOT_EXISTS); | |
| 55 | + } | |
| 56 | + } | |
| 57 | + | |
| 58 | + @Override | |
| 59 | + public IotThinkModelFunctionDO getThinkModelFunctionByProductKey(String productKey) { | |
| 60 | + return thinkModelFunctionMapper.selectByProductKey(productKey); | |
| 61 | + } | |
| 62 | + | |
| 63 | + @Override | |
| 64 | + public void updateThinkModelFunctionByProductKey(IotThinkModelFunctionSaveReqVO updateReqVO) { | |
| 65 | + // 校验存在 | |
| 66 | + validateThinkModelFunctionExistsByProductKey(updateReqVO.getProductKey()); | |
| 67 | + // 更新 | |
| 68 | + IotThinkModelFunctionDO thinkModelFunction = BeanUtils.toBean(updateReqVO, IotThinkModelFunctionDO.class); | |
| 69 | + // properties 字段,需要转换成 JSON | |
| 70 | + thinkModelFunction.setProperties(JSONUtil.toJsonStr(updateReqVO.getProperties())); | |
| 71 | + thinkModelFunctionMapper.updateByProductKey(thinkModelFunction); | |
| 72 | + } | |
| 73 | + | |
| 74 | +} | |
| 0 | 75 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/thinkmodelfunction/IotThinkModelFunctionMapper.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
| 3 | +<mapper namespace="cn.iocoder.yudao.module.iot.dal.mysql.thinkmodelfunction.IotThinkModelFunctionMapper"> | |
| 4 | + | |
| 5 | + <!-- | |
| 6 | + 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。 | |
| 7 | + 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。 | |
| 8 | + 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 | |
| 9 | + 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ | |
| 10 | + --> | |
| 11 | + | |
| 12 | +</mapper> | |
| 0 | 13 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/test/java/cn/iocoder/yudao/module/iot/service/thinkmodelfunction/IotThinkModelFunctionServiceImplTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.service.thinkmodelfunction; | |
| 2 | + | |
| 3 | +import org.junit.jupiter.api.Test; | |
| 4 | + | |
| 5 | +import jakarta.annotation.Resource; | |
| 6 | + | |
| 7 | +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | |
| 8 | + | |
| 9 | +import cn.iocoder.yudao.module.iot.controller.admin.thinkmodelfunction.vo.*; | |
| 10 | +import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkModelFunctionDO; | |
| 11 | +import cn.iocoder.yudao.module.iot.dal.mysql.thinkmodelfunction.IotThinkModelFunctionMapper; | |
| 12 | + | |
| 13 | +import org.springframework.context.annotation.Import; | |
| 14 | + | |
| 15 | +import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*; | |
| 16 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; | |
| 17 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | |
| 18 | +import static org.junit.jupiter.api.Assertions.*; | |
| 19 | + | |
| 20 | +/** | |
| 21 | + * {@link IotThinkModelFunctionServiceImpl} 的单元测试类 | |
| 22 | + * | |
| 23 | + * @author 芋道源码 | |
| 24 | + */ | |
| 25 | +@Import(IotThinkModelFunctionServiceImpl.class) | |
| 26 | +public class IotThinkModelFunctionServiceImplTest extends BaseDbUnitTest { | |
| 27 | + | |
| 28 | + @Resource | |
| 29 | + private IotThinkModelFunctionServiceImpl thinkModelFunctionService; | |
| 30 | + | |
| 31 | + @Resource | |
| 32 | + private IotThinkModelFunctionMapper thinkModelFunctionMapper; | |
| 33 | + | |
| 34 | + @Test | |
| 35 | + public void testCreateThinkModelFunction_success() { | |
| 36 | + // 准备参数 | |
| 37 | + IotThinkModelFunctionSaveReqVO createReqVO = randomPojo(IotThinkModelFunctionSaveReqVO.class); | |
| 38 | + | |
| 39 | + // 调用 | |
| 40 | + Long thinkModelFunctionId = thinkModelFunctionService.createThinkModelFunction(createReqVO); | |
| 41 | + // 断言 | |
| 42 | + assertNotNull(thinkModelFunctionId); | |
| 43 | + // 校验记录的属性是否正确 | |
| 44 | + IotThinkModelFunctionDO thinkModelFunction = thinkModelFunctionMapper.selectById(thinkModelFunctionId); | |
| 45 | + assertPojoEquals(createReqVO, thinkModelFunction, "id"); | |
| 46 | + } | |
| 47 | + | |
| 48 | + @Test | |
| 49 | + public void testDeleteThinkModelFunction_success() { | |
| 50 | + // mock 数据 | |
| 51 | + IotThinkModelFunctionDO dbThinkModelFunction = randomPojo(IotThinkModelFunctionDO.class); | |
| 52 | + thinkModelFunctionMapper.insert(dbThinkModelFunction);// @Sql: 先插入出一条存在的数据 | |
| 53 | + // 准备参数 | |
| 54 | + Long id = dbThinkModelFunction.getId(); | |
| 55 | + | |
| 56 | + // 调用 | |
| 57 | + thinkModelFunctionService.deleteThinkModelFunction(id); | |
| 58 | + // 校验数据不存在了 | |
| 59 | + assertNull(thinkModelFunctionMapper.selectById(id)); | |
| 60 | + } | |
| 61 | + | |
| 62 | + @Test | |
| 63 | + public void testDeleteThinkModelFunction_notExists() { | |
| 64 | + // 准备参数 | |
| 65 | + Long id = randomLongId(); | |
| 66 | + | |
| 67 | + // 调用, 并断言异常 | |
| 68 | + assertServiceException(() -> thinkModelFunctionService.deleteThinkModelFunction(id), THINK_MODEL_FUNCTION_NOT_EXISTS); | |
| 69 | + } | |
| 70 | + | |
| 71 | +} | |
| 0 | 72 | \ No newline at end of file | ... | ... |