From 98ed3d5f0866c50653bd46ee1daf840d408224ae Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期二, 27 一月 2026 17:36:39 +0800
Subject: [PATCH] fix: 审批类型、产品大类分布修改

---
 src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java |  435 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 390 insertions(+), 45 deletions(-)

diff --git a/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java b/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
index 85f9719..6085d2d 100644
--- a/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
+++ b/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
@@ -1,45 +1,43 @@
 package com.ruoyi.home.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.approve.mapper.ApproveProcessMapper;
 import com.ruoyi.approve.pojo.ApproveProcess;
+import com.ruoyi.basic.mapper.CustomerMapper;
+import com.ruoyi.basic.mapper.ProductMapper;
 import com.ruoyi.basic.mapper.ProductModelMapper;
+import com.ruoyi.basic.mapper.SupplierManageMapper;
+import com.ruoyi.basic.pojo.Customer;
+import com.ruoyi.basic.pojo.Product;
 import com.ruoyi.basic.pojo.ProductModel;
+import com.ruoyi.basic.pojo.SupplierManage;
 import com.ruoyi.collaborativeApproval.mapper.NoticeMapper;
 import com.ruoyi.collaborativeApproval.pojo.Notice;
+import com.ruoyi.common.enums.ApproveTypeEnum;
 import com.ruoyi.common.utils.SecurityUtils;
-import com.ruoyi.device.mapper.DeviceMaintenanceMapper;
 import com.ruoyi.device.mapper.DeviceRepairMapper;
-import com.ruoyi.device.pojo.DeviceMaintenance;
 import com.ruoyi.device.pojo.DeviceRepair;
 import com.ruoyi.dto.MapDto;
 import com.ruoyi.framework.security.LoginUser;
 import com.ruoyi.home.dto.*;
 import com.ruoyi.home.service.HomeService;
-import com.ruoyi.lavorissue.mapper.LavorIssueMapper;
-import com.ruoyi.lavorissue.pojo.LaborIssue;
-import com.ruoyi.procurementrecord.mapper.CustomStorageMapper;
 import com.ruoyi.procurementrecord.mapper.ProcurementRecordMapper;
-import com.ruoyi.procurementrecord.mapper.ProcurementRecordOutMapper;
-import com.ruoyi.procurementrecord.pojo.CustomStorage;
-import com.ruoyi.procurementrecord.pojo.ProcurementRecordOut;
 import com.ruoyi.procurementrecord.pojo.ProcurementRecordStorage;
 import com.ruoyi.procurementrecord.utils.StockUtils;
 import com.ruoyi.production.dto.ProductOrderDto;
 import com.ruoyi.production.dto.ProductWorkOrderDto;
-import com.ruoyi.production.dto.ProductionProductMainDto;
 import com.ruoyi.production.mapper.ProductOrderMapper;
-import com.ruoyi.production.mapper.ProductProcessMapper;
 import com.ruoyi.production.mapper.ProductWorkOrderMapper;
-import com.ruoyi.production.mapper.ProductionProductMainMapper;
-import com.ruoyi.production.pojo.ProductOrder;
-import com.ruoyi.production.pojo.ProductProcess;
 import com.ruoyi.production.pojo.ProductWorkOrder;
 import com.ruoyi.project.system.domain.SysDept;
+import com.ruoyi.project.system.domain.SysUser;
+import com.ruoyi.project.system.domain.SysUserDept;
 import com.ruoyi.project.system.mapper.SysDeptMapper;
+import com.ruoyi.project.system.mapper.SysUserDeptMapper;
+import com.ruoyi.project.system.mapper.SysUserMapper;
 import com.ruoyi.purchase.mapper.PaymentRegistrationMapper;
 import com.ruoyi.purchase.mapper.PurchaseLedgerMapper;
 import com.ruoyi.purchase.pojo.PaymentRegistration;
@@ -52,6 +50,8 @@
 import com.ruoyi.sales.pojo.ReceiptPayment;
 import com.ruoyi.sales.pojo.SalesLedger;
 import com.ruoyi.sales.pojo.SalesLedgerProduct;
+import com.ruoyi.staff.mapper.StaffOnJobMapper;
+import com.ruoyi.staff.pojo.StaffOnJob;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -60,13 +60,11 @@
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.text.ParseException;
-import java.text.SimpleDateFormat;
 import java.time.*;
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.ChronoUnit;
 import java.time.temporal.TemporalAdjusters;
 import java.util.*;
