Commit de92b737aa9f9a887f6d40df528cd001ea351054

Authored by 云中非
1 parent b900cebd

fix: 场景联动调用远程RPC

@@ -14,9 +14,11 @@ import org.thingsboard.server.common.data.device.profile.AlarmConditionFilter; @@ -14,9 +14,11 @@ import org.thingsboard.server.common.data.device.profile.AlarmConditionFilter;
14 import org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey; 14 import org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey;
15 import org.thingsboard.server.common.data.rule.RuleNodeState; 15 import org.thingsboard.server.common.data.rule.RuleNodeState;
16 import org.thingsboard.server.common.data.yunteng.dto.TriggerDTO; 16 import org.thingsboard.server.common.data.yunteng.dto.TriggerDTO;
  17 +import org.thingsboard.server.common.data.yunteng.enums.ActionTypeEnum;
17 import org.thingsboard.server.common.data.yunteng.utils.SpringBeanUtils; 18 import org.thingsboard.server.common.data.yunteng.utils.SpringBeanUtils;
18 import org.thingsboard.server.common.msg.TbMsg; 19 import org.thingsboard.server.common.msg.TbMsg;
19 import org.thingsboard.server.common.msg.TbMsgMetaData; 20 import org.thingsboard.server.common.msg.TbMsgMetaData;
  21 +import org.thingsboard.server.common.msg.queue.ServiceQueue;
20 import org.thingsboard.server.dao.yunteng.entities.DoAction; 22 import org.thingsboard.server.dao.yunteng.entities.DoAction;
21 import org.thingsboard.server.dao.yunteng.entities.DoCondition; 23 import org.thingsboard.server.dao.yunteng.entities.DoCondition;
22 import org.thingsboard.server.dao.yunteng.service.DoActionService; 24 import org.thingsboard.server.dao.yunteng.service.DoActionService;
@@ -78,9 +80,8 @@ class ReactState { @@ -78,9 +80,8 @@ class ReactState {
78 } 80 }
79 81
80 if(matched){ 82 if(matched){
81 - // TODO 输出动作  
82 for(DoAction item: actions){ 83 for(DoAction item: actions){
83 -// pushMsg(); 84 + pushMsg(ctx, msg, item);
84 } 85 }
85 } 86 }
86 87
@@ -110,26 +111,43 @@ class ReactState { @@ -110,26 +111,43 @@ class ReactState {
110 return null; 111 return null;
111 } 112 }
112 113
113 - private void pushMsg(TbContext ctx, TbMsg msg, TbAlarmResult alarmResult,DoAction action) {  
114 - JsonNode jsonNodes = JacksonUtil.valueToTree(alarmResult.getAlarm());  
115 - String data = jsonNodes.toString(); 114 + private void pushMsg(TbContext ctx, TbMsg msg, DoAction action) {
116 TbMsgMetaData metaData = //lastMsgMetaData != null ? lastMsgMetaData.copy() : 115 TbMsgMetaData metaData = //lastMsgMetaData != null ? lastMsgMetaData.copy() :
117 new TbMsgMetaData(); 116 new TbMsgMetaData();
118 - String relationType;  
119 - if (alarmResult.isCreated()) {  
120 - relationType = "Alarm Created";  
121 - metaData.putValue(DataConstants.IS_NEW_ALARM, Boolean.TRUE.toString());  
122 - } else if (alarmResult.isUpdated()) {  
123 - relationType = "Alarm Updated";  
124 - metaData.putValue(DataConstants.IS_EXISTING_ALARM, Boolean.TRUE.toString());  
125 - } else if (alarmResult.isSeverityUpdated()) {  
126 - relationType = "Alarm Severity Updated";  
127 - metaData.putValue(DataConstants.IS_EXISTING_ALARM, Boolean.TRUE.toString());  
128 - metaData.putValue(DataConstants.IS_SEVERITY_UPDATED_ALARM, Boolean.TRUE.toString());  
129 - } else {  
130 - relationType = "Alarm Cleared";  
131 - metaData.putValue(DataConstants.IS_CLEARED_ALARM, Boolean.TRUE.toString()); 117 + String relationType = "";
  118 + TbMsg newMsg = null;
  119 + switch(action.getOutTarget()){
  120 + case DEVICE_OUT:
  121 + relationType = "RPC Request";
  122 + newMsg = rpcMsg(ctx,msg,action.getDoContext());
  123 + break;
  124 + case SCENE_ACT:
  125 + //TODO: 场景联动关联场景联动
  126 + relationType = "Alarm Updated";
  127 + break;
  128 + case MSG_NOTIFY:
  129 + relationType = "Message";
  130 + break;
  131 + default:
  132 + ctx.tellSuccess(msg);
  133 + break;
132 } 134 }
133 - ctx.tellNext(msg, relationType); 135 +
  136 + if(newMsg != null){
  137 + ctx.tellNext(newMsg, relationType);
  138 + }
  139 + }
  140 +
  141 + private TbMsg rpcMsg(TbContext ctx, TbMsg msg,String context){
  142 + String lastMsgQueueName = msg.getQueueName();
  143 + TbMsgMetaData metaData = msg.getMetaData();
  144 + metaData.putValue(DataConstants.IS_CLEARED_ALARM, Boolean.TRUE.toString());
  145 + TbMsg newMsg = ctx.newMsg(lastMsgQueueName != null ? lastMsgQueueName : ServiceQueue.MAIN
  146 + , msg.getType()
  147 + , msg.getOriginator()
  148 + , msg != null ? msg.getCustomerId() : null
  149 + , metaData
  150 + , context);
  151 + return newMsg;
134 } 152 }
135 } 153 }
@@ -67,7 +67,7 @@ class TriggerState { @@ -67,7 +67,7 @@ class TriggerState {
67 private volatile Alarm currentAlarm; 67 private volatile Alarm currentAlarm;
68 private volatile boolean initialFetchDone; 68 private volatile boolean initialFetchDone;
69 private volatile TbMsgMetaData lastMsgMetaData; 69 private volatile TbMsgMetaData lastMsgMetaData;
70 - private volatile String lastMsgQueueName; 70 +
71 private final DynamicPredicateValueCtx dynamicPredicateValueCtx; 71 private final DynamicPredicateValueCtx dynamicPredicateValueCtx;
72 private DataSnapshot latestValues; 72 private DataSnapshot latestValues;
73 73
@@ -87,7 +87,6 @@ class TriggerState { @@ -87,7 +87,6 @@ class TriggerState {
87 latestValues = fetchLatestValues(ctx, originator); 87 latestValues = fetchLatestValues(ctx, originator);
88 } 88 }
89 lastMsgMetaData = msg.getMetaData(); 89 lastMsgMetaData = msg.getMetaData();
90 - lastMsgQueueName = msg.getQueueName();  
91 SnapshotUpdate update = null; 90 SnapshotUpdate update = null;
92 if(msg.getType().equals(SessionMsgType.POST_TELEMETRY_REQUEST.name())){ 91 if(msg.getType().equals(SessionMsgType.POST_TELEMETRY_REQUEST.name())){
93 update = processTelemetry(ctx,msg); 92 update = processTelemetry(ctx,msg);