package com.sunxung.factoring.service.financing.apply.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunxung.factoring.entity.financing.apply.CFinancingGoodsInfo;
import com.sunxung.factoring.mapper.financing.apply.CFinancingGoodsInfoMapper;
import com.sunxung.factoring.service.financing.apply.ICFinancingGoodsInfoService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * <p>
 * 融资申请-货物信息表 服务实现类
 * </p>
 *
 * @author liutao
 * @since 2023-12-19
 */
@Service
public class CFinancingGoodsInfoServiceImpl extends ServiceImpl<CFinancingGoodsInfoMapper, CFinancingGoodsInfo>
        implements ICFinancingGoodsInfoService {

    @Override
    public BigDecimal sumSalesTotalPrice(Long financingBasicInfoId) {
        BigDecimal salesTotalPriceSum = list(new QueryWrapper<CFinancingGoodsInfo>().eq("c_financing_basic_info_id", financingBasicInfoId))
                .stream().filter(goods -> goods.getSalesTotalPrice() != null)
                .map(CFinancingGoodsInfo::getSalesTotalPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
        return salesTotalPriceSum;
    }

    @Override
    public BigDecimal sumPurchaseTotalPrice(Long financingBasicInfoId) {
        BigDecimal purchaseTotalPriceSum = list(new QueryWrapper<CFinancingGoodsInfo>().eq("c_financing_basic_info_id", financingBasicInfoId))
                .stream().filter(goods -> goods.getPurchaseTotalPrice() != null)
                .map(CFinancingGoodsInfo::getPurchaseTotalPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
        return purchaseTotalPriceSum;
    }
}
