|
|
@@ -39,13 +39,10 @@ import java.time.LocalTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.time.format.DateTimeParseException;
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.HashSet;
|
|
|
-import java.util.LinkedHashMap;
|
|
|
-import java.util.LinkedHashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
@@ -225,22 +222,19 @@ public class VppDrMonitorServiceImpl implements VppDrMonitorService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public DrMonitorCurveVO getCurve(List<Long> siteIds, Integer baselineDays) {
|
|
|
- requireSiteIds(siteIds);
|
|
|
+ public DrMonitorCurveVO getCurve(Long siteId, Integer baselineDays) {
|
|
|
+ if (siteId == null) {
|
|
|
+ throw new BusinessException("站点ID不能为空");
|
|
|
+ }
|
|
|
if (baselineDays != null && baselineDays != 3 && baselineDays != 5) {
|
|
|
throw new BusinessException("基线负荷仅支持3天或5天维度查询!");
|
|
|
}
|
|
|
Integer tenantId = SecurityUtils.getTenantId();
|
|
|
- List<VppResourcePoint> peakResources = listPeakResources(siteIds, tenantId);
|
|
|
+ List<VppResourcePoint> peakResources = listPeakResources(siteId, tenantId);
|
|
|
if (peakResources.isEmpty()) {
|
|
|
throw new BusinessException("所选站点下无可参与调峰的资源点!");
|
|
|
}
|
|
|
int resourceCount = peakResources.size();
|
|
|
- Map<Long, Long> siteResourceCount = new HashMap<>();
|
|
|
- for (VppResourcePoint resource : peakResources) {
|
|
|
- siteResourceCount.merge(resource.getSiteId(), 1L, Long::sum);
|
|
|
- }
|
|
|
- Set<Long> peakSiteIds = siteResourceCount.keySet();
|
|
|
|
|
|
LocalDate today = LocalDate.now();
|
|
|
LocalDateTime windowStart = today.atStartOfDay();
|
|
|
@@ -250,59 +244,32 @@ public class VppDrMonitorServiceImpl implements VppDrMonitorService {
|
|
|
String actualEndTime = windowEnd.format(DATE_TIME_FMT);
|
|
|
int requiredDays = (baselineDays != null && baselineDays == 3) ? 3 : 5;
|
|
|
|
|
|
- BigDecimal actualSum = BigDecimal.ZERO;
|
|
|
- for (Long siteId : peakSiteIds) {
|
|
|
- actualSum = actualSum.add(resolveSiteActualResponseKw(
|
|
|
- siteId, responseStartTime, responseEndTime, BigDecimal.ZERO));
|
|
|
- }
|
|
|
- BigDecimal actualAvg = avg(actualSum, resourceCount);
|
|
|
-
|
|
|
- Map<String, BigDecimal> baselineWeighted = new LinkedHashMap<>();
|
|
|
- Set<String> dataSources = new LinkedHashSet<>();
|
|
|
- List<Long> usedSiteIds = new ArrayList<>();
|
|
|
+ BigDecimal actualAvg = avg(resolveSiteActualResponseKw(
|
|
|
+ siteId, responseStartTime, responseEndTime, BigDecimal.ZERO), resourceCount);
|
|
|
|
|
|
- for (Map.Entry<Long, Long> entry : siteResourceCount.entrySet()) {
|
|
|
- Long siteId = entry.getKey();
|
|
|
- BigDecimal weight = BigDecimal.valueOf(entry.getValue());
|
|
|
- SiteBaselineVO baseline = baselineService.getSiteBaseline(siteId, responseStartTime, requiredDays, actualEndTime);
|
|
|
- if (baseline == null || CollectionUtils.isEmpty(baseline.getPoints())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- usedSiteIds.add(siteId);
|
|
|
- if (StringUtils.hasText(baseline.getDataSource())) {
|
|
|
- dataSources.add(baseline.getDataSource());
|
|
|
- }
|
|
|
- for (BaselinePointVO point : baseline.getPoints()) {
|
|
|
- if (!StringUtils.hasText(point.getTime()) || !inCurveWindow(point.getTime(), windowStart, windowEnd)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- baselineWeighted.merge(point.getTime(),
|
|
|
- nz(point.getPredictedBaselineKw()).multiply(weight), BigDecimal::add);
|
|
|
- }
|
|
|
- }
|
|
|
+ SiteBaselineVO baseline = baselineService.getSiteBaseline(
|
|
|
+ siteId, responseStartTime, requiredDays, actualEndTime);
|
|
|
|
|
|
- BigDecimal divisor = BigDecimal.valueOf(resourceCount);
|
|
|
DrMonitorCurveVO curve = new DrMonitorCurveVO();
|
|
|
curve.setResponseDate(today.format(DATE_FMT));
|
|
|
- curve.setSiteIds(usedSiteIds);
|
|
|
+ curve.setSiteId(siteId);
|
|
|
curve.setActualResponseCapacityKw(actualAvg);
|
|
|
- if (dataSources.isEmpty()) {
|
|
|
- curve.setDataSource("mock");
|
|
|
- } else if (dataSources.size() == 1) {
|
|
|
- curve.setDataSource(dataSources.iterator().next());
|
|
|
- } else {
|
|
|
- curve.setDataSource("mixed");
|
|
|
- }
|
|
|
-
|
|
|
- List<String> times = new ArrayList<>(baselineWeighted.keySet());
|
|
|
- times.sort(Comparator.naturalOrder());
|
|
|
- for (String time : times) {
|
|
|
- DrMonitorCurveVO.Point point = new DrMonitorCurveVO.Point();
|
|
|
- point.setTime(time);
|
|
|
- point.setBaselineKw(baselineWeighted.getOrDefault(time, BigDecimal.ZERO)
|
|
|
- .divide(divisor, SCALE, RoundingMode.HALF_UP));
|
|
|
- point.setActualResponseCapacityKw(actualAvg);
|
|
|
- curve.getPoints().add(point);
|
|
|
+ if (baseline != null && StringUtils.hasText(baseline.getDataSource())) {
|
|
|
+ curve.setDataSource(baseline.getDataSource());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (baseline == null || CollectionUtils.isEmpty(baseline.getPoints())) {
|
|
|
+ return curve;
|
|
|
+ }
|
|
|
+ for (BaselinePointVO point : baseline.getPoints()) {
|
|
|
+ if (!StringUtils.hasText(point.getTime()) || !inCurveWindow(point.getTime(), windowStart, windowEnd)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ DrMonitorCurveVO.Point curvePoint = new DrMonitorCurveVO.Point();
|
|
|
+ curvePoint.setTime(point.getTime());
|
|
|
+ curvePoint.setBaselineKw(nz(point.getPredictedBaselineKw()).setScale(SCALE, RoundingMode.HALF_UP));
|
|
|
+ curvePoint.setActualResponseCapacityKw(actualAvg);
|
|
|
+ curve.getPoints().add(curvePoint);
|
|
|
}
|
|
|
return curve;
|
|
|
}
|
|
|
@@ -373,6 +340,14 @@ public class VppDrMonitorServiceImpl implements VppDrMonitorService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private List<VppResourcePoint> listPeakResources(Long siteId, Integer tenantId) {
|
|
|
+ return resourcePointMapper.selectList(new LambdaQueryWrapper<VppResourcePoint>()
|
|
|
+ .eq(VppResourcePoint::getDeleteFlag, VppAuditHelper.NOT_DELETED)
|
|
|
+ .eq(VppResourcePoint::getIsSupportPeak, SUPPORT_PEAK)
|
|
|
+ .eq(VppResourcePoint::getSiteId, siteId)
|
|
|
+ .eq(tenantId != null, VppResourcePoint::getTenantId, tenantId));
|
|
|
+ }
|
|
|
+
|
|
|
private List<VppResourcePoint> listPeakResources(List<Long> siteIds, Integer tenantId) {
|
|
|
return resourcePointMapper.selectList(new LambdaQueryWrapper<VppResourcePoint>()
|
|
|
.eq(VppResourcePoint::getDeleteFlag, VppAuditHelper.NOT_DELETED)
|