package com.ruoyi.web.dashboard;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
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.snapshot.domain.SnapshotQuery;
import com.ruoyi.bst.snapshot.domain.enums.SnapshotType;
import com.ruoyi.bst.snapshot.domain.vo.SnapshotDateVO;
import com.ruoyi.bst.snapshot.service.SnapshotService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.collection.CollectionUtils;


@RestController
@RequestMapping("/dashboard/snapshot")
public class DashboardSnapshotController extends BaseController {

    @Autowired
    private SnapshotService snapshotService;
    
    /**
     * 查询每日用户余额
     * @param param
     * @return
     */
    @GetMapping("/dailyUserBalance")
    public AjaxResult dailyUserBalance(SnapshotQuery query) {
        query.setType(SnapshotType.USER_BALANCE.getCode());
        List<SnapshotDateVO> list = snapshotService.selectSimpleForDate(query);
        if (query.getCreateDateRange() != null && query.getCreateDateRange().size() >= 2) {
            list = CollectionUtils.fillVoids(list, SnapshotDateVO::getDate, (date) -> {
                SnapshotDateVO vo = new SnapshotDateVO();
                vo.setDate(date);
                vo.setValue("0");
                return vo;
            },query.getCreateDateRange().get(0), query.getCreateDateRange().get(1));
        }
        return success(list);
    }
    
}
