Commit 592d4417c8c515c6aabf9883fa99f9a9b4bec5bb
Merge branch '20230418' into 'master_dev'
refactor: 优化网关子设备不存在的业务逻辑 See merge request yunteng/thingskit!178
Showing
2 changed files
with
13 additions
and
5 deletions
... | ... | @@ -32,6 +32,7 @@ import lombok.extern.slf4j.Slf4j; |
32 | 32 | import org.springframework.util.ConcurrentReferenceHashMap; |
33 | 33 | import org.springframework.util.StringUtils; |
34 | 34 | import org.thingsboard.common.util.JacksonUtil; |
35 | +import org.thingsboard.server.common.data.DeviceProfile; | |
35 | 36 | import org.thingsboard.server.common.data.yunteng.utils.ByteUtils; |
36 | 37 | import org.thingsboard.server.common.transport.TransportService; |
37 | 38 | import org.thingsboard.server.common.transport.TransportServiceCallback; |
... | ... | @@ -206,7 +207,13 @@ public class TcpGatewaySessionHandler { |
206 | 207 | new TransportServiceCallback<GetOrCreateDeviceFromGatewayResponse>() { |
207 | 208 | @Override |
208 | 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 | 217 | if (devices.putIfAbsent(deviceName, deviceSessionCtx) == null) { |
211 | 218 | log.trace("[{}] First got or created device [{}], type [{}] for the gateway session", sessionId, deviceName, deviceType); |
212 | 219 | SessionInfoProto deviceSessionInfo = deviceSessionCtx.getSessionInfo(); | ... | ... |
... | ... | @@ -192,8 +192,8 @@ public class TkDeviceScriptServiceImpl |
192 | 192 | LambdaQueryWrapper<TkDeviceScriptEntity> queryWrapper = |
193 | 193 | new QueryWrapper<TkDeviceScriptEntity>() |
194 | 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 | 197 | TkDeviceScriptEntity profile = baseMapper.selectOne(queryWrapper); |
198 | 198 | return Optional.ofNullable(profile) |
199 | 199 | .map( |
... | ... | @@ -250,8 +250,9 @@ public class TkDeviceScriptServiceImpl |
250 | 250 | LambdaQueryWrapper<TkDeviceScriptEntity> queryWrapper = |
251 | 251 | new QueryWrapper<TkDeviceScriptEntity>() |
252 | 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 | 256 | return baseMapper.selectList(queryWrapper).stream() |
256 | 257 | .map(item -> item.getDTO(TkDeviceScriptDTO.class)) |
257 | 258 | .collect(Collectors.toList()); | ... | ... |