longz
2026-08-04 2ec2505a3e5d6e474463c1610e83808beaec9f03
fix: use yesterday storage dashboard metrics
4个文件已修改
17 ■■■■■ 已修改文件
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/emind/mapper/EmindStorageDashboardMapper.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/emind/service/EmindStorageDashboardService.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/resources/mapper/other/EmindStorageDashboardMapper.xml 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/test/java/com/ruoyi/other/emind/service/EmindStorageDashboardServiceTest.java 1 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/emind/mapper/EmindStorageDashboardMapper.java
@@ -20,7 +20,7 @@
    int upsertDaily(@Param("stationId") Long stationId, @Param("rows") List<EmindIncomeHistoryDto> rows,
                    @Param("syncedAt") LocalDateTime syncedAt);
    List<Map<String, Object>> selectStations();
    Map<String, Object> selectOverview(@Param("stationId") Long stationId, @Param("today") LocalDate today);
    Map<String, Object> selectOverview(@Param("stationId") Long stationId, @Param("day") LocalDate day);
    List<Map<String, Object>> selectHistory(@Param("stationId") Long stationId, @Param("period") String period,
                                            @Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate);
    List<Map<String, Object>> selectCurve(@Param("stationId") Long stationId);
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/emind/service/EmindStorageDashboardService.java
@@ -23,7 +23,7 @@
        LocalDate start=query.getStartDate();
        if (start==null) start="YEAR".equals(period)?end.withDayOfYear(1):("MONTH".equals(period)?end.withDayOfMonth(1):end.minusDays(6));
        Map<String,Object> result=new LinkedHashMap<>();
        result.put("summary", mapper.selectOverview(query.getStationId(), LocalDate.now()));
        result.put("summary", mapper.selectOverview(query.getStationId(), LocalDate.now().minusDays(1)));
        result.put("history", completeHistory(mapper.selectHistory(query.getStationId(), period, start, end), period, start, end));
        result.put("curve", mapper.selectCurve(query.getStationId()));
        return result;
ruoyi-service/ruoyi-other/src/main/resources/mapper/other/EmindStorageDashboardMapper.xml
@@ -52,8 +52,12 @@
    <select id="selectOverview" resultType="map">
        SELECT COALESCE(SUM(income_sum),0) incomeSum, COALESCE(SUM(charged_energy_sum),0) chargedEnergySum,
          COALESCE(SUM(discharged_energy_sum),0) dischargedEnergySum,
          COALESCE(SUM(charged_energy_today),0) chargedEnergyToday,
          COALESCE(SUM(discharged_energy_today),0) dischargedEnergyToday,
          COALESCE((SELECT SUM(daily.charged_energy) FROM t_emind_dashboard_daily daily
            WHERE daily.stat_date=#{day}
            <if test="stationId != null">AND daily.station_id=#{stationId}</if>),0) chargedEnergyYesterday,
          COALESCE((SELECT SUM(daily.discharged_energy) FROM t_emind_dashboard_daily daily
            WHERE daily.stat_date=#{day}
            <if test="stationId != null">AND daily.station_id=#{stationId}</if>),0) dischargedEnergyYesterday,
          COALESCE(SUM(real_time_power),0) realTimePower, COALESCE(SUM(surplus_energy),0) surplusEnergy,
          COALESCE(SUM(capacity),0) capacity,
          CASE WHEN SUM(capacity)&gt;0 THEN ROUND(SUM(surplus_energy)/SUM(capacity)*100,2) ELSE COALESCE(AVG(soc),0) END soc,
@@ -64,7 +68,9 @@
            AND block.run_status BETWEEN 1 AND 4
            AND block.record_time IS NOT NULL AND block.record_time!=''
            <if test="stationId != null">AND block.station_id=#{stationId}</if>),0) eblockOnline,
          COALESCE(SUM(income_today),0) incomeToday,
          COALESCE((SELECT SUM(daily.income) FROM t_emind_dashboard_daily daily
            WHERE daily.stat_date=#{day}
            <if test="stationId != null">AND daily.station_id=#{stationId}</if>),0) incomeYesterday,
          MAX(synced_at) syncedAt
        FROM t_emind_dashboard_snapshot WHERE 1=1 <if test="stationId != null">AND station_id=#{stationId}</if>
    </select>
ruoyi-service/ruoyi-other/src/test/java/com/ruoyi/other/emind/service/EmindStorageDashboardServiceTest.java
@@ -24,6 +24,7 @@
        when(mapper.selectCurve(isNull())).thenReturn(Collections.emptyList());
        EmindDashboardQuery query=new EmindDashboardQuery();
        assertEquals(3, new EmindStorageDashboardService(mapper).overview(query).size());
        verify(mapper).selectOverview(isNull(), eq(LocalDate.now().minusDays(1)));
        verify(mapper).selectHistory(isNull(), eq("DAY"), eq(LocalDate.now().minusDays(6)), eq(LocalDate.now()));
    }