From a1f940531cdededefe0cf5369f66811ee8f6e61b Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期四, 21 五月 2026 11:41:19 +0800
Subject: [PATCH] refactor(home): 替换AjaxResult为自定义R类,提高代码统一性
---
src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java | 171 ++++++--------------------------------------------------
1 files changed, 20 insertions(+), 151 deletions(-)
diff --git a/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java b/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
index e01927c..a17c012 100644
--- a/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
+++ b/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
@@ -3,9 +3,8 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
-import com.ruoyi.account.mapper.AccountExpenseMapper;
-import com.ruoyi.account.mapper.AccountIncomeMapper;
-import com.ruoyi.account.pojo.AccountExpense;
+import com.ruoyi.account.mapper.purchase.AccountPurchasePaymentMapper;
+import com.ruoyi.account.mapper.sales.AccountSalesCollectionMapper;
import com.ruoyi.approve.mapper.ApproveProcessMapper;
import com.ruoyi.approve.pojo.ApproveProcess;
import com.ruoyi.basic.mapper.CustomerMapper;
@@ -30,18 +29,14 @@
import com.ruoyi.production.mapper.*;
import com.ruoyi.project.system.domain.SysDept;
import com.ruoyi.project.system.mapper.SysDeptMapper;
-import com.ruoyi.purchase.mapper.PaymentRegistrationMapper;
import com.ruoyi.purchase.mapper.PurchaseLedgerMapper;
-import com.ruoyi.purchase.pojo.PaymentRegistration;
import com.ruoyi.purchase.pojo.PurchaseLedger;
import com.ruoyi.quality.mapper.QualityInspectMapper;
import com.ruoyi.quality.mapper.QualityUnqualifiedMapper;
import com.ruoyi.quality.pojo.QualityInspect;
import com.ruoyi.quality.pojo.QualityUnqualified;
-import com.ruoyi.sales.mapper.ReceiptPaymentMapper;
import com.ruoyi.sales.mapper.SalesLedgerMapper;
import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
-import com.ruoyi.sales.pojo.ReceiptPayment;
import com.ruoyi.sales.pojo.SalesLedger;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import com.ruoyi.staff.mapper.StaffOnJobMapper;
@@ -83,10 +78,6 @@
private final ApproveProcessMapper approveProcessMapper;
- private final ReceiptPaymentMapper receiptPaymentMapper;
-
- private final PaymentRegistrationMapper paymentRegistrationMapper;
-
private final SysDeptMapper sysDeptMapper;
private final NoticeMapper noticeMapper;
@@ -111,9 +102,8 @@
private final ProductionOperationTaskMapper productionOperationTaskMapper;
- private final AccountExpenseMapper accountExpenseMapper;
-
- private final AccountIncomeMapper accountIncomeMapper;
+ private final AccountPurchasePaymentMapper accountPurchasePaymentMapper;
+ private final AccountSalesCollectionMapper accountSalesCollectionMapper;
private final ProductionAccountMapper productionAccountMapper;
@@ -141,12 +131,8 @@
salesLedgers.stream().map(SalesLedger::getId).collect(Collectors.toList()));
List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper
.selectList(salesLedgerProductMapperLambdaQueryWrapper);
- // 鏈紑绁ㄩ噾棰�
- BigDecimal noInvoiceAmountTotal = salesLedgerProducts.stream().map(SalesLedgerProduct::getNoInvoiceAmount)
- .filter(Objects::nonNull)
- .reduce(BigDecimal.ZERO, BigDecimal::add);
homeBusinessDto.setMonthSaleMoney(contractAmount.setScale(2, RoundingMode.HALF_UP).toString());
- homeBusinessDto.setMonthSaleHaveMoney(noInvoiceAmountTotal.setScale(2, RoundingMode.HALF_UP).toString());
+ homeBusinessDto.setMonthSaleHaveMoney(BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP).toString());
}
// 鍒涘缓LambdaQueryWrapper
LambdaQueryWrapper<PurchaseLedger> queryWrapper = new LambdaQueryWrapper<>();
@@ -169,14 +155,8 @@
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add);
- // 寰呬粯娆炬�婚噾棰�
- BigDecimal unReceiptPaymentAmount = salesLedgerProductsCopy.stream()
- .map(SalesLedgerProduct::getPendingTicketsTotal)
- .filter(Objects::nonNull)
- .reduce(BigDecimal.ZERO, BigDecimal::add);
-
homeBusinessDto.setMonthPurchaseMoney(receiveAmount.setScale(2, RoundingMode.HALF_UP).toString());
- homeBusinessDto.setMonthPurchaseHaveMoney(unReceiptPaymentAmount.setScale(2, RoundingMode.HALF_UP).toString());
+ homeBusinessDto.setMonthPurchaseHaveMoney(BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP).toString());
}
// 缁熻搴撳瓨
BigDecimal stockQuantityTotal = stockInventoryMapper.selectTotal();
@@ -414,6 +394,7 @@
*/
@Override
public StatisticsReceivablePayableDto statisticsReceivablePayable(Integer type) {
+ StatisticsReceivablePayableDto statisticsReceivablePayableDto = new StatisticsReceivablePayableDto();
LocalDate today = LocalDate.now();
LocalDate startDate = null;
LocalDate endDate = null;
@@ -440,48 +421,14 @@
break;
}
// 搴旀敹
- List<SalesLedger> salesLedgers = salesLedgerMapper.selectList(new LambdaQueryWrapper<SalesLedger>()
- // .ge(SalesLedger::getEntryDate, startDate)
- // .lt(SalesLedger::getEntryDate, endDate)
- );
- // BigDecimal receivableMoney =
- // salesLedgers.stream().map(SalesLedger::getContractAmount).reduce(BigDecimal.ZERO,
- // BigDecimal::add);
- BigDecimal receivableMoney = sumAmount(salesLedgers, SalesLedger::getContractAmount);
+
// 搴斾粯
- List<PurchaseLedger> procurementRecords = purchaseLedgerMapper
- .selectList(new LambdaQueryWrapper<PurchaseLedger>()
- // .ge(PurchaseLedger::getEntryDate, startDate)
- // .lt(PurchaseLedger::getEntryDate, endDate)
- );
- // BigDecimal payableMoney =
- // procurementRecords.stream().map(PurchaseLedger::getContractAmount).reduce(BigDecimal.ZERO,
- // BigDecimal::add);
- BigDecimal payableMoney = sumAmount(procurementRecords, PurchaseLedger::getContractAmount);
+
// 棰勬敹
- List<ReceiptPayment> receiptPayments = receiptPaymentMapper.selectList(new LambdaQueryWrapper<ReceiptPayment>()
- // .ge(ReceiptPayment::getReceiptPaymentDate, startDate)
- // .lt(ReceiptPayment::getReceiptPaymentDate, endDate)
- );
- // BigDecimal advanceMoney =
- // receiptPayments.stream().map(ReceiptPayment::getReceiptPaymentAmount).reduce(BigDecimal.ZERO,
- // BigDecimal::add);
- BigDecimal advanceMoney = sumAmount(receiptPayments, ReceiptPayment::getReceiptPaymentAmount);
+
// 棰勪粯
- List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper
- .selectList(new LambdaQueryWrapper<PaymentRegistration>()
- // .ge(PaymentRegistration::getPaymentDate, startDate)
- // .lt(PaymentRegistration::getPaymentDate, endDate)
- );
- // BigDecimal prepayMoney =
- // paymentRegistrations.stream().map(PaymentRegistration::getCurrentPaymentAmount).reduce(BigDecimal.ZERO,
- // BigDecimal::add);
- BigDecimal prepayMoney = sumAmount(paymentRegistrations, PaymentRegistration::getCurrentPaymentAmount);
- StatisticsReceivablePayableDto statisticsReceivablePayableDto = new StatisticsReceivablePayableDto();
- statisticsReceivablePayableDto.setPayableMoney(payableMoney.subtract(prepayMoney));
- statisticsReceivablePayableDto.setReceivableMoney(receivableMoney.subtract(advanceMoney));
- statisticsReceivablePayableDto.setAdvanceMoney(advanceMoney);
- statisticsReceivablePayableDto.setPrepayMoney(prepayMoney);
+
+
return statisticsReceivablePayableDto;
}
@@ -1164,13 +1111,9 @@
String endStr = endDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
// 2. 鏌ヨ鏁版嵁
- List<IncomeExpenseAnalysisDto> incomeList = accountIncomeMapper.selectIncomeStats(startStr, endStr, dateFormat);
+ List<IncomeExpenseAnalysisDto> incomeList = accountSalesCollectionMapper.selectIncomeStats(startStr, endStr, dateFormat);
+ List<IncomeExpenseAnalysisDto> expenseList = accountPurchasePaymentMapper.selectPayment(startStr, endStr, dateFormat);
- // List<IncomeExpenseAnalysisDto> purchaseList =
- // purchaseLedgerMapper.selectPurchaseStats(startStr, endStr, dateFormat);
-
- List<IncomeExpenseAnalysisDto> expenseList = accountExpenseMapper.selectAccountExpenseStats(startStr, endStr,
- dateFormat);
// 3. 杞� Map锛堣嚜鍔ㄥ悎骞讹級
Map<String, BigDecimal> incomeMap = incomeList.stream()
@@ -1179,11 +1122,7 @@
IncomeExpenseAnalysisDto::getAmount,
BigDecimal::add));
- // Map<String, BigDecimal> purchaseMap = purchaseList.stream()
- // .collect(Collectors.toMap(
- // IncomeExpenseAnalysisDto::getDateStr,
- // IncomeExpenseAnalysisDto::getAmount,
- // BigDecimal::add));
+
Map<String, BigDecimal> expenseMap = expenseList.stream()
.collect(Collectors.toMap(
@@ -1197,18 +1136,12 @@
for (String dateStr : xAxis) {
Map<String, Object> item = new HashMap<>();
item.put("date", dateStr);
-
// 鏀跺叆
BigDecimal income = incomeMap.getOrDefault(dateStr, BigDecimal.ZERO);
item.put("income", income.setScale(2, RoundingMode.HALF_UP));
-
- // 鏀嚭 = 閲囪喘 + 璐㈠姟鏀嚭
- // BigDecimal purchase = purchaseMap.getOrDefault(dateStr, BigDecimal.ZERO);
+ // 鏀嚭
BigDecimal expense = expenseMap.getOrDefault(dateStr, BigDecimal.ZERO);
- // BigDecimal totalExpense = purchase.add(expense);
- BigDecimal totalExpense = expense;
-
- item.put("expense", totalExpense.setScale(2, RoundingMode.HALF_UP));
+ item.put("expense", expense.setScale(2, RoundingMode.HALF_UP));
result.add(item);
}
@@ -1235,8 +1168,8 @@
String startStr = startDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
String endStr = endDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
- List<IncomeExpenseAnalysisDto> incomeList = accountIncomeMapper.selectIncomeStats(startStr, endStr, dateFormat);
- List<IncomeExpenseAnalysisDto> expenseList = accountExpenseMapper.selectAccountExpenseStats(startStr, endStr, dateFormat);
+ List<IncomeExpenseAnalysisDto> incomeList = accountSalesCollectionMapper.selectIncomeStats(startStr, endStr, dateFormat);
+ List<IncomeExpenseAnalysisDto> expenseList = accountPurchasePaymentMapper.selectPayment(startStr, endStr, dateFormat);
Map<String, BigDecimal> incomeMap = incomeList.stream().collect(Collectors
.toMap(IncomeExpenseAnalysisDto::getDateStr, IncomeExpenseAnalysisDto::getAmount, BigDecimal::add));
@@ -1272,11 +1205,6 @@
rawMaterialDto.setName("鍘熸潗鏂�");
rawMaterialDto.setValue(rawMaterialAmount != null ? rawMaterialAmount.toString() : "0");
result.add(rawMaterialDto);
-
- List<MapDto> expenseList = accountExpenseMapper.selectExpenseComposition(null, null);
- if (expenseList != null) {
- result.addAll(expenseList);
- }
}
BigDecimal total = BigDecimal.ZERO;
@@ -1327,34 +1255,6 @@
return dto;
}
- BigDecimal collected = products.stream()
- .map(SalesLedgerProduct::getInvoiceTotal)
- .filter(Objects::nonNull)
- .reduce(BigDecimal.ZERO, BigDecimal::add);
- dto.setMonthlyIncome(collected);
-
- BigDecimal overdue = products.stream()
- .map(SalesLedgerProduct::getPendingInvoiceTotal)
- .filter(Objects::nonNull)
- .reduce(BigDecimal.ZERO, BigDecimal::add);
- dto.setOverdueNum(overdue);
-
- BigDecimal total = collected.add(overdue);
-
- if (total.compareTo(BigDecimal.ZERO) > 0) {
- String collectionRate = collected.divide(total, 4, RoundingMode.HALF_UP)
- .multiply(new BigDecimal("100"))
- .setScale(2, RoundingMode.HALF_UP)
- .toString();
- dto.setCollectionRate(collectionRate);
-
- String overdueRate = overdue.divide(total, 4, RoundingMode.HALF_UP)
- .multiply(new BigDecimal("100"))
- .setScale(2, RoundingMode.HALF_UP)
- .toString();
- dto.setOverdueRate(overdueRate);
- }
-
return dto;
}
@@ -1386,38 +1286,14 @@
if (p.getTaxInclusiveTotalPrice() != null) {
rawMaterialCost = rawMaterialCost.add(p.getTaxInclusiveTotalPrice());
}
-
- if (p.getTicketsTotal() != null) {
- paidAmount = paidAmount.add(p.getTicketsTotal());
- }
-
- if (p.getPendingTicketsTotal() != null) {
- pendingAmount = pendingAmount.add(p.getPendingTicketsTotal());
- }
}
}
// 鍏朵粬璐圭敤
- LambdaQueryWrapper<AccountExpense> expenseWrapper = new LambdaQueryWrapper<>();
- expenseWrapper.ge(AccountExpense::getExpenseDate,
- java.sql.Date.valueOf(currentMonth.atDay(1)));
- expenseWrapper.le(AccountExpense::getExpenseDate,
- java.sql.Date.valueOf(currentMonth.atEndOfMonth()));
- List<AccountExpense> expenses = accountExpenseMapper.selectList(expenseWrapper);
-
- BigDecimal otherExpense = BigDecimal.ZERO;
- if (!CollectionUtils.isEmpty(expenses)) {
- for (AccountExpense e : expenses) {
- if (e.getExpenseMoney() != null) {
- otherExpense = otherExpense.add(e.getExpenseMoney());
- }
- }
- }
// 鏈堝害鎬绘敮鍑�
- // BigDecimal monthlyExpenditure = rawMaterialCost.add(otherExpense);
- BigDecimal monthlyExpenditure = otherExpense;
+ BigDecimal monthlyExpenditure = BigDecimal.ZERO;
dto.setMonthlyExpenditure(monthlyExpenditure);
// 宸蹭粯娆� 梅锛堝凡浠樻 + 寰呬粯娆撅級
@@ -1440,13 +1316,6 @@
List<SalesLedgerProduct> salesProducts = salesLedgerProductMapper.selectList(salesWrapper);
BigDecimal revenue = BigDecimal.ZERO;
- if (!CollectionUtils.isEmpty(salesProducts)) {
- for (SalesLedgerProduct s : salesProducts) {
- if (s.getInvoiceAmount() != null) {
- revenue = revenue.add(s.getInvoiceAmount());
- }
- }
- }
// 姣涘埄娑� & 鍒╂鼎鐜�
if (revenue.compareTo(BigDecimal.ZERO) > 0) {
--
Gitblit v1.9.3