From 93b93bacbe43fcd2f13884ec02782baf77193d35 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期二, 21 四月 2026 11:05:00 +0800
Subject: [PATCH] feat: 销售台账增加一个宽高搜索,页面加面积、数量的字段展示
---
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java | 193 +++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 164 insertions(+), 29 deletions(-)
diff --git a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
index 4d7e21f..9b21618 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -418,7 +418,112 @@
@Override
public IPage<SalesLedger> selectSalesLedgerListPage(Page page, SalesLedgerDto salesLedgerDto) {
- return salesLedgerMapper.selectSalesLedgerListPage(page, salesLedgerDto);
+ IPage<SalesLedger> iPage = salesLedgerMapper.selectSalesLedgerListPage(page, salesLedgerDto);
+
+ if (CollectionUtils.isEmpty(iPage.getRecords())) {
+ return iPage;
+ }
+
+ List<Long> salesLedgerIds = iPage.getRecords().stream().map(SalesLedger::getId).collect(Collectors.toList());
+
+ boolean hasWidthHeightFilter = salesLedgerDto.getWidth() != null || salesLedgerDto.getHeight() != null;
+ Map<Long, List<SalesLedgerProduct>> matchedProductsMap = Collections.emptyMap();
+ if (hasWidthHeightFilter) {
+ LambdaQueryWrapper<SalesLedgerProduct> productQueryWrapper = new LambdaQueryWrapper<SalesLedgerProduct>()
+ .in(SalesLedgerProduct::getSalesLedgerId, salesLedgerIds)
+ .eq(SalesLedgerProduct::getType, 1);
+ if (salesLedgerDto.getWidth() != null) {
+ productQueryWrapper.eq(SalesLedgerProduct::getWidth, salesLedgerDto.getWidth());
+ }
+ if (salesLedgerDto.getHeight() != null) {
+ productQueryWrapper.eq(SalesLedgerProduct::getHeight, salesLedgerDto.getHeight());
+ }
+ List<SalesLedgerProduct> matchedProducts = salesLedgerProductMapper.selectList(productQueryWrapper);
+ matchedProductsMap = CollectionUtils.isEmpty(matchedProducts) ? Collections.emptyMap()
+ : matchedProducts.stream().collect(Collectors.groupingBy(SalesLedgerProduct::getSalesLedgerId));
+ }
+
+ List<SalesLedgerProductTotalsDto> productTotals = salesLedgerProductMapper.selectSalesLedgerProductTotals(salesLedgerIds, 1);
+ Map<Long, SalesLedgerProductTotalsDto> productTotalsMap = CollectionUtils.isEmpty(productTotals)
+ ? Collections.emptyMap()
+ : productTotals.stream()
+ .filter(t -> t.getSalesLedgerId() != null)
+ .collect(Collectors.toMap(SalesLedgerProductTotalsDto::getSalesLedgerId, Function.identity(), (a, b) -> a));
+
+ List<InvoiceLedgerDto> invoiceLedgerDtoList = invoiceLedgerMapper.invoicedTotal(salesLedgerIds);
+ if (CollectionUtils.isEmpty(invoiceLedgerDtoList)) {
+ invoiceLedgerDtoList = Collections.emptyList();
+ }
+
+ Map<Long, BigDecimal> invoiceTotals = invoiceLedgerDtoList.stream()
+ .filter(dto -> dto.getSalesLedgerId() != null && dto.getInvoiceTotal() != null)
+ .collect(Collectors.toMap(
+ dto -> dto.getSalesLedgerId().longValue(),
+ InvoiceLedgerDto::getInvoiceTotal,
+ BigDecimal::add
+ ));
+
+ List<ReceiptPayment> receiptPayments = Collections.emptyList();
+ if (!CollectionUtils.isEmpty(salesLedgerIds)) {
+ receiptPayments = receiptPaymentMapper.selectList(new LambdaQueryWrapper<ReceiptPayment>()
+ .in(ReceiptPayment::getSalesLedgerId, salesLedgerIds));
+ }
+
+ Map<Long, BigDecimal> receiptTotals = new HashMap<>();
+ if (!CollectionUtils.isEmpty(receiptPayments)) {
+ for (ReceiptPayment receiptPayment : receiptPayments) {
+ if (receiptPayment.getSalesLedgerId() != null && receiptPayment.getReceiptPaymentAmount() != null) {
+ receiptTotals.merge(receiptPayment.getSalesLedgerId(), receiptPayment.getReceiptPaymentAmount(), BigDecimal::add);
+ }
+ }
+ }
+
+ for (SalesLedger salesLedger : iPage.getRecords()) {
+ Long ledgerId = salesLedger.getId();
+
+ SalesLedgerProductTotalsDto totals = productTotalsMap.get(ledgerId);
+ if (totals != null) {
+ salesLedger.setProductTotalQuantity(totals.getTotalQuantity() != null ? totals.getTotalQuantity() : BigDecimal.ZERO);
+ salesLedger.setProductTotalArea(totals.getTotalArea() != null ? totals.getTotalArea() : BigDecimal.ZERO);
+ } else {
+ salesLedger.setProductTotalQuantity(BigDecimal.ZERO);
+ salesLedger.setProductTotalArea(BigDecimal.ZERO);
+ }
+ if (hasWidthHeightFilter) {
+ salesLedger.setMatchedProducts(matchedProductsMap.getOrDefault(ledgerId, Collections.emptyList()));
+ }
+
+ BigDecimal contractAmount = salesLedger.getContractAmount() == null ? BigDecimal.ZERO : salesLedger.getContractAmount();
+ BigDecimal invoiceTotal = invoiceTotals.getOrDefault(ledgerId, BigDecimal.ZERO);
+ BigDecimal receiptPaymentAmountTotal = receiptTotals.getOrDefault(ledgerId, BigDecimal.ZERO);
+
+ BigDecimal noInvoiceAmountTotal = contractAmount.subtract(invoiceTotal);
+ if (noInvoiceAmountTotal.compareTo(BigDecimal.ZERO) < 0) {
+ noInvoiceAmountTotal = BigDecimal.ZERO;
+ }
+
+ BigDecimal noReceiptPaymentAmountTotal = invoiceTotal.subtract(receiptPaymentAmountTotal);
+ if (noReceiptPaymentAmountTotal.compareTo(BigDecimal.ZERO) < 0) {
+ noReceiptPaymentAmountTotal = BigDecimal.ZERO;
+ }
+
+ salesLedger.setNoInvoiceAmountTotal(noInvoiceAmountTotal);
+ salesLedger.setInvoiceTotal(invoiceTotal);
+ salesLedger.setReceiptPaymentAmountTotal(receiptPaymentAmountTotal);
+ salesLedger.setNoReceiptAmount(noReceiptPaymentAmountTotal);
+
+ boolean hasInvoiceOperation = invoiceTotal.compareTo(BigDecimal.ZERO) > 0;
+ boolean hasReceiptOperation = receiptPaymentAmountTotal.compareTo(BigDecimal.ZERO) > 0;
+ salesLedger.setIsEdit(!(hasInvoiceOperation || hasReceiptOperation));
+ }
+
+ if (salesLedgerDto.getStatus() != null && salesLedgerDto.getStatus()) {
+ iPage.getRecords().removeIf(salesLedger ->
+ Objects.equals(salesLedger.getNoInvoiceAmountTotal(), new BigDecimal("0.00")));
+ iPage.setTotal(iPage.getRecords().size());
+ }
+
+ return iPage;
}
@Override
@@ -1498,58 +1603,88 @@
// 鏌ヨ鎵�鏈変骇鍝�
List<SalesLedgerProduct> allProducts = salesLedgerProductMapper.selectList(
- new LambdaQueryWrapper<SalesLedgerProduct>().in(SalesLedgerProduct::getSalesLedgerId, salesLedgerIds));
+ new LambdaQueryWrapper<SalesLedgerProduct>()
+ .in(SalesLedgerProduct::getSalesLedgerId, salesLedgerIds)
+ .eq(SalesLedgerProduct::getType, 1));
if (CollectionUtils.isNotEmpty(allProducts)) {
Map<Long, SalesLedger> ledgerMap = ledgers.stream()
.collect(Collectors.toMap(SalesLedger::getId, Function.identity()));
- Map<Long, List<SalesLedgerProduct>> groupedData = new LinkedHashMap<>();
- for (SalesLedgerProduct p : allProducts) {
- groupedData.computeIfAbsent(p.getSalesLedgerId(), k -> new ArrayList<>()).add(p);
- }
-
List<SalesInvoicesDto.InvoiceOrderGroupDto> groups = new ArrayList<>();
BigDecimal totalQty = BigDecimal.ZERO;
BigDecimal totalArea = BigDecimal.ZERO;
- for (Map.Entry<Long, List<SalesLedgerProduct>> ledgerEntry : groupedData.entrySet()) {
- SalesLedger ledger = ledgerMap.get(ledgerEntry.getKey());
- String orderNo = ledger != null ? ledger.getSalesContractNo() : "";
- List<SalesLedgerProduct> products = ledgerEntry.getValue();
+ Map<String, List<SalesLedgerProduct>> groupedData = new LinkedHashMap<>();
+ Map<String, Set<String>> groupOrderNos = new LinkedHashMap<>();
+ for (SalesLedgerProduct p : allProducts) {
+ String productCategory = StringUtils.defaultString(p.getProductCategory(), "");
+ String specificationModel = StringUtils.defaultString(p.getSpecificationModel(), "");
+ String groupKey = productCategory + "||" + specificationModel;
+ groupedData.computeIfAbsent(groupKey, k -> new ArrayList<>()).add(p);
+
+ SalesLedger ledger = ledgerMap.get(p.getSalesLedgerId());
+ String orderNo = ledger != null ? StringUtils.defaultString(ledger.getSalesContractNo(), "") : "";
+ if (StringUtils.isNotEmpty(orderNo)) {
+ groupOrderNos.computeIfAbsent(groupKey, k -> new LinkedHashSet<>()).add(orderNo);
+ }
+ }
+
+ for (Map.Entry<String, List<SalesLedgerProduct>> productEntry : groupedData.entrySet()) {
+ String key = productEntry.getKey();
+ String[] parts = key.split("\\|\\|", -1);
+ String productName = parts.length > 0 ? parts[0] : "";
+ String specificationModel = parts.length > 1 ? parts[1] : "";
+ List<SalesLedgerProduct> products = productEntry.getValue();
SalesInvoicesDto.InvoiceOrderGroupDto group = new SalesInvoicesDto.InvoiceOrderGroupDto();
- group.setSalesContractNo(orderNo);
- if (CollectionUtils.isNotEmpty(products)) {
- group.setProductName(products.get(0).getProductCategory());
- }
+ Set<String> orderNos = groupOrderNos.getOrDefault(key, Collections.emptySet());
+ group.setSalesContractNo(String.join(",", orderNos));
+ group.setProductName(productName);
+ group.setSpecificationModel(specificationModel);
- List<SalesInvoicesDto.InvoiceItemDto> itemDtos = new ArrayList<>();
+ Map<String, SalesInvoicesDto.InvoiceItemDto> mergedItems = new LinkedHashMap<>();
BigDecimal groupQty = BigDecimal.ZERO;
BigDecimal groupArea = BigDecimal.ZERO;
for (SalesLedgerProduct p : products) {
- SalesInvoicesDto.InvoiceItemDto item = new SalesInvoicesDto.InvoiceItemDto();
- item.setFloorCode(p.getFloorCode());
- item.setWidthHeight((p.getWidth() != null ? p.getWidth().stripTrailingZeros().toPlainString() : "0") +
- " * " + (p.getHeight() != null ? p.getHeight().stripTrailingZeros().toPlainString() : "0"));
- item.setQuantity(p.getQuantity());
+ String widthHeight = (p.getWidth() != null ? p.getWidth().stripTrailingZeros().toPlainString() : "0") +
+ " * " + (p.getHeight() != null ? p.getHeight().stripTrailingZeros().toPlainString() : "0");
+ String floorCode = StringUtils.defaultString(p.getFloorCode(), "");
+ String remark = StringUtils.defaultString(p.getRemark(), "");
+ String processReq = StringUtils.defaultString(p.getProcessRequirement(), "");
+ String itemKey = floorCode + "||" + widthHeight + "||" + remark + "||" + processReq;
+
+ BigDecimal qty = p.getQuantity() != null ? p.getQuantity() : BigDecimal.ZERO;
// 闈㈢Н
BigDecimal area = p.getSettleTotalArea() != null ? p.getSettleTotalArea() : p.getActualTotalArea();
if (area == null && p.getWidth() != null && p.getHeight() != null && p.getQuantity() != null) {
area = p.getWidth().multiply(p.getHeight()).multiply(p.getQuantity()).divide(new BigDecimal(1000000), 2, RoundingMode.HALF_UP);
}
- item.setArea(area);
- item.setRemark(p.getRemark());
- item.setProcessRequirement(p.getProcessRequirement());
+ area = area != null ? area : BigDecimal.ZERO;
- itemDtos.add(item);
- groupQty = groupQty.add(p.getQuantity() != null ? p.getQuantity() : BigDecimal.ZERO);
- groupArea = groupArea.add(area != null ? area : BigDecimal.ZERO);
+ SalesInvoicesDto.InvoiceItemDto item = mergedItems.get(itemKey);
+ if (item == null) {
+ item = new SalesInvoicesDto.InvoiceItemDto();
+ item.setFloorCode(floorCode);
+ item.setWidthHeight(widthHeight);
+ item.setSpecificationModel(p.getSpecificationModel());
+ item.setQuantity(qty);
+ item.setArea(area);
+ item.setRemark(remark);
+ item.setProcessRequirement(processReq);
+ mergedItems.put(itemKey, item);
+ } else {
+ item.setQuantity((item.getQuantity() != null ? item.getQuantity() : BigDecimal.ZERO).add(qty));
+ item.setArea((item.getArea() != null ? item.getArea() : BigDecimal.ZERO).add(area));
+ }
+
+ groupQty = groupQty.add(qty);
+ groupArea = groupArea.add(area);
}
- group.setItems(itemDtos);
+ group.setItems(new ArrayList<>(mergedItems.values()));
group.setGroupTotalQuantity(groupQty);
group.setGroupTotalArea(groupArea.setScale(2, RoundingMode.HALF_UP));
groups.add(group);
@@ -1610,7 +1745,7 @@
SalesLabelDto dto = new SalesLabelDto();
dto.setCustomerName(salesLedger.getCustomerName());
dto.setSalesContractNo(salesLedger.getSalesContractNo());
- dto.setProductName(p.getProductCategory());
+ dto.setProductName(p.getSpecificationModel());
// 瀹�*楂�=鏁伴噺
String specification = (p.getWidth() != null ? p.getWidth().stripTrailingZeros().toPlainString() : "0") + "*" +
--
Gitblit v1.9.3