Bladeren bron

feat(water-usage): 添加用水数据统计功能

- 在 WaterUsageData 实体类中添加了 JsonFormat 注解,用于格式化日期时间
- 在 WaterUsageDataController 中添加了多个统计相关的 API接口
- 在 WaterUsageDataService 接口中定义了新的统计方法
- 实现了 WaterUsageDataServiceImpl 中的统计方法,包括:  - 按月份统计总用水量和总金额
  - 按客户汇总用水量和金额
  - TOP N 用户排名
  - 客户用水趋势分析
林仔 8 maanden geleden
bovenliggende
commit
5004643a15

+ 25 - 0
park-overview-service/src/main/java/com/zksy/park/controller/WaterUsageDataController.java

@@ -24,6 +24,7 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.time.LocalDateTime;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 智慧用工
@@ -84,6 +85,30 @@ public class WaterUsageDataController {
         return Result.ok(service.removeByIds(ids),"删除成功");
     }
 
+    @ApiOperation(value = "按月份统计")
+    @GetMapping("/month-summary")
+    public Result getMonthSummary() {
+        return Result.ok(service.getMonthSummary());
+    }
+
+    @ApiOperation(value = "按客户统计")
+    @GetMapping("/customer-summary")
+    public Result getCustomerSummary() {
+        return Result.ok(service.getCustomerSummary());
+    }
+
+    @ApiOperation(value = "按客户排名")
+    @GetMapping("/top-customers")
+    public Result getTopNCustomers(@RequestParam(defaultValue = "5") int topN) {
+        return Result.ok(service.getTopNCustomers(topN));
+    }
+
+    @ApiOperation(value = "客户趋势")
+    @GetMapping("/customer-trend/{customerCode}")
+    public Result getCustomerTrend(@PathVariable Long customerCode) {
+        return Result.ok(service.getCustomerTrend(customerCode));
+    }
+
     @GetMapping("/exportExcel")
     @ApiOperation(value = "导出用水信息Excel")
     @Log(title = "导出用水信息Excel", businessType = BusinessType.EXPORT)

+ 3 - 1
park-overview-service/src/main/java/com/zksy/park/domain/SmartEmployment.java

@@ -8,6 +8,7 @@ import com.alibaba.excel.annotation.write.style.ColumnWidth;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -119,12 +120,13 @@ public class SmartEmployment {
     @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
     @ExcelProperty("发布时间")
     @ColumnWidth(20)
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     private LocalDateTime createTime;
 
     /**
      * 修改时间
      */
     @ApiModelProperty(value = "修改时间")
-
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     private LocalDateTime updateTime;
 }

+ 9 - 0
park-overview-service/src/main/java/com/zksy/park/domain/WaterUsageData.java

@@ -1,6 +1,8 @@
 package com.zksy.park.domain;
 
+import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
 import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.annotation.format.DateTimeFormat;
 import com.alibaba.excel.annotation.write.style.ColumnWidth;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
@@ -11,13 +13,19 @@ import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.util.Date;
 
+import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 
 /**
  * 用水数据
  * @TableName wate_usage_data
  */
+@AllArgsConstructor
+@NoArgsConstructor
+@ExcelIgnoreUnannotated
 @TableName(value ="water_usage_data")
 @Data
 public class WaterUsageData implements Serializable {
@@ -71,6 +79,7 @@ public class WaterUsageData implements Serializable {
     /**
      * 创建时间
      */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     private LocalDateTime createTime;
 
     @TableField(exist = false)

+ 15 - 0
park-overview-service/src/main/java/com/zksy/park/service/WaterUsageDataService.java

@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+import java.util.Map;
 
 /**
 * @author Administrator
@@ -13,4 +15,17 @@ import javax.servlet.http.HttpServletResponse;
 * @createDate 2025-09-16 14:51:14
 */
 public interface WaterUsageDataService extends IService<WaterUsageData> {
+
+        // 1. 按月份统计总用水量、总金额
+        List<Map<String, Object>> getMonthSummary();
+
+        // 2. 按客户汇总
+        List<Map<String, Object>> getCustomerSummary();
+
+        // 3. TOP N 用户(水量/金额排名)
+        List<Map<String, Object>> getTopNCustomers(int topN);
+
+        // 4. 客户用水趋势
+        List<Map<String, Object>> getCustomerTrend(Long customerCode);
+
 }

+ 43 - 1
park-overview-service/src/main/java/com/zksy/park/service/impl/WaterUsageDataServiceImpl.java

@@ -3,6 +3,7 @@ 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;
@@ -20,6 +21,7 @@ import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 /**
 * @author Administrator
@@ -28,10 +30,50 @@ import java.util.List;
 */
 @Service
 public class WaterUsageDataServiceImpl extends ServiceImpl<WaterUsageDataMapper, WaterUsageData>
-    implements WaterUsageDataService {
+        implements WaterUsageDataService {
 
+    @Override
+    public List<Map<String, Object>> getMonthSummary() {
+        return this.listMaps(new QueryWrapper<WaterUsageData>()
+                .select("statistical_time as statTime",
+                        "SUM(water_volume) as totalWater",
+                        "SUM(amount) as totalAmount")
+                .groupBy("statistical_time"));
+    }
+
+    @Override
+    public List<Map<String, Object>> getCustomerSummary() {
+        return this.listMaps(new QueryWrapper<WaterUsageData>()
+                .select("customer_name as customerName",
+                        "SUM(water_volume) as totalWater",
+                        "SUM(amount) as totalAmount")
+                .groupBy("customer_name"));
+    }
+
+    @Override
+    public List<Map<String, Object>> getTopNCustomers(int topN) {
+        return this.listMaps(new QueryWrapper<WaterUsageData>()
+                .select("customer_name as customerName",
+                        "SUM(water_volume) as totalWater",
+                        "SUM(amount) as totalAmount")
+                .groupBy("customer_name")
+                .orderByDesc("SUM(amount)")
+                .last("LIMIT " + topN));
+    }
+
+    @Override
+    public List<Map<String, Object>> getCustomerTrend(Long customerCode) {
+        return this.listMaps(new QueryWrapper<WaterUsageData>()
+                .select("statistical_time as statTime",
+                        "SUM(water_volume) as totalWater",
+                        "SUM(amount) as totalAmount")
+                .eq("customer_code", customerCode)
+                .groupBy("statistical_time")
+                .orderByAsc("statistical_time"));
+    }
 }
 
 
 
 
+