!1306 新增场景联动所需接口

Merge pull request !1306 from puhui999/iot
This commit is contained in:
芋道源码 2025-03-30 01:51:36 +00:00 committed by Gitee
commit 2585c4753a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
11 changed files with 122 additions and 8 deletions

View File

@ -185,4 +185,12 @@ public class IotDeviceController {
return success(deviceService.getMqttConnectionParams(deviceId)); return success(deviceService.getMqttConnectionParams(deviceId));
} }
@GetMapping("/list-by-product-key-and-names")
@Operation(summary = "通过产品标识和设备名称列表获取设备")
@PreAuthorize("@ss.hasPermission('iot:device:query')")
public CommonResult<List<IotDeviceRespVO>> getDevicesByProductKeyAndNames(@Valid IotDeviceByProductKeyAndNamesReqVO reqVO) {
List<IotDeviceDO> devices = deviceService.getDevicesByProductKeyAndNames(reqVO.getProductKey(), reqVO.getDeviceNames());
return success(BeanUtils.toBean(devices, IotDeviceRespVO.class));
}
} }

View File

@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
import java.util.List;
@Schema(description = "管理后台 - 通过产品标识和设备名称列表获取设备 Request VO")
@Data
public class IotDeviceByProductKeyAndNamesReqVO {
@Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "1de24640dfe")
@NotBlank(message = "产品标识不能为空")
private String productKey;
@Schema(description = "设备名称列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "device001,device002")
@NotEmpty(message = "设备名称列表不能为空")
private List<String> deviceNames;
}

View File

@ -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')")

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.iot.controller.admin.rule; package cn.iocoder.yudao.module.iot.controller.admin.rule;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
@ -17,7 +18,10 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
@Tag(name = "管理后台 - IoT 数据桥梁") @Tag(name = "管理后台 - IoT 数据桥梁")
@RestController @RestController
@ -69,4 +73,12 @@ public class IotDataBridgeController {
return success(BeanUtils.toBean(pageResult, IotDataBridgeRespVO.class)); return success(BeanUtils.toBean(pageResult, IotDataBridgeRespVO.class));
} }
@GetMapping("/simple-list")
@Operation(summary = "获取数据桥梁的精简信息列表", description = "主要用于前端的下拉选项")
public CommonResult<List<IotDataBridgeRespVO>> getSimpleDataBridgeList() {
List<IotDataBridgeDO> list = dataBridgeService.getDataBridgeList(CommonStatusEnum.ENABLE.getStatus());
return success(convertList(list, dataBridge -> // 只返回 idname 字段
new IotDataBridgeRespVO().setId(dataBridge.getId()).setName(dataBridge.getName())));
}
} }

View File

@ -144,8 +144,16 @@ public class IotRuleSceneDO extends TenantBaseDO {
@Data @Data
public static class TriggerConditionParameter { public static class TriggerConditionParameter {
// TODO @芋艿: identifier0 存事件和服务的 identifier 属性的情况 identifier0 就为 null 解决前端回显问题
/** /**
* 标识符属性事件服务 * 标识符事件服务
*
* 关联 {@link IotThingModelDO#getIdentifier()}
*/
private String identifier0;
/**
* 标识符属性
* *
* 关联 {@link IotThingModelDO#getIdentifier()} * 关联 {@link IotThingModelDO#getIdentifier()}
*/ */

View File

@ -11,6 +11,7 @@ import org.apache.ibatis.annotations.Mapper;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -77,6 +78,12 @@ public interface IotDeviceMapper extends BaseMapperX<IotDeviceDO> {
.geIfPresent(IotDeviceDO::getCreateTime, createTime)); .geIfPresent(IotDeviceDO::getCreateTime, createTime));
} }
default List<IotDeviceDO> selectByProductKeyAndDeviceNames(String productKey, Collection<String> deviceNames) {
return selectList(new LambdaQueryWrapperX<IotDeviceDO>()
.eq(IotDeviceDO::getProductKey, productKey)
.in(IotDeviceDO::getDeviceName, deviceNames));
}
/** /**
* 查询指定产品下各状态的设备数量 * 查询指定产品下各状态的设备数量
* *

View File

@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.IotDataBr
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO; import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/** /**
* IoT 数据桥梁 Mapper * IoT 数据桥梁 Mapper
* *
@ -23,4 +25,10 @@ public interface IotDataBridgeMapper extends BaseMapperX<IotDataBridgeDO> {
.orderByDesc(IotDataBridgeDO::getId)); .orderByDesc(IotDataBridgeDO::getId));
} }
default List<IotDataBridgeDO> selectList(Integer status) {
return selectList(new LambdaQueryWrapperX<IotDataBridgeDO>()
.eqIfPresent(IotDataBridgeDO::getStatus, status)
.orderByDesc(IotDataBridgeDO::getId));
}
} }

View File

@ -219,4 +219,13 @@ public interface IotDeviceService {
*/ */
Map<Integer, Long> getDeviceCountMapByState(); Map<Integer, Long> getDeviceCountMapByState();
/**
* 通过产品标识和设备名称列表获取设备列表
*
* @param productKey 产品标识
* @param deviceNames 设备名称列表
* @return 设备列表
*/
List<IotDeviceDO> getDevicesByProductKeyAndNames(String productKey, List<String> deviceNames);
} }

View File

@ -451,4 +451,12 @@ public class IotDeviceServiceImpl implements IotDeviceService {
)); ));
} }
@Override
public List<IotDeviceDO> getDevicesByProductKeyAndNames(String productKey, List<String> deviceNames) {
if (StrUtil.isBlank(productKey) || CollUtil.isEmpty(deviceNames)) {
return Collections.emptyList();
}
return deviceMapper.selectByProductKeyAndDeviceNames(productKey, deviceNames);
}
} }

View File

@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.IotDataBr
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO; import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import java.util.List;
/** /**
* IoT 数据桥梁 Service 接口 * IoT 数据桥梁 Service 接口
* *
@ -51,4 +53,12 @@ public interface IotDataBridgeService {
*/ */
PageResult<IotDataBridgeDO> getDataBridgePage(IotDataBridgePageReqVO pageReqVO); PageResult<IotDataBridgeDO> getDataBridgePage(IotDataBridgePageReqVO pageReqVO);
/**
* 获取数据桥梁列表
*
* @param status 状态如果为空则不进行筛选
* @return 数据桥梁列表
*/
List<IotDataBridgeDO> getDataBridgeList(Integer status);
} }

View File

@ -10,6 +10,8 @@ import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.DATA_BRIDGE_NOT_EXISTS; import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.DATA_BRIDGE_NOT_EXISTS;
@ -67,4 +69,9 @@ public class IotDataBridgeServiceImpl implements IotDataBridgeService {
return dataBridgeMapper.selectPage(pageReqVO); return dataBridgeMapper.selectPage(pageReqVO);
} }
@Override
public List<IotDataBridgeDO> getDataBridgeList(Integer status) {
return dataBridgeMapper.selectList(status);
}
} }