mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-18 00:45:55 +08:00
fix(规则脚本增加日志): 规则脚本增加日志
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
package com.fastbee.iot.ruleEngine;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MsgContext {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger("script");
|
||||
|
||||
/** 消息主题 */
|
||||
private String topic;
|
||||
|
||||
/** 消息内容 */
|
||||
private String payload;
|
||||
|
||||
/**
|
||||
* 设备编号
|
||||
*/
|
||||
private String serialNumber;
|
||||
/**
|
||||
* 产品id
|
||||
*/
|
||||
private Long productId;
|
||||
/**
|
||||
* 协议编码
|
||||
*/
|
||||
private String protocolCode;
|
||||
}
|
||||
@@ -7,8 +7,9 @@ import com.fastbee.iot.model.ProductCode;
|
||||
import com.fastbee.iot.model.ScriptCondition;
|
||||
import com.fastbee.iot.service.IProductService;
|
||||
import com.fastbee.iot.service.IScriptService;
|
||||
import com.fastbee.ruleEngine.context.MsgContext;
|
||||
import com.fastbee.ruleEngine.core.FlowLogExecutor;
|
||||
import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -27,7 +28,7 @@ import java.util.Objects;
|
||||
public class RuleProcess {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
private FlowLogExecutor flowLogExecutor;
|
||||
@Resource
|
||||
private IScriptService scriptService;
|
||||
@Resource
|
||||
@@ -55,20 +56,29 @@ public class RuleProcess {
|
||||
scriptCondition.setScriptEvent(event); // 事件 1=设备上报 2=平台下发 3=设备上线 4=设备下线
|
||||
scriptCondition.setScriptPurpose(1); // 脚本用途:数据流=1
|
||||
String[] scriptIds = scriptService.selectRuleScriptIdArray(scriptCondition);
|
||||
MsgContext context = new MsgContext(topic, payload, serialNumber, productCode.getProductId(), productCode.getProtocolCode());
|
||||
MsgContext context = MsgContext.builder()
|
||||
.serialNumber(serialNumber)
|
||||
.productId(productCode.getProductId())
|
||||
.protocolCode(productCode.getProtocolCode())
|
||||
.payload(payload)
|
||||
.topic(topic)
|
||||
.build();
|
||||
//如果查询不到脚本,则认为是不用处理
|
||||
if (Objects.isNull(scriptIds) || scriptIds.length == 0) {
|
||||
return new MsgContext();
|
||||
}
|
||||
// 动态构造Chain和EL表达式
|
||||
String el = String.join(",", scriptIds); // THEN(a,b,c,d)
|
||||
LiteFlowChainELBuilder.createChain().setChainName("dataChain").setEL("THEN(" + el + ")").build();
|
||||
// 执行规则脚本
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("dataChain", null, context);
|
||||
if (!response.isSuccess()) {
|
||||
log.error("规则脚本执行发生错误:" + response.getMessage());
|
||||
for (String script : scriptIds) {
|
||||
String eChainName = "dataChain_" + script;
|
||||
String requestId = "script/" + script;
|
||||
String el = "THEN(" + script + ")";
|
||||
LiteFlowChainELBuilder.createChain().setChainName(eChainName).setEL(el).build();
|
||||
// 执行规则脚本
|
||||
LiteflowResponse response = flowLogExecutor.execute2RespWithRid(eChainName, null, requestId, context);
|
||||
if (!response.isSuccess()) {
|
||||
log.error("规则脚本执行发生错误:" + response.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
Reference in New Issue
Block a user