Commit 30880e57cdb44d5820c8c1e831cba2e4e3e85b84
1 parent
203e3b58
fix(DEFECT-1444): 场景联动产品级,触发器和执行条件组织过滤无法问题修复
Showing
3 changed files
with
44 additions
and
22 deletions
1 | package org.thingsboard.server.controller.yunteng; | 1 | package org.thingsboard.server.controller.yunteng; |
2 | 2 | ||
3 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | ||
4 | + | ||
3 | import com.fasterxml.jackson.databind.JsonNode; | 5 | import com.fasterxml.jackson.databind.JsonNode; |
4 | import io.swagger.annotations.Api; | 6 | import io.swagger.annotations.Api; |
5 | import io.swagger.annotations.ApiOperation; | 7 | import io.swagger.annotations.ApiOperation; |
6 | import io.swagger.annotations.ApiParam; | 8 | import io.swagger.annotations.ApiParam; |
9 | +import java.util.*; | ||
10 | +import java.util.concurrent.ConcurrentMap; | ||
7 | import lombok.RequiredArgsConstructor; | 11 | import lombok.RequiredArgsConstructor; |
8 | import org.springframework.beans.factory.annotation.Autowired; | 12 | import org.springframework.beans.factory.annotation.Autowired; |
9 | import org.springframework.beans.factory.annotation.Value; | 13 | import org.springframework.beans.factory.annotation.Value; |
@@ -25,10 +29,10 @@ import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; | @@ -25,10 +29,10 @@ import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; | ||
25 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | 29 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
26 | import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; | 30 | import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; |
27 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | 31 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
32 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | ||
28 | import org.thingsboard.server.common.data.yunteng.dto.convert.ConvertConfigDTO; | 33 | import org.thingsboard.server.common.data.yunteng.dto.convert.ConvertConfigDTO; |
29 | import org.thingsboard.server.common.data.yunteng.dto.convert.ConvertConfigReqDTO; | 34 | import org.thingsboard.server.common.data.yunteng.dto.convert.ConvertConfigReqDTO; |
30 | import org.thingsboard.server.common.data.yunteng.dto.convert.ConvertReqDTO; | 35 | import org.thingsboard.server.common.data.yunteng.dto.convert.ConvertReqDTO; |
31 | -import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | ||
32 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | 36 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
33 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | 37 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
34 | import org.thingsboard.server.controller.BaseController; | 38 | import org.thingsboard.server.controller.BaseController; |
@@ -38,11 +42,6 @@ import org.thingsboard.server.dao.yunteng.service.TkRuleChainService; | @@ -38,11 +42,6 @@ import org.thingsboard.server.dao.yunteng.service.TkRuleChainService; | ||
38 | import org.thingsboard.server.service.rule.TbRuleChainService; | 42 | import org.thingsboard.server.service.rule.TbRuleChainService; |
39 | import org.thingsboard.server.service.security.permission.Operation; | 43 | import org.thingsboard.server.service.security.permission.Operation; |
40 | 44 | ||
41 | -import java.util.*; | ||
42 | -import java.util.concurrent.ConcurrentMap; | ||
43 | - | ||
44 | -import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | ||
45 | - | ||
46 | @RestController | 45 | @RestController |
47 | @RequiredArgsConstructor | 46 | @RequiredArgsConstructor |
48 | @RequestMapping("api/yt/convert") | 47 | @RequestMapping("api/yt/convert") |
@@ -52,10 +51,13 @@ public class TkConvertDataToController extends BaseController { | @@ -52,10 +51,13 @@ public class TkConvertDataToController extends BaseController { | ||
52 | private final TkRuleChainService tkRuleChainService; | 51 | private final TkRuleChainService tkRuleChainService; |
53 | private final ConvertConfigService convertConfigService; | 52 | private final ConvertConfigService convertConfigService; |
54 | private final SceneLinkageService sceneLinkageService; | 53 | private final SceneLinkageService sceneLinkageService; |
54 | + | ||
55 | @Value("${actors.rule.chain.debug_mode_rate_limits_per_tenant.enabled}") | 55 | @Value("${actors.rule.chain.debug_mode_rate_limits_per_tenant.enabled}") |
56 | private boolean debugPerTenantEnabled; | 56 | private boolean debugPerTenantEnabled; |
57 | + | ||
57 | @Autowired(required = false) | 58 | @Autowired(required = false) |
58 | private ActorSystemContext actorContext; | 59 | private ActorSystemContext actorContext; |
60 | + | ||
59 | @Autowired private TbRuleChainService tbRuleChainService; | 61 | @Autowired private TbRuleChainService tbRuleChainService; |
60 | 62 | ||
61 | @GetMapping(params = {PAGE_SIZE, PAGE}) | 63 | @GetMapping(params = {PAGE_SIZE, PAGE}) |
@@ -79,7 +81,7 @@ public class TkConvertDataToController extends BaseController { | @@ -79,7 +81,7 @@ public class TkConvertDataToController extends BaseController { | ||
79 | queryMap.put("nodeType", nodeType); | 81 | queryMap.put("nodeType", nodeType); |
80 | queryMap.put("name", name); | 82 | queryMap.put("name", name); |
81 | queryMap.put("status", status); | 83 | queryMap.put("status", status); |
82 | - checkTimeAndPut(queryMap,startTime,endTime); | 84 | + checkTimeAndPut(queryMap, startTime, endTime); |
83 | if (orderType != null) { | 85 | if (orderType != null) { |
84 | queryMap.put(ORDER_TYPE, orderType.name()); | 86 | queryMap.put(ORDER_TYPE, orderType.name()); |
85 | } | 87 | } |
@@ -90,7 +92,7 @@ public class TkConvertDataToController extends BaseController { | @@ -90,7 +92,7 @@ public class TkConvertDataToController extends BaseController { | ||
90 | @ApiOperation("获取详情") | 92 | @ApiOperation("获取详情") |
91 | public ResponseEntity<ConvertConfigDTO> findConvertConfigDTOById(@PathVariable("id") String id) | 93 | public ResponseEntity<ConvertConfigDTO> findConvertConfigDTOById(@PathVariable("id") String id) |
92 | throws ThingsboardException { | 94 | throws ThingsboardException { |
93 | - if(StringUtils.isEmpty(id)){ | 95 | + if (StringUtils.isEmpty(id)) { |
94 | throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | 96 | throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); |
95 | } | 97 | } |
96 | return ResponseEntity.ok( | 98 | return ResponseEntity.ok( |
@@ -230,6 +232,7 @@ public class TkConvertDataToController extends BaseController { | @@ -230,6 +232,7 @@ public class TkConvertDataToController extends BaseController { | ||
230 | Map<String, Map<String, String>> origConfig = new HashMap<>(); | 232 | Map<String, Map<String, String>> origConfig = new HashMap<>(); |
231 | Map<String, String> fields = new HashMap<>(); | 233 | Map<String, String> fields = new HashMap<>(); |
232 | fields.put("deviceProfileId", "deviceProfileId"); | 234 | fields.put("deviceProfileId", "deviceProfileId"); |
235 | + fields.put("tenantId", "tenantId"); | ||
233 | origConfig.put("fieldsMapping", fields); | 236 | origConfig.put("fieldsMapping", fields); |
234 | origNode.setConfiguration(JacksonUtil.valueToTree(origConfig)); | 237 | origNode.setConfiguration(JacksonUtil.valueToTree(origConfig)); |
235 | ruleNodes.add(origNode); | 238 | ruleNodes.add(origNode); |
@@ -261,9 +264,12 @@ public class TkConvertDataToController extends BaseController { | @@ -261,9 +264,12 @@ public class TkConvertDataToController extends BaseController { | ||
261 | ruleChainService.loadRuleChainMetaData(getTenantId(), ruleChain.getId()); | 264 | ruleChainService.loadRuleChainMetaData(getTenantId(), ruleChain.getId()); |
262 | // 3. SETUP CONNECTION AND ADD OR DELETE RULE NODE | 265 | // 3. SETUP CONNECTION AND ADD OR DELETE RULE NODE |
263 | if (status == FastIotConstants.MagicNumber.ZERO) { | 266 | if (status == FastIotConstants.MagicNumber.ZERO) { |
264 | - needSaveRuleNode = convertConfigService.deleteRuleNode(nodes, ruleChainMetaData, nodeType,getCurrentUser().getCurrentTenantId()); | 267 | + needSaveRuleNode = |
268 | + convertConfigService.deleteRuleNode( | ||
269 | + nodes, ruleChainMetaData, nodeType, getCurrentUser().getCurrentTenantId()); | ||
265 | } else { | 270 | } else { |
266 | - convertConfigService.addRuleNode(nodes, ruleChainMetaData, nodeType,getCurrentUser().getCurrentTenantId()); | 271 | + convertConfigService.addRuleNode( |
272 | + nodes, ruleChainMetaData, nodeType, getCurrentUser().getCurrentTenantId()); | ||
267 | needSaveRuleNode = true; | 273 | needSaveRuleNode = true; |
268 | } | 274 | } |
269 | // 4. SAVE METADATA | 275 | // 4. SAVE METADATA |
@@ -16,6 +16,7 @@ package org.thingsboard.rule.engine.yunteng.scene; | @@ -16,6 +16,7 @@ package org.thingsboard.rule.engine.yunteng.scene; | ||
16 | import com.fasterxml.jackson.databind.ObjectMapper; | 16 | import com.fasterxml.jackson.databind.ObjectMapper; |
17 | import java.util.List; | 17 | import java.util.List; |
18 | import java.util.Map; | 18 | import java.util.Map; |
19 | +import java.util.Optional; | ||
19 | import java.util.concurrent.ConcurrentHashMap; | 20 | import java.util.concurrent.ConcurrentHashMap; |
20 | import lombok.extern.slf4j.Slf4j; | 21 | import lombok.extern.slf4j.Slf4j; |
21 | import org.thingsboard.rule.engine.api.*; | 22 | import org.thingsboard.rule.engine.api.*; |
@@ -58,6 +59,7 @@ public class TbSceneReactNode implements TbNode { | @@ -58,6 +59,7 @@ public class TbSceneReactNode implements TbNode { | ||
58 | public void onMsg(TbContext ctx, TbMsg msg) { | 59 | public void onMsg(TbContext ctx, TbMsg msg) { |
59 | String deviceId = msg.getOriginator().getId().toString(); | 60 | String deviceId = msg.getOriginator().getId().toString(); |
60 | String tbProfileId = msg.getMetaData().getValue("deviceProfileId"); | 61 | String tbProfileId = msg.getMetaData().getValue("deviceProfileId"); |
62 | + String tenantId = msg.getMetaData().getValue("tenantId"); | ||
61 | String projectId = config.getProfile().get(tbProfileId); | 63 | String projectId = config.getProfile().get(tbProfileId); |
62 | boolean deviceHas = config.getScenes().containsKey(deviceId); | 64 | boolean deviceHas = config.getScenes().containsKey(deviceId); |
63 | boolean profileHas = config.getProject().containsKey(projectId); | 65 | boolean profileHas = config.getProject().containsKey(projectId); |
@@ -73,7 +75,7 @@ public class TbSceneReactNode implements TbNode { | @@ -73,7 +75,7 @@ public class TbSceneReactNode implements TbNode { | ||
73 | ReactState react = getOrCreateReactState(ctx, config, t.getScenId()); | 75 | ReactState react = getOrCreateReactState(ctx, config, t.getScenId()); |
74 | if (react != null) { | 76 | if (react != null) { |
75 | try { | 77 | try { |
76 | - react.process(ctx, msg,t.getRuleId(), deviceId); | 78 | + react.process(ctx, msg, t.getRuleId(), deviceId); |
77 | } catch (Exception e) { | 79 | } catch (Exception e) { |
78 | ctx.tellFailure(msg, e); | 80 | ctx.tellFailure(msg, e); |
79 | } | 81 | } |
@@ -85,14 +87,24 @@ public class TbSceneReactNode implements TbNode { | @@ -85,14 +87,24 @@ public class TbSceneReactNode implements TbNode { | ||
85 | projectScence.stream() | 87 | projectScence.stream() |
86 | .forEach( | 88 | .forEach( |
87 | t -> { | 89 | t -> { |
88 | - ReactState react = getOrCreateReactState(ctx, config, t.getScenId()); | ||
89 | - if (react != null) { | ||
90 | - try { | ||
91 | - react.process(ctx, msg,t.getRuleId(), deviceId); | ||
92 | - } catch (Exception e) { | ||
93 | - ctx.tellFailure(msg, e); | ||
94 | - } | ||
95 | - } | 90 | + String scenId = t.getScenId(); |
91 | + List<String> orgDevices = | ||
92 | + ctx.getTkDeviceService() | ||
93 | + .rpcDevices(tenantId, config.getOrgs().get(scenId), projectId); | ||
94 | + Optional.ofNullable(orgDevices) | ||
95 | + .ifPresent( | ||
96 | + f -> { | ||
97 | + if (f.contains(deviceId)) { | ||
98 | + ReactState react = getOrCreateReactState(ctx, config, scenId); | ||
99 | + if (react != null) { | ||
100 | + try { | ||
101 | + react.process(ctx, msg, t.getRuleId(), deviceId); | ||
102 | + } catch (Exception e) { | ||
103 | + ctx.tellFailure(msg, e); | ||
104 | + } | ||
105 | + } | ||
106 | + } | ||
107 | + }); | ||
96 | }); | 108 | }); |
97 | } | 109 | } |
98 | } | 110 | } |
@@ -13,13 +13,17 @@ public class TbSceneReactNodeConfig implements NodeConfiguration<TbSceneReactNod | @@ -13,13 +13,17 @@ public class TbSceneReactNodeConfig implements NodeConfiguration<TbSceneReactNod | ||
13 | 13 | ||
14 | /** 【TB设备配置ID,TK产品ID】产品信息 */ | 14 | /** 【TB设备配置ID,TK产品ID】产品信息 */ |
15 | private Map<String, String> profile; | 15 | private Map<String, String> profile; |
16 | - /** 【TK产品ID,场景】哪些产品会触发场景联动 */ | 16 | + |
17 | + /** 【TK产品ID,场景】哪些产品会触发场景联动,包含产品的每一个触发器 */ | ||
17 | private Map<String, List<RuleFilterDTO>> project; | 18 | private Map<String, List<RuleFilterDTO>> project; |
18 | - /** 【TB设备ID,场景】哪些设备会触发场景联动 */ | 19 | + |
20 | + /** 【TB设备ID,场景】哪些设备会触发场景联动,包含设备的每一个触发器 */ | ||
19 | private Map<String, List<RuleFilterDTO>> scenes; | 21 | private Map<String, List<RuleFilterDTO>> scenes; |
22 | + | ||
20 | /** 【TK场景ID,场景名称】场景联动信息 */ | 23 | /** 【TK场景ID,场景名称】场景联动信息 */ |
21 | private Map<String, String> names; | 24 | private Map<String, String> names; |
22 | - /** 【TK场景ID,组织ID】场景联动所属组织信息 */ | 25 | + |
26 | + /** 【TK场景ID,场景联动的根组织ID】场景联动所属组织信息 */ | ||
23 | private Map<String, String> orgs; | 27 | private Map<String, String> orgs; |
24 | 28 | ||
25 | @Override | 29 | @Override |