Commit 7b114e19867922b5bb3e3537d2fea038a96c5ece

Authored by YunaiV
1 parent 7e49c901

feat:【IoT 物联网】移除 deviceKey 参数

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,10 +20,6 @@ public class IotDeviceRespVO {
20 @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "177") 20 @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "177")
21 private Long id; 21 private Long id;
22 22
23 - @Schema(description = "设备唯一标识符", requiredMode = Schema.RequiredMode.REQUIRED)  
24 - @ExcelProperty("设备唯一标识符")  
25 - private String deviceKey;  
26 -  
27 @Schema(description = "设备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") 23 @Schema(description = "设备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
28 @ExcelProperty("设备名称") 24 @ExcelProperty("设备名称")
29 private String deviceName; 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 package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device; 1 package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device;
2 2
3 import io.swagger.v3.oas.annotations.media.Schema; 3 import io.swagger.v3.oas.annotations.media.Schema;
4 -import jakarta.validation.constraints.Size;  
5 import lombok.Data; 4 import lombok.Data;
6 5
7 import java.util.Set; 6 import java.util.Set;
@@ -13,10 +12,6 @@ public class IotDeviceSaveReqVO { @@ -13,10 +12,6 @@ public class IotDeviceSaveReqVO {
13 @Schema(description = "设备编号", example = "177") 12 @Schema(description = "设备编号", example = "177")
14 private Long id; 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 @Schema(description = "设备名称", requiredMode = Schema.RequiredMode.AUTO, example = "王五") 15 @Schema(description = "设备名称", requiredMode = Schema.RequiredMode.AUTO, example = "王五")
21 private String deviceName; 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,13 +33,6 @@ public class IotDeviceDO extends TenantBaseDO {
33 */ 33 */
34 @TableId 34 @TableId
35 private Long id; 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,7 +6,6 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
6 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; 6 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
7 import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDevicePageReqVO; 7 import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDevicePageReqVO;
8 import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; 8 import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
9 -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;  
10 import org.apache.ibatis.annotations.Mapper; 9 import org.apache.ibatis.annotations.Mapper;
11 10
12 import javax.annotation.Nullable; 11 import javax.annotation.Nullable;
@@ -51,11 +50,6 @@ public interface IotDeviceMapper extends BaseMapperX&lt;IotDeviceDO&gt; { @@ -51,11 +50,6 @@ public interface IotDeviceMapper extends BaseMapperX&lt;IotDeviceDO&gt; {
51 return selectCount(IotDeviceDO::getProductId, productId); 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 default List<IotDeviceDO> selectListByDeviceType(Integer deviceType) { 53 default List<IotDeviceDO> selectListByDeviceType(Integer deviceType) {
60 return selectList(IotDeviceDO::getDeviceType, deviceType); 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,14 +143,6 @@ public interface IotDeviceService {
143 IotDeviceDO getDeviceFromCache(String productKey, String deviceName); 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 * @param pageReqVO 分页查询 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,7 +70,7 @@ public class IotDeviceServiceImpl implements IotDeviceService {
70 throw exception(PRODUCT_NOT_EXISTS); 70 throw exception(PRODUCT_NOT_EXISTS);
71 } 71 }
72 // 1.2 统一校验 72 // 1.2 统一校验
73 - validateCreateDeviceParam(product.getProductKey(), createReqVO.getDeviceName(), createReqVO.getDeviceKey(), 73 + validateCreateDeviceParam(product.getProductKey(), createReqVO.getDeviceName(),
74 createReqVO.getGatewayId(), product); 74 createReqVO.getGatewayId(), product);
75 // 1.3 校验分组存在 75 // 1.3 校验分组存在
76 deviceGroupService.validateDeviceGroupExists(createReqVO.getGroupIds()); 76 deviceGroupService.validateDeviceGroupExists(createReqVO.getGroupIds());
@@ -84,7 +84,6 @@ public class IotDeviceServiceImpl implements IotDeviceService { @@ -84,7 +84,6 @@ public class IotDeviceServiceImpl implements IotDeviceService {
84 84
85 @Override 85 @Override
86 public IotDeviceDO createDevice(String productKey, String deviceName, Long gatewayId) { 86 public IotDeviceDO createDevice(String productKey, String deviceName, Long gatewayId) {
87 - String deviceKey = generateDeviceKey();  
88 // 1.1 校验产品是否存在 87 // 1.1 校验产品是否存在
89 IotProductDO product = TenantUtils.executeIgnore(() -> productService.getProductByProductKey(productKey)); 88 IotProductDO product = TenantUtils.executeIgnore(() -> productService.getProductByProductKey(productKey));
90 if (product == null) { 89 if (product == null) {
@@ -92,28 +91,23 @@ public class IotDeviceServiceImpl implements IotDeviceService { @@ -92,28 +91,23 @@ public class IotDeviceServiceImpl implements IotDeviceService {
92 } 91 }
93 return TenantUtils.execute(product.getTenantId(), () -> { 92 return TenantUtils.execute(product.getTenantId(), () -> {
94 // 1.2 校验设备名称在同一产品下是否唯一 93 // 1.2 校验设备名称在同一产品下是否唯一
95 - validateCreateDeviceParam(productKey, deviceName, deviceKey, gatewayId, product); 94 + validateCreateDeviceParam(productKey, deviceName, gatewayId, product);
96 95
97 // 2. 插入到数据库 96 // 2. 插入到数据库
98 - IotDeviceDO device = new IotDeviceDO().setDeviceName(deviceName).setDeviceKey(deviceKey)  
99 - .setGatewayId(gatewayId); 97 + IotDeviceDO device = new IotDeviceDO().setDeviceName(deviceName).setGatewayId(gatewayId);
100 initDevice(device, product); 98 initDevice(device, product);
101 deviceMapper.insert(device); 99 deviceMapper.insert(device);
102 return device; 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 Long gatewayId, IotProductDO product) { 105 Long gatewayId, IotProductDO product) {
108 TenantUtils.executeIgnore(() -> { 106 TenantUtils.executeIgnore(() -> {
109 // 校验设备名称在同一产品下是否唯一 107 // 校验设备名称在同一产品下是否唯一
110 if (deviceMapper.selectByProductKeyAndDeviceName(productKey, deviceName) != null) { 108 if (deviceMapper.selectByProductKeyAndDeviceName(productKey, deviceName) != null) {
111 throw exception(DEVICE_NAME_EXISTS); 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,7 +128,7 @@ public class IotDeviceServiceImpl implements IotDeviceService {
134 128
135 @Override 129 @Override
136 public void updateDevice(IotDeviceSaveReqVO updateReqVO) { 130 public void updateDevice(IotDeviceSaveReqVO updateReqVO) {
137 - updateReqVO.setDeviceKey(null).setDeviceName(null).setProductId(null); // 不允许更新 131 + updateReqVO.setDeviceName(null).setProductId(null); // 不允许更新
138 // 1.1 校验存在 132 // 1.1 校验存在
139 IotDeviceDO device = validateDeviceExists(updateReqVO.getId()); 133 IotDeviceDO device = validateDeviceExists(updateReqVO.getId());
140 // 1.2 校验父设备是否为合法网关 134 // 1.2 校验父设备是否为合法网关
@@ -266,11 +260,6 @@ public class IotDeviceServiceImpl implements IotDeviceService { @@ -266,11 +260,6 @@ public class IotDeviceServiceImpl implements IotDeviceService {
266 } 260 }
267 261
268 @Override 262 @Override
269 - public IotDeviceDO getDeviceByDeviceKey(String deviceKey) {  
270 - return deviceMapper.selectByDeviceKey(deviceKey);  
271 - }  
272 -  
273 - @Override  
274 public PageResult<IotDeviceDO> getDevicePage(IotDevicePageReqVO pageReqVO) { 263 public PageResult<IotDeviceDO> getDevicePage(IotDevicePageReqVO pageReqVO) {
275 return deviceMapper.selectPage(pageReqVO); 264 return deviceMapper.selectPage(pageReqVO);
276 } 265 }
@@ -401,7 +390,7 @@ public class IotDeviceServiceImpl implements IotDeviceService { @@ -401,7 +390,7 @@ public class IotDeviceServiceImpl implements IotDeviceService {
401 IotDeviceDO existDevice = deviceMapper.selectByDeviceName(importDevice.getDeviceName()); 390 IotDeviceDO existDevice = deviceMapper.selectByDeviceName(importDevice.getDeviceName());
402 if (existDevice == null) { 391 if (existDevice == null) {
403 createDevice(new IotDeviceSaveReqVO() 392 createDevice(new IotDeviceSaveReqVO()
404 - .setDeviceName(importDevice.getDeviceName()).setDeviceKey(generateDeviceKey()) 393 + .setDeviceName(importDevice.getDeviceName())
405 .setProductId(product.getId()).setGatewayId(gatewayId).setGroupIds(groupIds)); 394 .setProductId(product.getId()).setGatewayId(gatewayId).setGroupIds(groupIds));
406 respVO.getCreateDeviceNames().add(importDevice.getDeviceName()); 395 respVO.getCreateDeviceNames().add(importDevice.getDeviceName());
407 return; 396 return;