maven
2025-12-11 8d04ade530ef1bafe4553f6b44b561ee0faf70c2
src/main/java/com/ruoyi/sales/service/impl/ReceiptPaymentServiceImpl.java
@@ -4,18 +4,25 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.account.pojo.AccountIncome;
import com.ruoyi.account.service.AccountIncomeService;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.sales.dto.CustomerInteractionDto;
import com.ruoyi.sales.dto.InvoiceLedgerDto;
import com.ruoyi.sales.dto.ReceiptPaymentDto;
import com.ruoyi.sales.dto.ReceiptPaymentExeclDto;
import com.ruoyi.sales.mapper.InvoiceLedgerMapper;
import com.ruoyi.sales.mapper.ReceiptPaymentMapper;
import com.ruoyi.sales.mapper.SalesLedgerMapper;
import com.ruoyi.sales.pojo.InvoiceLedger;
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;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
@@ -34,6 +41,10 @@
    @Autowired
    private SalesLedgerMapper salesLedgerMapper;
    @Autowired
    private InvoiceLedgerMapper invoiceLedgerMapper;
    @Autowired
    private AccountIncomeService accountIncomeService;
    /**
     * 回款登记新增
@@ -41,10 +52,47 @@
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int receiptPaymentSaveOrUpdate(ReceiptPayment receiptPayment) {
        ReceiptPayment byId = receiptPayment;
        if (!ObjectUtils.isEmpty(receiptPayment.getId())){
             byId = this.getById(receiptPayment.getId());
        }
        InvoiceLedger invoiceLedger = invoiceLedgerMapper.selectById(byId.getInvoiceLedgerId());
        Page<ReceiptPaymentDto> objectPage = new Page<>();
        ReceiptPaymentDto receiptPaymentDto = new ReceiptPaymentDto();
        receiptPaymentDto.setInvoiceLedgerId(invoiceLedger.getId());
        IPage<ReceiptPaymentDto> receiptPaymentDtoIPage = receiptPaymentMapper.bindInvoiceNoRegPage(objectPage, receiptPaymentDto);
        ReceiptPaymentDto receiptPaymentDto1 = receiptPaymentDtoIPage.getRecords().get(0);
        if (!ObjectUtils.isEmpty(byId.getId())){
            receiptPaymentDto1.setNoReceiptAmount(receiptPaymentDto1.getNoReceiptAmount().add(byId.getReceiptPaymentAmount()));
        }
        if (receiptPaymentDto1.getNoReceiptAmount().compareTo(receiptPayment.getReceiptPaymentAmount())<0){
            throw new RuntimeException("本次回款金额不能大于待回款金额");
        }
        if(null==receiptPayment.getId()){
            AccountIncome accountIncome = new AccountIncome();
            accountIncome.setIncomeDate(DateUtils.toDate(receiptPayment.getReceiptPaymentDate()));
            accountIncome.setIncomeType("0");
            accountIncome.setCustomerName(receiptPaymentDto1.getCustomerName());
            accountIncome.setIncomeMoney(receiptPayment.getReceiptPaymentAmount());
            accountIncome.setIncomeMethod("0");
            accountIncome.setInputTime(new Date());
            accountIncome.setInputUser(receiptPayment.getRegistrant());
            accountIncome.setIncomeDescribed("回款登记:" + invoiceLedger.getInvoiceNo());
            accountIncome.setInvoiceNumber(invoiceLedger.getInvoiceNo());
            accountIncomeService.save(accountIncome);
            return receiptPaymentMapper.insert(receiptPayment);
        }else {
            AccountIncome salesLedgerDB = accountIncomeService.getByInvoiceNumber(invoiceLedger.getInvoiceNo());
            List<AccountIncome> accountIncomeDBs = accountIncomeService.getByInvoiceNumberList(salesLedgerDB.getInvoiceNumber());
            if (!org.springframework.util.CollectionUtils.isEmpty(accountIncomeDBs)) {
                accountIncomeDBs.forEach(accountIncomeDB -> {
                    accountIncomeDB.setIncomeMoney(receiptPayment.getReceiptPaymentAmount());
                    accountIncomeDB.setInputUser(receiptPayment.getRegistrant());
                    accountIncomeService.updateById(accountIncomeDB);
                });
            }
            return receiptPaymentMapper.updateById(receiptPayment);
        }
    }
@@ -141,6 +189,15 @@
        if (receiptPaymentDto.getStatus()) {
            receiptPaymentDtoIPage.getRecords().removeIf(receiptPaymentDto1 -> new BigDecimal("0.00").equals(receiptPaymentDto1.getNoReceiptAmount()));
        }
        receiptPaymentDtoIPage.getRecords().forEach(item -> {
            // 比较回款金额 == 待回款金额
            if (item.getInvoiceTotal().compareTo(item.getReceiptPaymentAmountTotal()) == 0) {
                item.setStatusName("已完成回款");
            }else{
                item.setStatusName("未完成回款");
            }
        });
        return receiptPaymentDtoIPage;
    }
@@ -246,7 +303,19 @@
            customerInteractionDto.setUnReceiptAmount(amountTotal);
            result.add(customerInteractionDto);
        }
        return result;
        ArrayList<CustomerInteractionDto> newResult = new ArrayList<>();
        for (int i = 0; i < result.size(); i++) {
            CustomerInteractionDto customerInteractionDto = result.get(i);
            if (i == 0) {
                customerInteractionDto.setUnReceiptAmount(customerInteractionDto.getInvoiceAmount().subtract(customerInteractionDto.getReceiptAmount()));
            }else {
                CustomerInteractionDto customerInteractionDto1 = result.get(i-1);
                customerInteractionDto.setUnReceiptAmount(customerInteractionDto1.getUnReceiptAmount()
                        .add(customerInteractionDto.getInvoiceAmount()).subtract(customerInteractionDto.getReceiptAmount()));
            }
            newResult.add(customerInteractionDto);
        }
        return newResult;
    }
    /**
@@ -266,8 +335,15 @@
    @Override
    public void exportPaymentList(HttpServletResponse response, List<Long> ids) {
        List<ReceiptPaymentExeclDto> receiptPaymentDtoList =  receiptPaymentMapper.bindInvoiceNoRegListByIds(ids);
        ExcelUtil<ReceiptPaymentExeclDto> util = new ExcelUtil<ReceiptPaymentExeclDto>(ReceiptPaymentExeclDto.class);
        util.exportExcel(response, receiptPaymentDtoList, "回款登记");
        if (ids == null) {
            List<ReceiptPaymentExeclDto> receiptPaymentDtoList =  receiptPaymentMapper.bindInvoiceNoRegListByIds(new ArrayList<>(), SecurityUtils.getLoginUser().getTenantId());
            ExcelUtil<ReceiptPaymentExeclDto> util = new ExcelUtil<ReceiptPaymentExeclDto>(ReceiptPaymentExeclDto.class);
            util.exportExcel(response, receiptPaymentDtoList, "回款登记");
        }else {
            List<ReceiptPaymentExeclDto> receiptPaymentDtoList =  receiptPaymentMapper.bindInvoiceNoRegListByIds(ids,SecurityUtils.getLoginUser().getTenantId());
            ExcelUtil<ReceiptPaymentExeclDto> util = new ExcelUtil<ReceiptPaymentExeclDto>(ReceiptPaymentExeclDto.class);
            util.exportExcel(response, receiptPaymentDtoList, "回款登记");
        }
    }
}