| | |
| | | |
| | | // 查询所有产品 |
| | | 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()) { |
| | | Map<Long, Map<String, List<SalesLedgerProduct>>> groupedData = new LinkedHashMap<>(); |
| | | for (SalesLedgerProduct p : allProducts) { |
| | | Long ledgerId = p.getSalesLedgerId(); |
| | | String productCategory = StringUtils.defaultString(p.getProductCategory(), ""); |
| | | String specificationModel = StringUtils.defaultString(p.getSpecificationModel(), ""); |
| | | String groupKey = productCategory + "||" + specificationModel; |
| | | groupedData.computeIfAbsent(ledgerId, k -> new LinkedHashMap<>()) |
| | | .computeIfAbsent(groupKey, k -> new ArrayList<>()) |
| | | .add(p); |
| | | } |
| | | |
| | | for (Map.Entry<Long, Map<String, List<SalesLedgerProduct>>> ledgerEntry : groupedData.entrySet()) { |
| | | SalesLedger ledger = ledgerMap.get(ledgerEntry.getKey()); |
| | | String orderNo = ledger != null ? ledger.getSalesContractNo() : ""; |
| | | List<SalesLedgerProduct> products = ledgerEntry.getValue(); |
| | | |
| | | for (Map.Entry<String, List<SalesLedgerProduct>> productEntry : ledgerEntry.getValue().entrySet()) { |
| | | String key = productEntry.getKey(); |
| | | String[] parts = key.split("\\|\\|", -1); |
| | | String productName = parts.length > 0 ? parts[0] : ""; |
| | | List<SalesLedgerProduct> products = productEntry.getValue(); |
| | | |
| | | SalesInvoicesDto.InvoiceOrderGroupDto group = new SalesInvoicesDto.InvoiceOrderGroupDto(); |
| | | group.setSalesContractNo(orderNo); |
| | | if (CollectionUtils.isNotEmpty(products)) { |
| | | group.setProductName(products.get(0).getProductCategory()); |
| | | } |
| | | |
| | | group.setProductName(productName); |
| | | List<SalesInvoicesDto.InvoiceItemDto> itemDtos = new ArrayList<>(); |
| | | BigDecimal groupQty = BigDecimal.ZERO; |
| | | BigDecimal groupArea = BigDecimal.ZERO; |
| | |
| | | item.setFloorCode(p.getFloorCode()); |
| | | item.setWidthHeight((p.getWidth() != null ? p.getWidth().stripTrailingZeros().toPlainString() : "0") + |
| | | " * " + (p.getHeight() != null ? p.getHeight().stripTrailingZeros().toPlainString() : "0")); |
| | | item.setSpecificationModel(p.getSpecificationModel()); |
| | | item.setQuantity(p.getQuantity()); |
| | | |
| | | // 面积 |
| | |
| | | totalQty = totalQty.add(groupQty); |
| | | totalArea = totalArea.add(groupArea); |
| | | } |
| | | } |
| | | dto.setGroups(groups); |
| | | dto.setTotalQuantity(totalQty); |
| | | dto.setTotalArea(totalArea.setScale(2, RoundingMode.HALF_UP)); |