|
@@ -0,0 +1,626 @@
|
|
|
+package com.jiayue.ipfcst.service;
|
|
|
+
|
|
|
+import com.jiayue.ipfcst.common.data.entity.ElectricField;
|
|
|
+import com.jiayue.ipfcst.common.data.entity.PowerStationStatusData;
|
|
|
+import com.jiayue.ipfcst.common.data.entity.PowerStationStatusDataOne;
|
|
|
+import com.jiayue.ipfcst.common.data.entity.SysParameter;
|
|
|
+import com.jiayue.ipfcst.common.data.repository.PowerStationStatusDataOneRepository;
|
|
|
+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 com.jiayue.ipfcst.dto.TableColumn;
|
|
|
+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.lang.reflect.Method;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 场站功率状态业务层
|
|
|
+ *
|
|
|
+ * @author yh
|
|
|
+ * @version 1.0
|
|
|
+ * @since 2019/8/5 16:02
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class PowerStationStatusDataOneService extends BaseService {
|
|
|
+
|
|
|
+ private final PowerStationStatusDataOneRepository powerStationStatusDataOneRepository;
|
|
|
+
|
|
|
+ private final SysParameterRepository sysParameterRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public PowerStationStatusDataOneService(PowerStationStatusDataRepository powerStationStatusDataRepository, PowerStationStatusDataOneRepository powerStationStatusDataOneRepository, SysParameterRepository sysParameterRepository) {
|
|
|
+ this.powerStationStatusDataOneRepository = powerStationStatusDataOneRepository;
|
|
|
+ this.sysParameterRepository = sysParameterRepository;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据开始时间和结束时间查询 场站功率状态 yh
|
|
|
+ *
|
|
|
+ * @param startTime 开始时间
|
|
|
+ * @param endTime 结束时间
|
|
|
+ * @return 结果集
|
|
|
+ */
|
|
|
+ @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
|
|
|
+ public Map<String, Object> findByTimeBetween(Date startTime, Date endTime) throws Exception {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ ElectricField electricField = super.getElectricField();
|
|
|
+ map.put("cap", electricField.getCapacity());
|
|
|
+ List<PowerStationStatusDataOne> list = new ArrayList<>();
|
|
|
+ List<PowerStationStatusDataOne> checkList = new ArrayList<>();
|
|
|
+ list = powerStationStatusDataOneRepository.findByTimeBetween(startTime, endTime);
|
|
|
+
|
|
|
+ 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> referencePowerByHubSpeedDatas= new ArrayList<>();
|
|
|
+ List<Float> ablePowerByMeasuringDatas = new ArrayList<>();
|
|
|
+ List<Float> ablePowerBySampleDatas = new ArrayList<>();
|
|
|
+ List<Float> ablePowerByHubSpeedDatas = new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+ List<String> times = new ArrayList<>();
|
|
|
+
|
|
|
+ for (long i = startTimeLong; i < endTimeLong; i = i + 300000) {
|
|
|
+ long finalI = i;
|
|
|
+ List<PowerStationStatusDataOne> 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 PowerStationStatusDataOne());
|
|
|
+ }
|
|
|
+ String timeFormat = sdf.format(new Date(i));
|
|
|
+ times.add(timeFormat);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<BigDecimal> realValues = checkList.stream().map(PowerStationStatusDataOne::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 powerChartLine = super.getSysParameter("power_chart_line", "disable");
|
|
|
+
|
|
|
+ String hasChartLine = Boolean.FALSE.toString();
|
|
|
+
|
|
|
+ //数据形式严格遵守示例,示例:"备用字段1==data1,备用字段2==data2"
|
|
|
+ if(!powerChartLine.equals("disable")){
|
|
|
+ hasChartLine = Boolean.TRUE.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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(PowerStationStatusDataOne::getAbleValue).collect(Collectors.toList());
|
|
|
+ List<BigDecimal> theoryValue = checkList.stream().map(PowerStationStatusDataOne::getTheoryValue).collect(Collectors.toList());
|
|
|
+ List<BigDecimal> referencePowerByMeasuring = checkList.stream().map(PowerStationStatusDataOne::getReferencePowerByMeasuring).collect(Collectors.toList());
|
|
|
+ List<BigDecimal> referencePowerBySample = checkList.stream().map(PowerStationStatusDataOne::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(PowerStationStatusDataOne::getAblePowerByMeasuring).collect(Collectors.toList());
|
|
|
+ List<BigDecimal> ablePowerBySample = checkList.stream().map(PowerStationStatusDataOne::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);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (hasChartLine.equals(Boolean.TRUE.toString())){
|
|
|
+
|
|
|
+ String[] column = powerChartLine.split(",");
|
|
|
+
|
|
|
+ List<TableColumn> tableColumns = new ArrayList<>();
|
|
|
+ for (String c : column) {
|
|
|
+ String[] split = c.split("==");
|
|
|
+ TableColumn tableColumn = new TableColumn();
|
|
|
+ tableColumn.setTitle(split[0]);
|
|
|
+ tableColumn.setField(split[1]);
|
|
|
+ char[] chars = split[1].toCharArray();
|
|
|
+ chars[0] -= 32;
|
|
|
+ String s = new String(chars);
|
|
|
+ Method method = PowerStationStatusDataOne.class.getMethod("get" + s);
|
|
|
+ List<Float> bigDecimals = new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+ for (PowerStationStatusDataOne powerStationStatusDataOne : checkList) {
|
|
|
+ BigDecimal value = (BigDecimal) method.invoke(powerStationStatusDataOne);
|
|
|
+
|
|
|
+ if (value == null || value.compareTo(nullValue) == 0) {
|
|
|
+ bigDecimals.add(null);
|
|
|
+ } else {
|
|
|
+ bigDecimals.add(value.floatValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ map.put(split[1],bigDecimals);
|
|
|
+ tableColumns.add(tableColumn);
|
|
|
+ }
|
|
|
+ map.put("powerChartLine",tableColumns);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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";
|
|
|
+ }
|
|
|
+
|
|
|
+ String displayJt = "0";
|
|
|
+ SysParameter sysParameter1 = sysParameterRepository.findBySysKeyEquals("DISPLAY_JT");
|
|
|
+
|
|
|
+ if (sysParameter1 !=null && sysParameter1.getSysValue().equals("1")){
|
|
|
+ displayJt = "1";
|
|
|
+ List<BigDecimal> ableValue = checkList.stream().map(PowerStationStatusDataOne::getAbleValue).collect(Collectors.toList());
|
|
|
+ List<BigDecimal> theoryValue = checkList.stream().map(PowerStationStatusDataOne::getTheoryValue).collect(Collectors.toList());
|
|
|
+ List<BigDecimal> referencePowerByMeasuring = checkList.stream().map(PowerStationStatusDataOne::getReferencePowerByMeasuring).collect(Collectors.toList());
|
|
|
+ List<BigDecimal> referencePowerBySample = checkList.stream().map(PowerStationStatusDataOne::getReferencePowerBySample).collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<BigDecimal> referencePowerByHubSpeed = checkList.stream().map(PowerStationStatusDataOne::getReferencePowerByHubSpeed).collect(Collectors.toList());
|
|
|
+ List<BigDecimal> ablePowerByHugSpeed = checkList.stream().map(PowerStationStatusDataOne::getAblePowerByHubSpeed).collect(Collectors.toList());
|
|
|
+ for (BigDecimal b : referencePowerByHubSpeed) {
|
|
|
+ if (b.compareTo(nullValue) == 0) {
|
|
|
+ referencePowerByHubSpeedDatas.add(null);
|
|
|
+ } else {
|
|
|
+ referencePowerByHubSpeedDatas.add(b.floatValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (BigDecimal b : ablePowerByHugSpeed) {
|
|
|
+ if (b == null || b.compareTo(nullValue) == 0) {
|
|
|
+ ablePowerByHubSpeedDatas.add(null);
|
|
|
+ } else {
|
|
|
+ ablePowerByHubSpeedDatas.add(b.floatValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put("ablePowerByHubSpeedDatas", ablePowerByHubSpeedDatas);
|
|
|
+ map.put("referencePowerByHubSpeedDatas", referencePowerByHubSpeedDatas);
|
|
|
+
|
|
|
+ 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 hasTableColumn = Boolean.FALSE.toString();
|
|
|
+
|
|
|
+ String powerTableColumn = super.getSysParameter("power_table_column", "disable");
|
|
|
+
|
|
|
+
|
|
|
+ //数据形式严格遵守示例,示例:"备用字段1==data1,备用字段2==data2"
|
|
|
+ if(!powerTableColumn.equals("disable")){
|
|
|
+ hasTableColumn = Boolean.TRUE.toString();
|
|
|
+
|
|
|
+ String[] column = powerTableColumn.split(",");
|
|
|
+
|
|
|
+ List<TableColumn> tableColumns = new ArrayList<>();
|
|
|
+ for (String c : column) {
|
|
|
+ String[] split = c.split("==");
|
|
|
+ TableColumn tableColumn = new TableColumn();
|
|
|
+ tableColumn.setTitle(split[0]);
|
|
|
+ tableColumn.setField(split[1]);
|
|
|
+ tableColumns.add(tableColumn);
|
|
|
+ }
|
|
|
+ map.put("tableColumns",tableColumns);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ map.put("times", times);
|
|
|
+ map.put("realValueDatas", realValueDatas);
|
|
|
+ map.put("displayKyLl", displayKyLl);
|
|
|
+ map.put("displaySz", displaySz);
|
|
|
+ map.put("displayJt",displayJt);
|
|
|
+ map.put("hasTableColumn", hasTableColumn);
|
|
|
+ map.put("hasChartLine", hasChartLine);
|
|
|
+ map.put("abnormalShow", abnormalShow);
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询 场站功率状态 yh
|
|
|
+ *
|
|
|
+ * @param startTime 开始时间
|
|
|
+ * @param endTime 结束时间
|
|
|
+ * @param page 页码
|
|
|
+ * @param size 条数
|
|
|
+ * @param sortOrder 排序
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
|
|
|
+ public Map<String, Object> findByTimeBetweenForPaging(Date startTime, Date endTime,
|
|
|
+ Integer page, Integer size,
|
|
|
+ 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<PowerStationStatusDataOne> specification = this.Specification(startTime, endTime);
|
|
|
+ Pageable pageable = PageRequest.of(page - 1, size, sort);
|
|
|
+ Page powerStationStatusDataOne = powerStationStatusDataOneRepository.findAll(specification, pageable);
|
|
|
+ List<PowerStationStatusDataOne> datas = new ArrayList<>();
|
|
|
+ datas = powerStationStatusDataOne.getContent();
|
|
|
+ this.defaultReplace(datas);
|
|
|
+ List<Map<String, Object>> list = new ArrayList<>();
|
|
|
+ for (PowerStationStatusDataOne 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("referencePowerByHubSpeed", powerStationStatusData1.getReferencePowerByHubSpeed());
|
|
|
+ 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("abnormalOfHubSpeed", powerStationStatusData1.getAbnormalOfHubSpeed());
|
|
|
+ map1.put("isRationingByManualControl", powerStationStatusData1.getIsRationingByManualControl());
|
|
|
+ map1.put("isRationingByAutoControl", powerStationStatusData1.getIsRationingByAutoControl());
|
|
|
+ map1.put("ablePowerByMeasuring", powerStationStatusData1.getAblePowerByMeasuring());
|
|
|
+ map1.put("ablePowerBySample", powerStationStatusData1.getAblePowerBySample());
|
|
|
+ map1.put("ablePowerByHubSpeed", powerStationStatusData1.getAblePowerByHubSpeed());
|
|
|
+ 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", powerStationStatusDataOne.getTotalElements());
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询条件 yh
|
|
|
+ *
|
|
|
+ * @param startTime 开始时间
|
|
|
+ * @param endTime 结束时间
|
|
|
+ * @return 过滤条件
|
|
|
+ */
|
|
|
+ Specification<PowerStationStatusDataOne> Specification(final Date startTime, final Date endTime) {
|
|
|
+ return (Specification<PowerStationStatusDataOne>) (root, criteriaQuery, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ 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> findByTimeBetweenForContrast(Date startTime, Date endTime, Long timeStep) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ List<PowerStationStatusDataOne> list = new ArrayList<>();
|
|
|
+
|
|
|
+ list = powerStationStatusDataOneRepository.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<PowerStationStatusDataOne> 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<PowerStationStatusDataOne> datas) {
|
|
|
+ BigDecimal nullBig = new BigDecimal(-99);
|
|
|
+ for (PowerStationStatusDataOne 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<PowerStationStatusDataOne> powerStationStatusDataList = powerStationStatusDataOneRepository.findByTimeBetween(startTime, endTime);
|
|
|
+
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ for (PowerStationStatusDataOne 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<PowerStationStatusDataOne> findByTimeBetween(Long startTime, Long endTime) {
|
|
|
+ List<PowerStationStatusDataOne> powerStationStatusDataList = powerStationStatusDataOneRepository.findByTimeBetween(new Date(startTime), new Date(endTime));
|
|
|
+ Collections.sort(powerStationStatusDataList, Comparator.comparing(PowerStationStatusDataOne::getTime));
|
|
|
+ return powerStationStatusDataList;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|