| | |
| | | // .ge(SalesLedger::getEntryDate, startDate) |
| | | // .lt(SalesLedger::getEntryDate, endDate) |
| | | ); |
| | | BigDecimal receivableMoney = salesLedgers.stream().map(SalesLedger::getContractAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // 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 = 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 = 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 = 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)); |
| | |
| | | |
| | | return statisticsReceivablePayableDto; |
| | | } |
| | | |
| | | public static <T> BigDecimal sumAmount(List<T> list, java.util.function.Function<T, BigDecimal> amountExtractor) { |
| | | return list.stream() |
| | | // 提取金额时,将null替换为BigDecimal.ZERO |
| | | .map(item -> Optional.ofNullable(amountExtractor.apply(item)).orElse(BigDecimal.ZERO)) |
| | | // 累加,初始值为0,避免空流问题 |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | } |
| | | @Autowired |
| | | private DeviceRepairMapper deviceRepairMapper; |
| | | |