Pārlūkot izejas kodu

修复获取灯控流量信息统计图数据的异常

zhj 10 mēneši atpakaļ
vecāks
revīzija
1243e228f3

+ 5 - 4
src/main/java/com/welampiot/service/impl/NetCardInfoLogServiceImpl.java

@@ -28,10 +28,11 @@ public class NetCardInfoLogServiceImpl implements NetCardInfoLogService {
         String[] split = nowDate.split("-");
         String year = split[0];
         String month = split[1];
+        String monthStr = year + "-" + month;
         if (netCardLogVO.getDataType() == 1) {
             return getNetCardLogListByLampIdAndYear(netCardLogVO.getLampId(), year, month);
         }
-        return getNetCardLogListByLampIdAndMonth(netCardLogVO.getLampId(), year, month);
+        return getNetCardLogListByLampIdAndMonth(netCardLogVO.getLampId(), year, monthStr);
     }
 
     @Override
@@ -50,7 +51,7 @@ public class NetCardInfoLogServiceImpl implements NetCardInfoLogService {
         List<Object> dataList = new ArrayList<>();
         List<Object> dateList = new ArrayList<>();
 
-        LocalDate firstDayOfMonth = LocalDate.parse(year + "-" + month + "-01", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+        LocalDate firstDayOfMonth = LocalDate.parse(month + "-01", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
         LocalDate lastDayOfMonth = firstDayOfMonth.withDayOfMonth(firstDayOfMonth.lengthOfMonth());
 
         DecimalFormat df = new DecimalFormat("0.##");
@@ -86,7 +87,7 @@ public class NetCardInfoLogServiceImpl implements NetCardInfoLogService {
             allMonths.add(String.format("%s-%02d", year, i));
         }
 
-        // 按月份分组,取每个月的最后一笔记录
+        // 将 logs 转换为 Map,键为月份,值为 NetCardInfoLogDTO
         Map<String, NetCardInfoLogDTO> monthlyLogs = logs.stream()
                 .collect(Collectors.toMap(
                         log -> log.getUpdateTime().substring(0, 7), // 取前7个字符,即 "YYYY-MM"
@@ -101,7 +102,7 @@ public class NetCardInfoLogServiceImpl implements NetCardInfoLogService {
         DecimalFormat df = new DecimalFormat("0.##");
         // 遍历所有月份,填充 dataList 和 dateList
         for (String months : allMonths) {
-            NetCardInfoLogDTO log = monthlyLogs.get(month);
+            NetCardInfoLogDTO log = monthlyLogs.get(months);
             double usage = log != null ? log.getUseGprs() : 0.0;
             dataList.add(df.format(usage));
             dateList.add(months);