chenrui
6 天以前 3512270362c77fe45bc68ab7b6f28bd1bd2f8bfb
src/main/java/com/ruoyi/sales/service/impl/ReceiptPaymentServiceImpl.java
@@ -4,6 +4,8 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.purchase.dto.PaymentHistoryRecordVo;
import com.ruoyi.sales.dto.CustomerInteractionDto;
import com.ruoyi.sales.dto.InvoiceLedgerDto;
import com.ruoyi.sales.dto.ReceiptPaymentDto;
import com.ruoyi.sales.mapper.ReceiptPaymentMapper;
@@ -20,6 +22,7 @@
import java.time.LocalDate;
import java.time.YearMonth;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class ReceiptPaymentServiceImpl extends ServiceImpl<ReceiptPaymentMapper,ReceiptPayment> implements ReceiptPaymentService {
@@ -190,4 +193,53 @@
    public IPage<ReceiptPaymentDto> receiptPaymentHistoryListPage(Page page, ReceiptPaymentDto receiptPaymentDto) {
        return receiptPaymentMapper.receiptPaymentHistoryListPage(page, receiptPaymentDto);
    }
    /**
     * 客户往来记录查询
     * @param receiptPaymentDto
     * @return
     */
    @Override
    public List<CustomerInteractionDto> customerInteractions(ReceiptPaymentDto receiptPaymentDto) {
        ArrayList<CustomerInteractionDto> result = new ArrayList<>();
        List<CustomerInteractionDto> customerInteractionDtos = receiptPaymentMapper.customerInteractions(receiptPaymentDto);
        if(CollectionUtils.isEmpty(customerInteractionDtos)){
            return result;
        }
        // 应收总金额金额计算
        BigDecimal amountTotal = BigDecimal.ZERO;
        Map<LocalDate, List<CustomerInteractionDto>> dateListMap = customerInteractionDtos.stream().collect(
                Collectors.groupingBy(
                        CustomerInteractionDto::getHappenTime,
                        LinkedHashMap::new,
                        Collectors.toList()
                )
        );
        for (LocalDate localDate : dateListMap.keySet()) {
            BigDecimal currentReceiptAmount = BigDecimal.ZERO;
            BigDecimal invoiceAmount = BigDecimal.ZERO;
            BigDecimal currentDateTotal = BigDecimal.ZERO;
            List<CustomerInteractionDto> customerInteractionDtoList = dateListMap.get(localDate);
            // 计算当天收款数
            currentReceiptAmount = customerInteractionDtoList.stream()
                    .filter(item ->item.getType() == 0)
                    .map(CustomerInteractionDto::getReceiptAmount)
                    .reduce(BigDecimal.ZERO,BigDecimal::add);
            // 计算当天开票数
            invoiceAmount = customerInteractionDtoList.stream()
                    .filter(item ->item.getType() == 1)
                    .map(CustomerInteractionDto::getInvoiceAmount)
                    .reduce(BigDecimal.ZERO,BigDecimal::add);
            // 计算当日汇总
            currentDateTotal = currentDateTotal.add(invoiceAmount).subtract(currentReceiptAmount);
            CustomerInteractionDto customerInteractionDto = new CustomerInteractionDto();
            customerInteractionDto.setHappenTime(localDate);
            customerInteractionDto.setInvoiceAmount(invoiceAmount);
            customerInteractionDto.setReceiptAmount(currentReceiptAmount);
            amountTotal = amountTotal.add(currentDateTotal);
            customerInteractionDto.setUnReceiptAmount(amountTotal);
            result.add(customerInteractionDto);
        }
        return result;
    }
}