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

This commit is contained in:
YunaiV 2025-06-14 09:06:41 +08:00
parent 7e49c90156
commit 7b114e1986
6 changed files with 6 additions and 47 deletions

View File

@ -20,10 +20,6 @@ public class IotDeviceRespVO {
@Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "177") @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "177")
private Long id; private Long id;
@Schema(description = "设备唯一标识符", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("设备唯一标识符")
private String deviceKey;
@Schema(description = "设备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") @Schema(description = "设备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
@ExcelProperty("设备名称") @ExcelProperty("设备名称")
private String deviceName; private String deviceName;

View File

@ -1,7 +1,6 @@
package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device; package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Size;
import lombok.Data; import lombok.Data;
import java.util.Set; import java.util.Set;
@ -13,10 +12,6 @@ public class IotDeviceSaveReqVO {
@Schema(description = "设备编号", example = "177") @Schema(description = "设备编号", example = "177")
private Long id; private Long id;
@Schema(description = "设备编号", requiredMode = Schema.RequiredMode.AUTO, example = "177")
@Size(max = 50, message = "设备编号长度不能超过 50 个字符")
private String deviceKey;
@Schema(description = "设备名称", requiredMode = Schema.RequiredMode.AUTO, example = "王五") @Schema(description = "设备名称", requiredMode = Schema.RequiredMode.AUTO, example = "王五")
private String deviceName; private String deviceName;

View File

@ -33,13 +33,6 @@ public class IotDeviceDO extends TenantBaseDO {
*/ */
@TableId @TableId
private Long id; private Long id;
// TODO @芋艿看看怎么弱化 deviceKey
/**
* 设备唯一标识符全局唯一用于识别设备
*
* 类似阿里云 <a href="https://help.aliyun.com/zh/iot/developer-reference/api-querydeviceinfo">QueryDeviceInfo</a> IotInstanceId
*/
private String deviceKey;
/** /**
* 设备名称在产品内唯一用于标识设备 * 设备名称在产品内唯一用于标识设备
*/ */

View File

@ -6,7 +6,6 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDevicePageReqVO; import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDevicePageReqVO;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -51,11 +50,6 @@ public interface IotDeviceMapper extends BaseMapperX<IotDeviceDO> {
return selectCount(IotDeviceDO::getProductId, productId); return selectCount(IotDeviceDO::getProductId, productId);
} }
default IotDeviceDO selectByDeviceKey(String deviceKey) {
return selectOne(new LambdaQueryWrapper<IotDeviceDO>()
.apply("LOWER(device_key) = {0}", deviceKey.toLowerCase()));
}
default List<IotDeviceDO> selectListByDeviceType(Integer deviceType) { default List<IotDeviceDO> selectListByDeviceType(Integer deviceType) {
return selectList(IotDeviceDO::getDeviceType, deviceType); return selectList(IotDeviceDO::getDeviceType, deviceType);
} }

View File

@ -142,14 +142,6 @@ public interface IotDeviceService {
*/ */
IotDeviceDO getDeviceFromCache(String productKey, String deviceName); IotDeviceDO getDeviceFromCache(String productKey, String deviceName);
/**
* 根据设备 key 获得设备
*
* @param deviceKey 编号
* @return IoT 设备
*/
IotDeviceDO getDeviceByDeviceKey(String deviceKey);
/** /**
* 获得设备分页 * 获得设备分页
* *

View File

@ -70,7 +70,7 @@ public class IotDeviceServiceImpl implements IotDeviceService {
throw exception(PRODUCT_NOT_EXISTS); throw exception(PRODUCT_NOT_EXISTS);
} }
// 1.2 统一校验 // 1.2 统一校验
validateCreateDeviceParam(product.getProductKey(), createReqVO.getDeviceName(), createReqVO.getDeviceKey(), validateCreateDeviceParam(product.getProductKey(), createReqVO.getDeviceName(),
createReqVO.getGatewayId(), product); createReqVO.getGatewayId(), product);
// 1.3 校验分组存在 // 1.3 校验分组存在
deviceGroupService.validateDeviceGroupExists(createReqVO.getGroupIds()); deviceGroupService.validateDeviceGroupExists(createReqVO.getGroupIds());
@ -84,7 +84,6 @@ public class IotDeviceServiceImpl implements IotDeviceService {
@Override @Override
public IotDeviceDO createDevice(String productKey, String deviceName, Long gatewayId) { public IotDeviceDO createDevice(String productKey, String deviceName, Long gatewayId) {
String deviceKey = generateDeviceKey();
// 1.1 校验产品是否存在 // 1.1 校验产品是否存在
IotProductDO product = TenantUtils.executeIgnore(() -> productService.getProductByProductKey(productKey)); IotProductDO product = TenantUtils.executeIgnore(() -> productService.getProductByProductKey(productKey));
if (product == null) { if (product == null) {
@ -92,28 +91,23 @@ public class IotDeviceServiceImpl implements IotDeviceService {
} }
return TenantUtils.execute(product.getTenantId(), () -> { return TenantUtils.execute(product.getTenantId(), () -> {
// 1.2 校验设备名称在同一产品下是否唯一 // 1.2 校验设备名称在同一产品下是否唯一
validateCreateDeviceParam(productKey, deviceName, deviceKey, gatewayId, product); validateCreateDeviceParam(productKey, deviceName, gatewayId, product);
// 2. 插入到数据库 // 2. 插入到数据库
IotDeviceDO device = new IotDeviceDO().setDeviceName(deviceName).setDeviceKey(deviceKey) IotDeviceDO device = new IotDeviceDO().setDeviceName(deviceName).setGatewayId(gatewayId);
.setGatewayId(gatewayId);
initDevice(device, product); initDevice(device, product);
deviceMapper.insert(device); deviceMapper.insert(device);
return device; return device;
}); });
} }
private void validateCreateDeviceParam(String productKey, String deviceName, String deviceKey, private void validateCreateDeviceParam(String productKey, String deviceName,
Long gatewayId, IotProductDO product) { Long gatewayId, IotProductDO product) {
TenantUtils.executeIgnore(() -> { TenantUtils.executeIgnore(() -> {
// 校验设备名称在同一产品下是否唯一 // 校验设备名称在同一产品下是否唯一
if (deviceMapper.selectByProductKeyAndDeviceName(productKey, deviceName) != null) { if (deviceMapper.selectByProductKeyAndDeviceName(productKey, deviceName) != null) {
throw exception(DEVICE_NAME_EXISTS); throw exception(DEVICE_NAME_EXISTS);
} }
// 校验设备标识是否唯一
if (deviceMapper.selectByDeviceKey(deviceKey) != null) {
throw exception(DEVICE_KEY_EXISTS);
}
}); });
// 校验父设备是否为合法网关 // 校验父设备是否为合法网关
@ -134,7 +128,7 @@ public class IotDeviceServiceImpl implements IotDeviceService {
@Override @Override
public void updateDevice(IotDeviceSaveReqVO updateReqVO) { public void updateDevice(IotDeviceSaveReqVO updateReqVO) {
updateReqVO.setDeviceKey(null).setDeviceName(null).setProductId(null); // 不允许更新 updateReqVO.setDeviceName(null).setProductId(null); // 不允许更新
// 1.1 校验存在 // 1.1 校验存在
IotDeviceDO device = validateDeviceExists(updateReqVO.getId()); IotDeviceDO device = validateDeviceExists(updateReqVO.getId());
// 1.2 校验父设备是否为合法网关 // 1.2 校验父设备是否为合法网关
@ -265,11 +259,6 @@ public class IotDeviceServiceImpl implements IotDeviceService {
return deviceMapper.selectByProductKeyAndDeviceName(productKey, deviceName); return deviceMapper.selectByProductKeyAndDeviceName(productKey, deviceName);
} }
@Override
public IotDeviceDO getDeviceByDeviceKey(String deviceKey) {
return deviceMapper.selectByDeviceKey(deviceKey);
}
@Override @Override
public PageResult<IotDeviceDO> getDevicePage(IotDevicePageReqVO pageReqVO) { public PageResult<IotDeviceDO> getDevicePage(IotDevicePageReqVO pageReqVO) {
return deviceMapper.selectPage(pageReqVO); return deviceMapper.selectPage(pageReqVO);
@ -401,7 +390,7 @@ public class IotDeviceServiceImpl implements IotDeviceService {
IotDeviceDO existDevice = deviceMapper.selectByDeviceName(importDevice.getDeviceName()); IotDeviceDO existDevice = deviceMapper.selectByDeviceName(importDevice.getDeviceName());
if (existDevice == null) { if (existDevice == null) {
createDevice(new IotDeviceSaveReqVO() createDevice(new IotDeviceSaveReqVO()
.setDeviceName(importDevice.getDeviceName()).setDeviceKey(generateDeviceKey()) .setDeviceName(importDevice.getDeviceName())
.setProductId(product.getId()).setGatewayId(gatewayId).setGroupIds(groupIds)); .setProductId(product.getId()).setGatewayId(gatewayId).setGroupIds(groupIds));
respVO.getCreateDeviceNames().add(importDevice.getDeviceName()); respVO.getCreateDeviceNames().add(importDevice.getDeviceName());
return; return;