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

import java.util.List;

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

import com.ruoyi.bst.order.domain.OrderQuery;
import com.ruoyi.bst.order.domain.query.OrderRefundQuery;
import com.ruoyi.bst.order.domain.vo.OrderDailyRefundStatVO;
import com.ruoyi.bst.order.domain.vo.OrderDailyStatVO;
import com.ruoyi.bst.order.domain.vo.OrderRankVO;
import com.ruoyi.bst.order.domain.vo.OrderRefundStatVO;
import com.ruoyi.bst.order.domain.vo.OrderStatVO;
import com.ruoyi.bst.order.mapper.OrderMapper;
import com.ruoyi.bst.order.service.OrderDashboard;
import com.ruoyi.common.utils.MathUtils;
import com.ruoyi.dashboard.constants.StatKeys;

@Service
public class OrderDashboardImpl implements OrderDashboard {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public OrderStatVO selectStat(OrderQuery query, List<String> keys) {
        OrderStatVO vo = new OrderStatVO();
        // 订单用户数量
        if (keys.contains(StatKeys.ORDER_USER_COUNT)) {
            vo.setUserCount(MathUtils.dv(orderMapper.selectUserCount(query)));
        }
        // 订单数量
        if (keys.contains(StatKeys.ORDER_COUNT)) {
            vo.setCount(MathUtils.dv(orderMapper.selectCount(query)));
        }
        // 订单支付金额
        if (keys.contains(StatKeys.ORDER_PAY_AMOUNT)) {
            vo.setPayAmount(MathUtils.dv(orderMapper.selectSumOfPayAmount(query)));
        }
        return vo;
    }

    @Override
    public OrderRefundStatVO selectRefundStat(OrderRefundQuery query, List<String> keys) {
        OrderRefundStatVO vo = new OrderRefundStatVO();
        // 退款金额
        if (keys.contains(StatKeys.ORDER_REFUND_AMOUNT)) {
            vo.setAmount(MathUtils.dv(orderMapper.selectSumOfRefundAmount(query)));
        }
        return vo;
    }
    
    // 查询订单的每日统计
    @Override
    public List<OrderDailyStatVO> selectDailyStat(OrderQuery query, List<String> keys) {
        return orderMapper.selectDailyStat(query, keys);
    }

    // 查询订单的每日退款统计
    @Override
    public List<OrderDailyRefundStatVO> selectDailyRefundStat(OrderRefundQuery query, List<String> keys) {
        return orderMapper.selectDailyRefundStat(query, keys);
    }

    // 查询订单排行榜
    @Override
    public List<OrderRankVO> selectRank(OrderQuery query) {
        return orderMapper.selectRank(query);
    }
    
}
