|
@@ -0,0 +1,213 @@
|
|
|
|
+package com.jiayue.ipfcst.console.service;
|
|
|
|
+import com.jiayue.ipfcst.common.data.entity.PowerStationStatusData;
|
|
|
|
+import com.jiayue.ipfcst.common.data.repository.PowerStationStatusDataRepository;
|
|
|
|
+import com.jiayue.ipfcst.common.data.service.BaseService;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 实际功率
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class PowerStationStatusDataService extends BaseService {
|
|
|
|
+
|
|
|
|
+ private final PowerStationStatusDataRepository powerStationStatusDataRepository;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ public PowerStationStatusDataService(PowerStationStatusDataRepository powerStationStatusDataRepository) {
|
|
|
|
+ this.powerStationStatusDataRepository = powerStationStatusDataRepository;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据开始时间和结束时间查询 场站功率状态
|
|
|
|
+ * 超短期数据展示搭配实际功率使用
|
|
|
|
+ *
|
|
|
|
+ * @param startTime 开始时间
|
|
|
|
+ * @param endTime 结束时间
|
|
|
|
+ * @return 结果集
|
|
|
|
+ */
|
|
|
|
+ @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
|
|
|
|
+ public Map<String, Object> findByTimeBetweenForContrast(Date startTime, Date endTime, Long timeStep) {
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+ List<PowerStationStatusData> list = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ list = powerStationStatusDataRepository.findByTimeBetween(startTime, endTime);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ long startTimeLong = startTime.getTime();
|
|
|
|
+ long endTimeLong = endTime.getTime();
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ if (startTimeLong % timeStep != 0) {
|
|
|
|
+ startTimeLong = startTimeLong - (startTimeLong % timeStep);
|
|
|
|
+ }
|
|
|
|
+ List<Float> realDatas = new ArrayList<>();
|
|
|
|
+ List<Float> ableDatas = new ArrayList<>();
|
|
|
|
+ List<Float> theoryDatas = new ArrayList<>();
|
|
|
|
+ List<Float> referencePowerByMeasuringDatas = new ArrayList<>();
|
|
|
|
+ List<Float> referencePowerBySampleDatas = new ArrayList<>();
|
|
|
|
+ List<String> times = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ for (long i = startTimeLong; i < endTimeLong; i = i + timeStep) {
|
|
|
|
+ long finalI = i;
|
|
|
|
+ List<PowerStationStatusData> p = list.stream().filter(t -> t.getTime().getTime() == finalI).collect(Collectors.toList());
|
|
|
|
+ if (p != null && p.size() > 0) {
|
|
|
|
+
|
|
|
|
+ if (p.get(0).getRealValue().compareTo(new BigDecimal(-99)) == 0) {
|
|
|
|
+ realDatas.add(null);
|
|
|
|
+ } else {
|
|
|
|
+ realDatas.add(p.get(0).getRealValue().floatValue());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (p.get(0).getAbleValue().compareTo(new BigDecimal(-99)) == 0) {
|
|
|
|
+ ableDatas.add(null);
|
|
|
|
+ } else {
|
|
|
|
+ ableDatas.add(p.get(0).getAbleValue().floatValue());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (p.get(0).getTheoryValue().compareTo(new BigDecimal(-99)) == 0) {
|
|
|
|
+ theoryDatas.add(null);
|
|
|
|
+ } else {
|
|
|
|
+ theoryDatas.add(p.get(0).getTheoryValue().floatValue());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (p.get(0).getReferencePowerByMeasuring().compareTo(new BigDecimal(-99)) == 0) {
|
|
|
|
+ referencePowerByMeasuringDatas.add(null);
|
|
|
|
+ } else {
|
|
|
|
+ referencePowerByMeasuringDatas.add(p.get(0).getReferencePowerByMeasuring().floatValue());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (p.get(0).getReferencePowerBySample().compareTo(new BigDecimal(-99)) == 0) {
|
|
|
|
+ referencePowerBySampleDatas.add(null);
|
|
|
|
+ } else {
|
|
|
|
+ referencePowerBySampleDatas.add(p.get(0).getReferencePowerBySample().floatValue());
|
|
|
|
+ }
|
|
|
|
+ String timeFormat = sdf.format(new Date(i));
|
|
|
|
+ times.add(timeFormat);
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ String timeFormat = sdf.format(new Date(i));
|
|
|
|
+ times.add(timeFormat);
|
|
|
|
+ realDatas.add(null);
|
|
|
|
+ ableDatas.add(null);
|
|
|
|
+ theoryDatas.add(null);
|
|
|
|
+ referencePowerByMeasuringDatas.add(null);
|
|
|
|
+ referencePowerBySampleDatas.add(null);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ map.put("times", times);
|
|
|
|
+ map.put("realDatas", realDatas);
|
|
|
|
+ map.put("ableDatas", ableDatas);
|
|
|
|
+ map.put("theoryDatas", theoryDatas);
|
|
|
|
+ map.put("referencePowerByMeasuringDatas", referencePowerByMeasuringDatas);
|
|
|
|
+ map.put("referencePowerBySampleDatas", referencePowerBySampleDatas);
|
|
|
|
+
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 对集合进行 -99替换null操作,主要用于图标展示空值
|
|
|
|
+ *
|
|
|
|
+ * @param datas 需要替换集合
|
|
|
|
+ */
|
|
|
|
+ public void defaultReplace(List<PowerStationStatusData> datas) {
|
|
|
|
+ BigDecimal nullBig = new BigDecimal(-99);
|
|
|
|
+ for (PowerStationStatusData p : datas) {
|
|
|
|
+ if (p.getRealValue().compareTo(nullBig) == 0) {
|
|
|
|
+ p.setRealValue(null);
|
|
|
|
+ }
|
|
|
|
+ if (p.getAbleValue().compareTo(nullBig) == 0) {
|
|
|
|
+ p.setAbleValue(null);
|
|
|
|
+ }
|
|
|
|
+ if (p.getTheoryValue().compareTo(nullBig) == 0) {
|
|
|
|
+ p.setTheoryValue(null);
|
|
|
|
+ }
|
|
|
|
+ if (p.getOpenCapacity().compareTo(nullBig) == 0) {
|
|
|
|
+ p.setOpenCapacity(null);
|
|
|
|
+ }
|
|
|
|
+ if (p.getCapacity().compareTo(nullBig) == 0) {
|
|
|
|
+ p.setCapacity(null);
|
|
|
|
+ }
|
|
|
|
+ if (p.getOnSiteObstructed().compareTo(nullBig) == 0) {
|
|
|
|
+ p.setOnSiteObstructed(null);
|
|
|
|
+ }
|
|
|
|
+ if (p.getOffSiteObstructed().compareTo(nullBig) == 0) {
|
|
|
|
+ p.setOffSiteObstructed(null);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 受阻电量查询(已废弃)
|
|
|
|
+ *
|
|
|
|
+ * @param startTime 开始时间
|
|
|
|
+ * @param endTime 结束时间
|
|
|
|
+ */
|
|
|
|
+ @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
|
|
|
|
+ public List<Map<String, Object>> findBalkPower(Date startTime, Date endTime) {
|
|
|
|
+
|
|
|
|
+ List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ List<PowerStationStatusData> powerStationStatusDataList = powerStationStatusDataRepository.findByTimeBetween(startTime, endTime);
|
|
|
|
+
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ for (PowerStationStatusData powerStationStatusData : powerStationStatusDataList) {
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+ map.put("time", sdf.format(powerStationStatusData.getTime()));
|
|
|
|
+ map.put("onSiteObstructed", powerStationStatusData.getOnSiteObstructed());
|
|
|
|
+ map.put("offSiteObstructed", powerStationStatusData.getOffSiteObstructed());
|
|
|
|
+ BigDecimal b = powerStationStatusData.getAbleValue().subtract(powerStationStatusData.getRealValue());
|
|
|
|
+ if (powerStationStatusData.getRealValue().floatValue() != 0) {
|
|
|
|
+ map.put("abandonmentRate", b.divide(powerStationStatusData.getRealValue(), 2, BigDecimal.ROUND_HALF_UP));
|
|
|
|
+ } else {
|
|
|
|
+ map.put("abandonmentRate", 0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ resultList.add(map);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// Sort sort = Sort.by(Sort.Direction.DESC, "time");
|
|
|
|
+// if (sortOrder.contains("asc")) {
|
|
|
|
+// sort = Sort.by(Sort.Direction.ASC, "time");
|
|
|
|
+// }
|
|
|
|
+// Specification<PowerStationStatusData> specification = this.Specification(startTime, endTime);
|
|
|
|
+// Pageable pageable = PageRequest.of(page - 1, size, sort);
|
|
|
|
+// Page pages = powerStationStatusDataRepository.findAll(specification, pageable);
|
|
|
|
+// List<PowerStationStatusData> datas = new ArrayList<>();
|
|
|
|
+// datas = pages.getContent();
|
|
|
|
+// map.put("content", datas);
|
|
|
|
+// map.put("count", pages.getTotalElements());
|
|
|
|
+
|
|
|
|
+ return resultList;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据时间查询数据并根据时间正序排序
|
|
|
|
+ *
|
|
|
|
+ * @param startTime 开始时间
|
|
|
|
+ * @param endTime 结束时间
|
|
|
|
+ */
|
|
|
|
+ @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
|
|
|
|
+ public List<PowerStationStatusData> findByTimeBetween(Long startTime, Long endTime) {
|
|
|
|
+ List<PowerStationStatusData> powerStationStatusDataList = powerStationStatusDataRepository.findByTimeBetween(new Date(startTime), new Date(endTime));
|
|
|
|
+ Collections.sort(powerStationStatusDataList, Comparator.comparing(PowerStationStatusData::getTime));
|
|
|
|
+ return powerStationStatusDataList;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|