|
@@ -1,24 +1,18 @@
|
|
package com.gyee.runeconomy.service.WindDirection;
|
|
package com.gyee.runeconomy.service.WindDirection;
|
|
|
|
|
|
import com.gyee.common.contant.ContantXk;
|
|
import com.gyee.common.contant.ContantXk;
|
|
-import com.gyee.common.model.PointData;
|
|
|
|
import com.gyee.runeconomy.dto.result.PowerPointData;
|
|
import com.gyee.runeconomy.dto.result.PowerPointData;
|
|
import com.gyee.runeconomy.init.CacheContext;
|
|
import com.gyee.runeconomy.init.CacheContext;
|
|
import com.gyee.runeconomy.model.auto.ProBasicEquipment;
|
|
import com.gyee.runeconomy.model.auto.ProBasicEquipment;
|
|
import com.gyee.runeconomy.model.auto.ProBasicEquipmentPoint;
|
|
import com.gyee.runeconomy.model.auto.ProBasicEquipmentPoint;
|
|
import com.gyee.runeconomy.service.auto.IProBasicEquipmentPointService;
|
|
import com.gyee.runeconomy.service.auto.IProBasicEquipmentPointService;
|
|
-import com.gyee.runeconomy.util.realtimesource.IEdosUtil;
|
|
|
|
|
|
+import com.gyee.runeconomy.util.DateUtils;
|
|
import com.gyee.runeconomy.util.realtimesource.feign.RemoteServiceBuilder;
|
|
import com.gyee.runeconomy.util.realtimesource.feign.RemoteServiceBuilder;
|
|
import com.gyee.runeconomy.util.realtimesource.feign.TsDoubleData;
|
|
import com.gyee.runeconomy.util.realtimesource.feign.TsDoubleData;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
-import java.text.SimpleDateFormat;
|
|
|
|
-import java.time.Instant;
|
|
|
|
-import java.time.LocalDateTime;
|
|
|
|
-import java.time.ZoneId;
|
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -27,8 +21,6 @@ import java.util.stream.Collectors;
|
|
public class WindDirectionService {
|
|
public class WindDirectionService {
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
- private IEdosUtil edosUtil;
|
|
|
|
- @Resource
|
|
|
|
private IProBasicEquipmentPointService proBasicEquipmentPointService;
|
|
private IProBasicEquipmentPointService proBasicEquipmentPointService;
|
|
@Resource
|
|
@Resource
|
|
private RemoteServiceBuilder remoteService;
|
|
private RemoteServiceBuilder remoteService;
|
|
@@ -39,7 +31,7 @@ public class WindDirectionService {
|
|
*/
|
|
*/
|
|
public Object fxRoses(String wtid, String kssj, String jssj) throws Exception {
|
|
public Object fxRoses(String wtid, String kssj, String jssj) throws Exception {
|
|
|
|
|
|
- Date[] sjcl = sjcl(kssj, jssj);
|
|
|
|
|
|
+ Date[] sjcl = DateUtils.sjcl(kssj, jssj);
|
|
|
|
|
|
// 获取 startDate 和 endDate
|
|
// 获取 startDate 和 endDate
|
|
Date startDate = sjcl[0];
|
|
Date startDate = sjcl[0];
|
|
@@ -81,7 +73,7 @@ public class WindDirectionService {
|
|
TsDoubleData glData = glMap.get(ts);
|
|
TsDoubleData glData = glMap.get(ts);
|
|
|
|
|
|
PowerPointData data = new PowerPointData();
|
|
PowerPointData data = new PowerPointData();
|
|
- data.setTime(formatTimestamp(ts));
|
|
|
|
|
|
+ data.setTime(DateUtils.formatTimestamp(ts));
|
|
data.setFx(fxData.getDoubleValue());
|
|
data.setFx(fxData.getDoubleValue());
|
|
data.setSpeed(fsData != null ? fsData.getDoubleValue() : 0);
|
|
data.setSpeed(fsData != null ? fsData.getDoubleValue() : 0);
|
|
data.setMxzt(ztData != null ? (int) ztData.getDoubleValue() : 0);
|
|
data.setMxzt(ztData != null ? (int) ztData.getDoubleValue() : 0);
|
|
@@ -100,10 +92,6 @@ public class WindDirectionService {
|
|
map.put("speeedtime", WindALG.speedtimeNewRoses(lslist));//风速
|
|
map.put("speeedtime", WindALG.speedtimeNewRoses(lslist));//风速
|
|
map.put("roses", WindALG.fxysNewRoses(lslist));//风速、风向
|
|
map.put("roses", WindALG.fxysNewRoses(lslist));//风速、风向
|
|
map.put("count", WindALG.fxNewCountRoses(lslist));//风速、风向
|
|
map.put("count", WindALG.fxNewCountRoses(lslist));//风速、风向
|
|
- int[] count = WindALG.windDeviationRatio(lslist);//风向、对风误差
|
|
|
|
- List<Point> scatter = WindALG.windDeviationScatter(lslist);//风速、风向、对风误差
|
|
|
|
- map.put("countpcl", count);
|
|
|
|
- map.put("scatter", scatter);
|
|
|
|
map.put("radar", WindALG.fxRadarRoses(lslist));//对风误差
|
|
map.put("radar", WindALG.fxRadarRoses(lslist));//对风误差
|
|
map.put("frequency", WindALG.windDeviationPoint(lslist)); //风速、风向、明细状态、功率、偏航角度
|
|
map.put("frequency", WindALG.windDeviationPoint(lslist)); //风速、风向、明细状态、功率、偏航角度
|
|
result.add(map);
|
|
result.add(map);
|
|
@@ -111,35 +99,64 @@ public class WindDirectionService {
|
|
|
|
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
+ /**
|
|
|
|
+ * 对风偏差率
|
|
|
|
|
|
- private Date[] sjcl (String kssj,String jssj) throws ParseException {
|
|
|
|
|
|
+ */
|
|
|
|
+ public List<Object> windDeviationRatio(String wtid, String kssj, String jssj) throws ParseException {
|
|
|
|
|
|
- // 时间格式,格式是 "yyyy-MM-dd HH:mm"
|
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
|
+ Date[] sjcl = DateUtils.sjcl(kssj, jssj);
|
|
|
|
|
|
- // 将字符串转换为 Date 对象
|
|
|
|
- Date kssjDate = sdf.parse(kssj);
|
|
|
|
- Date jssjDate = sdf.parse(jssj);
|
|
|
|
|
|
+ // 获取 startDate 和 endDate
|
|
|
|
+ Date startDate = sjcl[0];
|
|
|
|
+ Date endDate = sjcl[1];
|
|
|
|
|
|
- // 创建 Calendar 对象
|
|
|
|
- Calendar kssjCalendar = Calendar.getInstance();
|
|
|
|
- Calendar jssjCalendar = Calendar.getInstance();
|
|
|
|
|
|
+ List<Object> list = new ArrayList<>();
|
|
|
|
+ // 初始化设备点
|
|
|
|
+ Map<EquipmentPointType, ProBasicEquipmentPoint> points = Arrays.stream(EquipmentPointType.values())
|
|
|
|
+ .collect(Collectors.toMap(type -> type, type -> getEquipmentPoint(wtid, type)));
|
|
|
|
|
|
- // 将 Date 设置到 Calendar 对象中
|
|
|
|
- kssjCalendar.setTime(kssjDate);
|
|
|
|
- jssjCalendar.setTime(jssjDate);
|
|
|
|
|
|
+ // 获取历史数据
|
|
|
|
+ Map<EquipmentPointType, List<TsDoubleData>> historyData = points.entrySet().stream()
|
|
|
|
+ .collect(Collectors.toMap(Map.Entry::getKey,
|
|
|
|
+ entry -> getSortedHistory(entry.getValue(), startDate.getTime(), endDate.getTime(), 900)));
|
|
|
|
|
|
- // 设置 endDate 为当天的 23:59:59
|
|
|
|
- jssjCalendar.set(Calendar.HOUR_OF_DAY, 23);
|
|
|
|
- jssjCalendar.set(Calendar.MINUTE, 59);
|
|
|
|
- jssjCalendar.set(Calendar.SECOND, 59);
|
|
|
|
- jssjCalendar.set(Calendar.MILLISECOND, 999);
|
|
|
|
|
|
+ // 创建时间戳到数据的映射表
|
|
|
|
+ Map<Long, TsDoubleData> pjfsMap = historyData.get(EquipmentPointType.PJFS).stream()
|
|
|
|
+ .collect(Collectors.toMap(TsDoubleData::getTs, Function.identity(), (a, b) -> a));
|
|
|
|
+ Map<Long, TsDoubleData> dfwcMap = historyData.get(EquipmentPointType.DFWC).stream()
|
|
|
|
+ .collect(Collectors.toMap(TsDoubleData::getTs, Function.identity(), (a, b) -> a));
|
|
|
|
|
|
- // 获取 startDate 和 endDate
|
|
|
|
- Date startDate = kssjCalendar.getTime();
|
|
|
|
- Date endDate = jssjCalendar.getTime();
|
|
|
|
- return new Date[] {startDate, endDate};
|
|
|
|
|
|
+ // 构造结果数据
|
|
|
|
+ List<PowerPointData> lslist = new ArrayList<>();
|
|
|
|
+ for (TsDoubleData fxData : historyData.get(EquipmentPointType.PJFX)) {
|
|
|
|
+ long ts = fxData.getTs();
|
|
|
|
+ TsDoubleData fsData = pjfsMap.get(ts);
|
|
|
|
+ TsDoubleData dfwcData = dfwcMap.get(ts);
|
|
|
|
+
|
|
|
|
+ PowerPointData data = new PowerPointData();
|
|
|
|
+ data.setTime(DateUtils.formatTimestamp(ts));
|
|
|
|
+ data.setFx(fxData.getDoubleValue());
|
|
|
|
+ data.setSpeed(fsData != null ? fsData.getDoubleValue() : 0);
|
|
|
|
+ data.setDfwc(dfwcData != null ? dfwcData.getDoubleValue() : 0);
|
|
|
|
+ lslist.add(data);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<ProBasicEquipment> listObj = CacheContext.wtls.stream().filter(wt -> wtid.equals(wt.getId())).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ listObj.forEach(obj -> {
|
|
|
|
+ int[] count = WindALG.windDeviationRatio(lslist);//风向、对风误差
|
|
|
|
+ List<Point> scatter = WindALG.windDeviationScatter(lslist);//风速、风向、对风误差
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+ map.put("wtId", obj.getAname());
|
|
|
|
+ map.put("count", count);
|
|
|
|
+ map.put("scatter", scatter);
|
|
|
|
+ list.add(map);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return list;
|
|
}
|
|
}
|
|
|
|
+
|
|
// 工具方法:获取设备点
|
|
// 工具方法:获取设备点
|
|
private ProBasicEquipmentPoint getEquipmentPoint(String wtid, EquipmentPointType type) {
|
|
private ProBasicEquipmentPoint getEquipmentPoint(String wtid, EquipmentPointType type) {
|
|
return proBasicEquipmentPointService.getEquipmentPoint(wtid, type.getCode());
|
|
return proBasicEquipmentPointService.getEquipmentPoint(wtid, type.getCode());
|
|
@@ -153,11 +170,7 @@ public class WindDirectionService {
|
|
return data;
|
|
return data;
|
|
}
|
|
}
|
|
|
|
|
|
- // 工具方法:格式化时间戳
|
|
|
|
- private String formatTimestamp(long timestamp) {
|
|
|
|
- LocalDateTime dateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault());
|
|
|
|
- return dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
// 枚举定义
|
|
// 枚举定义
|
|
public enum EquipmentPointType {
|
|
public enum EquipmentPointType {
|
|
PJFS(ContantXk.CJ_SSFS),
|
|
PJFS(ContantXk.CJ_SSFS),
|