|
|
@@ -1,32 +1,14 @@
|
|
|
package com.zksy.park.service.impl;
|
|
|
|
|
|
-import com.alibaba.excel.EasyExcel;
|
|
|
-import com.alibaba.excel.ExcelWriter;
|
|
|
-import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.zksy.common.core.domain.Result;
|
|
|
import com.zksy.park.domain.WaterUsageData;
|
|
|
-import com.zksy.park.domain.vo.MonthlyWaterStats;
|
|
|
-import com.zksy.park.listener.WaterUsageDataListener;
|
|
|
import com.zksy.park.service.WaterUsageDataService;
|
|
|
import com.zksy.park.mapper.WaterUsageDataMapper;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.IOException;
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.net.URLEncoder;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
-import java.time.LocalDate;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author Administrator
|
|
|
@@ -37,6 +19,9 @@ import java.util.stream.Collectors;
|
|
|
public class WaterUsageDataServiceImpl extends ServiceImpl<WaterUsageDataMapper, WaterUsageData>
|
|
|
implements WaterUsageDataService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private WaterUsageDataMapper waterUsageDataMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public List<Map<String, Object>> getMonthSummary() {
|
|
|
return this.listMaps(new QueryWrapper<WaterUsageData>()
|
|
|
@@ -78,39 +63,8 @@ public class WaterUsageDataServiceImpl extends ServiceImpl<WaterUsageDataMapper,
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<MonthlyWaterStats> getYearlyMonthlyStats() {
|
|
|
- // 获取当前年份的字符串形式
|
|
|
- String currentYear = String.valueOf(LocalDate.now().getYear());
|
|
|
-
|
|
|
- // 从数据库查询当前年份已有的月度数据
|
|
|
- List<Map<String, Object>> dbStats = baseMapper.getMonthlyStatsByYear(currentYear);
|
|
|
-
|
|
|
- // 将查询结果转换为Map便于查找,key为月份(如"9")
|
|
|
- Map<String, Map<String, Object>> statsMap = dbStats.stream()
|
|
|
- .collect(Collectors.toMap(
|
|
|
- item -> item.get("month").toString(),
|
|
|
- item -> item
|
|
|
- ));
|
|
|
-
|
|
|
- // 构建12个月的完整数据列表
|
|
|
- List<MonthlyWaterStats> result = new ArrayList<>();
|
|
|
- for (int i = 1; i <= 12; i++) {
|
|
|
- // 月份转为字符串
|
|
|
- String month = String.valueOf(i);
|
|
|
-
|
|
|
- // 从查询结果中获取当前月份数据,无数据则用0填充
|
|
|
- Map<String, Object> monthData = statsMap.getOrDefault(month, new HashMap<>());
|
|
|
- Long waterVolume = monthData.containsKey("total_water_volume")
|
|
|
- ? ((Number) monthData.get("total_water_volume")).longValue()
|
|
|
- : 0L;
|
|
|
- BigDecimal amount = monthData.containsKey("total_amount")
|
|
|
- ? (BigDecimal) monthData.get("total_amount")
|
|
|
- : BigDecimal.ZERO;
|
|
|
-
|
|
|
- result.add(new MonthlyWaterStats(month, waterVolume, amount));
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
+ public List<Map<String, Object>> getYearlyStatistics(int year) {
|
|
|
+ return waterUsageDataMapper.getYearlyUsageStatistics(year);
|
|
|
}
|
|
|
}
|
|
|
|