فهرست منبع

feat(property): 添加退款信息统计功能

- 新增月度、季度和年度退款统计方法
- 实现退款信息的年份查询功能
- 在控制器中添加相应的统计接口
林仔 10 ماه پیش
والد
کامیت
083895bed3

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

@@ -55,5 +55,25 @@ public class ARefundController {
     public AjaxResult delete(@RequestBody String[] ids) {
         return service.removeBatchByIds(Arrays.asList(ids)) ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
     }
+    @GetMapping("/calculateMonthlyRefundStatistics")
+    @ApiOperation(value = "退款信息月度统计")
+    public AjaxResult calculateMonthlyRefundStatistics(int year) {
+        return AjaxResult.success(service.calculateMonthlyRefundStatistics(year));
+    }
+    @GetMapping("/calculateQuarterlyRefundStatistics")
+    @ApiOperation(value = "退款信息季度统计")
+    public AjaxResult calculateQuarterlyRefundStatistics(int year) {
+        return AjaxResult.success(service.calculateQuarterlyRefundStatistics(year));
+    }
+    @GetMapping("/calculateYearlyRefundStatistics")
+    @ApiOperation(value = "退款信息年度统计")
+    public AjaxResult calculateYearlyRefundStatistics() {
+        return AjaxResult.success(service.calculateYearlyRefundStatistics());
+    }
+    @GetMapping("/getExistingRefundYears")
+    @ApiOperation(value = "退款信息查询所有年份")
+    public AjaxResult getExistingRefundYears() {
+        return AjaxResult.success(service.getExistingRefundYears());
+    }
 
 }

+ 6 - 0
src/main/java/com/zksy/property/service/ARefundService.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.ARefund;
 
+import java.math.BigDecimal;
 import java.util.List;
+import java.util.Map;
 
 /**
 * @author Administrator
@@ -14,4 +16,8 @@ import java.util.List;
 public interface ARefundService extends IService<ARefund> {
     Page<ARefund> findByPage(long pageNum, long pageSize, String unit,String tenant,String generationDate);
     List<ARefund> getARefundList(String unit, String tenant, String generationDate);
+    Map<String, BigDecimal> calculateMonthlyRefundStatistics(int year);
+    Map<String, BigDecimal> calculateQuarterlyRefundStatistics(int year);
+    Map<String, BigDecimal> calculateYearlyRefundStatistics();
+    List<Integer> getExistingRefundYears();
 }

+ 0 - 2
src/main/java/com/zksy/property/service/impl/AReceiptInfoServiceImpl.java

@@ -48,7 +48,6 @@ public class AReceiptInfoServiceImpl extends ServiceImpl<AReceiptInfoMapper, ARe
 
     @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)));
@@ -113,7 +112,6 @@ public class AReceiptInfoServiceImpl extends ServiceImpl<AReceiptInfoMapper, ARe
 
     @Override
     public List<Integer> getExistingYears() {
-        // 从数据库查询所有收据
         List<AReceiptInfo> receiptList = list();
 
         return receiptList.stream()

+ 84 - 1
src/main/java/com/zksy/property/service/impl/ARefundServiceImpl.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.ARefund;
@@ -8,7 +9,10 @@ import com.zksy.property.mapper.ARefundMapper;
 import com.zksy.property.service.ARefundService;
 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
@@ -39,6 +43,85 @@ public class ARefundServiceImpl extends ServiceImpl<ARefundMapper, ARefund>
         List<ARefund> list = this.list(queryWrapper);
         return list;
     }
+
+    @Override
+    public Map<String, BigDecimal> calculateMonthlyRefundStatistics(int year) {
+        // 从数据库查询指定年份的所有退款记录
+        List<ARefund> refundList = list(new QueryWrapper<ARefund>()
+                .ge("generation_date", LocalDate.of(year, 1, 1))
+                .le("generation_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 (ARefund refund : refundList) {
+            if (refund.getGenerationDate() != null && refund.getTotalAmount() != null) {
+                String monthKey = String.format("%d-%02d",
+                        year,
+                        refund.getGenerationDate().getMonthValue()
+                );
+                monthlyData.merge(monthKey, refund.getTotalAmount(), BigDecimal::add);
+            }
+        }
+
+        return monthlyData;
+    }
+
+
+    @Override
+    public Map<String, BigDecimal> calculateQuarterlyRefundStatistics(int year) {
+        List<ARefund> refundList = list(new QueryWrapper<ARefund>()
+                .ge("generation_date", LocalDate.of(year, 1, 1))
+                .le("generation_date", LocalDate.of(year, 12, 31)));
+
+        // 初始化4个季度的容器(使用LinkedHashMap保证顺序)
+        Map<String, BigDecimal> quarterlyData = new LinkedHashMap<>();
+        for (int quarter = 1; quarter <= 4; quarter++) {
+            quarterlyData.put(year + "Q" + quarter, BigDecimal.ZERO);
+        }
+
+        for (ARefund refund : refundList) {
+            LocalDate date = refund.getGenerationDate();
+            if (date != null && refund.getTotalAmount() != null) {
+                int quarter = (date.getMonthValue() - 1) / 3 + 1;
+                String quarterKey = year + "Q" + quarter;
+                quarterlyData.merge(quarterKey, refund.getTotalAmount(), BigDecimal::add);
+            }
+        }
+
+        return quarterlyData;
+    }
+
+    @Override
+    public Map<String, BigDecimal> calculateYearlyRefundStatistics() {
+        List<ARefund> refundList = list();
+        Map<String, BigDecimal> yearlyData = new TreeMap<>();
+
+        // 统计数据
+        for (ARefund refund : refundList) {
+            LocalDate date = refund.getGenerationDate();
+            if (date != null && refund.getTotalAmount() != null) {
+                String yearKey = String.valueOf(date.getYear());
+                yearlyData.merge(yearKey, refund.getTotalAmount(), BigDecimal::add);
+            }
+        }
+
+        return yearlyData;
+    }
+
+    @Override
+    public List<Integer> getExistingRefundYears() {
+        List<ARefund> refundList = list();
+        return refundList.stream()
+                .map(ARefund::getGenerationDate)
+                .filter(Objects::nonNull)
+                .map(date -> date.getYear())
+                .distinct()
+                .sorted()
+                .collect(Collectors.toList());
+    }
 }