Commit 2073ecb2f36f83060c78016b102cb0100b7dff97
1 parent
38e8c852
【功能新增】IoT: 物模型 TSL 获取
Showing
6 changed files
with
72 additions
and
18 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotThingModelController.http
| @@ -174,8 +174,7 @@ GET {{baseUrl}}/iot/product-thing-model/get?id=67 | @@ -174,8 +174,7 @@ GET {{baseUrl}}/iot/product-thing-model/get?id=67 | ||
| 174 | tenant-id: {{adminTenentId}} | 174 | tenant-id: {{adminTenentId}} |
| 175 | Authorization: Bearer {{token}} | 175 | Authorization: Bearer {{token}} |
| 176 | 176 | ||
| 177 | - | ||
| 178 | -### 请求 /iot/product-thing-model/list-by-product-id 接口 => 成功 | ||
| 179 | -GET {{baseUrl}}/iot/product-thing-model/list-by-product-id?productId=1001 | 177 | +### 请求 /iot/product-thing-model/tsl-by-product-id 接口 => 成功 |
| 178 | +GET {{baseUrl}}/iot/product-thing-model/tsl-by-product-id?productId=1001 | ||
| 180 | tenant-id: {{adminTenentId}} | 179 | tenant-id: {{adminTenentId}} |
| 181 | Authorization: Bearer {{token}} | 180 | Authorization: Bearer {{token}} |
| 182 | \ No newline at end of file | 181 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotThingModelController.java
| @@ -3,10 +3,7 @@ package cn.iocoder.yudao.module.iot.controller.admin.thingmodel; | @@ -3,10 +3,7 @@ package cn.iocoder.yudao.module.iot.controller.admin.thingmodel; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 6 | -import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelListReqVO; | ||
| 7 | -import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelPageReqVO; | ||
| 8 | -import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelRespVO; | ||
| 9 | -import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelSaveReqVO; | 6 | +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.*; |
| 10 | import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; | 7 | import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; |
| 11 | import cn.iocoder.yudao.module.iot.service.thingmodel.IotThingModelService; | 8 | import cn.iocoder.yudao.module.iot.service.thingmodel.IotThingModelService; |
| 12 | import io.swagger.v3.oas.annotations.Operation; | 9 | import io.swagger.v3.oas.annotations.Operation; |
| @@ -64,13 +61,12 @@ public class IotThingModelController { | @@ -64,13 +61,12 @@ public class IotThingModelController { | ||
| 64 | return success(BeanUtils.toBean(thingModel, IotThingModelRespVO.class)); | 61 | return success(BeanUtils.toBean(thingModel, IotThingModelRespVO.class)); |
| 65 | } | 62 | } |
| 66 | 63 | ||
| 67 | - @GetMapping("/list-by-product-id") | ||
| 68 | - @Operation(summary = "获得产品物模型") | 64 | + @GetMapping("/tsl-by-product-id") |
| 65 | + @Operation(summary = "获得产品物模型 TSL") | ||
| 69 | @Parameter(name = "productId", description = "产品ID", required = true, example = "1024") | 66 | @Parameter(name = "productId", description = "产品ID", required = true, example = "1024") |
| 70 | @PreAuthorize("@ss.hasPermission('iot:thing-model:query')") | 67 | @PreAuthorize("@ss.hasPermission('iot:thing-model:query')") |
| 71 | - public CommonResult<List<IotThingModelRespVO>> getThingModelListByProductId(@RequestParam("productId") Long productId) { | ||
| 72 | - List<IotThingModelDO> list = thingModelService.getThingModelListByProductId(productId); | ||
| 73 | - return success(BeanUtils.toBean(list, IotThingModelRespVO.class)); | 68 | + public CommonResult<IotThingModelTSLRespVO> getThingModelTslByProductId(@RequestParam("productId") Long productId) { |
| 69 | + return success(thingModelService.getThingModelTslByProductId(productId)); | ||
| 74 | } | 70 | } |
| 75 | 71 | ||
| 76 | // TODO @puhui @super:getThingModelListByProductId 和 getThingModelListByProductId 可以融合么? | 72 | // TODO @puhui @super:getThingModelListByProductId 和 getThingModelListByProductId 可以融合么? |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotThingModelRespVO.java
| @@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo; | @@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo; | ||
| 3 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelEvent; | 3 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelEvent; |
| 4 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelProperty; | 4 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelProperty; |
| 5 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelService; | 5 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelService; |
| 6 | -import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | ||
| 7 | -import com.alibaba.excel.annotation.ExcelProperty; | ||
| 8 | import io.swagger.v3.oas.annotations.media.Schema; | 6 | import io.swagger.v3.oas.annotations.media.Schema; |
| 9 | import lombok.Data; | 7 | import lombok.Data; |
| 10 | 8 | ||
| @@ -12,18 +10,15 @@ import java.time.LocalDateTime; | @@ -12,18 +10,15 @@ import java.time.LocalDateTime; | ||
| 12 | 10 | ||
| 13 | @Schema(description = "管理后台 - IoT 产品物模型 Response VO") | 11 | @Schema(description = "管理后台 - IoT 产品物模型 Response VO") |
| 14 | @Data | 12 | @Data |
| 15 | -@ExcelIgnoreUnannotated | ||
| 16 | public class IotThingModelRespVO { | 13 | public class IotThingModelRespVO { |
| 17 | 14 | ||
| 18 | @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "21816") | 15 | @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "21816") |
| 19 | - @ExcelProperty("产品ID") | ||
| 20 | private Long id; | 16 | private Long id; |
| 21 | 17 | ||
| 22 | @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | 18 | @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 23 | private Long productId; | 19 | private Long productId; |
| 24 | 20 | ||
| 25 | @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "temperature_sensor") | 21 | @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "temperature_sensor") |
| 26 | - @ExcelProperty("产品标识") | ||
| 27 | private String productKey; | 22 | private String productKey; |
| 28 | 23 | ||
| 29 | @Schema(description = "功能标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "temperature") | 24 | @Schema(description = "功能标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "temperature") |
| @@ -48,7 +43,6 @@ public class IotThingModelRespVO { | @@ -48,7 +43,6 @@ public class IotThingModelRespVO { | ||
| 48 | private ThingModelService service; | 43 | private ThingModelService service; |
| 49 | 44 | ||
| 50 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | 45 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) |
| 51 | - @ExcelProperty("创建时间") | ||
| 52 | private LocalDateTime createTime; | 46 | private LocalDateTime createTime; |
| 53 | 47 | ||
| 54 | } | 48 | } |
| 55 | \ No newline at end of file | 49 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotThingModelTSLRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelEvent; | ||
| 4 | +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelProperty; | ||
| 5 | +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelService; | ||
| 6 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 7 | +import lombok.Data; | ||
| 8 | + | ||
| 9 | +import java.util.List; | ||
| 10 | + | ||
| 11 | +@Schema(description = "管理后台 - IoT 产品物模型 TSL Response VO") | ||
| 12 | +@Data | ||
| 13 | +public class IotThingModelTSLRespVO { | ||
| 14 | + | ||
| 15 | + @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 16 | + private Long productId; | ||
| 17 | + | ||
| 18 | + @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "temperature_sensor") | ||
| 19 | + private String productKey; | ||
| 20 | + | ||
| 21 | + @Schema(description = "属性列表", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 22 | + private List<ThingModelProperty> properties; | ||
| 23 | + | ||
| 24 | + @Schema(description = "服务列表", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 25 | + private List<ThingModelEvent> events; | ||
| 26 | + | ||
| 27 | + @Schema(description = "事件列表", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 28 | + private List<ThingModelService> services; | ||
| 29 | + | ||
| 30 | +} | ||
| 0 | \ No newline at end of file | 31 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotThingModelService.java
| @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelListReqVO; | 4 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelListReqVO; |
| 5 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelPageReqVO; | 5 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelPageReqVO; |
| 6 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelSaveReqVO; | 6 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelSaveReqVO; |
| 7 | +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelTSLRespVO; | ||
| 7 | import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; | 8 | import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; |
| 8 | import jakarta.validation.Valid; | 9 | import jakarta.validation.Valid; |
| 9 | 10 | ||
| @@ -90,4 +91,12 @@ public interface IotThingModelService { | @@ -90,4 +91,12 @@ public interface IotThingModelService { | ||
| 90 | */ | 91 | */ |
| 91 | Long getThingModelCount(LocalDateTime createTime); | 92 | Long getThingModelCount(LocalDateTime createTime); |
| 92 | 93 | ||
| 94 | + /** | ||
| 95 | + * 通过产品 ID 获取产品物模型 TSL | ||
| 96 | + * | ||
| 97 | + * @param productId 产品 ID | ||
| 98 | + * @return 产品物模型 TSL | ||
| 99 | + */ | ||
| 100 | + IotThingModelTSLRespVO getThingModelTslByProductId(Long productId); | ||
| 101 | + | ||
| 93 | } | 102 | } |
| 94 | \ No newline at end of file | 103 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotThingModelServiceImpl.java
| 1 | package cn.iocoder.yudao.module.iot.service.thingmodel; | 1 | package cn.iocoder.yudao.module.iot.service.thingmodel; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.hutool.core.util.ObjUtil; | ||
| 4 | import cn.hutool.core.util.ObjectUtil; | 5 | import cn.hutool.core.util.ObjectUtil; |
| 5 | import cn.hutool.core.util.StrUtil; | 6 | import cn.hutool.core.util.StrUtil; |
| 6 | import cn.hutool.extra.spring.SpringUtil; | 7 | import cn.hutool.extra.spring.SpringUtil; |
| @@ -13,6 +14,7 @@ import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelS | @@ -13,6 +14,7 @@ import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelS | ||
| 13 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelListReqVO; | 14 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelListReqVO; |
| 14 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelPageReqVO; | 15 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelPageReqVO; |
| 15 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelSaveReqVO; | 16 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelSaveReqVO; |
| 17 | +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelTSLRespVO; | ||
| 16 | import cn.iocoder.yudao.module.iot.convert.thingmodel.IotThingModelConvert; | 18 | import cn.iocoder.yudao.module.iot.convert.thingmodel.IotThingModelConvert; |
| 17 | import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; | 19 | import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; |
| 18 | import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; | 20 | import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; |
| @@ -149,6 +151,30 @@ public class IotThingModelServiceImpl implements IotThingModelService { | @@ -149,6 +151,30 @@ public class IotThingModelServiceImpl implements IotThingModelService { | ||
| 149 | return thingModelMapper.selectList(reqVO); | 151 | return thingModelMapper.selectList(reqVO); |
| 150 | } | 152 | } |
| 151 | 153 | ||
| 154 | + @Override | ||
| 155 | + public IotThingModelTSLRespVO getThingModelTslByProductId(Long productId) { | ||
| 156 | + IotThingModelTSLRespVO tslRespVO = new IotThingModelTSLRespVO(); | ||
| 157 | + // 1. 获得产品所有物模型定义 | ||
| 158 | + List<IotThingModelDO> thingModelList = thingModelMapper.selectListByProductId(productId); | ||
| 159 | + if (CollUtil.isEmpty(thingModelList)) { | ||
| 160 | + return tslRespVO; | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + // 2.1 设置公共部分参数 | ||
| 164 | + IotThingModelDO thingModel = thingModelList.get(0); | ||
| 165 | + tslRespVO.setProductId(thingModel.getProductId()).setProductKey(thingModel.getProductKey()); | ||
| 166 | + // 2.2 处理属性列表 | ||
| 167 | + tslRespVO.setProperties(convertList(filterList(thingModelList, item -> | ||
| 168 | + ObjUtil.equal(IotThingModelTypeEnum.PROPERTY.getType(), item.getType())), IotThingModelDO::getProperty)); | ||
| 169 | + // 2.3 处理服务列表 | ||
| 170 | + tslRespVO.setServices(convertList(filterList(thingModelList, item -> | ||
| 171 | + ObjUtil.equal(IotThingModelTypeEnum.SERVICE.getType(), item.getType())), IotThingModelDO::getService)); | ||
| 172 | + // 2.4 处理事件列表 | ||
| 173 | + tslRespVO.setEvents(convertList(filterList(thingModelList, item -> | ||
| 174 | + ObjUtil.equal(IotThingModelTypeEnum.EVENT.getType(), item.getType())), IotThingModelDO::getEvent)); | ||
| 175 | + return tslRespVO; | ||
| 176 | + } | ||
| 177 | + | ||
| 152 | /** | 178 | /** |
| 153 | * 校验功能是否存在 | 179 | * 校验功能是否存在 |
| 154 | * | 180 | * |