-import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
 /**
@@ -87,13 +85,7 @@
     private SalesLedgerProductMapper salesLedgerProductMapper;
 
     @Autowired
-    private ProcurementRecordOutMapper procurementRecordOutMapper;
-
-    @Autowired
     private ProcurementRecordMapper procurementRecordStorageMapper;
-
-    @Autowired
-    private CustomStorageMapper customStorageMapper;
 
     @Autowired
     private QualityInspectMapper qualityStatisticsMapper;
@@ -108,9 +100,6 @@
     private PaymentRegistrationMapper paymentRegistrationMapper;
 
     @Autowired
-    private LavorIssueMapper lavorIssueMapper;
-
-    @Autowired
     private SysDeptMapper sysDeptMapper;
 
     @Autowired
@@ -118,13 +107,24 @@
     @Autowired
     private ProductOrderMapper productOrderMapper;
     @Autowired
-    private ProductProcessMapper productProcessMapper;
-    @Autowired
     private ProductWorkOrderMapper productWorkOrderMapper;
     @Autowired
     private ProductModelMapper productModelMapper;
     @Autowired
+    private ProductMapper productMapper;
+    @Autowired
     private StockUtils stockUtils;
+    @Autowired
+    private StaffOnJobMapper staffOnJobMapper;
+    @Autowired
+    private CustomerMapper customerMapper;
+    @Autowired
+    private SupplierManageMapper supplierManageMapper;
+    @Autowired
+    private SysUserMapper sysUserMapper;
+    @Autowired
+    private SysUserDeptMapper sysUserDeptMapper;
+
     @Override
     public HomeBusinessDto business() {
         // 鏋勫缓缁撴灉
@@ -400,29 +400,37 @@
         LambdaQueryWrapper<ApproveProcess> approveProcessLambdaQueryWrapper = new LambdaQueryWrapper<>();
         approveProcessLambdaQueryWrapper.eq(ApproveProcess::getApproveDelete, 0)
                 .eq(ApproveProcess::getApproveUserCurrentId, loginUser.getUserId())
-                .ne(ApproveProcess::getApproveStatus, 2)
-                .eq(ApproveProcess::getTenantId, loginUser.getTenantId());
+                .ne(ApproveProcess::getApproveStatus, 2);
+//                .eq(ApproveProcess::getTenantId, loginUser.getTenantId());
         List<ApproveProcess> approveProcesses = approveProcessMapper.selectList(approveProcessLambdaQueryWrapper);
-        if(CollectionUtils.isEmpty(approveProcesses)){
+        if (CollectionUtils.isEmpty(approveProcesses)) {
             approveProcesses = new ArrayList<>();
         }
-        // 鏌ヨ鏈鐢ㄥ姵淇濊褰�
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
 
-        LaborIssue laborIssue1 = new LaborIssue();
-        laborIssue1.setAdoptedDate(new Date());
-        laborIssue1.setIssueDate(sdf.parse(sdf.format(new Date())));
-        List<LaborIssue> laborIssues = lavorIssueMapper.list(laborIssue1);
-        if(!CollectionUtils.isEmpty(laborIssues)){
-            for (LaborIssue laborIssue : laborIssues) {
-                ApproveProcess approveProcess = new ApproveProcess();
-                approveProcess.setApproveId(laborIssue.getOrderNo());
-                approveProcess.setApproveDeptName(sysDeptMapper.selectDeptById(loginUser.getTenantId()).getDeptName());
-                approveProcess.setApproveTime(laborIssue.getIssueDate());
-                approveProcess.setApproveReason(laborIssue.getDictTypeName() + "-" + laborIssue.getDictName() + "瓒呮椂鏈鍙�");
-                approveProcesses.add(approveProcess);
+        approveProcesses.forEach(a -> {
+            if (a.getApproveType() != null) {
+                a.setApproveTypeName(ApproveTypeEnum.getNameByCode(a.getApproveType()));
             }
-        }
+        });
+//        // 鏌ヨ鏈鐢ㄥ姵淇濊褰�
+//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+//
+//        LaborIssue laborIssue1 = new LaborIssue();
+//        laborIssue1.setAdoptedDate(new Date());
+//        laborIssue1.setIssueDate(sdf.parse(sdf.format(new Date())));
+//        List<LaborIssue> laborIssues = lavorIssueMapper.list(laborIssue1);  //staff_join_leave_record琛ㄨ鍒犻櫎
+//        if(!CollectionUtils.isEmpty(laborIssues)){
+//            for (LaborIssue laborIssue : laborIssues) {
+//                ApproveProcess approveProcess = new ApproveProcess();
+//                approveProcess.setApproveId(laborIssue.getOrderNo());
+//                approveProcess.setApproveDeptName(sysDeptMapper.selectDeptById(loginUser.getTenantId()).getDeptName());
+//                approveProcess.setApproveTime(laborIssue.getIssueDate());
+//                approveProcess.setApproveReason(laborIssue.getDictTypeName() + "-" + laborIssue.getDictName() + "瓒呮椂鏈鍙�");
+//                approveProcesses.add(approveProcess);
+//            }
+//        }
+
+
         return approveProcesses;
     }
 
@@ -581,6 +589,343 @@
         productionTurnoverDto.setProcessDetails(strings);
         productionTurnoverDto.setProcessQuantityDetails(processQuantityDetails);
         return productionTurnoverDto;
+    }
 
+    @Override
+    public DeptStaffDistributionDto deptStaffDistribution() {
+        DeptStaffDistributionDto dto = new DeptStaffDistributionDto();
+        List<MapDto> items = new ArrayList<>();
+
+        // 鏌ヨ鎵�鏈夋甯镐笖鏈垹闄ょ殑閮ㄩ棬
+        List<SysDept> depts = sysDeptMapper.selectDeptList(new SysDept());
+        if (CollectionUtils.isEmpty(depts)) {
+            dto.setItems(items);
+            return dto;
+        }
+
+        long totalUsers = 0;
+        List<Map<String, Object>> countsByDept = new ArrayList<>();
+
+        for (SysDept dept : depts) {
+            if ("0".equals(dept.getStatus()) && "0".equals(dept.getDelFlag())) {
+                Long count = sysUserDeptMapper.selectCount(new LambdaQueryWrapper<SysUserDept>()
+                        .eq(SysUserDept::getDeptId, dept.getDeptId()));
+                if (count > 0) {
+                    Map<String, Object> map = new HashMap<>();
+                    map.put("name", dept.getDeptName());
+                    map.put("count", count);
+                    countsByDept.add(map);
+                    totalUsers += count;
+                }
+            }
+        }
+
+        if (totalUsers > 0) {
+            BigDecimal total = BigDecimal.valueOf(totalUsers);
+            for (Map<String, Object> map : countsByDept) {
+                MapDto mapDto = new MapDto();
+                mapDto.setName((String) map.get("name"));
+                Long count = (Long) map.get("count");
+                mapDto.setValue(count.toString());
+                mapDto.setRate(BigDecimal.valueOf(count).multiply(new BigDecimal("100"))
+                        .divide(total, 2, RoundingMode.HALF_UP).toString());
+                items.add(mapDto);
+            }
+        }
+
+        dto.setTotal(totalUsers);
+        dto.setItems(items);
+        return dto;
+    }
+
+    @Override
+    public HomeSummaryDto summaryStatistics() {
+        HomeSummaryDto dto = new HomeSummaryDto();
+        LocalDate now = LocalDate.now();
+        YearMonth currentMonth = YearMonth.from(now);
+        YearMonth prevMonth = currentMonth.minusMonths(1);
+
+        LocalDateTime currentMonthEnd = currentMonth.atEndOfMonth().atTime(23, 59, 59);
+        LocalDateTime prevMonthEnd = prevMonth.atEndOfMonth().atTime(23, 59, 59);
+
+        //  鎬诲伐浣滀汉鍛�
+        Long currentStaff = countStaff(currentMonthEnd);
+        Long prevStaff = countStaff(prevMonthEnd);
+        dto.setTotalStaff(currentStaff);
+        dto.setStaffGrowthRate(calculateMoM(currentStaff, prevStaff));
+
+        //  鎬诲鎴锋暟
+        Long currentCustomers = countCustomers(currentMonthEnd);
+        Long prevCustomers = countCustomers(prevMonthEnd);
+        dto.setTotalCustomer(currentCustomers);
+        dto.setCustomerGrowthRate(calculateMoM(currentCustomers, prevCustomers));
+
+        //  鎬讳緵搴斿晢鏁�
+        Long currentSuppliers = countSuppliers(currentMonthEnd);
+        Long prevSuppliers = countSuppliers(prevMonthEnd);
+        dto.setTotalSupplier(currentSuppliers);
+        dto.setSupplierGrowthRate(calculateMoM(currentSuppliers, prevSuppliers));
+
+        return dto;
+    }
+
+    private Long countStaff(LocalDateTime dateTime) {
+        Long sysUserCount = sysUserMapper.selectCount(new LambdaQueryWrapper<SysUser>()
+                .eq(SysUser::getDelFlag, "0")
+                .le(SysUser::getCreateTime, dateTime));
+        Long staffCountItem = staffOnJobMapper.selectCount(new LambdaQueryWrapper<StaffOnJob>()
+                .le(StaffOnJob::getCreateTime, dateTime));
+        return sysUserCount + staffCountItem;
+    }
+
+
+    private Long countCustomers(LocalDateTime dateTime) {
+        return customerMapper.selectCount(new LambdaQueryWrapper<Customer>()
+                .le(Customer::getMaintenanceTime, dateTime.toLocalDate()));
+    }
+
+    private Long countSuppliers(LocalDateTime dateTime) {
+        return supplierManageMapper.selectCount(new LambdaQueryWrapper<SupplierManage>()
+                .le(SupplierManage::getCreateTime, dateTime));
+    }
+
+    private String calculateMoM(Number current, Number prev) {
+        BigDecimal curVal = new BigDecimal(current.toString());
+        BigDecimal prevVal = new BigDecimal(prev.toString());
+        if (prevVal.compareTo(BigDecimal.ZERO) == 0) {
+            return curVal.compareTo(BigDecimal.ZERO) > 0 ? "100.00" : "0.00";
+        }
+        return curVal.subtract(prevVal)
+                .divide(prevVal, 4, RoundingMode.HALF_UP)
+                .multiply(new BigDecimal("100"))
+                .setScale(2, RoundingMode.HALF_UP)
+                .toString();
+    }
+
+    @Override
+    public List<SupplierPurchaseRankingDto> supplierPurchaseRanking(Integer type) {
+        LocalDate today = LocalDate.now();
+        LocalDate startDate;
+        LocalDate endDate;
+        switch (type) {
+            case 1: // 鍛�
+                startDate = today.with(DayOfWeek.MONDAY);
+                endDate = today.with(DayOfWeek.SUNDAY);
+                break;
+            case 2: // 鏈�
+                startDate = today.with(TemporalAdjusters.firstDayOfMonth());
+                endDate = today.with(TemporalAdjusters.lastDayOfMonth());
+                break;
+            case 3: // 瀛e害
+                Month currentMonth = today.getMonth();
+                Month firstMonthOfQuarter = currentMonth.firstMonthOfQuarter();
+                Month lastMonthOfQuarter = Month.of(firstMonthOfQuarter.getValue() + 2);
+
+                startDate = today.withMonth(firstMonthOfQuarter.getValue()).with(TemporalAdjusters.firstDayOfMonth());
+                endDate = today.withMonth(lastMonthOfQuarter.getValue()).with(TemporalAdjusters.lastDayOfMonth());
+                break;
+            default:
+                return new ArrayList<>();
+        }
+
+        QueryWrapper<PurchaseLedger> queryWrapper = new QueryWrapper<>();
+        queryWrapper.select("supplier_name", "SUM(contract_amount) as total_amount")
+                .ge("entry_date", startDate)
+                .le("entry_date", endDate)
+//                .ne("approval_status", 3)
+                .groupBy("supplier_name")
+                .orderByDesc("total_amount")
+                .last("LIMIT 5");
+
+        List<Map<String, Object>> maps = purchaseLedgerMapper.selectMaps(queryWrapper);
+        return maps.stream().map(map -> {
+            SupplierPurchaseRankingDto dto = new SupplierPurchaseRankingDto();
+            dto.setSupplierName(map.get("supplier_name") != null ? map.get("supplier_name").toString() : "");
+            Object amount = map.get("total_amount");
+            dto.setTotalAmount(amount != null ? new BigDecimal(amount.toString()) : BigDecimal.ZERO);
+            return dto;
+        }).collect(Collectors.toList());
+    }
+
+    @Override
+    public CustomerRevenueAnalysisDto customerRevenueAnalysis(Long customerId, Integer type) {
+        CustomerRevenueAnalysisDto dto = new CustomerRevenueAnalysisDto();
+        List<MapDto> items = new ArrayList<>();
+        LocalDate today = LocalDate.now();
+
+        LocalDate start;
+        LocalDate end;
+        boolean groupByMonth = false;
+
+        switch (type) {
+            case 1: // 鍛�
+                start = today.with(DayOfWeek.MONDAY);
+                end = today.with(DayOfWeek.SUNDAY);
+                break;
+            case 2: // 鏈�
+                start = today.with(TemporalAdjusters.firstDayOfMonth());
+                end = today.with(TemporalAdjusters.lastDayOfMonth());
+                break;
+            case 3: // 瀛e害
+                Month firstMonthOfQuarter = today.getMonth().firstMonthOfQuarter();
+                start = today.withMonth(firstMonthOfQuarter.getValue()).with(TemporalAdjusters.firstDayOfMonth());
+                end = today.withMonth(firstMonthOfQuarter.plus(2).getValue()).with(TemporalAdjusters.lastDayOfMonth());
+                groupByMonth = true;
+                break;
+            default:
+                dto.setItems(items);
+                return dto;
+        }
+
+        List<SalesLedger> list = salesLedgerMapper.selectList(new LambdaQueryWrapper<SalesLedger>()
+                .eq(SalesLedger::getCustomerId, customerId)
+                .ge(SalesLedger::getEntryDate, start)
+                .le(SalesLedger::getEntryDate, end));
+
+        if (groupByMonth) {
+            for (int i = 0; i < 3; i++) {
+                LocalDate m = start.plusMonths(i);
+                String monthName = m.getMonthValue() + "鏈�";
+                BigDecimal sum = list.stream()
+                        .filter(l -> l.getEntryDate() != null)
+                        .filter(l -> {
+                            LocalDate ld = l.getEntryDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+                            return ld.getMonth() == m.getMonth() && ld.getYear() == m.getYear();
+                        })
+                        .map(SalesLedger::getContractAmount)
+                        .filter(Objects::nonNull)
+                        .reduce(BigDecimal.ZERO, BigDecimal::add);
+                MapDto mapDto = new MapDto();
+                mapDto.setName(monthName);
+                mapDto.setValue(sum.setScale(2, RoundingMode.HALF_UP).toString());
+                items.add(mapDto);
+            }
+        } else {
+            long days = ChronoUnit.DAYS.between(start, end) + 1;
+            for (int i = 0; i < days; i++) {
+                LocalDate d = start.plusDays(i);
+                String dayName = d.getMonthValue() + "/" + d.getDayOfMonth();
+                BigDecimal sum = list.stream()
+                        .filter(l -> l.getEntryDate() != null)
+                        .filter(l -> l.getEntryDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate().equals(d))
+                        .map(SalesLedger::getContractAmount)
+                        .filter(Objects::nonNull)
+                        .reduce(BigDecimal.ZERO, BigDecimal::add);
+                MapDto mapDto = new MapDto();
+                mapDto.setName(dayName);
+                mapDto.setValue(sum.setScale(2, RoundingMode.HALF_UP).toString());
+                items.add(mapDto);
+            }
+        }
+
+        dto.setItems(items);
+        return dto;
+    }
+
+    @Override
+    public ProductCategoryDistributionDto productCategoryDistribution() {
+        ProductCategoryDistributionDto dto = new ProductCategoryDistributionDto();
+        List<ProductCategoryDistributionDto.MajorCategoryDto> majorItems = new ArrayList<>();
+
+        // 鏌ヨ鎵�鏈夌殑浜у搧绫诲埆
+        List<Product> allProducts = productMapper.selectList(new LambdaQueryWrapper<>());
+        if (CollectionUtils.isEmpty(allProducts)) {
+            dto.setItems(majorItems);
+            return dto;
+        }
+
+        // 鍒嗙澶х被鍜屽皬绫�
+        List<Product> majorCategories = allProducts.stream()
+                .filter(p -> p.getParentId() == null)
+                .collect(Collectors.toList());
+        List<Product> minorCategories = allProducts.stream()
+                .filter(p -> p.getParentId() != null)
+                .collect(Collectors.toList());
+
+        // 鎸夌埗绫籌D瀵瑰皬绫昏繘琛屽垎缁�
+        Map<Long, List<Product>> minorGroupMap = minorCategories.stream()
+                .collect(Collectors.groupingBy(Product::getParentId));
+
+        int totalMinorCount = minorCategories.size();
+
+        for (Product major : majorCategories) {
+            ProductCategoryDistributionDto.MajorCategoryDto majorDto = new ProductCategoryDistributionDto.MajorCategoryDto();
+            majorDto.setName(major.getProductName());
+
+            List<Product> children = minorGroupMap.getOrDefault(major.getId(), new ArrayList<>());
+            int childrenSize = children.size();
+            // 璁剧疆灏忕被鐨勬�绘暟
+            majorDto.setValue(String.valueOf(childrenSize));
+
+            // 璁$畻鍗犳瘮
+            if (totalMinorCount > 0) {
+                BigDecimal rate = BigDecimal.valueOf(childrenSize)
+                        .multiply(new BigDecimal("100"))
+                        .divide(BigDecimal.valueOf(totalMinorCount), 2, RoundingMode.HALF_UP);
+                majorDto.setRate(rate.toString());
+            } else {
+                majorDto.setRate("0.00");
+            }
+
+            List<ProductCategoryDistributionDto.MinorCategoryDto> minorDtos = new ArrayList<>();
+            for (Product minor : children) {
+                ProductCategoryDistributionDto.MinorCategoryDto minorDto = new ProductCategoryDistributionDto.MinorCategoryDto();
+                minorDto.setName(minor.getProductName());
+                minorDto.setValue("0");
+                minorDto.setRate("0.00");
+                minorDto.setChildren(new ArrayList<>());
+                minorDtos.add(minorDto);
+            }
+            majorDto.setChildren(minorDtos);
+            majorItems.add(majorDto);
+        }
+
+        dto.setItems(majorItems);
+        return dto;
+    }
+
+    @Override
+    public List<CustomerContributionRankingDto> customerContributionRanking(Integer type) {
+        LocalDate today = LocalDate.now();
+        LocalDate startDate = null;
+        LocalDate endDate = null;
+        switch (type) {
+            case 1:
+                startDate = today.with(DayOfWeek.MONDAY);
+                endDate = today.with(DayOfWeek.SUNDAY);
+                break;
+            case 2:
+                startDate = today.with(TemporalAdjusters.firstDayOfMonth());
+                endDate = today.with(TemporalAdjusters.lastDayOfMonth());
+                break;
+            case 3:
+                Month currentMonth = today.getMonth();
+                Month firstMonthOfQuarter = currentMonth.firstMonthOfQuarter();
+                Month lastMonthOfQuarter = Month.of(firstMonthOfQuarter.getValue() + 2);
+                startDate = today.withMonth(firstMonthOfQuarter.getValue()).with(TemporalAdjusters.firstDayOfMonth());
+                endDate = today.withMonth(lastMonthOfQuarter.getValue()).with(TemporalAdjusters.lastDayOfMonth());
+                break;
+        }
+
+        QueryWrapper<SalesLedger> queryWrapper = new QueryWrapper<>();
+        queryWrapper.select("customer_name", "SUM(contract_amount) as total_amount")
+                .isNotNull("customer_name")
+                .groupBy("customer_name")
+                .orderByDesc("total_amount")
+                .last("LIMIT 5");
+
+        if (startDate != null && endDate != null) {
+            queryWrapper.between("entry_date", startDate, endDate);
+        }
+
+        List<Map<String, Object>> maps = salesLedgerMapper.selectMaps(queryWrapper);
+        List<CustomerContributionRankingDto> result = new ArrayList<>();
+        for (Map<String, Object> map : maps) {
+            CustomerContributionRankingDto rankingDto = new CustomerContributionRankingDto();
+            rankingDto.setCustomerName(map.get("customer_name").toString());
+            rankingDto.setTotalAmount(map.get("total_amount") != null ? new BigDecimal(map.get("total_amount").toString()) : BigDecimal.ZERO);
+            result.add(rankingDto);
+        }
+        return result;
     }
 }

--
Gitblit v1.9.3