refactor: 优化设备注销逻辑
This commit is contained in:
parent
270583033a
commit
28d323a2f8
|
|
@ -31,6 +31,7 @@ import org.springframework.dao.QueryTimeoutException;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
import reactor.core.Disposable;
|
import reactor.core.Disposable;
|
||||||
import reactor.core.Disposables;
|
import reactor.core.Disposables;
|
||||||
import reactor.core.publisher.BufferOverflowStrategy;
|
import reactor.core.publisher.BufferOverflowStrategy;
|
||||||
|
|
@ -209,18 +210,15 @@ public class DeviceMessageBusinessHandler {
|
||||||
Message childMessage = message.getChildDeviceMessage();
|
Message childMessage = message.getChildDeviceMessage();
|
||||||
if (childMessage instanceof DeviceUnRegisterMessage) {
|
if (childMessage instanceof DeviceUnRegisterMessage) {
|
||||||
String childId = ((DeviceUnRegisterMessage) childMessage).getDeviceId();
|
String childId = ((DeviceUnRegisterMessage) childMessage).getDeviceId();
|
||||||
return registry
|
if(!StringUtils.hasText(childId)){
|
||||||
.getDevice(childId)
|
return Mono.empty();
|
||||||
.flatMap(dev -> dev
|
}
|
||||||
.removeConfig(DeviceConfigKey.parentGatewayId.getKey())
|
return deviceService
|
||||||
.then(dev.checkState()))
|
.createUpdate()
|
||||||
.flatMap(state -> deviceService
|
.setNull(DeviceInstanceEntity::getParentId)
|
||||||
.createUpdate()
|
.where(DeviceInstanceEntity::getId, childId)
|
||||||
.setNull(DeviceInstanceEntity::getParentId)
|
.execute()
|
||||||
.set(DeviceInstanceEntity::getState, DeviceState.of(state))
|
.then();
|
||||||
.where(DeviceInstanceEntity::getId, childId)
|
|
||||||
.execute()
|
|
||||||
.then());
|
|
||||||
}
|
}
|
||||||
return Mono.empty();
|
return Mono.empty();
|
||||||
}
|
}
|
||||||
|
|
@ -228,6 +226,9 @@ public class DeviceMessageBusinessHandler {
|
||||||
@Subscribe("/device/*/*/unregister")
|
@Subscribe("/device/*/*/unregister")
|
||||||
@Transactional(propagation = Propagation.NEVER)
|
@Transactional(propagation = Propagation.NEVER)
|
||||||
public Mono<Void> unRegisterDevice(DeviceUnRegisterMessage message) {
|
public Mono<Void> unRegisterDevice(DeviceUnRegisterMessage message) {
|
||||||
|
if(message.getHeader(Headers.ignore).orElse(false)){
|
||||||
|
return Mono.empty();
|
||||||
|
}
|
||||||
//注销设备
|
//注销设备
|
||||||
return deviceService
|
return deviceService
|
||||||
.unregisterDevice(message.getDeviceId())
|
.unregisterDevice(message.getDeviceId())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue