feat:【IoT 物联网】移除 deviceKey 参数
This commit is contained in:
parent
7e49c90156
commit
7b114e1986
|
@ -20,10 +20,6 @@ public class IotDeviceRespVO {
|
|||
@Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "177")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "设备唯一标识符", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("设备唯一标识符")
|
||||
private String deviceKey;
|
||||
|
||||
@Schema(description = "设备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
||||
@ExcelProperty("设备名称")
|
||||
private String deviceName;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Set;
|
||||
|
@ -13,10 +12,6 @@ public class IotDeviceSaveReqVO {
|
|||
@Schema(description = "设备编号", example = "177")
|
||||
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 = "王五")
|
||||
private String deviceName;
|
||||
|
||||
|
|
|
@ -33,13 +33,6 @@ public class IotDeviceDO extends TenantBaseDO {
|
|||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
// TODO @芋艿:看看怎么弱化 deviceKey
|
||||
/**
|
||||
* 设备唯一标识符,全局唯一,用于识别设备
|
||||
*
|
||||
* 类似阿里云 <a href="https://help.aliyun.com/zh/iot/developer-reference/api-querydeviceinfo">QueryDeviceInfo</a> 的 IotInstanceId
|
||||
*/
|
||||
private String deviceKey;
|
||||
/**
|
||||
* 设备名称,在产品内唯一,用于标识设备
|
||||
*/
|
||||
|
|
|
@ -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.module.iot.controller.admin.device.vo.device.IotDevicePageReqVO;
|
||||
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 javax.annotation.Nullable;
|
||||
|
@ -51,11 +50,6 @@ public interface IotDeviceMapper extends BaseMapperX<IotDeviceDO> {
|
|||
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) {
|
||||
return selectList(IotDeviceDO::getDeviceType, deviceType);
|
||||
}
|
||||
|
|
|
@ -142,14 +142,6 @@ public interface IotDeviceService {
|
|||
*/
|
||||
IotDeviceDO getDeviceFromCache(String productKey, String deviceName);
|
||||
|
||||
/**
|
||||
* 根据设备 key 获得设备
|
||||
*
|
||||
* @param deviceKey 编号
|
||||
* @return IoT 设备
|
||||
*/
|
||||
IotDeviceDO getDeviceByDeviceKey(String deviceKey);
|
||||
|
||||
/**
|
||||
* 获得设备分页
|
||||
*
|
||||
|
|
|
@ -70,7 +70,7 @@ public class IotDeviceServiceImpl implements IotDeviceService {
|
|||
throw exception(PRODUCT_NOT_EXISTS);
|
||||
}
|
||||
// 1.2 统一校验
|
||||
validateCreateDeviceParam(product.getProductKey(), createReqVO.getDeviceName(), createReqVO.getDeviceKey(),
|
||||
validateCreateDeviceParam(product.getProductKey(), createReqVO.getDeviceName(),
|
||||
createReqVO.getGatewayId(), product);
|
||||
// 1.3 校验分组存在
|
||||
deviceGroupService.validateDeviceGroupExists(createReqVO.getGroupIds());
|
||||
|
@ -84,7 +84,6 @@ public class IotDeviceServiceImpl implements IotDeviceService {
|
|||
|
||||
@Override
|
||||
public IotDeviceDO createDevice(String productKey, String deviceName, Long gatewayId) {
|
||||
String deviceKey = generateDeviceKey();
|
||||
// 1.1 校验产品是否存在
|
||||
IotProductDO product = TenantUtils.executeIgnore(() -> productService.getProductByProductKey(productKey));
|
||||
if (product == null) {
|
||||
|
@ -92,28 +91,23 @@ public class IotDeviceServiceImpl implements IotDeviceService {
|
|||
}
|
||||
return TenantUtils.execute(product.getTenantId(), () -> {
|
||||
// 1.2 校验设备名称在同一产品下是否唯一
|
||||
validateCreateDeviceParam(productKey, deviceName, deviceKey, gatewayId, product);
|
||||
validateCreateDeviceParam(productKey, deviceName, gatewayId, product);
|
||||
|
||||
// 2. 插入到数据库
|
||||
IotDeviceDO device = new IotDeviceDO().setDeviceName(deviceName).setDeviceKey(deviceKey)
|
||||
.setGatewayId(gatewayId);
|
||||
IotDeviceDO device = new IotDeviceDO().setDeviceName(deviceName).setGatewayId(gatewayId);
|
||||
initDevice(device, product);
|
||||
deviceMapper.insert(device);
|
||||
return device;
|
||||
});
|
||||
}
|
||||
|
||||
private void validateCreateDeviceParam(String productKey, String deviceName, String deviceKey,
|
||||
private void validateCreateDeviceParam(String productKey, String deviceName,
|
||||
Long gatewayId, IotProductDO product) {
|
||||
TenantUtils.executeIgnore(() -> {
|
||||
// 校验设备名称在同一产品下是否唯一
|
||||
if (deviceMapper.selectByProductKeyAndDeviceName(productKey, deviceName) != null) {
|
||||
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
|
||||
public void updateDevice(IotDeviceSaveReqVO updateReqVO) {
|
||||
updateReqVO.setDeviceKey(null).setDeviceName(null).setProductId(null); // 不允许更新
|
||||
updateReqVO.setDeviceName(null).setProductId(null); // 不允许更新
|
||||
// 1.1 校验存在
|
||||
IotDeviceDO device = validateDeviceExists(updateReqVO.getId());
|
||||
// 1.2 校验父设备是否为合法网关
|
||||
|
@ -265,11 +259,6 @@ public class IotDeviceServiceImpl implements IotDeviceService {
|
|||
return deviceMapper.selectByProductKeyAndDeviceName(productKey, deviceName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IotDeviceDO getDeviceByDeviceKey(String deviceKey) {
|
||||
return deviceMapper.selectByDeviceKey(deviceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<IotDeviceDO> getDevicePage(IotDevicePageReqVO pageReqVO) {
|
||||
return deviceMapper.selectPage(pageReqVO);
|
||||
|
@ -401,7 +390,7 @@ public class IotDeviceServiceImpl implements IotDeviceService {
|
|||
IotDeviceDO existDevice = deviceMapper.selectByDeviceName(importDevice.getDeviceName());
|
||||
if (existDevice == null) {
|
||||
createDevice(new IotDeviceSaveReqVO()
|
||||
.setDeviceName(importDevice.getDeviceName()).setDeviceKey(generateDeviceKey())
|
||||
.setDeviceName(importDevice.getDeviceName())
|
||||
.setProductId(product.getId()).setGatewayId(gatewayId).setGroupIds(groupIds));
|
||||
respVO.getCreateDeviceNames().add(importDevice.getDeviceName());
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue