|
|
@@ -1,6 +1,7 @@
|
|
|
package com.hdkj.lt.bf.scheduler;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.hdkj.lt.bf.entity.FhzgSeCapacityDaily;
|
|
|
import com.hdkj.lt.bf.entity.FhzgSeCurrentEvent;
|
|
|
import com.hdkj.lt.bf.entity.FhzgSeSnapshotDetail;
|
|
|
@@ -49,60 +50,78 @@ public class SeCapacityDailyScheduler {
|
|
|
LocalDateTime startTime = date.atStartOfDay();
|
|
|
LocalDateTime endTime = date.atTime(23, 59, 59);
|
|
|
|
|
|
- // 查当天所有馈线断面(负载率)
|
|
|
- LambdaQueryWrapper<FhzgSeSnapshotDetail> wrapper = new LambdaQueryWrapper<FhzgSeSnapshotDetail>()
|
|
|
- .eq(FhzgSeSnapshotDetail::getDeviceType, "feeder")
|
|
|
- .isNotNull(FhzgSeSnapshotDetail::getLoadRate)
|
|
|
- .ge(FhzgSeSnapshotDetail::getSnapshotTime, startTime)
|
|
|
- .le(FhzgSeSnapshotDetail::getSnapshotTime, endTime);
|
|
|
-
|
|
|
- List<FhzgSeSnapshotDetail> snapshots = snapshotDetailMapper.selectList(wrapper);
|
|
|
-
|
|
|
- // 查当天重过载事件(事件数,口径与 fhzg_se_current_event 一致)
|
|
|
- LambdaQueryWrapper<FhzgSeCurrentEvent> eventWrapper = new LambdaQueryWrapper<FhzgSeCurrentEvent>()
|
|
|
- .ge(FhzgSeCurrentEvent::getFirstOverTime, startTime)
|
|
|
- .lt(FhzgSeCurrentEvent::getFirstOverTime, date.plusDays(1).atStartOfDay())
|
|
|
- .in(FhzgSeCurrentEvent::getAlarmType, "current_heavy", "current_overload");
|
|
|
- List<FhzgSeCurrentEvent> events = currentEventMapper.selectList(eventWrapper);
|
|
|
-
|
|
|
- if (snapshots.isEmpty() && events.isEmpty()) {
|
|
|
+ // 断面按馈线 SQL 聚合
|
|
|
+ QueryWrapper<FhzgSeSnapshotDetail> wrapper = new QueryWrapper<FhzgSeSnapshotDetail>()
|
|
|
+ .select("feeder_id",
|
|
|
+ "MAX(county_id) AS county_id",
|
|
|
+ "MAX(subs_id) AS subs_id",
|
|
|
+ "MAX(feeder_name) AS feeder_name",
|
|
|
+ "MAX(load_rate) AS max_load_rate",
|
|
|
+ "COALESCE(SUM(load_rate), 0) AS sum_load_rate",
|
|
|
+ "COUNT(load_rate) AS cnt")
|
|
|
+ .eq("device_type", "feeder")
|
|
|
+ .isNotNull("load_rate")
|
|
|
+ .ge("snapshot_time", startTime)
|
|
|
+ .le("snapshot_time", endTime)
|
|
|
+ .isNotNull("feeder_id")
|
|
|
+ .groupBy("feeder_id");
|
|
|
+
|
|
|
+ List<Map<String, Object>> snapshotRows = snapshotDetailMapper.selectMaps(wrapper);
|
|
|
+
|
|
|
+ // 重过载事件按馈线 SQL 聚合(事件数,口径与 fhzg_se_current_event 一致)
|
|
|
+ QueryWrapper<FhzgSeCurrentEvent> eventWrapper = new QueryWrapper<FhzgSeCurrentEvent>()
|
|
|
+ .select("feeder_id",
|
|
|
+ "MAX(county_id) AS county_id",
|
|
|
+ "MAX(subs_id) AS subs_id",
|
|
|
+ "MAX(feeder_name) AS feeder_name",
|
|
|
+ "COALESCE(SUM(CASE WHEN alarm_type = 'current_heavy' THEN 1 ELSE 0 END), 0) AS heavy",
|
|
|
+ "COALESCE(SUM(CASE WHEN alarm_type = 'current_overload' THEN 1 ELSE 0 END), 0) AS overload")
|
|
|
+ .ge("first_over_time", startTime)
|
|
|
+ .lt("first_over_time", date.plusDays(1).atStartOfDay())
|
|
|
+ .in("alarm_type", "current_heavy", "current_overload")
|
|
|
+ .isNotNull("feeder_id")
|
|
|
+ .groupBy("feeder_id");
|
|
|
+
|
|
|
+ List<Map<String, Object>> eventRows = currentEventMapper.selectMaps(eventWrapper);
|
|
|
+
|
|
|
+ if ((snapshotRows == null || snapshotRows.isEmpty()) && (eventRows == null || eventRows.isEmpty())) {
|
|
|
log.info("[供电能力日汇总] {} 无断面/事件数据,跳过", date);
|
|
|
return date + " 无断面/事件数据";
|
|
|
}
|
|
|
|
|
|
- // 按馈线分组聚合
|
|
|
+ // 按馈线分组聚合(断面维度)
|
|
|
Map<String, DailyAccumulator> accumulatorMap = new HashMap<>();
|
|
|
- for (FhzgSeSnapshotDetail s : snapshots) {
|
|
|
- String feederId = s.getFeederId();
|
|
|
- if (feederId == null) continue;
|
|
|
-
|
|
|
- DailyAccumulator acc = accumulatorMap.computeIfAbsent(feederId, k -> new DailyAccumulator());
|
|
|
- acc.countyId = s.getCountyId();
|
|
|
- acc.subsId = s.getSubsId();
|
|
|
- if (acc.feederName == null) acc.feederName = s.getFeederName();
|
|
|
-
|
|
|
- BigDecimal loadRate = s.getLoadRate();
|
|
|
- if (loadRate != null) {
|
|
|
- if (loadRate.compareTo(acc.maxLoadRate) > 0) {
|
|
|
- acc.maxLoadRate = loadRate;
|
|
|
- }
|
|
|
- acc.sumLoadRate = acc.sumLoadRate.add(loadRate);
|
|
|
- acc.totalSnapshots++;
|
|
|
+ if (snapshotRows != null) {
|
|
|
+ for (Map<String, Object> row : snapshotRows) {
|
|
|
+ String feederId = (String) row.get("feeder_id");
|
|
|
+ if (feederId == null) continue;
|
|
|
+
|
|
|
+ DailyAccumulator acc = new DailyAccumulator();
|
|
|
+ acc.countyId = (String) row.get("county_id");
|
|
|
+ acc.subsId = (String) row.get("subs_id");
|
|
|
+ acc.feederName = (String) row.get("feeder_name");
|
|
|
+ BigDecimal maxLoadRate = (BigDecimal) row.get("max_load_rate");
|
|
|
+ if (maxLoadRate != null) acc.maxLoadRate = maxLoadRate;
|
|
|
+ acc.sumLoadRate = (BigDecimal) row.get("sum_load_rate");
|
|
|
+ acc.totalSnapshots = ((Number) row.get("cnt")).intValue();
|
|
|
+ accumulatorMap.put(feederId, acc);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 事件数按馈线累加(同一条馈线当日多个事件算多次)
|
|
|
- for (FhzgSeCurrentEvent e : events) {
|
|
|
- String feederId = e.getFeederId();
|
|
|
- if (feederId == null) continue;
|
|
|
-
|
|
|
- DailyAccumulator acc = accumulatorMap.computeIfAbsent(feederId, k -> new DailyAccumulator());
|
|
|
- if (acc.countyId == null) acc.countyId = e.getCountyId();
|
|
|
- if (acc.subsId == null) acc.subsId = e.getSubsId();
|
|
|
- if (acc.feederName == null) acc.feederName = e.getFeederName();
|
|
|
-
|
|
|
- if ("current_heavy".equals(e.getAlarmType())) acc.heavyCount++;
|
|
|
- else if ("current_overload".equals(e.getAlarmType())) acc.overloadCount++;
|
|
|
+ if (eventRows != null) {
|
|
|
+ for (Map<String, Object> row : eventRows) {
|
|
|
+ String feederId = (String) row.get("feeder_id");
|
|
|
+ if (feederId == null) continue;
|
|
|
+
|
|
|
+ DailyAccumulator acc = accumulatorMap.computeIfAbsent(feederId, k -> new DailyAccumulator());
|
|
|
+ if (acc.countyId == null) acc.countyId = (String) row.get("county_id");
|
|
|
+ if (acc.subsId == null) acc.subsId = (String) row.get("subs_id");
|
|
|
+ if (acc.feederName == null) acc.feederName = (String) row.get("feeder_name");
|
|
|
+
|
|
|
+ acc.heavyCount += ((Number) row.get("heavy")).intValue();
|
|
|
+ acc.overloadCount += ((Number) row.get("overload")).intValue();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 先删当天已有数据(避免重复运行时叠加)
|