Commit 2585c4753ab33baa81c0a4aae0ecc0640c6bdb8c
Committed by
Gitee
!1306 新增场景联动所需接口
Merge pull request !1306 from puhui999/iot
Showing
11 changed files
with
122 additions
and
8 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.java
| ... | ... | @@ -185,4 +185,12 @@ public class IotDeviceController { |
| 185 | 185 | return success(deviceService.getMqttConnectionParams(deviceId)); |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | -} | |
| 189 | 188 | \ No newline at end of file |
| 189 | + @GetMapping("/list-by-product-key-and-names") | |
| 190 | + @Operation(summary = "通过产品标识和设备名称列表获取设备") | |
| 191 | + @PreAuthorize("@ss.hasPermission('iot:device:query')") | |
| 192 | + public CommonResult<List<IotDeviceRespVO>> getDevicesByProductKeyAndNames(@Valid IotDeviceByProductKeyAndNamesReqVO reqVO) { | |
| 193 | + List<IotDeviceDO> devices = deviceService.getDevicesByProductKeyAndNames(reqVO.getProductKey(), reqVO.getDeviceNames()); | |
| 194 | + return success(BeanUtils.toBean(devices, IotDeviceRespVO.class)); | |
| 195 | + } | |
| 196 | + | |
| 197 | +} | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceByProductKeyAndNamesReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import jakarta.validation.constraints.NotBlank; | |
| 5 | +import jakarta.validation.constraints.NotEmpty; | |
| 6 | +import lombok.Data; | |
| 7 | + | |
| 8 | +import java.util.List; | |
| 9 | + | |
| 10 | +@Schema(description = "管理后台 - 通过产品标识和设备名称列表获取设备 Request VO") | |
| 11 | +@Data | |
| 12 | +public class IotDeviceByProductKeyAndNamesReqVO { | |
| 13 | + | |
| 14 | + @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "1de24640dfe") | |
| 15 | + @NotBlank(message = "产品标识不能为空") | |
| 16 | + private String productKey; | |
| 17 | + | |
| 18 | + @Schema(description = "设备名称列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "device001,device002") | |
| 19 | + @NotEmpty(message = "设备名称列表不能为空") | |
| 20 | + private List<String> deviceNames; | |
| 21 | + | |
| 22 | +} | ... | ... |
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 { |
| 93 | 93 | })); |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | + @GetMapping("/get-by-key") | |
| 97 | + @Operation(summary = "通过 ProductKey 获得产品") | |
| 98 | + @Parameter(name = "productKey", description = "产品Key", required = true, example = "abc123") | |
| 99 | + @PreAuthorize("@ss.hasPermission('iot:product:query')") | |
| 100 | + public CommonResult<IotProductRespVO> getProductByKey(@RequestParam("productKey") String productKey) { | |
| 101 | + IotProductDO product = productService.getProductByProductKey(productKey); | |
| 102 | + // 拼接数据 | |
| 103 | + IotProductCategoryDO category = categoryService.getProductCategory(product.getCategoryId()); | |
| 104 | + return success(BeanUtils.toBean(product, IotProductRespVO.class, bean -> { | |
| 105 | + if (category != null) { | |
| 106 | + bean.setCategoryName(category.getName()); | |
| 107 | + } | |
| 108 | + })); | |
| 109 | + } | |
| 110 | + | |
| 96 | 111 | @GetMapping("/page") |
| 97 | 112 | @Operation(summary = "获得产品分页") |
| 98 | 113 | @PreAuthorize("@ss.hasPermission('iot:product:query')") | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/IotDataBridgeController.java
| 1 | 1 | package cn.iocoder.yudao.module.iot.controller.admin.rule; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| ... | ... | @@ -17,7 +18,10 @@ import org.springframework.security.access.prepost.PreAuthorize; |
| 17 | 18 | import org.springframework.validation.annotation.Validated; |
| 18 | 19 | import org.springframework.web.bind.annotation.*; |
| 19 | 20 | |
| 21 | +import java.util.List; | |
| 22 | + | |
| 20 | 23 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 24 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | |
| 21 | 25 | |
| 22 | 26 | @Tag(name = "管理后台 - IoT 数据桥梁") |
| 23 | 27 | @RestController |
| ... | ... | @@ -69,4 +73,12 @@ public class IotDataBridgeController { |
| 69 | 73 | return success(BeanUtils.toBean(pageResult, IotDataBridgeRespVO.class)); |
| 70 | 74 | } |
| 71 | 75 | |
| 72 | -} | |
| 73 | 76 | \ No newline at end of file |
| 77 | + @GetMapping("/simple-list") | |
| 78 | + @Operation(summary = "获取数据桥梁的精简信息列表", description = "主要用于前端的下拉选项") | |
| 79 | + public CommonResult<List<IotDataBridgeRespVO>> getSimpleDataBridgeList() { | |
| 80 | + List<IotDataBridgeDO> list = dataBridgeService.getDataBridgeList(CommonStatusEnum.ENABLE.getStatus()); | |
| 81 | + return success(convertList(list, dataBridge -> // 只返回 id、name 字段 | |
| 82 | + new IotDataBridgeRespVO().setId(dataBridge.getId()).setName(dataBridge.getName()))); | |
| 83 | + } | |
| 84 | + | |
| 85 | +} | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotRuleSceneDO.java
| ... | ... | @@ -144,8 +144,16 @@ public class IotRuleSceneDO extends TenantBaseDO { |
| 144 | 144 | @Data |
| 145 | 145 | public static class TriggerConditionParameter { |
| 146 | 146 | |
| 147 | + // TODO @芋艿: identifier0 存事件和服务的 identifier 属性的情况 identifier0 就为 null 解决前端回显问题 | |
| 147 | 148 | /** |
| 148 | - * 标识符(属性、事件、服务) | |
| 149 | + * 标识符(事件、服务) | |
| 150 | + * | |
| 151 | + * 关联 {@link IotThingModelDO#getIdentifier()} | |
| 152 | + */ | |
| 153 | + private String identifier0; | |
| 154 | + | |
| 155 | + /** | |
| 156 | + * 标识符(属性) | |
| 149 | 157 | * |
| 150 | 158 | * 关联 {@link IotThingModelDO#getIdentifier()} |
| 151 | 159 | */ | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/IotDeviceMapper.java
| ... | ... | @@ -11,6 +11,7 @@ import org.apache.ibatis.annotations.Mapper; |
| 11 | 11 | |
| 12 | 12 | import javax.annotation.Nullable; |
| 13 | 13 | import java.time.LocalDateTime; |
| 14 | +import java.util.Collection; | |
| 14 | 15 | import java.util.List; |
| 15 | 16 | import java.util.Map; |
| 16 | 17 | |
| ... | ... | @@ -77,6 +78,12 @@ public interface IotDeviceMapper extends BaseMapperX<IotDeviceDO> { |
| 77 | 78 | .geIfPresent(IotDeviceDO::getCreateTime, createTime)); |
| 78 | 79 | } |
| 79 | 80 | |
| 81 | + default List<IotDeviceDO> selectByProductKeyAndDeviceNames(String productKey, Collection<String> deviceNames) { | |
| 82 | + return selectList(new LambdaQueryWrapperX<IotDeviceDO>() | |
| 83 | + .eq(IotDeviceDO::getProductKey, productKey) | |
| 84 | + .in(IotDeviceDO::getDeviceName, deviceNames)); | |
| 85 | + } | |
| 86 | + | |
| 80 | 87 | /** |
| 81 | 88 | * 查询指定产品下各状态的设备数量 |
| 82 | 89 | * |
| ... | ... | @@ -93,4 +100,4 @@ public interface IotDeviceMapper extends BaseMapperX<IotDeviceDO> { |
| 93 | 100 | */ |
| 94 | 101 | List<Map<String, Object>> selectDeviceCountGroupByState(); |
| 95 | 102 | |
| 96 | -} | |
| 97 | 103 | \ No newline at end of file |
| 104 | +} | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/rule/IotDataBridgeMapper.java
| ... | ... | @@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.IotDataBr |
| 7 | 7 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO; |
| 8 | 8 | import org.apache.ibatis.annotations.Mapper; |
| 9 | 9 | |
| 10 | +import java.util.List; | |
| 11 | + | |
| 10 | 12 | /** |
| 11 | 13 | * IoT 数据桥梁 Mapper |
| 12 | 14 | * |
| ... | ... | @@ -23,4 +25,10 @@ public interface IotDataBridgeMapper extends BaseMapperX<IotDataBridgeDO> { |
| 23 | 25 | .orderByDesc(IotDataBridgeDO::getId)); |
| 24 | 26 | } |
| 25 | 27 | |
| 28 | + default List<IotDataBridgeDO> selectList(Integer status) { | |
| 29 | + return selectList(new LambdaQueryWrapperX<IotDataBridgeDO>() | |
| 30 | + .eqIfPresent(IotDataBridgeDO::getStatus, status) | |
| 31 | + .orderByDesc(IotDataBridgeDO::getId)); | |
| 32 | + } | |
| 33 | + | |
| 26 | 34 | } |
| 27 | 35 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceService.java
| ... | ... | @@ -219,4 +219,13 @@ public interface IotDeviceService { |
| 219 | 219 | */ |
| 220 | 220 | Map<Integer, Long> getDeviceCountMapByState(); |
| 221 | 221 | |
| 222 | -} | |
| 223 | 222 | \ No newline at end of file |
| 223 | + /** | |
| 224 | + * 通过产品标识和设备名称列表获取设备列表 | |
| 225 | + * | |
| 226 | + * @param productKey 产品标识 | |
| 227 | + * @param deviceNames 设备名称列表 | |
| 228 | + * @return 设备列表 | |
| 229 | + */ | |
| 230 | + List<IotDeviceDO> getDevicesByProductKeyAndNames(String productKey, List<String> deviceNames); | |
| 231 | + | |
| 232 | +} | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceServiceImpl.java
| ... | ... | @@ -451,4 +451,12 @@ public class IotDeviceServiceImpl implements IotDeviceService { |
| 451 | 451 | )); |
| 452 | 452 | } |
| 453 | 453 | |
| 454 | -} | |
| 455 | 454 | \ No newline at end of file |
| 455 | + @Override | |
| 456 | + public List<IotDeviceDO> getDevicesByProductKeyAndNames(String productKey, List<String> deviceNames) { | |
| 457 | + if (StrUtil.isBlank(productKey) || CollUtil.isEmpty(deviceNames)) { | |
| 458 | + return Collections.emptyList(); | |
| 459 | + } | |
| 460 | + return deviceMapper.selectByProductKeyAndDeviceNames(productKey, deviceNames); | |
| 461 | + } | |
| 462 | + | |
| 463 | +} | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/IotDataBridgeService.java
| ... | ... | @@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.IotDataBr |
| 6 | 6 | import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO; |
| 7 | 7 | import jakarta.validation.Valid; |
| 8 | 8 | |
| 9 | +import java.util.List; | |
| 10 | + | |
| 9 | 11 | /** |
| 10 | 12 | * IoT 数据桥梁 Service 接口 |
| 11 | 13 | * |
| ... | ... | @@ -51,4 +53,12 @@ public interface IotDataBridgeService { |
| 51 | 53 | */ |
| 52 | 54 | PageResult<IotDataBridgeDO> getDataBridgePage(IotDataBridgePageReqVO pageReqVO); |
| 53 | 55 | |
| 54 | -} | |
| 55 | 56 | \ No newline at end of file |
| 57 | + /** | |
| 58 | + * 获取数据桥梁列表 | |
| 59 | + * | |
| 60 | + * @param status 状态,如果为空,则不进行筛选 | |
| 61 | + * @return 数据桥梁列表 | |
| 62 | + */ | |
| 63 | + List<IotDataBridgeDO> getDataBridgeList(Integer status); | |
| 64 | + | |
| 65 | +} | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/IotDataBridgeServiceImpl.java
| ... | ... | @@ -10,6 +10,8 @@ import jakarta.annotation.Resource; |
| 10 | 10 | import org.springframework.stereotype.Service; |
| 11 | 11 | import org.springframework.validation.annotation.Validated; |
| 12 | 12 | |
| 13 | +import java.util.List; | |
| 14 | + | |
| 13 | 15 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 14 | 16 | import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.DATA_BRIDGE_NOT_EXISTS; |
| 15 | 17 | |
| ... | ... | @@ -67,4 +69,9 @@ public class IotDataBridgeServiceImpl implements IotDataBridgeService { |
| 67 | 69 | return dataBridgeMapper.selectPage(pageReqVO); |
| 68 | 70 | } |
| 69 | 71 | |
| 70 | -} | |
| 71 | 72 | \ No newline at end of file |
| 73 | + @Override | |
| 74 | + public List<IotDataBridgeDO> getDataBridgeList(Integer status) { | |
| 75 | + return dataBridgeMapper.selectList(status); | |
| 76 | + } | |
| 77 | + | |
| 78 | +} | ... | ... |