yangys
2024-11-03 d187cd0fa46d01ec293e2aba1a1e54fdfab2ec80
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package com.qianwen.mdc.collect.vo;
 
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
 
import org.apache.commons.lang3.StringUtils;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
 
import cn.hutool.core.util.ObjectUtil;
import io.swagger.annotations.ApiModelProperty;
 
 
/**
 * 工位采集数据点VO
 */
public class WorkstationDatapointsVO implements Serializable{
    
    /**
     * 序列化,应为需要spring缓存
     */
    private static final long serialVersionUID = 6558493027948435061L;
 
    @ApiModelProperty("点位表头(json数组)")
    private String dpHead;
    
    @ApiModelProperty("点位配置(json数组)")
    private String dpConfig;
    
    /**
     * 工位id
     */
    private long workstationId;
   
    /**
     * IOT平台appId
     */
    private String appId;
    
    //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;
        this.workstationId = workstationId;
        this.appId = appId;
        
        initPoints();
    }
    void initPoints() {
        if(ObjectUtil.isEmpty(dpConfig)) {
            return;
        }
        
        JSONArray ptArr = JSONArray.parseArray(dpConfig);
        
        points = new ArrayList<>();
        JSONObject ptObj;
        String dpName;
        for(int i=0;i<ptArr.size();i++) {
            ptObj = ptArr.getJSONObject(i);
            
            dpName = ptObj.getString("dpName");
            points.add(dpName);
            
            DataPoint dp = new DataPoint();
            dp.setDpName(dpName);
            dp.setRuleContent(ptObj.getString("ruleContent"));
            dpList.add(dp);
            
        }
    }
 
    public String getDpConfig() {
        return dpConfig;
    }
 
    public void setDpConfig(String dpConfig) {
        this.dpConfig = dpConfig;
    }
 
    public long getWorkstationId() {
        return workstationId;
    }
 
    public void setWorkstationId(long workstationId) {
        this.workstationId = workstationId;
    }
 
    public String getDpHead() {
        return dpHead;
    }
 
    public void setDpHead(String dpHead) {
        this.dpHead = dpHead;
    }
 
    public String getAppId() {
        return appId;
    }
 
    public void setAppId(String appId) {
        this.appId = appId;
    }
 
    
    /**
     * 判断采集变量名称是否在数据点配置种
     * @param dpName
     * @return
     */
    public boolean containsDataPointOld(String dpName) {
        if(ObjectUtil.isEmpty(points)) {
            return false;
        }
        
        return points.contains(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 implements Serializable{
    private String dpName;
    private String ruleContent;
    
    /**
     * 数据点是否包含计算规则
     */
    public boolean hasRuleContent() {
        return StringUtils.isNotBlank(StringUtils.trim(ruleContent));
    }
    public String getDpName() {
        return dpName;
    }
 
    public void setDpName(String dpName) {
        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 + "]";
    }
    
    
}