liding
6 天以前 360f96ffb62a0ba418c0de0a4a5b5f537912872e
首页数据
已修改11个文件
已添加1个文件
551 ■■■■ 文件已修改
src/main/java/com/ruoyi/purchase/controller/PaymentRegistrationController.java 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/purchase/service/IPaymentRegistrationService.java 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java 270 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/controller/ReceiptPaymentController.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/controller/SalesLedgerController.java 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/dto/MonthlyAmountDto.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/mapper/SalesLedgerMapper.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/service/ISalesLedgerService.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/service/ReceiptPaymentService.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/service/impl/InvoiceLedgerServiceImpl.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/service/impl/ReceiptPaymentServiceImpl.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java 125 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/purchase/controller/PaymentRegistrationController.java
@@ -1,5 +1,7 @@
package com.ruoyi.purchase.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
@@ -13,6 +15,7 @@
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
 * ä»˜æ¬¾ç™»è®°Controller
@@ -22,8 +25,7 @@
 */
@RestController
@RequestMapping("/purchase/paymentRegistration")
public class PaymentRegistrationController extends BaseController
{
public class PaymentRegistrationController extends BaseController {
    @Autowired
    private IPaymentRegistrationService paymentRegistrationService;
@@ -32,8 +34,7 @@
     */
//    @PreAuthorize("@ss.hasPermi('system:registration:list')")
    @GetMapping("/list")
    public TableDataInfo list(PaymentRegistrationDto paymentRegistrationDto)
    {
    public TableDataInfo list(PaymentRegistrationDto paymentRegistrationDto) {
        startPage();
        List<PaymentRegistrationDto> list = paymentRegistrationService.selectPaymentRegistrationList(paymentRegistrationDto);
        return getDataTable(list);
@@ -55,8 +56,7 @@
     * èŽ·å–ä»˜æ¬¾ç™»è®°è¯¦ç»†ä¿¡æ¯
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(paymentRegistrationService.selectPaymentRegistrationById(id));
    }
@@ -65,8 +65,7 @@
     */
    @Log(title = "付款登记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PaymentRegistration paymentRegistration)
    {
    public AjaxResult add(@RequestBody PaymentRegistration paymentRegistration) {
        return toAjax(paymentRegistrationService.insertPaymentRegistration(paymentRegistration));
    }
@@ -75,8 +74,7 @@
     */
    @Log(title = "付款登记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PaymentRegistration paymentRegistration)
    {
    public AjaxResult edit(@RequestBody PaymentRegistration paymentRegistration) {
        return toAjax(paymentRegistrationService.updatePaymentRegistration(paymentRegistration));
    }
@@ -85,8 +83,7 @@
     */
    @Log(title = "付款登记", businessType = BusinessType.DELETE)
    @DeleteMapping("/del")
    public AjaxResult remove(@RequestBody Long[] ids)
    {
    public AjaxResult remove(@RequestBody Long[] ids) {
        return toAjax(paymentRegistrationService.deletePaymentRegistrationByIds(ids));
    }
@@ -94,8 +91,7 @@
     * èŽ·å–ä»˜æ¬¾ç™»è®°è¯¦ç»†ä¿¡æ¯
     */
    @GetMapping(value = "/byPurchaseId/{id}")
    public AjaxResult getPurchaseInfo(@PathVariable("id") Long id)
    {
    public AjaxResult getPurchaseInfo(@PathVariable("id") Long id) {
        return success(paymentRegistrationService.selectPaymentRegistrationByPurchaseId(id));
    }
@@ -103,8 +99,18 @@
     * èŽ·å–ä»˜æ¬¾ç™»è®°è¯¦ç»†ä¿¡æ¯
     */
    @GetMapping(value = "/paymentLedgerList")
    public AjaxResult paymentLedgerList(PaymentLedgerDto paymentLedgerDto)
    {
        return success(paymentRegistrationService.selectPaymentLedgerList(paymentLedgerDto));
    public AjaxResult paymentLedgerList(PaymentLedgerDto paymentLedgerDto, Page page,
                                        Integer detailPageNum,
                                        Integer detailPageSize) {
        IPage<Map<String, Object>> mapIPage = paymentRegistrationService.selectPaymentLedgerList(paymentLedgerDto, page, detailPageNum, detailPageSize);
        return success(mapIPage);
    }
    /**
     * èŽ·å–æœ¬æœˆåº”ä»˜ä¿¡æ¯
     */
    @GetMapping(value = "/paymentMonthList")
    public AjaxResult paymentMonthList() {
        return success(paymentRegistrationService.paymentMonthList());
    }
}
src/main/java/com/ruoyi/purchase/service/IPaymentRegistrationService.java
@@ -1,10 +1,13 @@
package com.ruoyi.purchase.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.purchase.dto.PaymentLedgerDto;
import com.ruoyi.purchase.dto.PaymentRegistrationDto;
import com.ruoyi.purchase.pojo.PaymentRegistration;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
@@ -63,5 +66,9 @@
     */
    PaymentRegistration selectPaymentRegistrationByPurchaseId(Long purchaseId);
    List<Map<String, Object>> selectPaymentLedgerList(PaymentLedgerDto paymentLedgerDto);
    IPage<Map<String, Object>> selectPaymentLedgerList(PaymentLedgerDto paymentLedgerDto, Page page,
                                                       Integer detailPageNum,
                                                       Integer detailPageSize);
    Map<String, BigDecimal> paymentMonthList();
}
src/main/java/com/ruoyi/purchase/service/impl/PaymentRegistrationServiceImpl.java
@@ -2,7 +2,9 @@
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.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.basic.mapper.SupplierManageMapper;
import com.ruoyi.basic.pojo.SupplierManage;
@@ -27,6 +29,8 @@
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.YearMonth;
import java.util.*;
import java.util.stream.Collectors;
@@ -176,8 +180,11 @@
    }
    @Override
    public List<Map<String, Object>> selectPaymentLedgerList(PaymentLedgerDto paymentLedgerDto) {
        List<Map<String, Object>> result = new ArrayList<>();
    public IPage<Map<String, Object>> selectPaymentLedgerList(
            PaymentLedgerDto paymentLedgerDto,
            Page page,
            Integer detailPageNum,
            Integer detailPageSize) {
        LambdaQueryWrapper<SupplierManage> queryWrapper = new LambdaQueryWrapper<>();
        Optional.ofNullable(paymentLedgerDto)
                .ifPresent(dto -> {
@@ -186,80 +193,223 @@
                    }
                });
        List<SupplierManage> supplierManages = supplierManageMapper.selectList(queryWrapper);
        IPage<SupplierManage> supplierPage = supplierManageMapper.selectPage(page, queryWrapper);
        List<SupplierManage> supplierManages = supplierPage.getRecords();
        IPage<Map<String, Object>> resultPage = new Page<>(page.getCurrent(), page.getSize(), supplierPage.getTotal());
        List<Map<String, Object>> result = new ArrayList<>();
        for (SupplierManage supplierManage : supplierManages) {
            Map<String, Object> res = new HashMap<>();
            res.put("supplierName", supplierManage.getSupplierName());
            // åº”付金额
            // åº”付金额计算
            BigDecimal payableAmount = BigDecimal.ZERO;
            List<PurchaseLedger> purchaseLedgers = purchaseLedgerMapper.selectList(new QueryWrapper<PurchaseLedger>().eq("supplier_id", supplierManage.getId()));
            if (purchaseLedgers != null && purchaseLedgers.size() > 0) {
                List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectList(new QueryWrapper<SalesLedgerProduct>()
                        .in("sales_ledger_id", purchaseLedgers.stream().map(PurchaseLedger::getId).collect(Collectors.toList())));
                // åº”付金额
                payableAmount = salesLedgerProducts.stream().map(SalesLedgerProduct::getTaxInclusiveTotalPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
            }
            BigDecimal invoiceAmount = BigDecimal.ZERO;
            List<TicketRegistration> ticketRegistrations = Collections.emptyList();
            // å¢žåŠ ç©ºå€¼æ£€æŸ¥ï¼Œé¿å…NullPointerException
            if (CollectionUtils.isNotEmpty(purchaseLedgers)) {
                Long[] ids = purchaseLedgers.stream()
                        .map(PurchaseLedger::getId)
                        .toArray(Long[]::new);
                // æ£€æŸ¥æ•°ç»„是否有元素
                if (ids.length > 0) {
                    ticketRegistrations = ticketRegistrationMapper.selectList(
                            new LambdaQueryWrapper<TicketRegistration>()
                                    .in(TicketRegistration::getPurchaseLedgerId, ids)
            List<PurchaseLedger> purchaseLedgers = purchaseLedgerMapper.selectList(
                    new QueryWrapper<PurchaseLedger>().eq("supplier_id", supplierManage.getId())
                    );
                }
            }
            if (ticketRegistrations != null && ticketRegistrations.size() > 0) {
                // æ¥ç¥¨é‡‘额
                invoiceAmount = ticketRegistrations.stream().map(TicketRegistration::getInvoiceAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
            }
            // ä»˜æ¬¾é‡‘额
            List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectList(new QueryWrapper<PaymentRegistration>()
                    .eq("supplier_id", supplierManage.getId()));
            List<SalesLedgerProduct> salesLedgerProducts = purchaseLedgers.stream()
                    .filter(Objects::nonNull)
                    .map(PurchaseLedger::getId)
                    .filter(Objects::nonNull)
                    .flatMap(id -> salesLedgerProductMapper.selectList(
                            new QueryWrapper<SalesLedgerProduct>().eq("sales_ledger_id", id)
                    ).stream())
                    .collect(Collectors.toList());
            payableAmount = salesLedgerProducts.stream()
                    .map(SalesLedgerProduct::getTaxInclusiveTotalPrice)
                    .filter(Objects::nonNull)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal paymentAmount = BigDecimal.ZERO;
            if (paymentRegistrations != null && paymentRegistrations.size() > 0) {
                paymentAmount = paymentRegistrations.stream().map(PaymentRegistration::getCurrentPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
            // æ¥ç¥¨é‡‘额计算
            List<TicketRegistration> ticketRegistrations = purchaseLedgers.stream()
                    .map(PurchaseLedger::getId)
                    .filter(Objects::nonNull)
                    .map(id -> ticketRegistrationMapper.selectList(
                            new LambdaQueryWrapper<TicketRegistration>().eq(TicketRegistration::getPurchaseLedgerId, id)
                    ))
                    .flatMap(Collection::stream)
                    .collect(Collectors.toList());
            BigDecimal invoiceAmount = ticketRegistrations.stream()
                    .map(TicketRegistration::getInvoiceAmount)
                    .filter(Objects::nonNull)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);
            // ä»˜æ¬¾è®°å½•及详情分页
            List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectList(
                    new QueryWrapper<PaymentRegistration>().eq("supplier_id", supplierManage.getId())
            );
            BigDecimal paymentAmount = paymentRegistrations.stream()
                    .map(PaymentRegistration::getCurrentPaymentAmount)
                    .filter(Objects::nonNull)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);
            // è¯¦æƒ…分页处理
            detailPageNum = detailPageNum != null ? detailPageNum : 1;
            detailPageSize = detailPageSize != null ? detailPageSize : paymentRegistrations.size(); // é»˜è®¤æ˜¾ç¤ºå…¨éƒ¨
            int totalDetails = paymentRegistrations.size();
            int start = (detailPageNum - 1) * detailPageSize;
            int end = Math.min(start + detailPageSize, totalDetails);
            List<PaymentRegistration> pagedDetails = paymentRegistrations.subList(start, end);
            // æž„建详情列表
            List<Map<String, Object>> details = pagedDetails.stream()
                    .filter(Objects::nonNull)
                    .map(pr -> {
                        Map<String, Object> detail = new HashMap<>();
                        detail.put("paymentAmount", pr.getCurrentPaymentAmount());
                        // æ‰¹é‡æŸ¥è¯¢ TicketRegistration(避免 N+1)
                        TicketRegistration ticketRegistration = ticketRegistrationMapper.selectById(pr.getTicketRegistrationId());
                        if (ticketRegistration != null) {
                            detail.put("payableAmount", ticketRegistration.getInvoiceAmount());
                            BigDecimal voteCount = productRecordMapper.selectList(
                                            new LambdaQueryWrapper<ProductRecord>().eq(ProductRecord::getTicketRegistrationId, ticketRegistration.getId())
                                    ).stream()
                                    .map(ProductRecord::getTicketsNum)
                                    .map(BigDecimal::new)
                                    .filter(Objects::nonNull)
                                    .reduce(BigDecimal.ZERO, BigDecimal::add);
                            detail.put("voteCount", voteCount);
            }
                        // æ—¥æœŸæ ¼å¼åŒ–(建议使用 LocalDateTime)
                        if (pr.getPaymentDate() != null) {
                            detail.put("paymentDate", new SimpleDateFormat("yyyy-MM-dd").format(pr.getPaymentDate()));
                        }
                        return detail;
                    })
                    .collect(Collectors.toList());
            // å°è£…详情分页元数据
            Map<String, Object> detailPagination = new HashMap<>();
            detailPagination.put("total", totalDetails);
            detailPagination.put("pageNum", detailPageNum);
            detailPagination.put("pageSize", detailPageSize);
            detailPagination.put("pages", (int) Math.ceil((double) totalDetails / detailPageSize));
            res.put("invoiceAmount", invoiceAmount);
            res.put("payableAmount", payableAmount);
            res.put("paymentAmount", paymentAmount);
            // è¯¦æƒ…
            List<Map<String, Object>> details = new ArrayList<>();
            for (PaymentRegistration paymentRegistration : paymentRegistrations) {
                Map<String, Object> detail = new HashMap<>();
                detail.put("paymentAmount", paymentRegistration.getCurrentPaymentAmount()); // ä»˜æ¬¾é‡‘额
                TicketRegistration ticketRegistration = ticketRegistrationMapper.selectById(paymentRegistration.getTicketRegistrationId());
                detail.put("payableAmount", ticketRegistration.getInvoiceAmount()); // åº”付金额
                BigDecimal voteCount = productRecordMapper.selectList(
                                new LambdaQueryWrapper<ProductRecord>()
                                        .eq(ProductRecord::getTicketRegistrationId, ticketRegistration.getId()))
                        .stream()
                        .map(ProductRecord::getTicketsNum)
                        .map(BigDecimal::new)
                        .reduce(BigDecimal.ZERO, BigDecimal::add);
                detail.put("voteCount", voteCount); // ç¥¨æ•°
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                String formattedDate = sdf.format(paymentRegistration.getPaymentDate());
                detail.put("paymentDate", formattedDate); // å‘生时间
                details.add(detail);
            }
            res.put("details", details);
            res.put("detailPagination", detailPagination); // æ·»åŠ è¯¦æƒ…åˆ†é¡µä¿¡æ¯
            result.add(res);
        }
        resultPage.setRecords(result);
        return resultPage;
    }
    @Override
    public Map<String, BigDecimal> paymentMonthList() {
        // æŸ¥è¯¢ä¾›åº”商列表
        List<SupplierManage> suppliers = supplierManageMapper.selectList(null);
        if (CollectionUtils.isEmpty(suppliers)) {
            Map<String, BigDecimal> result = new HashMap<>();
            result.put("payableAmount", BigDecimal.ZERO);
            result.put("paymentAmount", BigDecimal.ZERO);
        return result;
    }
        // æå–所有供应商ID
        List<Long> supplierIds = suppliers.stream()
                .map(SupplierManage::getId) // å…ˆèŽ·å–Integer类型的ID
                .filter(Objects::nonNull)    // è¿‡æ»¤æŽ‰å¯èƒ½çš„null值
                .map(Integer::longValue)    // å°†Integer转换为Long
                .collect(Collectors.toList());
        // èŽ·å–å½“æœˆçš„å¼€å§‹å’Œç»“æŸæ—¥æœŸ
        YearMonth currentMonth = YearMonth.now();
        LocalDate startDate = currentMonth.atDay(1);
        LocalDate endDate = currentMonth.atEndOfMonth();
        // æ‰¹é‡æŸ¥è¯¢é‡‡è´­å°è´¦ï¼ˆå½“月)
        Map<Long, List<PurchaseLedger>> purchaseLedgerMap = batchQueryPurchaseLedgers(supplierIds, startDate, endDate);
        // æ‰¹é‡æŸ¥è¯¢é”€å”®å°è´¦äº§å“
        Map<Long, List<SalesLedgerProduct>> salesLedgerProductMap = batchQuerySalesLedgerProducts(purchaseLedgerMap);
        // æ‰¹é‡æŸ¥è¯¢ä»˜æ¬¾è®°å½•(当月)
        Map<Long, List<PaymentRegistration>> paymentRegistrationMap = batchQueryPaymentRegistrations(supplierIds, startDate, endDate);
        // è®¡ç®—应付金额和付款金额
        BigDecimal totalPayableAmount = calculateTotalPayableAmount(purchaseLedgerMap, salesLedgerProductMap);
        BigDecimal totalPaymentAmount = calculateTotalPaymentAmount(paymentRegistrationMap);
        // æž„建结果
        Map<String, BigDecimal> result = new HashMap<>();
        result.put("payableAmount", totalPayableAmount);
        result.put("paymentAmount", totalPaymentAmount);
        return result;
    }
    // æ‰¹é‡æŸ¥è¯¢é‡‡è´­å°è´¦ï¼ˆå½“月)
    private Map<Long, List<PurchaseLedger>> batchQueryPurchaseLedgers(List<Long> supplierIds, LocalDate startDate, LocalDate endDate) {
        LambdaQueryWrapper<PurchaseLedger> query = new LambdaQueryWrapper<>();
        query.in(PurchaseLedger::getSupplierId, supplierIds)
                .ge(PurchaseLedger::getCreatedAt, startDate)
                .le(PurchaseLedger::getCreatedAt, endDate);
        List<PurchaseLedger> purchaseLedgers = purchaseLedgerMapper.selectList(query);
        return purchaseLedgers.stream()
                .filter(pl -> pl.getSupplierId() != null)
                .collect(Collectors.groupingBy(PurchaseLedger::getSupplierId));
    }
    // æ‰¹é‡æŸ¥è¯¢é”€å”®å°è´¦äº§å“
    private Map<Long, List<SalesLedgerProduct>> batchQuerySalesLedgerProducts(Map<Long, List<PurchaseLedger>> purchaseLedgerMap) {
        // æå–所有采购台账ID
        List<Long> purchaseLedgerIds = purchaseLedgerMap.values().stream()
                .flatMap(Collection::stream)
                .map(PurchaseLedger::getId)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
        if (purchaseLedgerIds.isEmpty()) {
            return Collections.emptyMap();
        }
        LambdaQueryWrapper<SalesLedgerProduct> query = new LambdaQueryWrapper<>();
        query.in(SalesLedgerProduct::getSalesLedgerId, purchaseLedgerIds);
        List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(query);
        return products.stream()
                .filter(slp -> slp.getSalesLedgerId() != null)
                .collect(Collectors.groupingBy(SalesLedgerProduct::getSalesLedgerId));
    }
    // æ‰¹é‡æŸ¥è¯¢ä»˜æ¬¾è®°å½•(当月)
    private Map<Long, List<PaymentRegistration>> batchQueryPaymentRegistrations(List<Long> supplierIds, LocalDate startDate, LocalDate endDate) {
        LambdaQueryWrapper<PaymentRegistration> query = new LambdaQueryWrapper<>();
        query.in(PaymentRegistration::getSupplierId, supplierIds)
                .ge(PaymentRegistration::getPaymentDate, startDate)
                .le(PaymentRegistration::getPaymentDate, endDate);
        List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectList(query);
        return paymentRegistrations.stream()
                .filter(pr -> pr.getSupplierId() != null)
                .collect(Collectors.groupingBy(PaymentRegistration::getSupplierId));
    }
    // è®¡ç®—总应付金额
    private BigDecimal calculateTotalPayableAmount(Map<Long, List<PurchaseLedger>> purchaseLedgerMap,
                                                   Map<Long, List<SalesLedgerProduct>> salesLedgerProductMap) {
        return purchaseLedgerMap.values().stream()
                .flatMap(Collection::stream)
                .map(pl -> salesLedgerProductMap.getOrDefault(pl.getId(), Collections.emptyList()))
                .flatMap(Collection::stream)
                .map(SalesLedgerProduct::getTaxInclusiveTotalPrice)
                .filter(Objects::nonNull)
                .reduce(BigDecimal.ZERO, BigDecimal::add);
    }
    // è®¡ç®—总付款金额
    private BigDecimal calculateTotalPaymentAmount(Map<Long, List<PaymentRegistration>> paymentRegistrationMap) {
        return paymentRegistrationMap.values().stream()
                .flatMap(Collection::stream)
                .map(PaymentRegistration::getCurrentPaymentAmount)
                .filter(Objects::nonNull)
                .reduce(BigDecimal.ZERO, BigDecimal::add);
    }
}
src/main/java/com/ruoyi/sales/controller/ReceiptPaymentController.java
@@ -76,10 +76,10 @@
    @GetMapping("/getReceiptAmount")
    public AjaxResult getReceiptAmount() {
        try {
            BigDecimal amount = receiptPaymentService.getReceiptAmount();
            return AjaxResult.success(amount != null ? amount : BigDecimal.ZERO);
            BigDecimal receiptAmount = receiptPaymentService.getReceiptAmount();
            return AjaxResult.success(receiptAmount != null ? receiptAmount : BigDecimal.ZERO);
        } catch (Exception e) {
            return AjaxResult.error("获取合同金额失败:" + e.getMessage());
            return AjaxResult.error("获取回款金额失败:" + e.getMessage());
        }
    }
@@ -103,4 +103,12 @@
    public AjaxResult invoiceInfo (Integer id) {
        return AjaxResult.success(receiptPaymentService.invoiceInfo(id));
    }
    /**
     * æœ¬æœˆåº”æ”¶,回款金额
     */
    @GetMapping("/getAmountMouth")
    public AjaxResult getAmountMouth() {
        return  AjaxResult.success(receiptPaymentService.getAmountMouth());
    }
}
src/main/java/com/ruoyi/sales/controller/SalesLedgerController.java
@@ -112,8 +112,8 @@
    @GetMapping("/getContractAmount")
    public AjaxResult getContractAmount() {
        try {
            BigDecimal amount = salesLedgerService.getContractAmount();
            return AjaxResult.success(amount != null ? amount : BigDecimal.ZERO);
            BigDecimal contractAmount = salesLedgerService.getContractAmount();
            return AjaxResult.success(contractAmount != null ? contractAmount : BigDecimal.ZERO);
        } catch (Exception e) {
            return AjaxResult.error("获取合同金额失败:" + e.getMessage());
        }
@@ -126,4 +126,12 @@
    public AjaxResult getTopFiveList() {
        return AjaxResult.success(salesLedgerService.getTopFiveList());
    }
    /**
     * è¿‘半年开票,回款金额
     */
    @GetMapping("/getAmountHalfYear")
    public AjaxResult getAmountHalfYear() {
        return AjaxResult.success(salesLedgerService.getAmountHalfYear());
    }
}
src/main/java/com/ruoyi/sales/dto/MonthlyAmountDto.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,13 @@
package com.ruoyi.sales.dto;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class MonthlyAmountDto {
    private String month;
    private BigDecimal invoiceAmount; // å¼€ç¥¨é‡‘额
    private BigDecimal receiptAmount; // å›žæ¬¾é‡‘额
}
src/main/java/com/ruoyi/sales/mapper/SalesLedgerMapper.java
@@ -1,9 +1,13 @@
package com.ruoyi.sales.mapper;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.ruoyi.sales.pojo.SalesLedger;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.List;
/**
@@ -21,4 +25,6 @@
    List<Integer> selectSequencesByDate(@Param("datePart") String datePart);
    List getSalesNo();
    <T> BigDecimal selectSum(LambdaQueryWrapper<T> wrapper, SFunction<T, BigDecimal> column);
}
src/main/java/com/ruoyi/sales/service/ISalesLedgerService.java
@@ -1,6 +1,7 @@
package com.ruoyi.sales.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.sales.dto.MonthlyAmountDto;
import com.ruoyi.sales.dto.SalesLedgerDto;
import com.ruoyi.sales.pojo.SalesLedger;
@@ -28,4 +29,6 @@
    BigDecimal getContractAmount();
    List getTopFiveList();
    List<MonthlyAmountDto> getAmountHalfYear();
}
src/main/java/com/ruoyi/sales/service/ReceiptPaymentService.java
@@ -8,6 +8,7 @@
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
public interface ReceiptPaymentService {
@@ -63,4 +64,6 @@
     * @return
     */
    InvoiceLedgerDto invoiceInfo(Integer id);
    Map<String,BigDecimal> getAmountMouth();
}
src/main/java/com/ruoyi/sales/service/impl/InvoiceLedgerServiceImpl.java
@@ -13,11 +13,8 @@
import com.ruoyi.sales.mapper.InvoiceLedgerFileMapper;
import com.ruoyi.sales.mapper.InvoiceLedgerMapper;
import com.ruoyi.sales.mapper.InvoiceRegistrationProductMapper;
import com.ruoyi.sales.mapper.ReceiptPaymentMapper;
import com.ruoyi.sales.pojo.InvoiceLedger;
import com.ruoyi.sales.pojo.InvoiceLedgerFile;
import com.ruoyi.sales.pojo.InvoiceRegistrationProduct;
import com.ruoyi.sales.pojo.ReceiptPayment;
import com.ruoyi.sales.service.InvoiceLedgerService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
@@ -33,7 +30,6 @@
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.YearMonth;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
@@ -258,13 +254,12 @@
        // æ‰§è¡ŒæŸ¥è¯¢å¹¶è®¡ç®—总和
        List<InvoiceLedger> invoiceLedgers = invoiceLedgerMapper.selectList(queryWrapper);
//        BigDecimal totalContractAmount = invoiceLedgers.stream()
//                .map(InvoiceLedger::getInvoiceAmount)
//                .filter(Objects::nonNull)
//                .reduce(BigDecimal.ZERO, BigDecimal::add);
//
//        return totalContractAmount;
        return null;
        BigDecimal totalContractAmount = invoiceLedgers.stream()
                .map(InvoiceLedger::getInvoiceTotal)
                .filter(Objects::nonNull)
                .reduce(BigDecimal.ZERO, BigDecimal::add);
        return totalContractAmount;
    }
    /**
src/main/java/com/ruoyi/sales/service/impl/ReceiptPaymentServiceImpl.java
@@ -7,7 +7,9 @@
import com.ruoyi.sales.dto.InvoiceLedgerDto;
import com.ruoyi.sales.dto.ReceiptPaymentDto;
import com.ruoyi.sales.mapper.ReceiptPaymentMapper;
import com.ruoyi.sales.mapper.SalesLedgerMapper;
import com.ruoyi.sales.pojo.ReceiptPayment;
import com.ruoyi.sales.pojo.SalesLedger;
import com.ruoyi.sales.service.ReceiptPaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -17,7 +19,9 @@
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.YearMonth;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Service
@@ -25,6 +29,9 @@
    @Autowired
    private ReceiptPaymentMapper receiptPaymentMapper;
    @Autowired
    private SalesLedgerMapper salesLedgerMapper;
    /**
     * å›žæ¬¾ç™»è®°æ–°å¢ž
@@ -140,4 +147,34 @@
    public InvoiceLedgerDto invoiceInfo(Integer id) {
        return receiptPaymentMapper.invoiceInfo(id);
    }
    @Override
    public Map<String,BigDecimal> getAmountMouth() {
        List<SalesLedger> salesLedgers = salesLedgerMapper.selectList(null);
        BigDecimal contractAmount = salesLedgers.stream().map(SalesLedger::getContractAmount)
                .filter(Objects::nonNull)
                .reduce(BigDecimal.ZERO, BigDecimal::add);
        LocalDate now = LocalDate.now();
        YearMonth currentMonth = YearMonth.from(now);
        // åˆ›å»ºLambdaQueryWrapper
        LambdaQueryWrapper<ReceiptPayment> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.ge(ReceiptPayment::getReceiptPaymentDate, currentMonth.atDay(1).atStartOfDay())  // å¤§äºŽç­‰äºŽæœ¬æœˆç¬¬ä¸€å¤©
                .lt(ReceiptPayment::getReceiptPaymentDate, currentMonth.plusMonths(1).atDay(1).atStartOfDay()); // å°äºŽä¸‹æœˆç¬¬ä¸€å¤©
        // æ‰§è¡ŒæŸ¥è¯¢å¹¶è®¡ç®—总和
        List<ReceiptPayment> receiptPayments = receiptPaymentMapper.selectList(queryWrapper);
        BigDecimal receiveAmount = receiptPayments.stream()
                .map(ReceiptPayment::getReceiptPaymentAmount)
                .filter(Objects::nonNull)
                .reduce(BigDecimal.ZERO, BigDecimal::add);
        // æž„建结果
        Map<String, BigDecimal> result = new HashMap<>();
        result.put("receiveAmount", receiveAmount);
        result.put("contractAmount", contractAmount);
        return result;
    }
}
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -1,7 +1,6 @@
package com.ruoyi.sales.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -12,15 +11,10 @@
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.other.mapper.TempFileMapper;
import com.ruoyi.other.pojo.TempFile;
import com.ruoyi.sales.dto.MonthlyAmountDto;
import com.ruoyi.sales.dto.SalesLedgerDto;
import com.ruoyi.sales.mapper.CommonFileMapper;
import com.ruoyi.sales.mapper.InvoiceRegistrationProductMapper;
import com.ruoyi.sales.mapper.SalesLedgerMapper;
import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
import com.ruoyi.sales.pojo.CommonFile;
import com.ruoyi.sales.pojo.InvoiceRegistrationProduct;
import com.ruoyi.sales.pojo.SalesLedger;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import com.ruoyi.sales.mapper.*;
import com.ruoyi.sales.pojo.*;
import com.ruoyi.sales.service.ISalesLedgerService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -32,7 +26,6 @@
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import java.io.IOException;
import java.lang.reflect.Field;
@@ -70,6 +63,10 @@
    private final CommonFileMapper commonFileMapper;
    private final TempFileMapper tempFileMapper;
    private final ReceiptPaymentMapper receiptPaymentMapper;
    private final InvoiceLedgerMapper invoiceLedgerMapper;
    @Autowired
    private InvoiceRegistrationProductMapper invoiceRegistrationProductMapper;
@@ -159,8 +156,114 @@
    @Override
    public List getTopFiveList() {
        // æŸ¥è¯¢åŽŸå§‹æ•°æ®
        LambdaQueryWrapper<SalesLedger> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.select(SalesLedger::getCustomerId,
                        SalesLedger::getCustomerName,
                        SalesLedger::getContractAmount)
                .orderByDesc(SalesLedger::getContractAmount);
        List<SalesLedger> records = salesLedgerMapper.selectList(queryWrapper);
        
        return null;
        // æŒ‰å®¢æˆ·ID分组并聚合金额
        Map<Long, GroupedCustomer> groupedMap = new LinkedHashMap<>(); // ä½¿ç”¨LinkedHashMap保持排序
        for (SalesLedger record : records) {
            groupedMap.computeIfAbsent(record.getCustomerId(),
                            k -> new GroupedCustomer(record.getCustomerId(), record.getCustomerName()))
                    .addAmount(record.getContractAmount());
        }
        // è½¬æ¢ä¸ºç»“果列表并取前5
        return groupedMap.values().stream()
                .sorted(Comparator.comparing(GroupedCustomer::getTotalAmount).reversed())
                .limit(5)
                .map(customer -> {
                    Map<String, Object> result = new HashMap<>();
                    result.put("customerId", customer.getCustomerId());
                    result.put("customerName", customer.getCustomerName());
                    result.put("totalAmount", customer.getTotalAmount());
                    return result;
                })
                .collect(Collectors.toList());
    }
    @Override
    public List<MonthlyAmountDto> getAmountHalfYear() {
        LocalDate now = LocalDate.now();
        YearMonth currentMonth = YearMonth.from(now);
        List<MonthlyAmountDto> monthlyAmounts = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            YearMonth targetMonth = currentMonth.minusMonths(i);
            LocalDate firstDayOfMonth = targetMonth.atDay(1);
            LocalDate firstDayOfNextMonth = targetMonth.plusMonths(1).atDay(1);
            LocalDateTime startOfMonth = firstDayOfMonth.atStartOfDay();
            LocalDateTime startOfNextMonth = firstDayOfNextMonth.atStartOfDay();
            LambdaQueryWrapper<ReceiptPayment> receiptPaymentLambdaQueryWrapper = new LambdaQueryWrapper<>();
            receiptPaymentLambdaQueryWrapper.ge(ReceiptPayment::getCreateTime, startOfMonth)
                    .lt(ReceiptPayment::getCreateTime, startOfNextMonth);
            LambdaQueryWrapper<InvoiceLedger> invoiceLedgerLambdaQueryWrapper = new LambdaQueryWrapper<>();
            invoiceLedgerLambdaQueryWrapper.ge(InvoiceLedger::getCreateTime, startOfMonth)
                    .lt(InvoiceLedger::getCreateTime, startOfNextMonth);
            // èŽ·å–å›žæ¬¾é‡‘é¢
            List<ReceiptPayment> receiptPaymentList = receiptPaymentMapper.selectList(receiptPaymentLambdaQueryWrapper);
            //开票金额
            List<InvoiceLedger> invoiceLedgerList = invoiceLedgerMapper.selectList(invoiceLedgerLambdaQueryWrapper);
            // ä½¿ç”¨ Stream æ±‚å’Œ
            BigDecimal invoiceAmount = invoiceLedgerList.stream()
                    .map(InvoiceLedger::getInvoiceTotal)
                    .filter(Objects::nonNull)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal receiptAmount = receiptPaymentList.stream()
                    .map(ReceiptPayment::getReceiptPaymentAmount)
                    .filter(Objects::nonNull)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);
            MonthlyAmountDto monthlyAmount = new MonthlyAmountDto();
            monthlyAmount.setMonth(targetMonth.format(DateTimeFormatter.ofPattern("yyyy-MM")));
            monthlyAmount.setInvoiceAmount(invoiceAmount);
            monthlyAmount.setReceiptAmount(receiptAmount);
            monthlyAmounts.add(monthlyAmount);
        }
        return monthlyAmounts;
    }
    // å†…部类用于存储聚合结果
    private static class GroupedCustomer {
        private final Long customerId;
        private final String customerName;
        private BigDecimal totalAmount = BigDecimal.ZERO;
        public GroupedCustomer(Long customerId, String customerName) {
            this.customerId = customerId;
            this.customerName = customerName;
        }
        public void addAmount(BigDecimal amount) {
            if (amount != null) {
                this.totalAmount = this.totalAmount.add(amount);
            }
        }
        public Long getCustomerId() {
            return customerId;
        }
        public String getCustomerName() {
            return customerName;
        }
        public BigDecimal getTotalAmount() {
            return totalAmount;
        }
    }
    /**