package com.sunxung.factoring.service.cashflowmanage.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunxung.factoring.entity.cashflowmanage.CashFlowManageOutInfo;
import com.sunxung.factoring.mapper.cashflowmanage.CashFlowManageOutInfoMapper;
import com.sunxung.factoring.service.cashflowmanage.CashFlowManageOutInfoService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Description : 现现金流管理出账信息service实现类
 * @Author : JiaYf
 * @Date: 2021-11-02 18:20
 */
@Service
public class CashFlowManageOutInfoServiceImpl extends ServiceImpl<CashFlowManageOutInfoMapper, CashFlowManageOutInfo>
        implements CashFlowManageOutInfoService {


    @Override
    public List<CashFlowManageOutInfo> findByBaseInfoId(Long baseInfoId) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("cash_flow_manage_basic_info_id", baseInfoId);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public BigDecimal sumLoanAmount(Long baseInfoId) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.select("IFNULL(SUM(loan_amount),0.00) AS loan_amount");
        queryWrapper.eq("cash_flow_manage_basic_info_id", baseInfoId);
        return baseMapper.selectOne(queryWrapper).getLoanAmount();
    }
}
