Browse Source

【功能新增】IoT: 通过 ProductKey 获得产品

puhui999 7 months ago
parent
commit
b3dcd7b133

+ 15 - 0
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/IotProductController.java

@@ -93,6 +93,21 @@ public class IotProductController {
         }));
         }));
     }
     }
 
 
+    @GetMapping("/get-by-key")
+    @Operation(summary = "通过 ProductKey 获得产品")
+    @Parameter(name = "productKey", description = "产品Key", required = true, example = "abc123")
+    @PreAuthorize("@ss.hasPermission('iot:product:query')")
+    public CommonResult<IotProductRespVO> getProductByKey(@RequestParam("productKey") String productKey) {
+        IotProductDO product = productService.getProductByProductKey(productKey);
+        // 拼接数据
+        IotProductCategoryDO category = categoryService.getProductCategory(product.getCategoryId());
+        return success(BeanUtils.toBean(product, IotProductRespVO.class, bean -> {
+            if (category != null) {
+                bean.setCategoryName(category.getName());
+            }
+        }));
+    }
+
     @GetMapping("/page")
     @GetMapping("/page")
     @Operation(summary = "获得产品分页")
     @Operation(summary = "获得产品分页")
     @PreAuthorize("@ss.hasPermission('iot:product:query')")
     @PreAuthorize("@ss.hasPermission('iot:product:query')")