From 4ea1509f0e88ee331e821459d4eefb0c9902b3e7 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期三, 12 八月 2026 13:16:04 +0800
Subject: [PATCH] feat(account): 实现采购付款和销售回款功能
---
src/main/java/com/ruoyi/account/service/impl/purchase/AccountPurchasePaymentServiceImpl.java | 66 ++++++++++++++++++++++++++++++++
1 files changed, 65 insertions(+), 1 deletions(-)
diff --git a/src/main/java/com/ruoyi/account/service/impl/purchase/AccountPurchasePaymentServiceImpl.java b/src/main/java/com/ruoyi/account/service/impl/purchase/AccountPurchasePaymentServiceImpl.java
index b9953a0..1246d68 100644
--- a/src/main/java/com/ruoyi/account/service/impl/purchase/AccountPurchasePaymentServiceImpl.java
+++ b/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);
}
--
Gitblit v1.9.3