yangys
2024-11-03 d187cd0fa46d01ec293e2aba1a1e54fdfab2ec80
数据点位过滤修复,使用了计算规则的点位存储_n的。
已修改3个文件
91 ■■■■ 文件已修改
collect/src/main/java/com/qianwen/mdc/collect/service/IOTMqttReceiveService.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/vo/WorkstationDatapointsVO.java 69 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/resources/application-dev.yml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/service/IOTMqttReceiveService.java
@@ -19,6 +19,7 @@
@Service
public class IOTMqttReceiveService {
    public static final String NEWDP_SUFFIX = "_n";//计算规则使用之后新数据点的结尾
    private static final Logger log = LoggerFactory.getLogger(IOTMqttReceiveService.class);
    @Autowired
    private CollectDataService collectDataService;
@@ -27,6 +28,7 @@
    private PackedDataService packedDataService;
    @Autowired
    private WorkstationDatapointsService dpService;
    /**
     * 处理收到的消息,对应TelemetryDataPostingConsumer
     * @param payload
@@ -54,15 +56,13 @@
        Set<String> keySet = jsonObj.keySet();
        String[] keys = keySet.toArray(new String[] {});
        
        //WorkstationDatapointsVO dpVo;
        
        final String NEWDP_SUFFIX = "_n";//计算规则使用之后新数据点的结尾
        for(String key : keys) {
            String appId = key;//iot系统中的应用id,本应用中应该用表去对应
            
            //TODO 获取工位数据点配置,只保存配置好的数据点,没有配置的采集数据抛弃。
            //获取工位数据点配置,只保存配置好的数据点,没有配置的采集数据抛弃。
            final WorkstationDatapointsVO dpVo = dpService.getDatapointsByAppIdFromCache(appId);
            //final WorkstationDatapointsVO dpVo = dpService.getDataPointByAppId(appId);
            if(dpVo == null) {
                //工位没有定义过数据点或者appId不匹配
                log.warn("appId={}未找到数据点定义记录,丢弃数据",appId);
@@ -86,14 +86,16 @@
                
                Set<String> valueKeySet = values.keySet();
                valueKeySet.forEach(valueKey ->{
                    String oriValueKey = valueKey;;//由于使用计算规则的采集点名称会后面增加一个"_n",所以这个oriValueKey代表没有增加"_n"的
                    if(StringUtils.endsWith(valueKey, NEWDP_SUFFIX)) {
                        oriValueKey = StringUtils.removeEnd(valueKey, NEWDP_SUFFIX);
                    }
                    if(!dpVo.containsDataPoint(oriValueKey)) {
                    if(!dpVo.containsDataPoint(valueKey)) {
                        //如果不存在该数据点配置,该数据直接忽略
                        return;
                    }
                    String oriValueKey = valueKey;//由于使用计算规则的采集点名称会后面增加一个"_n",所以这个oriValueKey代表没有增加"_n"的
                    if(StringUtils.endsWith(valueKey, NEWDP_SUFFIX)) {
                        oriValueKey = StringUtils.removeEnd(valueKey, NEWDP_SUFFIX);
                    }
                    tdataItem.addPoint(oriValueKey,values.getString(valueKey));//使用原始配置点保持保存数据
                });
                
collect/src/main/java/com/qianwen/mdc/collect/vo/WorkstationDatapointsVO.java
@@ -10,7 +10,6 @@
import com.alibaba.fastjson.JSONObject;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import io.swagger.annotations.ApiModelProperty;
@@ -43,6 +42,8 @@
    //private List<DataPoint> points = null;
    private List<String> points = new ArrayList<>();
    private List<DataPoint> dpList = new ArrayList<>();
    public WorkstationDatapointsVO(long workstationId, String appId,String dpConfig) {
        super();
        this.dpConfig = dpConfig;
@@ -60,13 +61,18 @@
        
        points = new ArrayList<>();
        JSONObject ptObj;
        String dpName;
        for(int i=0;i<ptArr.size();i++) {
            ptObj = ptArr.getJSONObject(i);
            
            //DataPoint dp = new DataPoint();
            //dp.setDpName(ptObj.getString("dpName"));
            dpName = ptObj.getString("dpName");
            points.add(dpName);
            
            points.add(ptObj.getString("dpName"));
            DataPoint dp = new DataPoint();
            dp.setDpName(dpName);
            dp.setRuleContent(ptObj.getString("ruleContent"));
            dpList.add(dp);
        }
    }
@@ -108,28 +114,51 @@
     * @param dpName
     * @return
     */
    public boolean containsDataPoint(String dpName) {
    public boolean containsDataPointOld(String dpName) {
        if(ObjectUtil.isEmpty(points)) {
            return false;
        }
        
        return points.contains(dpName);
        /*
        for(String dpn : points) {
            if(StringUtils.equals(dpn, dpName)) {
    }
    public boolean containsDataPoint(String receiveDpName) {
        if(ObjectUtil.isEmpty(dpList)) {
            return false;
        }
        if(receiveDpName.startsWith("DeviceStatus")) {
            System.out.println("recname="+receiveDpName);
        }
        for(DataPoint dp : dpList) {
            //无计算规则,直接数据点名称匹配
            if(!dp.hasRuleContent()){
                if(StringUtils.equals(dp.getDpName(), receiveDpName)){
                    return true;
                }
            }else {
                //有计算规则,用数据点名称_n匹配
                if(StringUtils.equals(dp.getDpName()+"_n", receiveDpName)) {
                return true;
            }
        }
        }
        return false;
        */
    }
    
}
/*
class DataPoint{
}
class DataPoint implements Serializable{
    private String dpName;
    private String ruleContent;
    /**
     * 数据点是否包含计算规则
     */
    public boolean hasRuleContent() {
        return StringUtils.isNotBlank(StringUtils.trim(ruleContent));
    }
    public String getDpName() {
        return dpName;
    }
@@ -138,6 +167,18 @@
        this.dpName = dpName;
    }
    
    public String getRuleContent() {
        return ruleContent;
    }
    public void setRuleContent(String ruleContent) {
        this.ruleContent = ruleContent;
    }
    @Override
    public String toString() {
        return "DataPoint [dpName=" + dpName + ", ruleContent=" + ruleContent + "]";
    }
    
}
*/
collect/src/main/resources/application-dev.yml
@@ -27,7 +27,7 @@
  # mysql
datasource:
  type: mysql
  url: jdbc:mysql://120.46.212.231:3306/smart_boot?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
  url: jdbc:mysql://120.46.212.231:3306/smartman?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
  port: 3306
  username: qwmdc
  password: Kknd_1234