From 061977e873182b0c7249d02fe0253a291fa4e69d Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期五, 12 六月 2026 09:46:31 +0800
Subject: [PATCH] fix(customer): 修复客户数据查询中的空值问题并优化生产订单状态管理
---
src/main/java/com/ruoyi/account/service/impl/purchase/AccountPurchasePaymentServiceImpl.java | 75 ++++++++++++++++++++++++++++++++++++-
1 files changed, 73 insertions(+), 2 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 14936f2..7d0740d 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
@@ -8,8 +8,10 @@
import com.ruoyi.account.bean.dto.purchase.AccountPurchasePaymentDto;
import com.ruoyi.account.bean.vo.purchase.AccountPurchasePaymentVo;
import com.ruoyi.account.mapper.AccountStatementDetailsMapper;
+import com.ruoyi.account.mapper.purchase.AccountPaymentApplicationMapper;
import com.ruoyi.account.mapper.purchase.AccountPurchasePaymentMapper;
import com.ruoyi.account.pojo.AccountStatementDetails;
+import com.ruoyi.account.pojo.purchase.AccountPaymentApplication;
import com.ruoyi.account.pojo.purchase.AccountPurchasePayment;
import com.ruoyi.account.service.purchase.AccountPurchasePaymentService;
import com.ruoyi.common.exception.ServiceException;
@@ -19,6 +21,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
+import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
@@ -39,6 +42,7 @@
private static final DateTimeFormatter CODE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyMMddHHmmss");
private final AccountPurchasePaymentMapper accountPurchasePaymentMapper;
private final AccountStatementDetailsMapper accountStatementDetailsMapper;
+ private final AccountPaymentApplicationMapper accountPaymentApplicationMapper;
@Override
public IPage<AccountPurchasePaymentVo> listPageAccountPurchasePayment(Page page, AccountPurchasePaymentDto accountPurchasePaymentDto) {
@@ -50,7 +54,31 @@
if (StringUtils.isEmpty(accountPurchasePayment.getPaymentNumber())) {
accountPurchasePayment.setPaymentNumber(genAccountPurchasePaymentNo());
}
- return save(accountPurchasePayment);
+ //鏍¢獙浠樻鐢宠鏄惁瀛樺湪涓斿鏍搁�氳繃
+ AccountPaymentApplication accountPaymentApplication = accountPaymentApplicationMapper.selectById(accountPurchasePayment.getAccountPaymentApplicationId());
+ if (accountPaymentApplication == null) {
+ throw new ServiceException("浠樻鐢宠涓嶅瓨鍦�");
+ }
+ if (accountPaymentApplication.getStatus() == null || accountPaymentApplication.getStatus() != 1) {
+ throw new ServiceException("浠樻鐢宠鏈鏍搁�氳繃锛屼笉鑳戒粯娆�");
+ }
+ //鏍¢獙绱浠樻閲戦涓嶈兘瓒呰繃鐢宠閲戦
+ List<AccountPurchasePayment> accountPurchasePayments = accountPurchasePaymentMapper.selectList(
+ Wrappers.<AccountPurchasePayment>lambdaQuery()
+ .eq(AccountPurchasePayment::getAccountPaymentApplicationId, accountPurchasePayment.getAccountPaymentApplicationId()));
+ BigDecimal totalPaymentAmount = accountPurchasePayments.stream()
+ .map(AccountPurchasePayment::getPaymentAmount)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+ BigDecimal newTotal = totalPaymentAmount.add(accountPurchasePayment.getPaymentAmount());
+ if (newTotal.compareTo(accountPaymentApplication.getPaymentAmount()) > 0) {
+ throw new ServiceException("绱浠樻閲戦涓嶈兘瓒呰繃鐢宠閲戦");
+ }
+ boolean result = save(accountPurchasePayment);
+ // 鏇存柊浠樻鐢宠鐨勪粯娆剧姸鎬�
+ if (result) {
+ updatePaymentStatus(accountPaymentApplication, newTotal);
+ }
+ return result;
}
@Override
@@ -62,6 +90,9 @@
@Override
public boolean deleteAccountPurchasePayment(List<Long> ids) {
+ if (CollectionUtils.isEmpty(ids)) {
+ return false;
+ }
//濡傛灉璇ヤ粯娆惧崟宸茬粡鐢熸垚瀵硅处鍗曞垯鏃犳硶鍒犻櫎
List<AccountPurchasePayment> accountPurchasePayments = accountPurchasePaymentMapper.selectByIds(ids);
List<String> strings = accountPurchasePayments.stream().map(AccountPurchasePayment::getPaymentNumber).toList();
@@ -70,7 +101,47 @@
if (CollectionUtils.isNotEmpty(accountStatementDetails)){
throw new ServiceException("璇ヤ粯娆惧崟宸茬粡鐢熸垚瀵硅处鍗曪紝鏃犳硶鍒犻櫎");
}
- return removeByIds(ids);
+ boolean result = removeByIds(ids);
+ // 鍒犻櫎鎴愬姛鍚庯紝鏇存柊浠樻鐢宠鐨勪粯娆剧姸鎬�
+ if (result) {
+ for (AccountPurchasePayment payment : accountPurchasePayments) {
+ if (payment.getAccountPaymentApplicationId() != null) {
+ AccountPaymentApplication application = accountPaymentApplicationMapper.selectById(payment.getAccountPaymentApplicationId());
+ if (application != null) {
+ // 璁$畻鍓╀綑浠樻閲戦
+ List<AccountPurchasePayment> remainingPayments = accountPurchasePaymentMapper.selectList(
+ Wrappers.<AccountPurchasePayment>lambdaQuery()
+ .eq(AccountPurchasePayment::getAccountPaymentApplicationId, application.getId()));
+ BigDecimal remainingAmount = remainingPayments.stream()
+ .map(AccountPurchasePayment::getPaymentAmount)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+ updatePaymentStatus(application, remainingAmount);
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * 鏇存柊浠樻鐢宠鐨勪粯娆剧姸鎬�
+ * @param application 浠樻鐢宠
+ * @param paidAmount 宸蹭粯娆鹃噾棰�
+ */
+ private void updatePaymentStatus(AccountPaymentApplication application, BigDecimal paidAmount) {
+ BigDecimal applyAmount = application.getPaymentAmount();
+ int newPaymentStatus;
+ if (paidAmount.compareTo(BigDecimal.ZERO) == 0) {
+ newPaymentStatus = 0; // 鏈粯娆�
+ } else if (paidAmount.compareTo(applyAmount) < 0) {
+ newPaymentStatus = 1; // 閮ㄥ垎浠樻
+ } else {
+ newPaymentStatus = 2; // 宸蹭粯娆�
+ }
+ if (application.getPaymentStatus() == null || application.getPaymentStatus() != newPaymentStatus) {
+ application.setPaymentStatus(newPaymentStatus);
+ accountPaymentApplicationMapper.updateById(application);
+ }
}
private String genAccountPurchasePaymentNo() {
--
Gitblit v1.9.3