| | |
| | | public class EmindStorageDashboardController { |
| | | private final EmindStorageDashboardService service; |
| | | public EmindStorageDashboardController(EmindStorageDashboardService service) { this.service=service; } |
| | | @GetMapping("/stations") public R<List<Map<String,Object>>> stations() { return R.ok(service.stations()); } |
| | | @GetMapping("/stations") public R<List<Map<String,Object>>> stations(@RequestParam(required = false) List<String> platformNames) { return R.ok(service.stations(platformNames)); } |
| | | @PostMapping("/overview") public R<Map<String,Object>> overview(@RequestBody EmindDashboardQuery query) { return R.ok(service.overview(query)); } |
| | | } |
| | |
| | | |
| | | import lombok.Data; |
| | | import java.time.LocalDate; |
| | | import java.util.List; |
| | | |
| | | @Data |
| | | public class EmindDashboardQuery { |
| | | private Long stationId; |
| | | private List<String> platformNames; |
| | | private String period; |
| | | private LocalDate startDate; |
| | | private LocalDate endDate; |
| | |
| | | @Param("syncedAt") LocalDateTime syncedAt); |
| | | int upsertDaily(@Param("stationId") Long stationId, @Param("rows") List<EmindIncomeHistoryDto> rows, |
| | | @Param("syncedAt") LocalDateTime syncedAt); |
| | | List<Map<String, Object>> selectStations(); |
| | | List<Map<String, Object>> selectSnapshotRows(@Param("stationId") Long stationId); |
| | | List<Map<String, Object>> selectStations(@Param("platformNames") List<String> platformNames); |
| | | List<Map<String, Object>> selectSnapshotRows(@Param("stationId") Long stationId, @Param("platformNames") List<String> platformNames); |
| | | List<Map<String, Object>> selectDailyRows(@Param("stationId") Long stationId, |
| | | @Param("platformNames") List<String> platformNames, |
| | | @Param("startDate") LocalDate startDate, |
| | | @Param("endDate") LocalDate endDate); |
| | | List<Map<String, Object>> selectCurveRows(@Param("stationId") Long stationId); |
| | | List<Map<String, Object>> selectEnergyBlockRows(@Param("stationId") Long stationId); |
| | | List<Map<String, Object>> selectCurveRows(@Param("stationId") Long stationId, @Param("platformNames") List<String> platformNames); |
| | | List<Map<String, Object>> selectEnergyBlockRows(@Param("stationId") Long stationId, @Param("platformNames") List<String> platformNames); |
| | | } |
| | |
| | | |
| | | public EmindStorageDashboardService(EmindStorageDashboardMapper mapper) { this.mapper = mapper; } |
| | | |
| | | public List<Map<String, Object>> stations() { return mapper.selectStations(); } |
| | | public List<Map<String, Object>> stations(List<String> platformNames) { return mapper.selectStations(platformNames); } |
| | | |
| | | public Map<String, Object> overview(EmindDashboardQuery query) { |
| | | LocalDate end = query.getEndDate() == null ? LocalDate.now().minusDays(1) : query.getEndDate(); |
| | |
| | | LocalDate start = query.getStartDate(); |
| | | if (start == null) start = "YEAR".equals(period) ? end.withDayOfYear(1) |
| | | : ("MONTH".equals(period) ? end.withDayOfMonth(1) : end.minusDays(6)); |
| | | List<Map<String, Object>> dailyRows = mapper.selectDailyRows(query.getStationId(), start, end); |
| | | List<Map<String, Object>> dailyRows = mapper.selectDailyRows(query.getStationId(), query.getPlatformNames(), start, end); |
| | | LocalDate yesterday = LocalDate.now().minusDays(1); |
| | | List<Map<String, Object>> yesterdayRows = start.equals(yesterday) && end.equals(yesterday) |
| | | ? dailyRows : mapper.selectDailyRows(query.getStationId(), yesterday, yesterday); |
| | | ? dailyRows : mapper.selectDailyRows(query.getStationId(), query.getPlatformNames(), yesterday, yesterday); |
| | | Map<String, Object> result = new LinkedHashMap<>(); |
| | | result.put("summary", summarize(mapper.selectSnapshotRows(query.getStationId()), yesterdayRows, yesterday, |
| | | mapper.selectEnergyBlockRows(query.getStationId()))); |
| | | result.put("summary", summarize(mapper.selectSnapshotRows(query.getStationId(), query.getPlatformNames()), yesterdayRows, yesterday, |
| | | mapper.selectEnergyBlockRows(query.getStationId(), query.getPlatformNames()))); |
| | | result.put("history", completeHistory(dailyRows, period, start, end)); |
| | | result.put("curve", summarizeCurve(mapper.selectCurveRows(query.getStationId()))); |
| | | result.put("curve", summarizeCurve(mapper.selectCurveRows(query.getStationId(), query.getPlatformNames()))); |
| | | return result; |
| | | } |
| | | |
| | |
| | | </insert> |
| | | <select id="selectStations" resultType="map"> |
| | | SELECT station_id stationId, station_name stationName, platform_name platformName |
| | | FROM t_emind_dashboard_snapshot ORDER BY station_name |
| | | FROM t_emind_dashboard_snapshot WHERE 1=1 |
| | | <if test="platformNames != null and platformNames.size() > 0">AND platform_name IN <foreach collection="platformNames" item="name" open="(" separator="," close=")">#{name}</foreach></if> |
| | | ORDER BY station_name |
| | | </select> |
| | | <select id="selectSnapshotRows" resultType="map"> |
| | | SELECT income_sum incomeSum, charged_energy_sum chargedEnergySum, |
| | |
| | | elink_online elinkOnline, synced_at syncedAt |
| | | FROM t_emind_dashboard_snapshot WHERE 1=1 |
| | | <if test="stationId != null">AND station_id=#{stationId}</if> |
| | | <if test="platformNames != null and platformNames.size() > 0">AND platform_name IN <foreach collection="platformNames" item="name" open="(" separator="," close=")">#{name}</foreach></if> |
| | | </select> |
| | | <select id="selectDailyRows" resultType="map"> |
| | | SELECT stat_date statDate, income, charged_energy chargedEnergy, discharged_energy dischargedEnergy |
| | | FROM t_emind_dashboard_daily WHERE stat_date BETWEEN #{startDate} AND #{endDate} |
| | | <if test="stationId != null">AND station_id=#{stationId}</if> |
| | | ORDER BY stat_date |
| | | SELECT daily.stat_date statDate, daily.income, daily.charged_energy chargedEnergy, daily.discharged_energy dischargedEnergy |
| | | FROM t_emind_dashboard_daily daily INNER JOIN t_emind_dashboard_snapshot snapshot ON snapshot.station_id=daily.station_id |
| | | WHERE daily.stat_date BETWEEN #{startDate} AND #{endDate} |
| | | <if test="stationId != null">AND daily.station_id=#{stationId}</if> |
| | | <if test="platformNames != null and platformNames.size() > 0">AND snapshot.platform_name IN <foreach collection="platformNames" item="name" open="(" separator="," close=")">#{name}</foreach></if> |
| | | ORDER BY daily.stat_date |
| | | </select> |
| | | <select id="selectCurveRows" resultType="map"> |
| | | SELECT record_time recordTime, power, soc FROM t_emind_dashboard_curve WHERE 1=1 |
| | | <if test="stationId != null">AND station_id=#{stationId}</if> |
| | | ORDER BY record_time |
| | | SELECT curve.record_time recordTime, curve.power, curve.soc FROM t_emind_dashboard_curve curve INNER JOIN t_emind_dashboard_snapshot snapshot ON snapshot.station_id=curve.station_id WHERE 1=1 |
| | | <if test="stationId != null">AND curve.station_id=#{stationId}</if> |
| | | <if test="platformNames != null and platformNames.size() > 0">AND snapshot.platform_name IN <foreach collection="platformNames" item="name" open="(" separator="," close=")">#{name}</foreach></if> |
| | | ORDER BY curve.record_time |
| | | </select> |
| | | <select id="selectEnergyBlockRows" resultType="map"> |
| | | SELECT run_status runStatus, record_time recordTime FROM t_emind_energy_block WHERE del_flag=0 |
| | | <if test="stationId != null">AND station_id=#{stationId}</if> |
| | | SELECT block.run_status runStatus, block.record_time recordTime FROM t_emind_energy_block block INNER JOIN t_emind_dashboard_snapshot snapshot ON snapshot.station_id=block.station_id WHERE block.del_flag=0 |
| | | <if test="stationId != null">AND block.station_id=#{stationId}</if> |
| | | <if test="platformNames != null and platformNames.size() > 0">AND snapshot.platform_name IN <foreach collection="platformNames" item="name" open="(" separator="," close=")">#{name}</foreach></if> |
| | | </select> |
| | | </mapper> |