package com.ruoyi.bst.withdraw.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.withdraw.domain.WithdrawQuery;
import com.ruoyi.bst.withdraw.domain.enums.WithdrawStatus;
import com.ruoyi.bst.withdraw.domain.vo.WithdrawStatVO;
import com.ruoyi.bst.withdraw.mapper.WithdrawMapper;
import com.ruoyi.bst.withdraw.service.WithdrawDashboard;
import com.ruoyi.common.utils.MathUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.dashboard.constants.StatKeys;

@Service
public class WithdrawDashboardImpl implements WithdrawDashboard {
    
    @Autowired
    private WithdrawMapper withdrawMapper;

    @Override
    public WithdrawStatVO selectStat(WithdrawQuery query, List<String> keys) {
        WithdrawStatVO vo = new WithdrawStatVO();
        if (keys.contains(StatKeys.WITHDRAW_SUCCESS_AMOUNT)) {
            vo.setSuccessAmount(this.selectSuccessAmount(query));
        }
        return vo;
    }

    private BigDecimal selectSuccessAmount(WithdrawQuery query) {
        WithdrawQuery successQuery = new WithdrawQuery();
        BeanUtils.copyProperties(query, successQuery);
        successQuery.setStatus(WithdrawStatus.SUCCESS.getCode());
        return MathUtils.dv(withdrawMapper.selectSumOfAmount(successQuery));
    }
}
