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 + "]";
|
}
|
|
|
}
|