|
@@ -1,12 +1,22 @@
|
|
|
package com.jiayue.ipfcst.console.service;
|
|
|
+import com.jiayue.ipfcst.common.core.exception.BusinessException;
|
|
|
+import com.jiayue.ipfcst.common.data.entity.ElectricField;
|
|
|
import com.jiayue.ipfcst.common.data.entity.PowerStationStatusData;
|
|
|
+import com.jiayue.ipfcst.common.data.entity.SysParameter;
|
|
|
import com.jiayue.ipfcst.common.data.repository.PowerStationStatusDataRepository;
|
|
|
+import com.jiayue.ipfcst.common.data.repository.SysParameterRepository;
|
|
|
import com.jiayue.ipfcst.common.data.service.BaseService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
@@ -19,12 +29,284 @@ import java.util.stream.Collectors;
|
|
|
public class PowerStationStatusDataService extends BaseService {
|
|
|
|
|
|
private final PowerStationStatusDataRepository powerStationStatusDataRepository;
|
|
|
+ private final SysParameterRepository sysParameterRepository;
|
|
|
|
|
|
@Autowired
|
|
|
- public PowerStationStatusDataService(PowerStationStatusDataRepository powerStationStatusDataRepository) {
|
|
|
+ public PowerStationStatusDataService(PowerStationStatusDataRepository powerStationStatusDataRepository, SysParameterRepository sysParameterRepository) {
|
|
|
this.powerStationStatusDataRepository = powerStationStatusDataRepository;
|
|
|
+ this.sysParameterRepository = sysParameterRepository;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 分页查询 场站功率状态 yh
|
|
|
+ *
|
|
|
+ * @param startTime 开始时间
|
|
|
+ * @param endTime 结束时间
|
|
|
+ * @param page 页码
|
|
|
+ * @param size 条数
|
|
|
+ * @param stationCode 场站编号
|
|
|
+ * @param sortOrder 排序
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
|
|
|
+ public Map<String, Object> findByTimeBetweenForPaging(Date startTime, Date endTime,
|
|
|
+ Integer page, Integer size,String stationCode,
|
|
|
+ String sortOrder) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ Sort sort = Sort.by(Sort.Direction.ASC, "time");
|
|
|
+ if (sortOrder.contains("desc")) {
|
|
|
+ sort = Sort.by(Sort.Direction.DESC, "time");
|
|
|
+ }
|
|
|
+ Specification<PowerStationStatusData> specification = this.Specification(startTime, endTime,stationCode);
|
|
|
+ Pageable pageable = PageRequest.of(page - 1, size, sort);
|
|
|
+ Page powerStationStatusData = powerStationStatusDataRepository.findAll(specification, pageable);
|
|
|
+ List<PowerStationStatusData> datas = new ArrayList<>();
|
|
|
+ datas = powerStationStatusData.getContent();
|
|
|
+ this.defaultReplace(datas);
|
|
|
+ List<Map<String, Object>> list = new ArrayList<>();
|
|
|
+ for (PowerStationStatusData powerStationStatusData1 : datas) {
|
|
|
+
|
|
|
+ Map<String, Object> map1 = new HashMap<>();
|
|
|
+
|
|
|
+ map1.put("time", powerStationStatusData1.getTime());
|
|
|
+ map1.put("ableValue", powerStationStatusData1.getAbleValue());
|
|
|
+ map1.put("theoryValue", powerStationStatusData1.getTheoryValue());
|
|
|
+ map1.put("realValue", powerStationStatusData1.getRealValue());
|
|
|
+ map1.put("referencePowerByMeasuring", powerStationStatusData1.getReferencePowerByMeasuring());
|
|
|
+ map1.put("referencePowerBySample", powerStationStatusData1.getReferencePowerBySample());
|
|
|
+ map1.put("openCapacity", powerStationStatusData1.getOpenCapacity());
|
|
|
+ map1.put("capacity", powerStationStatusData1.getCapacity());
|
|
|
+ map1.put("onGridNum", powerStationStatusData1.getOnGridNum());
|
|
|
+ map1.put("onSiteObstructed", powerStationStatusData1.getOnSiteObstructed());
|
|
|
+ map1.put("offSiteObstructed", powerStationStatusData1.getOffSiteObstructed());
|
|
|
+ map1.put("abnormalOfMeasuring", powerStationStatusData1.getAbnormalOfMeasuring());
|
|
|
+ map1.put("abnormalOfSample", powerStationStatusData1.getAbnormalOfSample());
|
|
|
+ map1.put("isRationingByManualControl", powerStationStatusData1.getIsRationingByManualControl());
|
|
|
+ map1.put("isRationingByAutoControl", powerStationStatusData1.getIsRationingByAutoControl());
|
|
|
+ map1.put("ablePowerByMeasuring", powerStationStatusData1.getAblePowerByMeasuring());
|
|
|
+ map1.put("ablePowerBySample", powerStationStatusData1.getAblePowerBySample());
|
|
|
+ if (powerStationStatusData1.getRealValue() != null && powerStationStatusData1.getRealValue().floatValue() != 0) {
|
|
|
+ BigDecimal b = powerStationStatusData1.getAbleValue().subtract(powerStationStatusData1.getRealValue());
|
|
|
+ map1.put("abandonmentRates", b.divide(powerStationStatusData1.getRealValue(), 2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ } else {
|
|
|
+ map1.put("abandonmentRates", 0);
|
|
|
+ }
|
|
|
+ list.add(map1);
|
|
|
+ }
|
|
|
+
|
|
|
+ map.put("content", list);
|
|
|
+ map.put("count", powerStationStatusData.getTotalElements());
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 查询条件 yh
|
|
|
+ *
|
|
|
+ * @param startTime 开始时间
|
|
|
+ * @param endTime 结束时间
|
|
|
+ * @return 过滤条件
|
|
|
+ */
|
|
|
+ Specification<PowerStationStatusData> Specification(final Date startTime, final Date endTime,final String stationCode) {
|
|
|
+ return (Specification<PowerStationStatusData>) (root, criteriaQuery, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ predicates.add(cb.equal(root.get("stationCode").as(String.class),stationCode));
|
|
|
+ if (startTime != null) {
|
|
|
+ //大于或等于传入时间
|
|
|
+ predicates.add(cb.greaterThanOrEqualTo(root.get("time").as(Date.class), startTime));
|
|
|
+ }
|
|
|
+ if (endTime != null) {
|
|
|
+ //小于传入时间
|
|
|
+ predicates.add(cb.lessThan(root.get("time").as(Date.class), endTime));
|
|
|
+ }
|
|
|
+ //添加排序的功能
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+
|
|
|
+ };
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 根据开始时间和结束时间查询 场站功率状态 yh
|
|
|
+ *
|
|
|
+ * @param startTime 开始时间
|
|
|
+ * @param endTime 结束时间
|
|
|
+ * @return 结果集
|
|
|
+ */
|
|
|
+ @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
|
|
|
+ public Map<String, Object> findByTimeBetweenAndStationCode(Date startTime, Date endTime,String stationCode){
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ ElectricField electricField = null;
|
|
|
+ try {
|
|
|
+ electricField = super.getSingleStation(stationCode);
|
|
|
+ } catch (BusinessException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ map.put("cap", electricField.getCapacity());
|
|
|
+ List<PowerStationStatusData> list = new ArrayList<>();
|
|
|
+ List<PowerStationStatusData> checkList = new ArrayList<>();
|
|
|
+ list = powerStationStatusDataRepository.findByTimeBetweenAndStationCode(startTime, endTime,stationCode);
|
|
|
+
|
|
|
+ long startTimeLong = startTime.getTime();
|
|
|
+ long endTimeLong = endTime.getTime();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ long timeStep = 300000L;
|
|
|
+ if (startTimeLong % timeStep != 0) {
|
|
|
+ startTimeLong = startTimeLong - (startTimeLong % timeStep) + timeStep;
|
|
|
+ }
|
|
|
+ List<Float> realValueDatas = new ArrayList<>();
|
|
|
+ List<Float> ableValueDatas = new ArrayList<>();
|
|
|
+ List<Float> theoryValueDatas = new ArrayList<>();
|
|
|
+ List<Float> referencePowerByMeasuringDatas = new ArrayList<>();
|
|
|
+ List<Float> referencePowerBySampleDatas = new ArrayList<>();
|
|
|
+ List<Float> ablePowerByMeasuringDatas = new ArrayList<>();
|
|
|
+ List<Float> ablePowerBySampleDatas = new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+ List<String> times = new ArrayList<>();
|
|
|
+
|
|
|
+ for (long i = startTimeLong; i < endTimeLong; i = i + 300000) {
|
|
|
+ long finalI = i;
|
|
|
+ List<PowerStationStatusData> p = list.stream().filter(t -> t.getTime().getTime() == finalI).collect(Collectors.toList());
|
|
|
+ if (p != null && p.size() > 0) {
|
|
|
+ checkList.add(p.get(0));
|
|
|
+ } else {
|
|
|
+ checkList.add(new PowerStationStatusData());
|
|
|
+ }
|
|
|
+ String timeFormat = sdf.format(new Date(i));
|
|
|
+ times.add(timeFormat);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<BigDecimal> realValues = checkList.stream().map(PowerStationStatusData::getRealValue).collect(Collectors.toList());
|
|
|
+
|
|
|
+ BigDecimal nullValue = new BigDecimal(-99);
|
|
|
+ for (BigDecimal b : realValues) {
|
|
|
+ if (b.compareTo(nullValue) == 0) {
|
|
|
+ realValueDatas.add(null);
|
|
|
+ } else {
|
|
|
+ realValueDatas.add(b.floatValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String displayKyLl = "0";
|
|
|
+ SysParameter sysParameter = sysParameterRepository.findBySysKeyEquals("DISPLAY_KY_LL");
|
|
|
+
|
|
|
+ if (sysParameter != null && sysParameter.getSysValue().equals("1")) {
|
|
|
+ displayKyLl = "1";
|
|
|
+
|
|
|
+ List<BigDecimal> ableValue = checkList.stream().map(PowerStationStatusData::getAbleValue).collect(Collectors.toList());
|
|
|
+ List<BigDecimal> theoryValue = checkList.stream().map(PowerStationStatusData::getTheoryValue).collect(Collectors.toList());
|
|
|
+ List<BigDecimal> referencePowerByMeasuring = checkList.stream().map(PowerStationStatusData::getReferencePowerByMeasuring).collect(Collectors.toList());
|
|
|
+ List<BigDecimal> referencePowerBySample = checkList.stream().map(PowerStationStatusData::getReferencePowerBySample).collect(Collectors.toList());
|
|
|
+ for (BigDecimal b : ableValue) {
|
|
|
+ if (b.compareTo(nullValue) == 0) {
|
|
|
+ ableValueDatas.add(null);
|
|
|
+ } else {
|
|
|
+ ableValueDatas.add(b.floatValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (BigDecimal b : theoryValue) {
|
|
|
+ if (b.compareTo(nullValue) == 0) {
|
|
|
+ theoryValueDatas.add(null);
|
|
|
+ } else {
|
|
|
+ theoryValueDatas.add(b.floatValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (BigDecimal b : referencePowerByMeasuring) {
|
|
|
+ if (b.compareTo(nullValue) == 0) {
|
|
|
+ referencePowerByMeasuringDatas.add(null);
|
|
|
+ } else {
|
|
|
+ referencePowerByMeasuringDatas.add(b.floatValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (BigDecimal b : referencePowerBySample) {
|
|
|
+ if (b.compareTo(nullValue) == 0) {
|
|
|
+ referencePowerBySampleDatas.add(null);
|
|
|
+ } else {
|
|
|
+ referencePowerBySampleDatas.add(b.floatValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<BigDecimal> ablePowerByMeasuring = checkList.stream().map(PowerStationStatusData::getAblePowerByMeasuring).collect(Collectors.toList());
|
|
|
+ List<BigDecimal> ablePowerBySample = checkList.stream().map(PowerStationStatusData::getAblePowerBySample).collect(Collectors.toList());
|
|
|
+
|
|
|
+ for (BigDecimal b : ablePowerByMeasuring) {
|
|
|
+ if (b == null || b.compareTo(nullValue) == 0) {
|
|
|
+ ablePowerByMeasuringDatas.add(null);
|
|
|
+ } else {
|
|
|
+ ablePowerByMeasuringDatas.add(b.floatValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (BigDecimal b : ablePowerBySample) {
|
|
|
+ if (b == null || b.compareTo(nullValue) == 0) {
|
|
|
+ ablePowerBySampleDatas.add(null);
|
|
|
+ } else {
|
|
|
+ ablePowerBySampleDatas.add(b.floatValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put("ablePowerByMeasuringDatas", ablePowerByMeasuringDatas);
|
|
|
+ map.put("ablePowerBySampleDatas", ablePowerBySampleDatas);
|
|
|
+
|
|
|
+ map.put("ableValueDatas", ableValueDatas);
|
|
|
+ map.put("theoryValueDatas", theoryValueDatas);
|
|
|
+ map.put("referencePowerByMeasuringDatas", referencePowerByMeasuringDatas);
|
|
|
+ map.put("referencePowerBySampleDatas", referencePowerBySampleDatas);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ String displaySz = "0";
|
|
|
+ SysParameter sysParameter2 = sysParameterRepository.findBySysKeyEquals("DISPLAY_SZ");
|
|
|
+
|
|
|
+ if (sysParameter2 != null && sysParameter2.getSysValue().equals("1")) {
|
|
|
+ displaySz = "1";
|
|
|
+ }
|
|
|
+
|
|
|
+ String abnormalShow = "0";
|
|
|
+ SysParameter abnormal_show = sysParameterRepository.findBySysKeyEquals("abnormal_show");
|
|
|
+
|
|
|
+ if (abnormal_show != null && abnormal_show.getSysValue().equals("1")) {
|
|
|
+ abnormalShow = "1";
|
|
|
+ }
|
|
|
+
|
|
|
+ map.put("times", times);
|
|
|
+ map.put("realValueDatas", realValueDatas);
|
|
|
+ map.put("displayKyLl", displayKyLl);
|
|
|
+ map.put("displaySz", displaySz);
|
|
|
+
|
|
|
+ map.put("abnormalShow", abnormalShow);
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 根据开始时间和结束时间查询 场站功率状态
|
|
@@ -37,7 +319,7 @@ public class PowerStationStatusDataService extends BaseService {
|
|
|
@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 ;
|
|
|
+ List<PowerStationStatusData> list = new ArrayList<>();
|
|
|
|
|
|
list = powerStationStatusDataRepository.findByTimeBetween(startTime, endTime);
|
|
|
|
|
@@ -114,85 +396,5 @@ public class PowerStationStatusDataService extends BaseService {
|
|
|
|
|
|
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);
|
|
|
-
|
|
|
- }
|
|
|
- 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;
|
|
|
- }
|
|
|
}
|
|
|
|