Просмотр исходного кода

feat(property): 添加收据信息统计功能

- 新增按月、季度、年统计收缴金额的接口和实现
- 添加获取已存在年份列表的功能
- 在控制器中添加相关API的映射
林仔 10 месяцев назад
Родитель
Сommit
6e296a23ad

+ 20 - 0
src/main/java/com/zksy/controller/property/AReceiptInfoController.java

@@ -55,5 +55,25 @@ public class AReceiptInfoController {
     public AjaxResult delete(@RequestBody String[] ids) {
         return service.removeBatchByIds(Arrays.asList(ids)) ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
     }
+    @GetMapping("/calculateMonthlyStatistics")
+    @ApiOperation(value = "计算某年每月的收缴金额")
+    public AjaxResult calculateMonthlyStatistics(int year) {
+        return AjaxResult.success(service.calculateMonthlyStatistics(year));
+    }
+    @GetMapping("/calculateQuarterlyStatistics")
+    @ApiOperation(value = "计算某年每季度的收缴金额")
+    public AjaxResult calculateQuarterlyStatistics(int year) {
+        return AjaxResult.success(service.calculateQuarterlyStatistics(year));
+    }
+    @GetMapping("/calculateYearlyStatistics")
+    @ApiOperation(value = "计算某年的收缴金额")
+    public AjaxResult calculateYearlyStatistics() {
+        return AjaxResult.success(service.calculateYearlyStatistics());
+    }
+    @GetMapping("/getExistingYears")
+    @ApiOperation(value = "获取已存在的年份")
+    public AjaxResult getExistingYears() {
+        return AjaxResult.success(service.getExistingYears());
+    }
 
 }

+ 7 - 1
src/main/java/com/zksy/property/service/AReceiptInfoService.java

@@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.zksy.property.domain.AReceiptInfo;
 
+import java.math.BigDecimal;
 import java.util.List;
+import java.util.Map;
 
 /**
 * @author Administrator
@@ -14,5 +16,9 @@ import java.util.List;
 public interface AReceiptInfoService extends IService<AReceiptInfo> {
     Page<AReceiptInfo> findByPage(long pageNum, long pageSize, String receiptNumber,String payer,String paymentMethod,String generationDate);
     List<AReceiptInfo> getAReceiptInfoList(String receiptNumber,String payer,String paymentMethod,String generationDate);
-
+    Map<String, BigDecimal> calculateMonthlyStatistics(int year);
+    Map<String, BigDecimal> calculateQuarterlyStatistics(int year);
+    Map<String, BigDecimal> calculateYearlyStatistics();
+    // 获取数据库中存在的年份列表
+    List<Integer> getExistingYears();
 }

+ 84 - 1
src/main/java/com/zksy/property/service/impl/AReceiptInfoServiceImpl.java

@@ -1,6 +1,7 @@
 package com.zksy.property.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+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.property.domain.AReceiptInfo;
@@ -8,7 +9,10 @@ import com.zksy.property.mapper.AReceiptInfoMapper;
 import com.zksy.property.service.AReceiptInfoService;
 import org.springframework.stereotype.Service;
 
-import java.util.List;
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
 * @author Administrator
@@ -41,6 +45,85 @@ public class AReceiptInfoServiceImpl extends ServiceImpl<AReceiptInfoMapper, ARe
         List<AReceiptInfo> list = this.list(queryWrapper);
         return list;
     }
+
+    @Override
+    public Map<String, BigDecimal> calculateMonthlyStatistics(int year) {
+        // 从数据库查询指定年份的所有收据
+        List<AReceiptInfo> receiptList = list(new QueryWrapper<AReceiptInfo>()
+                .ge("accounting_date", LocalDate.of(year, 1, 1))
+                .le("accounting_date", LocalDate.of(year, 12, 31)));
+
+        Map<String, BigDecimal> monthlyData = new LinkedHashMap<>();
+        for (int month = 1; month <= 12; month++) {
+            monthlyData.put(String.format("%d-%02d", year, month), BigDecimal.ZERO);
+        }
+
+        // 统计数据
+        for (AReceiptInfo receipt : receiptList) {
+            if (receipt.getAccountingDate() != null && receipt.getTotalAmount() != null) {
+                String monthKey = String.format("%d-%02d",
+                        year,
+                        receipt.getAccountingDate().getMonthValue()
+                );
+                monthlyData.merge(monthKey, receipt.getTotalAmount(), BigDecimal::add);
+            }
+        }
+
+        return monthlyData;
+    }
+
+    @Override
+    public Map<String, BigDecimal> calculateQuarterlyStatistics(int year) {
+        List<AReceiptInfo> receiptList = list(new QueryWrapper<AReceiptInfo>()
+                .ge("accounting_date", LocalDate.of(year, 1, 1))
+                .le("accounting_date", LocalDate.of(year, 12, 31)));
+
+        Map<String, BigDecimal> quarterlyData = new TreeMap<>();
+        for (int quarter = 1; quarter <= 4; quarter++) {
+            quarterlyData.put(year + "Q" + quarter, BigDecimal.ZERO);
+        }
+
+        for (AReceiptInfo receipt : receiptList) {
+            LocalDate date = receipt.getAccountingDate();
+            if (date != null && receipt.getTotalAmount() != null) {
+                int quarter = (date.getMonthValue() - 1) / 3 + 1;
+                String quarterKey = year + "Q" + quarter;
+                quarterlyData.merge(quarterKey, receipt.getTotalAmount(), BigDecimal::add);
+            }
+        }
+
+        return quarterlyData;
+    }
+
+    @Override
+    public Map<String, BigDecimal> calculateYearlyStatistics() {
+        List<AReceiptInfo> receiptList = list();
+        Map<String, BigDecimal> yearlyData = new TreeMap<>();
+
+        for (AReceiptInfo receipt : receiptList) {
+            LocalDate date = receipt.getAccountingDate();
+            if (date != null && receipt.getTotalAmount() != null) {
+                String yearKey = String.valueOf(date.getYear());
+                yearlyData.merge(yearKey, receipt.getTotalAmount(), BigDecimal::add);
+            }
+        }
+
+        return yearlyData;
+    }
+
+    @Override
+    public List<Integer> getExistingYears() {
+        // 从数据库查询所有收据
+        List<AReceiptInfo> receiptList = list();
+
+        return receiptList.stream()
+                .map(AReceiptInfo::getAccountingDate)
+                .filter(Objects::nonNull)
+                .map(date -> date.getYear())
+                .distinct()
+                .sorted()
+                .collect(Collectors.toList());
+    }
 }