package com.ruoyi.web.dashboard;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.bst.bonus.domain.enums.BonusStatus;
import com.ruoyi.bst.bonusRefund.constants.BonusRefundDailyKeys;
import com.ruoyi.bst.bonusRefund.domain.BonusRefundQuery;
import com.ruoyi.bst.bonusRefund.domain.vo.BonusRefundDailyStatVO;
import com.ruoyi.bst.bonusRefund.service.BonusRefundDashboard;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.collection.CollectionUtils;

@RestController
@RequestMapping("/dashboard/bonusRefund")
public class DashboardBonusRefundController extends BaseController {

    @Autowired
    private BonusRefundDashboard bonusRefundDashboard;

    @PreAuthorize("@ss.hasPermi('dashboard:bonusRefund:dailyAmount')")
    @GetMapping("/dailyAmount")
    public AjaxResult getDailyAmount(BonusRefundQuery query) {
        query.setScope(true);
        query.setBonusStatusList(BonusStatus.valid());
        List<String> keys = Arrays.asList(BonusRefundDailyKeys.CREATE_DATE, BonusRefundDailyKeys.BONUS_REFUND_AMOUNT);
        List<BonusRefundDailyStatVO> list = bonusRefundDashboard.selectDailyStat(query, keys);
        if (query.getCreateDateRange() != null && query.getCreateDateRange().size() >= 2) {
            list = CollectionUtils.fillVoids(list, BonusRefundDailyStatVO::getDate, (date) -> {
                BonusRefundDailyStatVO vo = new BonusRefundDailyStatVO();
                vo.setDate(date);
                return vo;
            }, query.getCreateDateRange().get(0), query.getCreateDateRange().get(1));
        }
        return success(list);
    }
    
    
}
