Commit 26a92ae74a53dd1d9c891c8fd272da48dd9ec5ea
Merge branch 'master_dev' into 'master'
fix: 场景联动事件触发,选择全部时未触发 See merge request yunteng/thingskit!297
Showing
4 changed files
with
28 additions
and
11 deletions
... | ... | @@ -808,13 +808,13 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev |
808 | 808 | } |
809 | 809 | |
810 | 810 | @Override |
811 | - public String getTbDeviceIdByDeviceNameAndGateWayId(String tenantId, String name,String gateWayId) { | |
811 | + public DeviceDTO getDeviceByDeviceNameOrIdAndGateWayId(String tenantId, String nameOrTbDeviceId, String gateWayId) { | |
812 | 812 | TkDeviceEntity entity = |
813 | 813 | baseMapper.selectOne(new LambdaQueryWrapper<TkDeviceEntity>() |
814 | 814 | .eq(TkDeviceEntity::getTenantId, tenantId) |
815 | - .eq(TkDeviceEntity::getName, name) | |
816 | - .eq(TkDeviceEntity::getGatewayId,gateWayId)); | |
817 | - return Optional.ofNullable(entity).map(obj->obj.getTbDeviceId()).orElse(null); | |
815 | + .eq(TkDeviceEntity::getGatewayId,gateWayId) | |
816 | + .eq(TkDeviceEntity::getName, nameOrTbDeviceId).or().eq(TkDeviceEntity::getTbDeviceId,nameOrTbDeviceId)); | |
817 | + return Optional.ofNullable(entity).map(obj->obj.getDTO(DeviceDTO.class)).orElse(null); | |
818 | 818 | } |
819 | 819 | @Override |
820 | 820 | @Transactional | ... | ... |
... | ... | @@ -244,13 +244,13 @@ public interface TkDeviceService extends BaseService<TkDeviceEntity> { |
244 | 244 | boolean updateDeviceStateByTbDeviceId(String tenantId, String tbDeviceId, DeviceState deviceState); |
245 | 245 | |
246 | 246 | /** |
247 | - * 根据租户ID和设备名称查询该设备的TBDeviceId | |
247 | + * 根据租户ID和设备名称或设备ID查询该设备的信息 | |
248 | 248 | * @param tenantId 租户ID |
249 | - * @param name 设备名称 | |
249 | + * @param nameOrTbDeviceId 设备名称或TBDeviceId | |
250 | 250 | * @param gateWayId Tb网关ID |
251 | 251 | * @return TBDeviceId |
252 | 252 | */ |
253 | - String getTbDeviceIdByDeviceNameAndGateWayId(String tenantId, String name,String gateWayId); | |
253 | + DeviceDTO getDeviceByDeviceNameOrIdAndGateWayId(String tenantId, String nameOrTbDeviceId, String gateWayId); | |
254 | 254 | |
255 | 255 | /** |
256 | 256 | * 修改设备的产品ID(profileId) | ... | ... |
... | ... | @@ -22,9 +22,11 @@ import org.thingsboard.rule.engine.telemetry.TelemetryNodeCallback; |
22 | 22 | import org.thingsboard.server.common.data.DeviceProfile; |
23 | 23 | import org.thingsboard.server.common.data.StringUtils; |
24 | 24 | import org.thingsboard.server.common.data.id.DeviceId; |
25 | +import org.thingsboard.server.common.data.id.DeviceProfileId; | |
25 | 26 | import org.thingsboard.server.common.data.id.TenantId; |
26 | 27 | import org.thingsboard.server.common.data.plugin.ComponentType; |
27 | 28 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
29 | +import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; | |
28 | 30 | import org.thingsboard.server.common.data.yunteng.dto.TkEventKvEntry; |
29 | 31 | import org.thingsboard.server.common.data.yunteng.dto.TkThingsModel; |
30 | 32 | import org.thingsboard.server.common.data.yunteng.enums.FunctionTypeEnum; |
... | ... | @@ -33,6 +35,7 @@ import org.thingsboard.server.common.msg.session.SessionMsgType; |
33 | 35 | |
34 | 36 | import java.util.ArrayList; |
35 | 37 | import java.util.List; |
38 | +import java.util.UUID; | |
36 | 39 | import java.util.stream.Collectors; |
37 | 40 | |
38 | 41 | |
... | ... | @@ -68,12 +71,19 @@ public class TkMsgEventNode implements TbNode { |
68 | 71 | String deviceIdStr = msg.getMetaData().getValue("deviceId"); |
69 | 72 | TenantId tenantId = ctx.getTenantId(); |
70 | 73 | if(selfData.equals(FastIotConstants.NO)){ |
71 | - String tbDeviceId = ctx.getTkDeviceService() | |
72 | - .getTbDeviceIdByDeviceNameAndGateWayId(tenantId.toString(),deviceIdStr, | |
74 | + DeviceDTO device = ctx.getTkDeviceService() | |
75 | + .getDeviceByDeviceNameOrIdAndGateWayId(tenantId.toString(),deviceIdStr, | |
73 | 76 | msg.getOriginator().toString()); |
74 | - if(StringUtils.isNotEmpty(tbDeviceId)){ | |
75 | - deviceIdStr = tbDeviceId; | |
77 | + //设备为null代表使用的设备ID,作为topic进行的上报 | |
78 | + if(null !=device && StringUtils.isNotEmpty(device.getTbDeviceId())){ | |
79 | + deviceIdStr = device.getTbDeviceId(); | |
76 | 80 | msg.getMetaData().putValue("deviceId",deviceIdStr); |
81 | + msg.getMetaData().putValue("deviceName",device.getName()); | |
82 | + DeviceProfile deviceProfile = ctx.getDeviceProfileCache().get(tenantId,new DeviceProfileId(UUID.fromString(device.getProfileId()))); | |
83 | + if(null != deviceProfile){ | |
84 | + msg.getMetaData().putValue("deviceProfileId",deviceProfile.getId().toString()); | |
85 | + msg.getMetaData().putValue("deviceType",deviceProfile.getName()); | |
86 | + } | |
77 | 87 | } |
78 | 88 | } |
79 | 89 | DeviceId deviceId = DeviceId.fromString(deviceIdStr); | ... | ... |
... | ... | @@ -17,6 +17,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; |
17 | 17 | import java.util.List; |
18 | 18 | import java.util.Map; |
19 | 19 | import java.util.Optional; |
20 | +import java.util.UUID; | |
20 | 21 | import java.util.concurrent.ConcurrentHashMap; |
21 | 22 | import lombok.extern.slf4j.Slf4j; |
22 | 23 | import org.thingsboard.rule.engine.api.*; |
... | ... | @@ -24,7 +25,9 @@ import org.thingsboard.rule.engine.api.util.TbNodeUtils; |
24 | 25 | import org.thingsboard.rule.engine.filter.TbCheckAlarmStatusNodeConfig; |
25 | 26 | import org.thingsboard.rule.engine.profile.SnapshotUpdate; |
26 | 27 | import org.thingsboard.rule.engine.yunteng.utils.TriggerRuleState; |
28 | +import org.thingsboard.server.common.data.DeviceProfile; | |
27 | 29 | import org.thingsboard.server.common.data.device.profile.AlarmConditionKeyType; |
30 | +import org.thingsboard.server.common.data.id.DeviceId; | |
28 | 31 | import org.thingsboard.server.common.data.plugin.ComponentType; |
29 | 32 | import org.thingsboard.server.common.data.yunteng.dto.scene.RuleFilterDTO; |
30 | 33 | import org.thingsboard.server.common.msg.TbMsg; |
... | ... | @@ -60,6 +63,10 @@ public class TbSceneReactNode implements TbNode { |
60 | 63 | String deviceId; |
61 | 64 | if(msg.getType().equals("POST_EVENT_REQUEST")){ |
62 | 65 | deviceId = msg.getMetaData().getData().get("deviceId"); |
66 | + DeviceProfile cache = ctx.getDeviceProfileCache().get(ctx.getTenantId(),new DeviceId(UUID.fromString(deviceId))); | |
67 | + if(null != cache){ | |
68 | + msg.getMetaData().putValue("deviceProfileId",cache.getId().toString()); | |
69 | + } | |
63 | 70 | }else{ |
64 | 71 | deviceId = msg.getOriginator().getId().toString(); |
65 | 72 | } | ... | ... |