mirror of
https://github.com/YunaiV/ruoyi-vue-pro.git
synced 2026-04-22 07:08:38 +00:00
feat(iot):【网关设备:80%】动态注册的初步实现(已测试)
This commit is contained in:
@@ -4,7 +4,6 @@ import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import cn.iocoder.yudao.module.iot.enums.DictTypeConstants;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -80,10 +79,6 @@ public class IotDeviceRespVO {
|
||||
@ExcelProperty("设备密钥")
|
||||
private String deviceSecret;
|
||||
|
||||
@Schema(description = "认证类型(如一机一密、动态注册)", example = "2")
|
||||
@ExcelProperty("认证类型(如一机一密、动态注册)")
|
||||
private String authType;
|
||||
|
||||
@Schema(description = "设备配置", example = "{\"abc\": \"efg\"}")
|
||||
private String config;
|
||||
|
||||
|
||||
@@ -123,11 +123,6 @@ public class IotDeviceDO extends TenantBaseDO {
|
||||
* 设备密钥,用于设备认证
|
||||
*/
|
||||
private String deviceSecret;
|
||||
/**
|
||||
* 认证类型(如一机一密、动态注册)
|
||||
*/
|
||||
// TODO @haohao:是不是要枚举哈
|
||||
private String authType;
|
||||
|
||||
/**
|
||||
* 设备位置的纬度
|
||||
|
||||
@@ -810,7 +810,8 @@ public class IotDeviceServiceImpl implements IotDeviceService {
|
||||
@Override
|
||||
public IotDeviceRegisterRespDTO registerDevice(IotDeviceRegisterReqDTO reqDTO) {
|
||||
// 1.1 校验产品
|
||||
IotProductDO product = productService.getProductByProductKey(reqDTO.getProductKey());
|
||||
IotProductDO product = TenantUtils.executeIgnore(() ->
|
||||
productService.getProductByProductKey(reqDTO.getProductKey()));
|
||||
if (product == null) {
|
||||
throw exception(PRODUCT_NOT_EXISTS);
|
||||
}
|
||||
@@ -822,21 +823,23 @@ public class IotDeviceServiceImpl implements IotDeviceService {
|
||||
if (ObjUtil.notEqual(product.getProductSecret(), reqDTO.getProductSecret())) {
|
||||
throw exception(DEVICE_REGISTER_SECRET_INVALID);
|
||||
}
|
||||
// 1.4 校验设备是否已存在(已存在则不允许重复注册)
|
||||
IotDeviceDO device = getSelf().getDeviceFromCache(reqDTO.getProductKey(), reqDTO.getDeviceName());
|
||||
if (device != null) {
|
||||
throw exception(DEVICE_REGISTER_ALREADY_EXISTS);
|
||||
}
|
||||
return TenantUtils.execute(product.getTenantId(), () -> {
|
||||
// 1.4 校验设备是否已存在(已存在则不允许重复注册)
|
||||
IotDeviceDO device = getSelf().getDeviceFromCache(reqDTO.getProductKey(), reqDTO.getDeviceName());
|
||||
if (device != null) {
|
||||
throw exception(DEVICE_REGISTER_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
// 2.1 自动创建设备
|
||||
IotDeviceSaveReqVO createReqVO = new IotDeviceSaveReqVO()
|
||||
.setDeviceName(reqDTO.getDeviceName())
|
||||
.setProductId(product.getId());
|
||||
device = createDevice0(createReqVO);
|
||||
log.info("[registerDevice][产品({}) 自动创建设备({})]",
|
||||
reqDTO.getProductKey(), reqDTO.getDeviceName());
|
||||
// 2.2 返回设备密钥
|
||||
return new IotDeviceRegisterRespDTO(device.getProductKey(), device.getDeviceName(), device.getDeviceSecret());
|
||||
// 2.1 自动创建设备
|
||||
IotDeviceSaveReqVO createReqVO = new IotDeviceSaveReqVO()
|
||||
.setDeviceName(reqDTO.getDeviceName())
|
||||
.setProductId(product.getId());
|
||||
device = createDevice0(createReqVO);
|
||||
log.info("[registerDevice][产品({}) 自动创建设备({})]",
|
||||
reqDTO.getProductKey(), reqDTO.getDeviceName());
|
||||
// 2.2 返回设备密钥
|
||||
return new IotDeviceRegisterRespDTO(device.getProductKey(), device.getDeviceName(), device.getDeviceSecret());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -845,7 +848,8 @@ public class IotDeviceServiceImpl implements IotDeviceService {
|
||||
IotDeviceDO gatewayDevice = getSelf().getDeviceFromCache(reqDTO.getGatewayProductKey(), reqDTO.getGatewayDeviceName());
|
||||
|
||||
// 2. 遍历注册每个子设备
|
||||
return registerSubDevices0(gatewayDevice, reqDTO.getSubDevices());
|
||||
return TenantUtils.execute(gatewayDevice.getTenantId(), () ->
|
||||
registerSubDevices0(gatewayDevice, reqDTO.getSubDevices()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -68,10 +68,8 @@ public class IotProductServiceImpl implements IotProductService {
|
||||
@CacheEvict(value = RedisKeyConstants.PRODUCT, key = "#updateReqVO.id")
|
||||
public void updateProduct(IotProductSaveReqVO updateReqVO) {
|
||||
updateReqVO.setProductKey(null); // 不更新产品标识
|
||||
// 1.1 校验存在
|
||||
IotProductDO iotProductDO = validateProductExists(updateReqVO.getId());
|
||||
// 1.2 发布状态不可更新
|
||||
validateProductStatus(iotProductDO);
|
||||
// 1. 校验存在
|
||||
validateProductExists(updateReqVO.getId());
|
||||
|
||||
// 2. 更新
|
||||
IotProductDO updateObj = BeanUtils.toBean(updateReqVO, IotProductDO.class);
|
||||
|
||||
Reference in New Issue
Block a user