Commit 7b114e19867922b5bb3e3537d2fea038a96c5ece
1 parent
7e49c901
feat:【IoT 物联网】移除 deviceKey 参数
Showing
6 changed files
with
6 additions
and
47 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceRespVO.java
| ... | ... | @@ -20,10 +20,6 @@ public class IotDeviceRespVO { |
| 20 | 20 | @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "177") |
| 21 | 21 | private Long id; |
| 22 | 22 | |
| 23 | - @Schema(description = "设备唯一标识符", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 24 | - @ExcelProperty("设备唯一标识符") | |
| 25 | - private String deviceKey; | |
| 26 | - | |
| 27 | 23 | @Schema(description = "设备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") |
| 28 | 24 | @ExcelProperty("设备名称") |
| 29 | 25 | private String deviceName; | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceSaveReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device; |
| 2 | 2 | |
| 3 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | -import jakarta.validation.constraints.Size; | |
| 5 | 4 | import lombok.Data; |
| 6 | 5 | |
| 7 | 6 | import java.util.Set; |
| ... | ... | @@ -13,10 +12,6 @@ public class IotDeviceSaveReqVO { |
| 13 | 12 | @Schema(description = "设备编号", example = "177") |
| 14 | 13 | private Long id; |
| 15 | 14 | |
| 16 | - @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.AUTO, example = "177") | |
| 17 | - @Size(max = 50, message = "设备编号长度不能超过 50 个字符") | |
| 18 | - private String deviceKey; | |
| 19 | - | |
| 20 | 15 | @Schema(description = "设备名称", requiredMode = Schema.RequiredMode.AUTO, example = "王五") |
| 21 | 16 | private String deviceName; |
| 22 | 17 | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceDO.java
| ... | ... | @@ -33,13 +33,6 @@ public class IotDeviceDO extends TenantBaseDO { |
| 33 | 33 | */ |
| 34 | 34 | @TableId |
| 35 | 35 | private Long id; |
| 36 | - // TODO @芋艿:看看怎么弱化 deviceKey | |
| 37 | - /** | |
| 38 | - * 设备唯一标识符,全局唯一,用于识别设备 | |
| 39 | - * | |
| 40 | - * 类似阿里云 <a href="https://help.aliyun.com/zh/iot/developer-reference/api-querydeviceinfo">QueryDeviceInfo</a> 的 IotInstanceId | |
| 41 | - */ | |
| 42 | - private String deviceKey; | |
| 43 | 36 | /** |
| 44 | 37 | * 设备名称,在产品内唯一,用于标识设备 |
| 45 | 38 | */ | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/IotDeviceMapper.java
| ... | ... | @@ -6,7 +6,6 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 6 | 6 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 7 | 7 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDevicePageReqVO; |
| 8 | 8 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; |
| 9 | -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |
| 10 | 9 | import org.apache.ibatis.annotations.Mapper; |
| 11 | 10 | |
| 12 | 11 | import javax.annotation.Nullable; |
| ... | ... | @@ -51,11 +50,6 @@ public interface IotDeviceMapper extends BaseMapperX<IotDeviceDO> { |
| 51 | 50 | return selectCount(IotDeviceDO::getProductId, productId); |
| 52 | 51 | } |
| 53 | 52 | |
| 54 | - default IotDeviceDO selectByDeviceKey(String deviceKey) { | |
| 55 | - return selectOne(new LambdaQueryWrapper<IotDeviceDO>() | |
| 56 | - .apply("LOWER(device_key) = {0}", deviceKey.toLowerCase())); | |
| 57 | - } | |
| 58 | - | |
| 59 | 53 | default List<IotDeviceDO> selectListByDeviceType(Integer deviceType) { |
| 60 | 54 | return selectList(IotDeviceDO::getDeviceType, deviceType); |
| 61 | 55 | } | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceService.java
| ... | ... | @@ -143,14 +143,6 @@ public interface IotDeviceService { |
| 143 | 143 | IotDeviceDO getDeviceFromCache(String productKey, String deviceName); |
| 144 | 144 | |
| 145 | 145 | /** |
| 146 | - * 根据设备 key 获得设备 | |
| 147 | - * | |
| 148 | - * @param deviceKey 编号 | |
| 149 | - * @return IoT 设备 | |
| 150 | - */ | |
| 151 | - IotDeviceDO getDeviceByDeviceKey(String deviceKey); | |
| 152 | - | |
| 153 | - /** | |
| 154 | 146 | * 获得设备分页 |
| 155 | 147 | * |
| 156 | 148 | * @param pageReqVO 分页查询 | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceServiceImpl.java
| ... | ... | @@ -70,7 +70,7 @@ public class IotDeviceServiceImpl implements IotDeviceService { |
| 70 | 70 | throw exception(PRODUCT_NOT_EXISTS); |
| 71 | 71 | } |
| 72 | 72 | // 1.2 统一校验 |
| 73 | - validateCreateDeviceParam(product.getProductKey(), createReqVO.getDeviceName(), createReqVO.getDeviceKey(), | |
| 73 | + validateCreateDeviceParam(product.getProductKey(), createReqVO.getDeviceName(), | |
| 74 | 74 | createReqVO.getGatewayId(), product); |
| 75 | 75 | // 1.3 校验分组存在 |
| 76 | 76 | deviceGroupService.validateDeviceGroupExists(createReqVO.getGroupIds()); |
| ... | ... | @@ -84,7 +84,6 @@ public class IotDeviceServiceImpl implements IotDeviceService { |
| 84 | 84 | |
| 85 | 85 | @Override |
| 86 | 86 | public IotDeviceDO createDevice(String productKey, String deviceName, Long gatewayId) { |
| 87 | - String deviceKey = generateDeviceKey(); | |
| 88 | 87 | // 1.1 校验产品是否存在 |
| 89 | 88 | IotProductDO product = TenantUtils.executeIgnore(() -> productService.getProductByProductKey(productKey)); |
| 90 | 89 | if (product == null) { |
| ... | ... | @@ -92,28 +91,23 @@ public class IotDeviceServiceImpl implements IotDeviceService { |
| 92 | 91 | } |
| 93 | 92 | return TenantUtils.execute(product.getTenantId(), () -> { |
| 94 | 93 | // 1.2 校验设备名称在同一产品下是否唯一 |
| 95 | - validateCreateDeviceParam(productKey, deviceName, deviceKey, gatewayId, product); | |
| 94 | + validateCreateDeviceParam(productKey, deviceName, gatewayId, product); | |
| 96 | 95 | |
| 97 | 96 | // 2. 插入到数据库 |
| 98 | - IotDeviceDO device = new IotDeviceDO().setDeviceName(deviceName).setDeviceKey(deviceKey) | |
| 99 | - .setGatewayId(gatewayId); | |
| 97 | + IotDeviceDO device = new IotDeviceDO().setDeviceName(deviceName).setGatewayId(gatewayId); | |
| 100 | 98 | initDevice(device, product); |
| 101 | 99 | deviceMapper.insert(device); |
| 102 | 100 | return device; |
| 103 | 101 | }); |
| 104 | 102 | } |
| 105 | 103 | |
| 106 | - private void validateCreateDeviceParam(String productKey, String deviceName, String deviceKey, | |
| 104 | + private void validateCreateDeviceParam(String productKey, String deviceName, | |
| 107 | 105 | Long gatewayId, IotProductDO product) { |
| 108 | 106 | TenantUtils.executeIgnore(() -> { |
| 109 | 107 | // 校验设备名称在同一产品下是否唯一 |
| 110 | 108 | if (deviceMapper.selectByProductKeyAndDeviceName(productKey, deviceName) != null) { |
| 111 | 109 | throw exception(DEVICE_NAME_EXISTS); |
| 112 | 110 | } |
| 113 | - // 校验设备标识是否唯一 | |
| 114 | - if (deviceMapper.selectByDeviceKey(deviceKey) != null) { | |
| 115 | - throw exception(DEVICE_KEY_EXISTS); | |
| 116 | - } | |
| 117 | 111 | }); |
| 118 | 112 | |
| 119 | 113 | // 校验父设备是否为合法网关 |
| ... | ... | @@ -134,7 +128,7 @@ public class IotDeviceServiceImpl implements IotDeviceService { |
| 134 | 128 | |
| 135 | 129 | @Override |
| 136 | 130 | public void updateDevice(IotDeviceSaveReqVO updateReqVO) { |
| 137 | - updateReqVO.setDeviceKey(null).setDeviceName(null).setProductId(null); // 不允许更新 | |
| 131 | + updateReqVO.setDeviceName(null).setProductId(null); // 不允许更新 | |
| 138 | 132 | // 1.1 校验存在 |
| 139 | 133 | IotDeviceDO device = validateDeviceExists(updateReqVO.getId()); |
| 140 | 134 | // 1.2 校验父设备是否为合法网关 |
| ... | ... | @@ -266,11 +260,6 @@ public class IotDeviceServiceImpl implements IotDeviceService { |
| 266 | 260 | } |
| 267 | 261 | |
| 268 | 262 | @Override |
| 269 | - public IotDeviceDO getDeviceByDeviceKey(String deviceKey) { | |
| 270 | - return deviceMapper.selectByDeviceKey(deviceKey); | |
| 271 | - } | |
| 272 | - | |
| 273 | - @Override | |
| 274 | 263 | public PageResult<IotDeviceDO> getDevicePage(IotDevicePageReqVO pageReqVO) { |
| 275 | 264 | return deviceMapper.selectPage(pageReqVO); |
| 276 | 265 | } |
| ... | ... | @@ -401,7 +390,7 @@ public class IotDeviceServiceImpl implements IotDeviceService { |
| 401 | 390 | IotDeviceDO existDevice = deviceMapper.selectByDeviceName(importDevice.getDeviceName()); |
| 402 | 391 | if (existDevice == null) { |
| 403 | 392 | createDevice(new IotDeviceSaveReqVO() |
| 404 | - .setDeviceName(importDevice.getDeviceName()).setDeviceKey(generateDeviceKey()) | |
| 393 | + .setDeviceName(importDevice.getDeviceName()) | |
| 405 | 394 | .setProductId(product.getId()).setGatewayId(gatewayId).setGroupIds(groupIds)); |
| 406 | 395 | respVO.getCreateDeviceNames().add(importDevice.getDeviceName()); |
| 407 | 396 | return; | ... | ... |