Commit 592d4417c8c515c6aabf9883fa99f9a9b4bec5bb

Authored by xp.Huang
2 parents 4673f8f4 5d5c40e3

Merge branch '20230418' into 'master_dev'

refactor: 优化网关子设备不存在的业务逻辑

See merge request yunteng/thingskit!178
@@ -32,6 +32,7 @@ import lombok.extern.slf4j.Slf4j; @@ -32,6 +32,7 @@ import lombok.extern.slf4j.Slf4j;
32 import org.springframework.util.ConcurrentReferenceHashMap; 32 import org.springframework.util.ConcurrentReferenceHashMap;
33 import org.springframework.util.StringUtils; 33 import org.springframework.util.StringUtils;
34 import org.thingsboard.common.util.JacksonUtil; 34 import org.thingsboard.common.util.JacksonUtil;
  35 +import org.thingsboard.server.common.data.DeviceProfile;
35 import org.thingsboard.server.common.data.yunteng.utils.ByteUtils; 36 import org.thingsboard.server.common.data.yunteng.utils.ByteUtils;
36 import org.thingsboard.server.common.transport.TransportService; 37 import org.thingsboard.server.common.transport.TransportService;
37 import org.thingsboard.server.common.transport.TransportServiceCallback; 38 import org.thingsboard.server.common.transport.TransportServiceCallback;
@@ -206,7 +207,13 @@ public class TcpGatewaySessionHandler { @@ -206,7 +207,13 @@ public class TcpGatewaySessionHandler {
206 new TransportServiceCallback<GetOrCreateDeviceFromGatewayResponse>() { 207 new TransportServiceCallback<GetOrCreateDeviceFromGatewayResponse>() {
207 @Override 208 @Override
208 public void onSuccess(GetOrCreateDeviceFromGatewayResponse msg) { 209 public void onSuccess(GetOrCreateDeviceFromGatewayResponse msg) {
209 - TcpGatewayDeviceSessionCtx deviceSessionCtx = new TcpGatewayDeviceSessionCtx(context, TcpGatewaySessionHandler.this, msg.getDeviceInfo(), msg.getDeviceProfile(), transportService); 210 + TransportDeviceInfo deviceInfo = msg.getDeviceInfo();
  211 + DeviceProfile deviceProfile = msg.getDeviceProfile();
  212 + if(deviceInfo == null || deviceProfile == null){
  213 + deviceFutures.remove(deviceName);
  214 + return;
  215 + }
  216 + TcpGatewayDeviceSessionCtx deviceSessionCtx = new TcpGatewayDeviceSessionCtx(context, TcpGatewaySessionHandler.this, deviceInfo, deviceProfile, transportService);
210 if (devices.putIfAbsent(deviceName, deviceSessionCtx) == null) { 217 if (devices.putIfAbsent(deviceName, deviceSessionCtx) == null) {
211 log.trace("[{}] First got or created device [{}], type [{}] for the gateway session", sessionId, deviceName, deviceType); 218 log.trace("[{}] First got or created device [{}], type [{}] for the gateway session", sessionId, deviceName, deviceType);
212 SessionInfoProto deviceSessionInfo = deviceSessionCtx.getSessionInfo(); 219 SessionInfoProto deviceSessionInfo = deviceSessionCtx.getSessionInfo();
@@ -192,8 +192,8 @@ public class TkDeviceScriptServiceImpl @@ -192,8 +192,8 @@ public class TkDeviceScriptServiceImpl
192 LambdaQueryWrapper<TkDeviceScriptEntity> queryWrapper = 192 LambdaQueryWrapper<TkDeviceScriptEntity> queryWrapper =
193 new QueryWrapper<TkDeviceScriptEntity>() 193 new QueryWrapper<TkDeviceScriptEntity>()
194 .lambda() 194 .lambda()
195 - .eq(TkDeviceScriptEntity::getTenantId, tenantId)  
196 - .eq(TkDeviceScriptEntity::getId, id); 195 + .eq(TkDeviceScriptEntity::getId, id).and(a -> a
  196 + .eq(TkDeviceScriptEntity::getTenantId, tenantId).or(b->b.eq(TkDeviceScriptEntity::getTenantId,EntityId.NULL_UUID.toString())));
197 TkDeviceScriptEntity profile = baseMapper.selectOne(queryWrapper); 197 TkDeviceScriptEntity profile = baseMapper.selectOne(queryWrapper);
198 return Optional.ofNullable(profile) 198 return Optional.ofNullable(profile)
199 .map( 199 .map(
@@ -250,8 +250,9 @@ public class TkDeviceScriptServiceImpl @@ -250,8 +250,9 @@ public class TkDeviceScriptServiceImpl
250 LambdaQueryWrapper<TkDeviceScriptEntity> queryWrapper = 250 LambdaQueryWrapper<TkDeviceScriptEntity> queryWrapper =
251 new QueryWrapper<TkDeviceScriptEntity>() 251 new QueryWrapper<TkDeviceScriptEntity>()
252 .lambda() 252 .lambda()
253 - .eq(scriptType!=null,TkDeviceScriptEntity::getScriptType, scriptType).and(s->s  
254 - .eq(TkDeviceScriptEntity::getTenantId, tenantId).or(r->r.eq(TkDeviceScriptEntity::getTenantId, EntityId.NULL_UUID.toString()))); 253 + .eq(TkDeviceScriptEntity::getStatus,1)
  254 + .eq(scriptType!=null,TkDeviceScriptEntity::getScriptType, scriptType)
  255 + .and(s->s.eq(TkDeviceScriptEntity::getTenantId, tenantId).or(r->r.eq(TkDeviceScriptEntity::getTenantId, EntityId.NULL_UUID.toString())));
255 return baseMapper.selectList(queryWrapper).stream() 256 return baseMapper.selectList(queryWrapper).stream()
256 .map(item -> item.getDTO(TkDeviceScriptDTO.class)) 257 .map(item -> item.getDTO(TkDeviceScriptDTO.class))
257 .collect(Collectors.toList()); 258 .collect(Collectors.toList());