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