From 50827659c0c6d9bfd797d9dc381c34fe52039608 Mon Sep 17 00:00:00 2001
From: longz <longzhaoz@qq.com>
Date: 星期一, 03 八月 2026 15:02:23 +0800
Subject: [PATCH] 修复光伏历史发电量同步

---
 ruoyi-service/ruoyi-other/src/test/java/com/ruoyi/other/service/impl/TStationInfoServiceImplTest.java |   16 ++++++++++++++++
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TStationInfoServiceImpl.java     |   16 ++++++----------
 2 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TStationInfoServiceImpl.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TStationInfoServiceImpl.java
index f2e1231..b49ac8f 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TStationInfoServiceImpl.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TStationInfoServiceImpl.java
@@ -81,16 +81,8 @@
         log.info("-------2结束同步科士达-逆变器列表----");
 
         log.info("-------3开始同步科士达-电站的电量和收益统计查询----");
-        LocalDate startDate = stationEarnService.getMaxSaveTime();
-        String startDateStr = "";
-        String endDateStr = "";
-        if(Objects.nonNull(startDate)) {
-            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
-            // String dateStr = startDate.plusDays(1).format(formatter);
-            String dateStr = startDate.format(formatter);
-            startDateStr = dateStr + " 00:00:00";
-            endDateStr = LocalDateTime.now().format(formatter);
-        }
+        String startDateStr = buildSyncStartDate(LocalDate.now());
+        String endDateStr = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
         JSONArray stationEarnList = KsolarUtils.getStationElecList(startDateStr, endDateStr, token);
         stationEarnService.saveStationEarnList(stationEarnList);
         log.info("-------3结束同步科士达-电站的电量和收益统计查询----");
@@ -248,6 +240,10 @@
         return baseMap;
     }
 
+    static String buildSyncStartDate(LocalDate date) {
+        return date.withDayOfYear(1).format(DateTimeFormatter.ISO_LOCAL_DATE) + " 00:00:00";
+    }
+
     private Long parseStationId(String stationId) {
         try {
             return Long.valueOf(stationId);
diff --git a/ruoyi-service/ruoyi-other/src/test/java/com/ruoyi/other/service/impl/TStationInfoServiceImplTest.java b/ruoyi-service/ruoyi-other/src/test/java/com/ruoyi/other/service/impl/TStationInfoServiceImplTest.java
new file mode 100644
index 0000000..b3938e3
--- /dev/null
+++ b/ruoyi-service/ruoyi-other/src/test/java/com/ruoyi/other/service/impl/TStationInfoServiceImplTest.java
@@ -0,0 +1,16 @@
+package com.ruoyi.other.service.impl;
+
+import org.junit.jupiter.api.Test;
+
+import java.time.LocalDate;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class TStationInfoServiceImplTest {
+
+    @Test
+    void syncsFromTheFirstDayOfTheCurrentYear() {
+        assertEquals("2026-01-01 00:00:00",
+                TStationInfoServiceImpl.buildSyncStartDate(LocalDate.of(2026, 8, 3)));
+    }
+}

--
Gitblit v1.7.1