6 天以前 4ea1509f0e88ee331e821459d4eefb0c9902b3e7
src/main/java/com/ruoyi/account/service/impl/purchase/AccountPurchasePaymentServiceImpl.java
@@ -1,10 +1,11 @@
package com.ruoyi.account.service.impl.purchase;
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.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.xiaoymin.knife4j.core.util.CollectionUtils;
import com.ruoyi.account.bean.dto.purchase.AccountPurchasePaymentDto;
import com.ruoyi.account.bean.vo.purchase.AccountPurchasePaymentVo;
import com.ruoyi.account.mapper.AccountStatementDetailsMapper;
@@ -17,15 +18,20 @@
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.purchase.dto.SavePaymentDto;
import com.ruoyi.purchase.mapper.PurchaseLedgerMapper;
import com.ruoyi.purchase.pojo.PurchaseLedger;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
/**
 * <p>
@@ -43,6 +49,7 @@
    private final AccountPurchasePaymentMapper accountPurchasePaymentMapper;
    private final AccountStatementDetailsMapper accountStatementDetailsMapper;
    private final AccountPaymentApplicationMapper accountPaymentApplicationMapper;
    private final PurchaseLedgerMapper purchaseLedgerMapper;
    @Override
    public IPage<AccountPurchasePaymentVo> listPageAccountPurchasePayment(Page page, AccountPurchasePaymentDto accountPurchasePaymentDto) {
@@ -84,6 +91,63 @@
        return removeByIds(ids);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean savePayment(SavePaymentDto dto) {
        if (dto.getPaymentDate() == null) {
            throw new ServiceException("请选择付款日期");
        }
        if (dto.getPaymentAmount() == null || dto.getPaymentAmount().compareTo(BigDecimal.valueOf(0.01)) < 0) {
            throw new ServiceException("请输入付款金额");
        }
        if (StringUtils.isEmpty(dto.getPurchaseContractNumber())) {
            throw new ServiceException("采购合同号不能为空");
        }
        if (dto.getSupplierId() == null) {
            throw new ServiceException("供应商不能为空");
        }
        PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectOne(new LambdaQueryWrapper<PurchaseLedger>()
                .eq(PurchaseLedger::getPurchaseContractNumber, dto.getPurchaseContractNumber()));
        if (purchaseLedger == null) {
            throw new ServiceException("采购合同不存在");
        }
        if (purchaseLedger.getSupplierId() == null || purchaseLedger.getSupplierId().longValue() != dto.getSupplierId().longValue()) {
            throw new ServiceException("供应商与合同不匹配");
        }
        List<Long> stockInRecordIds = accountPurchasePaymentMapper.selectStockInRecordIdsByPurchaseLedgerId(purchaseLedger.getId());
        if (CollectionUtils.isEmpty(stockInRecordIds)) {
            throw new ServiceException("该合同暂无可付款的采购入库记录");
        }
        AccountPaymentApplication application = new AccountPaymentApplication();
        application.setSupplierId(dto.getSupplierId().intValue());
        application.setStockInRecordIds(stockInRecordIds.stream().map(String::valueOf).collect(Collectors.joining(",")));
        application.setInvoiceApplicationNo(genPaymentApplicationNo());
        application.setPaymentMethod(dto.getPaymentMethod());
        application.setPaymentContent(dto.getPurchaseContractNumber());
        application.setApplyDate(dto.getPaymentDate());
        application.setRemark(dto.getRemark());
        application.setStatus(1);
        application.setPaymentAmount(dto.getPaymentAmount());
        accountPaymentApplicationMapper.insert(application);
        AccountPurchasePayment payment = new AccountPurchasePayment();
        payment.setAccountPaymentApplicationId(application.getId());
        payment.setSupplierId(dto.getSupplierId().intValue());
        payment.setPaymentDate(dto.getPaymentDate());
        payment.setPaymentMethod(dto.getPaymentMethod());
        payment.setPaymentAmount(dto.getPaymentAmount());
        payment.setPaymentNumber(genAccountPurchasePaymentNo());
        payment.setRemark(dto.getRemark());
        return save(payment);
    }
    private String genPaymentApplicationNo() {
        return "FK" + LocalDateTime.now().format(CODE_TIME_FORMATTER) + new Random().nextInt(10);
    }
    private String genAccountPurchasePaymentNo() {
        return "SK" + LocalDateTime.now().format(CODE_TIME_FORMATTER) + new Random().nextInt(10);
    }