yaowanxin
昨天 e2aa651db9f17d58819329de571037edc0f9eba2
src/main/java/com/ruoyi/sales/service/impl/ReceiptPaymentServiceImpl.java
@@ -4,8 +4,12 @@
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.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.sales.dto.CustomerInteractionDto;
import com.ruoyi.sales.dto.InvoiceLedgerDto;
import com.ruoyi.sales.dto.ReceiptPaymentDto;
import com.ruoyi.sales.dto.ReceiptPaymentExeclDto;
import com.ruoyi.sales.mapper.ReceiptPaymentMapper;
import com.ruoyi.sales.mapper.SalesLedgerMapper;
import com.ruoyi.sales.pojo.ReceiptPayment;
@@ -16,10 +20,12 @@
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
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 {
@@ -132,7 +138,11 @@
     */
    @Override
    public IPage<ReceiptPaymentDto> bindInvoiceNoRegPage(Page page, ReceiptPaymentDto receiptPaymentDto) {
        return receiptPaymentMapper.bindInvoiceNoRegPage(page, receiptPaymentDto);
        IPage<ReceiptPaymentDto> receiptPaymentDtoIPage = receiptPaymentMapper.bindInvoiceNoRegPage(page, receiptPaymentDto);
        if (receiptPaymentDto.getStatus()) {
            receiptPaymentDtoIPage.getRecords().removeIf(receiptPaymentDto1 -> new BigDecimal("0.00").equals(receiptPaymentDto1.getNoReceiptAmount()));
        }
        return receiptPaymentDtoIPage;
    }
    /**
@@ -182,4 +192,90 @@
    public List<ReceiptPaymentDto> receiptPaymentHistoryList(ReceiptPaymentDto receiptPaymentDto) {
        return receiptPaymentMapper.receiptPaymentHistoryList(receiptPaymentDto);
    }
    /**
     * 查询回款记录分页
     */
    @Override
    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 = customerInteractionDto.getInvoiceAmount().subtract(customerInteractionDto.getReceiptAmount());
            customerInteractionDto.setUnReceiptAmount(amountTotal);
            result.add(customerInteractionDto);
        }
        return result;
    }
    /**
     * 查询回款记录分页
     */
    @Override
    public List<ReceiptPaymentDto> receiptPaymentHistoryListNoPage(ReceiptPaymentDto receiptPaymentDto) {
        return receiptPaymentMapper.receiptPaymentHistoryListNoPage( receiptPaymentDto);
    }
    @Override
    public void exportPaymentList(HttpServletResponse response) {
       List<ReceiptPaymentDto> receiptPaymentDtoList =  receiptPaymentMapper.bindInvoiceNoRegListAll();
        ExcelUtil<ReceiptPaymentDto> util = new ExcelUtil<ReceiptPaymentDto>(ReceiptPaymentDto.class);
        util.exportExcel(response, receiptPaymentDtoList, "回款登记");
    }
    @Override
    public void exportPaymentList(HttpServletResponse response, List<Long> ids) {
        if (ids == null) {
            List<ReceiptPaymentExeclDto> receiptPaymentDtoList =  receiptPaymentMapper.bindInvoiceNoRegListByIds(new ArrayList<>(), SecurityUtils.getLoginUser().getTenantId());
            ExcelUtil<ReceiptPaymentExeclDto> util = new ExcelUtil<ReceiptPaymentExeclDto>(ReceiptPaymentExeclDto.class);
            util.exportExcel(response, receiptPaymentDtoList, "回款登记");
        }else {
            List<ReceiptPaymentExeclDto> receiptPaymentDtoList =  receiptPaymentMapper.bindInvoiceNoRegListByIds(ids,SecurityUtils.getLoginUser().getTenantId());
            ExcelUtil<ReceiptPaymentExeclDto> util = new ExcelUtil<ReceiptPaymentExeclDto>(ReceiptPaymentExeclDto.class);
            util.exportExcel(response, receiptPaymentDtoList, "回款登记");
        }
    }
}