|
@@ -6,10 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.ArrayBlockingQueue;
|
|
|
|
|
|
/**
|
|
@@ -26,6 +23,16 @@ public class ForcastService {
|
|
|
|
|
|
private ArrayBlockingQueue<ForcastModel> forcastQueue = new ArrayBlockingQueue<>(maxCacheCount);
|
|
|
|
|
|
+ private HashSet<String> typeSet = createTypeSet();
|
|
|
+
|
|
|
+ private HashSet<String> createTypeSet() {
|
|
|
+ HashSet<String> ret = new HashSet<>();
|
|
|
+ ret.add("UltraShortTermForcast_V2P"); //CDQ,LLCDQ
|
|
|
+ ret.add("ShortTermForcast"); //DQ
|
|
|
+ ret.add("MastData"); //CFT,QXZ
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
public void putForcastModel(ForcastModel forcastModel) {
|
|
|
//如果队列已满,移除头部元素,腾出空间添加新元素
|
|
|
if (forcastQueue.offer(forcastModel) == false) {
|
|
@@ -49,8 +56,8 @@ public class ForcastService {
|
|
|
String[] lineArray = fileString.split("\r\n");
|
|
|
//遍历数组lineArray
|
|
|
for (int i = 0; i < lineArray.length; i++) {
|
|
|
- //每行字符串line
|
|
|
- String line = lineArray[i];
|
|
|
+ //每行字符串line, 多个空格替换为一个空格
|
|
|
+ String line = lineArray[i].replaceAll(" +"," ");
|
|
|
//解析type和time,例子:<! Entity=ZWS05F type=CDQ time='2023-02-27_17:15' !>
|
|
|
if (line.startsWith("<!")) {
|
|
|
//每行字符串按空格分割为fieldArray数组
|
|
@@ -80,10 +87,18 @@ public class ForcastService {
|
|
|
xmlFlag = fieldArray[0].substring(1);
|
|
|
}
|
|
|
|
|
|
+ if (line.startsWith("</")) {
|
|
|
+ String[] fieldArray = line.split("::");
|
|
|
+ String endFlag = fieldArray[0].substring(2);
|
|
|
+ if (endFlag == xmlFlag) {
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//解析功率数据
|
|
|
if (line.startsWith("#") && (Objects.equals(xmlFlag, "UltraShortTermForcast_V2P")
|
|
|
|| Objects.equals(xmlFlag, "ShortTermForcast"))) {
|
|
|
- String[] fieldArray = line.split(" ");
|
|
|
+ String[] fieldArray = line.split(" ");
|
|
|
if (fieldArray.length > 1) {
|
|
|
TelemetryData td = new TelemetryData();
|
|
|
td.setKey(fieldArray[0]);
|
|
@@ -108,6 +123,7 @@ public class ForcastService {
|
|
|
}
|
|
|
|
|
|
public GYMessage ForcastModel2GYMessage(ForcastModel forcastModel) {
|
|
|
+ //todo: 如何保障顺序?有没有最大数据项数量限制?
|
|
|
GYMessage gyMessage = new GYMessage();
|
|
|
if("CDQ".equals(forcastModel.getDataType())) {
|
|
|
gyMessage.setAddressIndex(akConfig.getCdqAddressStart());
|
|
@@ -115,6 +131,10 @@ public class ForcastService {
|
|
|
gyMessage.setAddressIndex(akConfig.getDqAddressStart());
|
|
|
} else if ("CFT".equals(forcastModel.getDataType())) {
|
|
|
gyMessage.setAddressIndex(akConfig.getCftAddressStart());
|
|
|
+ } else if ("QXZ".equals(forcastModel.getDataType())) {
|
|
|
+ gyMessage.setAddressIndex(akConfig.getCftAddressStart());
|
|
|
+ } else if ("LLCDQ".equals(forcastModel.getDataType())) {
|
|
|
+ gyMessage.setAddressIndex(akConfig.getLlcdqAddressStart());
|
|
|
} else {
|
|
|
//无效的采集数据类型
|
|
|
return gyMessage;
|