Эх сурвалжийг харах

【功能新增】IoT: 物模型 TSL 获取

puhui999 7 сар өмнө
parent
commit
2073ecb2f3

+ 2 - 3
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
 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
+### 请求 /iot/product-thing-model/tsl-by-product-id 接口 => 成功
+GET {{baseUrl}}/iot/product-thing-model/tsl-by-product-id?productId=1001
 tenant-id: {{adminTenentId}}
 Authorization: Bearer {{token}}

+ 5 - 9
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;
 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.thingmodel.vo.IotThingModelListReqVO;
-import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelPageReqVO;
-import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelRespVO;
-import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelSaveReqVO;
+import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.*;
 import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO;
 import cn.iocoder.yudao.module.iot.service.thingmodel.IotThingModelService;
 import io.swagger.v3.oas.annotations.Operation;
@@ -64,13 +61,12 @@ public class IotThingModelController {
         return success(BeanUtils.toBean(thingModel, IotThingModelRespVO.class));
     }
 
-    @GetMapping("/list-by-product-id")
-    @Operation(summary = "获得产品物模型")
+    @GetMapping("/tsl-by-product-id")
+    @Operation(summary = "获得产品物模型 TSL")
     @Parameter(name = "productId", description = "产品ID", required = true, example = "1024")
     @PreAuthorize("@ss.hasPermission('iot:thing-model:query')")
-    public CommonResult<List<IotThingModelRespVO>> getThingModelListByProductId(@RequestParam("productId") Long productId) {
-        List<IotThingModelDO> list = thingModelService.getThingModelListByProductId(productId);
-        return success(BeanUtils.toBean(list, IotThingModelRespVO.class));
+    public CommonResult<IotThingModelTSLRespVO> getThingModelTslByProductId(@RequestParam("productId") Long productId) {
+        return success(thingModelService.getThingModelTslByProductId(productId));
     }
 
     // TODO @puhui @super:getThingModelListByProductId 和 getThingModelListByProductId 可以融合么?

+ 0 - 6
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;
 import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelEvent;
 import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelProperty;
 import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelService;
-import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
-import com.alibaba.excel.annotation.ExcelProperty;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 
@@ -12,18 +10,15 @@ import java.time.LocalDateTime;
 
 @Schema(description = "管理后台 - IoT 产品物模型 Response VO")
 @Data
-@ExcelIgnoreUnannotated
 public class IotThingModelRespVO {
 
     @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "21816")
-    @ExcelProperty("产品ID")
     private Long id;
 
     @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
     private Long productId;
 
     @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "temperature_sensor")
-    @ExcelProperty("产品标识")
     private String productKey;
 
     @Schema(description = "功能标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "temperature")
@@ -48,7 +43,6 @@ public class IotThingModelRespVO {
     private ThingModelService service;
 
     @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
-    @ExcelProperty("创建时间")
     private LocalDateTime createTime;
 
 }

+ 30 - 0
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotThingModelTSLRespVO.java

@@ -0,0 +1,30 @@
+package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo;
+
+import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelEvent;
+import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelProperty;
+import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelService;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.util.List;
+
+@Schema(description = "管理后台 - IoT 产品物模型 TSL Response VO")
+@Data
+public class IotThingModelTSLRespVO {
+
+    @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
+    private Long productId;
+
+    @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "temperature_sensor")
+    private String productKey;
+
+    @Schema(description = "属性列表", requiredMode = Schema.RequiredMode.REQUIRED)
+    private List<ThingModelProperty> properties;
+
+    @Schema(description = "服务列表", requiredMode = Schema.RequiredMode.REQUIRED)
+    private List<ThingModelEvent> events;
+
+    @Schema(description = "事件列表", requiredMode = Schema.RequiredMode.REQUIRED)
+    private List<ThingModelService> services;
+
+}

+ 9 - 0
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;
 import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelListReqVO;
 import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelPageReqVO;
 import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelSaveReqVO;
+import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelTSLRespVO;
 import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO;
 import jakarta.validation.Valid;
 
@@ -90,4 +91,12 @@ public interface IotThingModelService {
      */
     Long getThingModelCount(LocalDateTime createTime);
 
+    /**
+     * 通过产品 ID 获取产品物模型 TSL
+     *
+     * @param productId 产品 ID
+     * @return 产品物模型 TSL
+     */
+    IotThingModelTSLRespVO getThingModelTslByProductId(Long productId);
+
 }

+ 26 - 0
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotThingModelServiceImpl.java

@@ -1,6 +1,7 @@
 package cn.iocoder.yudao.module.iot.service.thingmodel;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.ObjUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.extra.spring.SpringUtil;
@@ -13,6 +14,7 @@ import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelS
 import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelListReqVO;
 import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelPageReqVO;
 import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelSaveReqVO;
+import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelTSLRespVO;
 import cn.iocoder.yudao.module.iot.convert.thingmodel.IotThingModelConvert;
 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
 import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO;
@@ -149,6 +151,30 @@ public class IotThingModelServiceImpl implements IotThingModelService {
         return thingModelMapper.selectList(reqVO);
     }
 
+    @Override
+    public IotThingModelTSLRespVO getThingModelTslByProductId(Long productId) {
+        IotThingModelTSLRespVO tslRespVO = new IotThingModelTSLRespVO();
+        // 1. 获得产品所有物模型定义
+        List<IotThingModelDO> thingModelList = thingModelMapper.selectListByProductId(productId);
+        if (CollUtil.isEmpty(thingModelList)) {
+            return tslRespVO;
+        }
+
+        // 2.1 设置公共部分参数
+        IotThingModelDO thingModel = thingModelList.get(0);
+        tslRespVO.setProductId(thingModel.getProductId()).setProductKey(thingModel.getProductKey());
+        // 2.2 处理属性列表
+        tslRespVO.setProperties(convertList(filterList(thingModelList, item ->
+                ObjUtil.equal(IotThingModelTypeEnum.PROPERTY.getType(), item.getType())), IotThingModelDO::getProperty));
+        // 2.3 处理服务列表
+        tslRespVO.setServices(convertList(filterList(thingModelList, item ->
+                ObjUtil.equal(IotThingModelTypeEnum.SERVICE.getType(), item.getType())), IotThingModelDO::getService));
+        // 2.4 处理事件列表
+        tslRespVO.setEvents(convertList(filterList(thingModelList, item ->
+                ObjUtil.equal(IotThingModelTypeEnum.EVENT.getType(), item.getType())), IotThingModelDO::getEvent));
+        return tslRespVO;
+    }
+
     /**
      * 校验功能是否存在
      *