|
|
|
@ -1,6 +1,5 @@
|
|
|
|
|
package com.xydl.cac.transform;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.excel.util.StringUtils;
|
|
|
|
|
import com.xydl.cac.entity.*;
|
|
|
|
|
import com.xydl.cac.model.StaticVariable;
|
|
|
|
|
import com.xydl.cac.model.i2sync.Attr;
|
|
|
|
@ -9,12 +8,10 @@ import com.xydl.cac.model.i2sync.Monitordata;
|
|
|
|
|
import com.xydl.cac.model.i2sync.Request;
|
|
|
|
|
import com.xydl.cac.util.DateUtil;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
@Component
|
|
|
|
|
@Slf4j
|
|
|
|
@ -34,23 +31,42 @@ public class I2DataTransformer {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LinkedHashMap<String, List<I2syncField>> fieldMap = this.sortFieldList(fieldList);
|
|
|
|
|
|
|
|
|
|
List<Datanode> nodeList = new ArrayList<>();
|
|
|
|
|
for (Map<String, Object> map : dataList) {
|
|
|
|
|
String date = (String) map.get("acquisitionTime");
|
|
|
|
|
Datanode node = new Datanode();
|
|
|
|
|
node.setSensorid(sensor.getSensorCode());
|
|
|
|
|
node.setEquipmentid(sensor.getEquipmentId());
|
|
|
|
|
node.setTimestamp(date);
|
|
|
|
|
|
|
|
|
|
List<Attr> attrs = new ArrayList<>();
|
|
|
|
|
Attr attr = new Attr();
|
|
|
|
|
attr.setName("Phase");
|
|
|
|
|
attr.setValue(sensor.getPhase());
|
|
|
|
|
attr.setAlarm("FALSE");
|
|
|
|
|
attrs.add(attr);
|
|
|
|
|
for (I2syncField field : fieldList) {
|
|
|
|
|
Object value = map.get(field.getFieldName());
|
|
|
|
|
attr = new Attr();
|
|
|
|
|
Iterator<String> fit = fieldMap.keySet().iterator();
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
String attach = fit.next();
|
|
|
|
|
List<I2syncField> fieldListNew = fieldMap.get(attach);
|
|
|
|
|
|
|
|
|
|
Datanode node = this.buildDatanode(sensor, config.getTypeCode(), attach,
|
|
|
|
|
fieldListNew, map, ruleList);
|
|
|
|
|
if (node != null) {
|
|
|
|
|
nodeList.add(node);
|
|
|
|
|
record.setLastDTime(DateUtil.parse(node.getTimestamp()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Monitordata monitordata = new Monitordata();
|
|
|
|
|
monitordata.setCacid(sensor.getSensorCode());
|
|
|
|
|
monitordata.setDatanodenum(nodeList.size());
|
|
|
|
|
monitordata.setDatanode(nodeList);
|
|
|
|
|
Request request = new Request();
|
|
|
|
|
request.setMonitordata(monitordata);
|
|
|
|
|
return request;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Datanode buildDatanode(NSensor sensor, String typeCode, String attach,
|
|
|
|
|
List<I2syncField> fieldList, Map<String, Object> dataMap,
|
|
|
|
|
List<WarnRule> ruleList) {
|
|
|
|
|
List<Attr> attrs = new ArrayList<>();
|
|
|
|
|
for (I2syncField field : fieldList) {
|
|
|
|
|
Object value = dataMap.get(field.getFieldName());
|
|
|
|
|
if (value != null) {
|
|
|
|
|
Attr attr = new Attr();
|
|
|
|
|
attr.setName(field.getDestFieldName());
|
|
|
|
|
attr.setValue(String.valueOf(value));
|
|
|
|
|
if (this.triggerRule(ruleList, field.getFieldName(), value)) {
|
|
|
|
@ -58,24 +74,49 @@ public class I2DataTransformer {
|
|
|
|
|
} else {
|
|
|
|
|
attr.setAlarm("FALSE");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isBlank(node.getType())) {
|
|
|
|
|
node.setType(config.getTypeCode());
|
|
|
|
|
}
|
|
|
|
|
attrs.add(attr);
|
|
|
|
|
}
|
|
|
|
|
node.setAttr(attrs);
|
|
|
|
|
}
|
|
|
|
|
if (attrs.size() < 1) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
String date = (String) dataMap.get("acquisitionTime");
|
|
|
|
|
Datanode node = new Datanode();
|
|
|
|
|
node.setType(typeCode);
|
|
|
|
|
node.setTimestamp(date);
|
|
|
|
|
node.setAttr(attrs);
|
|
|
|
|
|
|
|
|
|
nodeList.add(node);
|
|
|
|
|
record.setLastDTime(DateUtil.parse(date));
|
|
|
|
|
Attr attr = new Attr();
|
|
|
|
|
attr.setName("Phase");
|
|
|
|
|
attr.setAlarm("FALSE");
|
|
|
|
|
attrs.add(attr);
|
|
|
|
|
if (StringUtils.isBlank(attach)) {
|
|
|
|
|
attr.setValue(sensor.getPhase());
|
|
|
|
|
node.setSensorid(sensor.getSensorCode());
|
|
|
|
|
node.setEquipmentid(sensor.getEquipmentId());
|
|
|
|
|
} else {
|
|
|
|
|
attr.setValue("");
|
|
|
|
|
node.setSensorid(sensor.getSensorCode() + attach);
|
|
|
|
|
node.setEquipmentid(sensor.getEquipmentId() + attach);
|
|
|
|
|
}
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Monitordata monitordata = new Monitordata();
|
|
|
|
|
monitordata.setCacid(sensor.getSensorCode());
|
|
|
|
|
monitordata.setDatanodenum(nodeList.size());
|
|
|
|
|
monitordata.setDatanode(nodeList);
|
|
|
|
|
Request request = new Request();
|
|
|
|
|
request.setMonitordata(monitordata);
|
|
|
|
|
return request;
|
|
|
|
|
private LinkedHashMap<String, List<I2syncField>> sortFieldList(List<I2syncField> fieldList) {
|
|
|
|
|
LinkedHashMap<String, List<I2syncField>> map = new LinkedHashMap<>();
|
|
|
|
|
for (I2syncField item : fieldList) {
|
|
|
|
|
String attach = item.getAttach();
|
|
|
|
|
if (attach == null) {
|
|
|
|
|
attach = "";
|
|
|
|
|
}
|
|
|
|
|
List<I2syncField> list = map.get(attach);
|
|
|
|
|
if (list == null) {
|
|
|
|
|
list = new ArrayList<>();
|
|
|
|
|
map.put(attach, list);
|
|
|
|
|
}
|
|
|
|
|
list.add(item);
|
|
|
|
|
}
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean triggerRule(List<WarnRule> ruleList, String fieldName, Object value) {
|
|
|
|
|