From 10b88a7ff17caf92f3d4e8a550c1085a70c2517a Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期四, 28 五月 2026 17:43:26 +0800
Subject: [PATCH] Merge dev_New_pro into dev_山西_晋和园_pro
---
src/main/java/com/ruoyi/account/service/impl/AccountStatementServiceImpl.java | 298 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 298 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/ruoyi/account/service/impl/AccountStatementServiceImpl.java b/src/main/java/com/ruoyi/account/service/impl/AccountStatementServiceImpl.java
new file mode 100644
index 0000000..411d595
--- /dev/null
+++ b/src/main/java/com/ruoyi/account/service/impl/AccountStatementServiceImpl.java
@@ -0,0 +1,298 @@
+package com.ruoyi.account.service.impl;
+
+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.ruoyi.account.bean.dto.StatementAccountDto;
+import com.ruoyi.account.bean.dto.purchase.PurchaseInboundDto;
+import com.ruoyi.account.bean.dto.purchase.PurchaseReturnDto;
+import com.ruoyi.account.bean.dto.sales.SalesOutboundDto;
+import com.ruoyi.account.bean.dto.sales.SalesReturnDto;
+import com.ruoyi.account.bean.vo.StatementAccountVo;
+import com.ruoyi.account.bean.vo.purchase.PurchaseInboundVo;
+import com.ruoyi.account.bean.vo.purchase.PurchaseReturnVo;
+import com.ruoyi.account.bean.vo.sales.SalesOutboundVo;
+import com.ruoyi.account.bean.vo.sales.SalesReturnVo;
+import com.ruoyi.account.mapper.AccountStatementDetailsMapper;
+import com.ruoyi.account.mapper.AccountStatementMapper;
+import com.ruoyi.account.mapper.purchase.AccountPurchasePaymentMapper;
+import com.ruoyi.account.mapper.sales.AccountSalesCollectionMapper;
+import com.ruoyi.account.pojo.AccountStatement;
+import com.ruoyi.account.pojo.AccountStatementDetails;
+import com.ruoyi.account.pojo.purchase.AccountPurchasePayment;
+import com.ruoyi.account.pojo.sales.AccountSalesCollection;
+import com.ruoyi.account.service.AccountStatementService;
+import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.bean.BeanUtils;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.procurementrecord.mapper.ReturnManagementMapper;
+import com.ruoyi.purchase.mapper.PurchaseReturnOrdersMapper;
+import com.ruoyi.stock.mapper.StockInRecordMapper;
+import com.ruoyi.stock.mapper.StockOutRecordMapper;
+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.YearMonth;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+/**
+ * <p>
+ * 鏈嶅姟瀹炵幇绫�
+ * </p>
+ *
+ * @author 鑺杞欢锛堟睙鑻忥級鏈夐檺鍏徃
+ * @since 2026-05-19 09:42:47
+ */
+@Service
+@RequiredArgsConstructor
+@Transactional(rollbackFor = Exception.class)
+public class AccountStatementServiceImpl extends ServiceImpl<AccountStatementMapper, AccountStatement> implements AccountStatementService {
+
+ private final AccountStatementMapper accountStatementMapper;
+ private final AccountSalesCollectionMapper accountSalesCollectionMapper;
+ private final StockOutRecordMapper stockOutRecordMapper;
+ private final StockInRecordMapper stockInRecordMapper;
+ private final ReturnManagementMapper returnManagementMapper;
+ private final AccountStatementDetailsMapper accountStatementDetailsMapper;
+ private final AccountPurchasePaymentMapper accountPurchasePaymentMapper;
+ private final PurchaseReturnOrdersMapper purchaseReturnOrdersMapper;
+ private static final DateTimeFormatter CODE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyMMdd");
+
+ @Override
+ public StatementAccountVo getAccountStatementDetailsByMonth(StatementAccountDto statementAccountDto) {
+ //瀵硅处鏈堜唤杞崲鎴愬紑濮嬫棩鏈熷拰缁撴潫鏃ユ湡鍖洪棿
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
+ YearMonth yearMonth = YearMonth.parse(statementAccountDto.getStatementMonth(), formatter);
+ statementAccountDto.setStartDate(yearMonth.atDay(1));
+ statementAccountDto.setEndDate(yearMonth.atEndOfMonth());
+ if (statementAccountDto.getAccountType() == 1){
+ //搴旀敹瀵硅处--Customer
+ return getAccountStatementDetailsByCustomerAndMonth(statementAccountDto);
+ }else {
+ //搴斾粯瀵硅处--SupplierManage
+ return getAccountStatementDetailsBySupplierAndMonth(statementAccountDto);
+ }
+ }
+
+ @Override
+ public boolean addAccountStatement(StatementAccountVo statementAccountVo) {
+ //鍚屼竴瀹㈡埛鎴栬�呭悓涓�渚涘簲鍟�,涓�涓湀浠藉彧鑳芥湁涓�涓璐﹀崟
+ List<AccountStatement> accountStatements = accountStatementMapper.selectList(Wrappers.<AccountStatement>lambdaQuery()
+ .eq(AccountStatement::getStatementMonth, statementAccountVo.getStatementMonth())
+ .eq(AccountStatement::getAccountType, statementAccountVo.getAccountType())
+ .eq(AccountStatement::getCustomerId, statementAccountVo.getCustomerId()));
+ if (CollectionUtils.isNotEmpty(accountStatements)){
+ throw new ServiceException("鍚屼竴瀹㈡埛鎴栬�呭悓涓�渚涘簲鍟�,涓�涓湀浠藉彧鑳芥湁涓�涓璐﹀崟");
+ }
+ AccountStatement accountStatement = new AccountStatement();
+ BeanUtils.copyProperties(statementAccountVo, accountStatement);
+ accountStatement.setStatementNumber(genStatementAccountNo());
+ boolean save = save(accountStatement);
+ statementAccountVo.getAccountStatementDetails().stream().forEach(accountStatementDetails -> {
+ accountStatementDetails.setAccountStatementId(accountStatement.getId());
+ //娣诲姞瀵硅处鍗曟槑缁�
+ accountStatementDetailsMapper.insert(accountStatementDetails);
+ });
+ return save;
+ }
+
+ @Override
+ public boolean deleteAccountStatement(List<Long> ids) {
+ //鍒犻櫎瀵硅处鍗曟槑缁�
+ accountStatementDetailsMapper.delete(Wrappers.<AccountStatementDetails>lambdaQuery().in(AccountStatementDetails::getAccountStatementId, ids));
+ return removeByIds(ids);
+ }
+
+ @Override
+ public IPage<StatementAccountVo> listPageAccountStatement(Page page, StatementAccountDto statementAccountDto) {
+ return accountStatementMapper.listPageAccountStatement(page, statementAccountDto);
+ }
+
+ @Override
+ public void exportAccountStatement(HttpServletResponse response, StatementAccountDto statementAccountDto) {
+ List<StatementAccountVo> list = accountStatementMapper.listPageAccountStatement(new Page(1,-1),statementAccountDto).getRecords();
+ ExcelUtil<StatementAccountVo> util = new ExcelUtil<>(StatementAccountVo.class);
+ util.exportExcel(response, list , "瀵硅处鍗�");
+ }
+
+ //鏍规嵁瀹㈡埛鍜屾湀浠借幏鍙栧璐﹁鎯�(閿�鍞�)
+ private StatementAccountVo getAccountStatementDetailsByCustomerAndMonth(StatementAccountDto statementAccountDto) {
+ StatementAccountVo statementAccountVo = new StatementAccountVo();
+ statementAccountVo.setAccountType(1);//搴旀敹瀵硅处
+ List<AccountStatementDetails> accountStatementDetailsList = new ArrayList<>();
+ /*鏌ヨ鍑哄簱鏄庣粏*/
+ SalesOutboundDto salesOutboundDto = new SalesOutboundDto();
+ salesOutboundDto.setCustomerId(statementAccountDto.getCustomerId());
+ salesOutboundDto.setStartDate(statementAccountDto.getStartDate());
+ salesOutboundDto.setEndDate(statementAccountDto.getEndDate());
+ List<SalesOutboundVo> salesOutboundVos = stockOutRecordMapper.listPageAccountSales(new Page(1, -1), salesOutboundDto).getRecords();
+ salesOutboundVos.stream().forEach(salesOutboundVo -> {
+ AccountStatementDetails accountStatementDetails = new AccountStatementDetails();
+ //鏁版嵁鏃ユ湡=鍑哄簱鏃ユ湡
+ accountStatementDetails.setOccurrenceDate(salesOutboundVo.getShippingDate());
+ //鍗曟嵁缂栧彿=鍑哄簱鍗曞彿
+ accountStatementDetails.setReceiptNumber(salesOutboundVo.getOutboundBatches());
+ //绫诲瀷=鍑哄簱
+ accountStatementDetails.setType(1);
+ //閲戦=鍑哄簱閲戦
+ accountStatementDetails.setAmount(salesOutboundVo.getOutboundAmount());
+ //澶囨敞
+ accountStatementDetails.setRemark("浜у搧閿�鍞嚭搴擄紝浜у搧锛�"+salesOutboundVo.getProductName());
+ accountStatementDetailsList.add(accountStatementDetails);
+ });
+ /*鏌ヨ鏀舵鏄庣粏*/
+ List<AccountSalesCollection> accountSalesCollections = accountSalesCollectionMapper.selectList(Wrappers.<AccountSalesCollection>lambdaQuery()
+ .eq(AccountSalesCollection::getCustomerId, statementAccountDto.getCustomerId())
+ .between(AccountSalesCollection::getCollectionDate, statementAccountDto.getStartDate(), statementAccountDto.getEndDate()));
+ accountSalesCollections.stream().forEach(accountSalesCollection -> {
+ AccountStatementDetails accountStatementDetails = new AccountStatementDetails();
+ //鏁版嵁鏃ユ湡=鏀舵鏃ユ湡
+ accountStatementDetails.setOccurrenceDate(accountSalesCollection.getCollectionDate());
+ //鍗曟嵁缂栧彿=鏀舵鍗曞彿
+ accountStatementDetails.setReceiptNumber(accountSalesCollection.getCollectionNumber());
+ //绫诲瀷=鏀舵
+ accountStatementDetails.setType(3);
+ //閲戦=鏀舵閲戦
+ accountStatementDetails.setAmount(accountSalesCollection.getCollectionAmount());
+ //澶囨敞
+ accountStatementDetails.setRemark("瀹㈡埛鍥炴锛屽娉細"+accountSalesCollection.getRemark());
+ accountStatementDetailsList.add(accountStatementDetails);
+ });
+ /*鏌ヨ閫�璐ф槑缁�*/
+ SalesReturnDto salesReturnDto = new SalesReturnDto();
+ salesReturnDto.setCustomerId(statementAccountDto.getCustomerId());
+ salesReturnDto.setStartDate(statementAccountDto.getStartDate());
+ salesReturnDto.setEndDate(statementAccountDto.getEndDate());
+ List<SalesReturnVo> salesReturnVos = returnManagementMapper.listPageAccountSalesReturn(new Page(1, -1), salesReturnDto).getRecords();
+ salesReturnVos.stream().forEach(salesReturnVo -> {
+ AccountStatementDetails accountStatementDetails = new AccountStatementDetails();
+ //鏁版嵁鏃ユ湡=閫�璐ф棩鏈�
+ accountStatementDetails.setOccurrenceDate(salesReturnVo.getMakeTime().toLocalDate());
+ //鍗曟嵁缂栧彿=閫�璐у崟鍙�
+ accountStatementDetails.setReceiptNumber(salesReturnVo.getReturnNo());
+ //绫诲瀷=閫�璐�
+ accountStatementDetails.setType(5);
+ //閲戦=閫�娆鹃噾棰�
+ accountStatementDetails.setAmount(salesReturnVo.getRefundAmount());
+ //澶囨敞
+ accountStatementDetails.setRemark("浜у搧閫�璐э紝鍘熷洜锛�"+salesReturnVo.getReturnReason());
+ accountStatementDetailsList.add(accountStatementDetails);
+ });
+ //鏈熷垵浣欓=涓婁釜鏈堢殑鏈熸湯浣欓
+ statementAccountVo.setOpeningBalance(BigDecimal.ZERO);
+ List<AccountStatement> accountStatements = accountStatementMapper.selectList(Wrappers.<AccountStatement>lambdaQuery()
+ .eq(AccountStatement::getAccountType, 1)
+ .eq(AccountStatement::getCustomerId, statementAccountDto.getCustomerId())
+ .eq(AccountStatement::getStatementMonth,
+ YearMonth.parse(statementAccountDto.getStatementMonth()).minusMonths(1).toString()));
+ if (CollectionUtils.isNotEmpty(accountStatements)){
+ statementAccountVo.setOpeningBalance(accountStatements.get(accountStatements.size() - 1).getClosingBalance());
+ }
+ //鏈湡搴旀敹=鍑哄簱-閫�璐ч噾棰濈疮璁�
+ statementAccountVo.setCurrentPlan(salesOutboundVos.stream().map(SalesOutboundVo::getOutboundAmount).reduce(BigDecimal.ZERO, BigDecimal::add)
+ .subtract(salesReturnVos.stream().map(SalesReturnVo::getRefundAmount).reduce(BigDecimal.ZERO, BigDecimal::add)));
+ //鏈湡鏀舵=鏀舵閲戦绱
+ statementAccountVo.setCurrentActually(accountSalesCollections.stream().map(AccountSalesCollection::getCollectionAmount).reduce(BigDecimal.ZERO, BigDecimal::add));
+ //鏈熸湯浣欓=鏈熷垵+搴旀敹-鏀舵
+ statementAccountVo.setClosingBalance(statementAccountVo.getOpeningBalance().add(statementAccountVo.getCurrentPlan()).subtract(statementAccountVo.getCurrentActually()));
+ statementAccountVo.setAccountStatementDetails(accountStatementDetailsList);
+ return statementAccountVo;
+ }
+
+ //鏍规嵁渚涘簲鍟嗗拰鏈堜唤鑾峰彇瀵硅处璇︽儏(閲囪喘)
+ private StatementAccountVo getAccountStatementDetailsBySupplierAndMonth(StatementAccountDto statementAccountDto) {
+ StatementAccountVo statementAccountVo = new StatementAccountVo();
+ statementAccountVo.setAccountType(2);//搴斾粯瀵硅处
+ List<AccountStatementDetails> accountStatementDetailsList = new ArrayList<>();
+ /*鏌ヨ鍏ュ簱鏄庣粏*/
+ PurchaseInboundDto purchaseInboundDto = new PurchaseInboundDto();
+ purchaseInboundDto.setSupplierId(statementAccountDto.getCustomerId());
+ purchaseInboundDto.setStartDate(statementAccountDto.getStartDate());
+ purchaseInboundDto.setEndDate(statementAccountDto.getEndDate());
+ List<PurchaseInboundVo> purchaseInboundVos = stockInRecordMapper.listPageAccountPurchase(new Page(1, -1), purchaseInboundDto).getRecords();
+ purchaseInboundVos.stream().forEach(purchaseInboundVo -> {
+ AccountStatementDetails accountStatementDetails = new AccountStatementDetails();
+ //鏁版嵁鏃ユ湡=鍏ュ簱鏃ユ湡
+ accountStatementDetails.setOccurrenceDate(purchaseInboundVo.getInboundDate());
+ //鍗曟嵁缂栧彿=鍏ュ簱鍗曞彿
+ accountStatementDetails.setReceiptNumber(purchaseInboundVo.getInboundBatches());
+ //绫诲瀷=鍏ュ簱
+ accountStatementDetails.setType(2);
+ //閲戦=鍏ュ簱閲戦
+ accountStatementDetails.setAmount(purchaseInboundVo.getInboundAmount());
+ //澶囨敞
+ accountStatementDetails.setRemark("浜у搧閲囪喘鍏ュ簱锛屼骇鍝侊細"+purchaseInboundVo.getProductName());
+ accountStatementDetailsList.add(accountStatementDetails);
+ });
+ /*鏌ヨ浠樻鏄庣粏*/
+ List<AccountPurchasePayment> accountPurchasePayments = accountPurchasePaymentMapper.selectList(Wrappers.<AccountPurchasePayment>lambdaQuery()
+ .eq(AccountPurchasePayment::getSupplierId, statementAccountDto.getCustomerId())
+ .between(AccountPurchasePayment::getPaymentDate, statementAccountDto.getStartDate(), statementAccountDto.getEndDate()));
+ accountPurchasePayments.stream().forEach(accountPurchasePayment -> {
+ AccountStatementDetails accountStatementDetails = new AccountStatementDetails();
+ //鏁版嵁鏃ユ湡=浠樻鏃ユ湡
+ accountStatementDetails.setOccurrenceDate(accountPurchasePayment.getPaymentDate());
+ //鍗曟嵁缂栧彿=浠樻鍗曞彿
+ accountStatementDetails.setReceiptNumber(accountPurchasePayment.getPaymentNumber());
+ //绫诲瀷=浠樻
+ accountStatementDetails.setType(4);
+ //閲戦=浠樻閲戦
+ accountStatementDetails.setAmount(accountPurchasePayment.getPaymentAmount());
+ //澶囨敞
+ accountStatementDetails.setRemark("鏀粯璐ф锛屽娉細"+accountPurchasePayment.getRemark());
+ accountStatementDetailsList.add(accountStatementDetails);
+ });
+ /*鏌ヨ閫�璐ф槑缁�*/
+ PurchaseReturnDto purchaseReturnDto = new PurchaseReturnDto();
+ purchaseReturnDto.setSupplierId(statementAccountDto.getCustomerId());
+ purchaseReturnDto.setStartDate(statementAccountDto.getStartDate());
+ purchaseReturnDto.setEndDate(statementAccountDto.getEndDate());
+ List<PurchaseReturnVo> purchaseReturnVos = purchaseReturnOrdersMapper.listPageAccountPurchaseReturn(new Page(1, -1), purchaseReturnDto).getRecords();
+ purchaseReturnVos.stream().forEach(purchaseReturnVo -> {
+ AccountStatementDetails accountStatementDetails = new AccountStatementDetails();
+ //鏁版嵁鏃ユ湡=閫�璐ф棩鏈�
+ accountStatementDetails.setOccurrenceDate(purchaseReturnVo.getPreparedAt().toLocalDate());
+ //鍗曟嵁缂栧彿=閫�璐у崟鍙�
+ accountStatementDetails.setReceiptNumber(purchaseReturnVo.getReturnNo());
+ //绫诲瀷=閫�璐�
+ accountStatementDetails.setType(5);
+ //閲戦=閫�娆鹃噾棰�
+ accountStatementDetails.setAmount(purchaseReturnVo.getTotalAmount());
+ //澶囨敞
+ accountStatementDetails.setRemark("浜у搧閫�璐э紝閫�璐ф柟寮忥細"+purchaseReturnVo.getReturnType());
+ accountStatementDetailsList.add(accountStatementDetails);
+ });
+ //鏈熷垵浣欓=涓婁釜鏈堢殑鏈熸湯浣欓
+ statementAccountVo.setOpeningBalance(BigDecimal.ZERO);
+ List<AccountStatement> accountStatements = accountStatementMapper.selectList(Wrappers.<AccountStatement>lambdaQuery()
+ .eq(AccountStatement::getAccountType, 2)
+ .eq(AccountStatement::getCustomerId, statementAccountDto.getCustomerId())
+ .eq(AccountStatement::getStatementMonth,
+ YearMonth.parse(statementAccountDto.getStatementMonth()).minusMonths(1).toString()));
+ if (CollectionUtils.isNotEmpty(accountStatements)){
+ statementAccountVo.setOpeningBalance(accountStatements.get(accountStatements.size() - 1).getClosingBalance());
+ }
+ //鏈湡搴斾粯=鍏ュ簱-閫�璐ч噾棰濈疮璁�
+ statementAccountVo.setCurrentPlan(purchaseInboundVos.stream().map(PurchaseInboundVo::getInboundAmount).reduce(BigDecimal.ZERO, BigDecimal::add)
+ .subtract(purchaseReturnVos.stream().map(PurchaseReturnVo::getTotalAmount).reduce(BigDecimal.ZERO, BigDecimal::add)));
+ //鏈湡浠樻=浠樻閲戦绱
+ statementAccountVo.setCurrentActually(accountPurchasePayments.stream().map(AccountPurchasePayment::getPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add));
+ //鏈熸湯浣欓=鏈熷垵+搴旀敹-鏀舵
+ statementAccountVo.setClosingBalance(statementAccountVo.getOpeningBalance().add(statementAccountVo.getCurrentPlan()).subtract(statementAccountVo.getCurrentActually()));
+ statementAccountVo.setAccountStatementDetails(accountStatementDetailsList);
+ return statementAccountVo;
+ }
+
+ private String genStatementAccountNo() {
+ return "DZ" + LocalDateTime.now().format(CODE_TIME_FORMATTER) + new Random().nextInt(10);
+ }
+}
--
Gitblit v1.9.3