package com.ruoyi.bst.bonusRefund.service.impl;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.bst.bonus.domain.enums.BonusArrivalType;
import com.ruoyi.bst.bonusRefund.domain.BonusRefundQuery;
import com.ruoyi.bst.bonusRefund.domain.vo.BonusRefundDailyStatVO;
import com.ruoyi.bst.bonusRefund.domain.vo.BonusRefundStatVO;
import com.ruoyi.bst.bonusRefund.mapper.BonusRefundMapper;
import com.ruoyi.bst.bonusRefund.service.BonusRefundDashboard;
import com.ruoyi.common.utils.MathUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.dashboard.constants.StatKeys;

@Service
public class BonusRefundDashboardImpl implements BonusRefundDashboard {

    @Autowired
    private BonusRefundMapper bonusRefundMapper;

    @Override
    public BonusRefundStatVO selectStat(BonusRefundQuery query, List<String> keys) {
        BonusRefundStatVO vo = new BonusRefundStatVO();
        if (keys.contains(StatKeys.BONUS_REFUND_AMOUNT)) {
            vo.setAmount(this.selectSumOfAmount(query));
        }
        return vo;
    }

    // 查询分成退款总金额
    private BigDecimal selectSumOfAmount(BonusRefundQuery query) {
        return MathUtils.dv(bonusRefundMapper.selectSumOfAmount(query));
    }

    @Override
    public List<BonusRefundDailyStatVO> selectDailyStat(BonusRefundQuery query, List<String> keys) {
        return bonusRefundMapper.selectDailyStat(query, keys);
    }

    @Override
    public BigDecimal selectSumOfUserBonusRefund(BonusRefundQuery query) {
        BonusRefundQuery bonusRefundQuery = new BonusRefundQuery();
        BeanUtils.copyBeanProp(bonusRefundQuery, query);
        bonusRefundQuery.setBonusArrivalTypes(BonusArrivalType.userList());
        return this.selectSumOfAmount(bonusRefundQuery);
    }

    @Override
    public BigDecimal selectSumOfPlatformBonusRefund(BonusRefundQuery query) {
        BonusRefundQuery bonusRefundQuery = new BonusRefundQuery();
        BeanUtils.copyBeanProp(bonusRefundQuery, query);
        bonusRefundQuery.setBonusArrivalTypes(BonusArrivalType.platformList());
        return this.selectSumOfAmount(bonusRefundQuery);
    }
    
    
}
