perf: 调整结构,优化格式转换
parent
7f0c70cba2
commit
fffa18f452
@ -1,13 +1,17 @@
|
|||||||
package com.xydl.cac.model.i2sync;
|
package com.xydl.cac.model.i2sync;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
|
||||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class Monitordata {
|
public class Monitordata {
|
||||||
@JacksonXmlProperty(isAttribute = true)
|
@JacksonXmlProperty(isAttribute = true)
|
||||||
private String cacid;
|
private String cacid;
|
||||||
@JacksonXmlProperty(isAttribute = true)
|
@JacksonXmlProperty(isAttribute = true)
|
||||||
private int datanodenum;
|
private Integer datanodenum;
|
||||||
private Datanode datanode;
|
@JacksonXmlElementWrapper(useWrapping = false)
|
||||||
|
private List<Datanode> datanode;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,55 @@
|
|||||||
|
package com.xydl.cac.transform;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.I2syncField;
|
||||||
|
import com.xydl.cac.entity.I2syncRecord;
|
||||||
|
import com.xydl.cac.entity.NSensor;
|
||||||
|
import com.xydl.cac.model.i2sync.Attr;
|
||||||
|
import com.xydl.cac.model.i2sync.Datanode;
|
||||||
|
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.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class I2DataTransformer {
|
||||||
|
|
||||||
|
public Request transform(NSensor sensor, I2syncRecord record,
|
||||||
|
List<I2syncField> fieldList, List<Map<String, Object>> dataList) throws Exception {
|
||||||
|
|
||||||
|
List<Datanode> nodeList = new ArrayList<>();
|
||||||
|
for (Map<String, Object> map : dataList) {
|
||||||
|
String date = (String) map.get("acquisitionTime");
|
||||||
|
List<Attr> attrs = new ArrayList<>();
|
||||||
|
for (I2syncField field : fieldList) {
|
||||||
|
Object value = map.get(field.getFieldName());
|
||||||
|
Attr attr = new Attr();
|
||||||
|
attr.setName(field.getDestFieldName());
|
||||||
|
attr.setValue(String.valueOf(value));
|
||||||
|
attr.setAlarm("FALSE");
|
||||||
|
attrs.add(attr);
|
||||||
|
}
|
||||||
|
Datanode node = new Datanode();
|
||||||
|
node.setSensorid(sensor.getEquipmentId());
|
||||||
|
node.setType("027002");
|
||||||
|
node.setEquipmentid(sensor.getEquipmentId());
|
||||||
|
node.setTimestamp(date);
|
||||||
|
node.setAttr(attrs);
|
||||||
|
nodeList.add(node);
|
||||||
|
record.setLastDTime(DateUtil.parse(date));
|
||||||
|
}
|
||||||
|
|
||||||
|
Monitordata monitordata = new Monitordata();
|
||||||
|
monitordata.setCacid(sensor.getEquipmentId());
|
||||||
|
monitordata.setDatanodenum(nodeList.size());
|
||||||
|
monitordata.setDatanode(nodeList);
|
||||||
|
Request request = new Request();
|
||||||
|
request.setMonitordata(monitordata);
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue