liyong
5 天以前 37b697351e8e0a9200eee1276c4081c07588dc10
src/main/java/com/ruoyi/purchase/service/impl/TicketRegistrationServiceImpl.java
@@ -1,7 +1,10 @@
package com.ruoyi.purchase.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.DateUtils;
@@ -86,20 +89,21 @@
        }
        List<TicketRegistration> ticketRegistrationList = ticketRegistrationMapper.selectList(queryWrapper);
        // 计算已付款金额
        if(CollectionUtils.isNotEmpty(ticketRegistrationList)){
        if (CollectionUtils.isNotEmpty(ticketRegistrationList)) {
            List<Long> ids = ticketRegistrationList.stream().map(TicketRegistration::getId).collect(Collectors.toList());
            List<PaymentRegistrationDto> paymentRegistrationDtoList = paymentRegistrationMapper.countPaymentTotalByTicketRegId(ids);
            for (TicketRegistration registration : ticketRegistrationList) {
                BigDecimal paymentAmountTotal = BigDecimal.ZERO;
                for (PaymentRegistrationDto paymentRegistrationDto : paymentRegistrationDtoList) {
                    if(registration.getId().equals(paymentRegistrationDto.getTicketRegistrationId())){
                        BigDecimal paymentAmountTotal = paymentRegistrationDto.getPaymentAmountTotal();
                        BigDecimal invoiceAmount = registration.getInvoiceAmount();
                        registration.setPaymentAmountTotal(paymentAmountTotal);
                        BigDecimal subtractAmount = invoiceAmount.subtract(paymentAmountTotal);
                        registration.setUnPaymentAmountTotal(subtractAmount);
                    if (registration.getId().equals(paymentRegistrationDto.getTicketRegistrationId())) {
                        paymentAmountTotal = paymentRegistrationDto.getPaymentAmountTotal();
                        break;
                    }
                }
                BigDecimal invoiceAmount = registration.getInvoiceAmount();
                BigDecimal subtractAmount = invoiceAmount.subtract(paymentAmountTotal);
                registration.setPaymentAmountTotal(paymentAmountTotal);
                registration.setUnPaymentAmountTotal(subtractAmount);
            }
        }
@@ -135,13 +139,13 @@
        // 6. 增加采购台账产品开票记录
        List<SalesLedgerProduct> salesLedgerProducts = ticketRegistrationDto.getProductData();
        if (CollectionUtils.isNotEmpty(salesLedgerProducts)){
        if (CollectionUtils.isNotEmpty(salesLedgerProducts)) {
            for (SalesLedgerProduct salesLedgerProduct : salesLedgerProducts) {
                ProductRecord productRecord = new ProductRecord();
                productRecord.setTicketRegistrationId(ticketRegistration.getId());
                productRecord.setPurchaseLedgerId(ticketRegistrationDto.getPurchaseLedgerId());
                productRecord.setCreatedAt(DateUtils.getNowDate());
                BeanUtils.copyProperties(salesLedgerProduct,productRecord);
                BeanUtils.copyProperties(salesLedgerProduct, productRecord);
                productRecord.setId(null);
                productRecord.setType("2");
                productRecordMapper.insert(productRecord);
@@ -254,8 +258,8 @@
    @Override
    public List getTicketNo(TicketRegistrationDto ticketRegistrationDto) {
        LambdaQueryWrapper<TicketRegistration> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(TicketRegistration::getId,TicketRegistration::getInvoiceNumber,TicketRegistration::getInvoiceAmount)
                .eq(TicketRegistration::getPurchaseLedgerId,ticketRegistrationDto.getId());
        queryWrapper.select(TicketRegistration::getId, TicketRegistration::getInvoiceNumber, TicketRegistration::getInvoiceAmount)
                .eq(TicketRegistration::getPurchaseLedgerId, ticketRegistrationDto.getId());
        List<Map<String, Object>> result = ticketRegistrationMapper.selectMaps(queryWrapper);
        // 将下划线命名转换为驼峰命名
        return result.stream().map(map -> map.entrySet().stream()
@@ -263,6 +267,44 @@
                        entry -> underlineToCamel(entry.getKey()),
                        Map.Entry::getValue))
        ).collect(Collectors.toList());
    }
    @Override
    public IPage<TicketRegistration> selectTicketRegistrationListPage(Page page, TicketRegistration ticketRegistration) {
        LambdaQueryWrapper<TicketRegistration> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(ticketRegistration.getPurchaseContractNumber())) {
            queryWrapper.like(TicketRegistration::getPurchaseContractNumber, ticketRegistration.getPurchaseContractNumber())
                    .like(TicketRegistration::getSupplierName, ticketRegistration.getSupplierName());
        }
        if (ObjectUtils.isEmpty(ticketRegistration.getIssueDateStart())&&ObjectUtils.isEmpty(ticketRegistration.getIssueDateEnd())) {
            queryWrapper.between(TicketRegistration::getIssueDate,LocalDate.parse(ticketRegistration.getIssueDateStart(), DateTimeFormatter.ofPattern("yyyy-MM-dd")), LocalDate.parse(ticketRegistration.getIssueDateEnd(), DateTimeFormatter.ofPattern("yyyy-MM-dd")));
        }
        IPage<TicketRegistration> ticketRegistrationIPage = ticketRegistrationMapper.selectPage(page, queryWrapper);
        // 计算已付款金额
        if (CollectionUtils.isNotEmpty(ticketRegistrationIPage.getRecords())) {
            List<Long> ids = ticketRegistrationIPage.getRecords().stream().map(TicketRegistration::getId).collect(Collectors.toList());
            List<PaymentRegistrationDto> paymentRegistrationDtoList = paymentRegistrationMapper.countPaymentTotalByTicketRegId(ids);
            for (TicketRegistration registration : ticketRegistrationIPage.getRecords()) {
                BigDecimal paymentAmountTotal = BigDecimal.ZERO;
                for (PaymentRegistrationDto paymentRegistrationDto : paymentRegistrationDtoList) {
                    if (registration.getId().equals(paymentRegistrationDto.getTicketRegistrationId())) {
                        paymentAmountTotal = paymentRegistrationDto.getPaymentAmountTotal();
                        break;
                    }
                }
                BigDecimal invoiceAmount = registration.getInvoiceAmount();
                BigDecimal subtractAmount = invoiceAmount.subtract(paymentAmountTotal);
                registration.setPaymentAmountTotal(paymentAmountTotal);
                registration.setUnPaymentAmountTotal(subtractAmount);
            }
        }
        if (!ObjectUtils.isEmpty(ticketRegistration.getStatus())) {
            if (ticketRegistration.getStatus()) {
                ticketRegistrationIPage.getRecords().removeIf(receiptPaymentDto1 -> new BigDecimal("0.00").equals(receiptPaymentDto1.getUnPaymentAmountTotal()));
            }
        }
        return ticketRegistrationIPage;
    }
    private void handleSalesLedgerProducts(Long salesLedgerId, List<SalesLedgerProduct> products, Integer type) {
@@ -299,7 +341,7 @@
                // 计算 futureTickets(直接使用 BigDecimal 计算,避免精度丢失)
                product.setFutureTickets(
                        product.getQuantity()
                                .subtract(BigDecimal.valueOf(product.getTicketsNum()))
                                .subtract(product.getTicketsNum())
                );
                // 计算 futureTicketsAmount