package com.ruoyi.dashboard.service;


import com.ruoyi.bst.bonus.service.BonusDashboard;

import com.ruoyi.bst.device.service.DeviceDashboard;
import com.ruoyi.bst.lightingNum.service.LightingNumDashboard;
import com.ruoyi.bst.order.domain.query.OrderRefundQuery;
import com.ruoyi.bst.order.service.OrderDashboard;

import com.ruoyi.bst.refund.domain.RefundQuery;
import com.ruoyi.bst.store.service.StoreDashboard;
import com.ruoyi.common.utils.MathUtils;
import com.ruoyi.dashboard.constants.StatKeys;

import com.ruoyi.dashboard.domain.revenueStat.RevenueStatQuery;
import com.ruoyi.dashboard.domain.revenueStat.RevenueStatVO;

import com.ruoyi.system.user.service.UserDashboard;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service
public class DashboardService {

    @Autowired
    private OrderDashboard orderDashboard;
    @Autowired
    private StoreDashboard storeDashboard;
    @Autowired
    private DeviceDashboard deviceDashboard;
    @Autowired
    private LightingNumDashboard lightingNumDashboard;


    public RevenueStatVO selectRevenueStat(RevenueStatQuery query) {
        RevenueStatVO vo = new RevenueStatVO();
        List<String> keys = query.getKeys();
        // 订单用户数量
        if (keys.contains(StatKeys.ORDER_USER_COUNT)) {
            vo.setOrderUserCount(orderDashboard.selectUserCount(query.toOrderQuery()));
        }
        // 订单数量
        if (keys.contains(StatKeys.ORDER_COUNT)) {
            vo.setOrderCount(orderDashboard.selectCount(query.toOrderQuery()));
        }
        // 订单总金额
        if (keys.contains(StatKeys.ORDER_ACTUAL_TOTAL_AMOUNT)) {
            vo.setOrderActualTotalAmount(orderDashboard.selectSumOfActualTotalAmount(query.toOrderQueryForEnd()));
        }
        // 订单退款金额
        if (keys.contains(StatKeys.ORDER_REFUND_AMOUNT) || keys.contains(StatKeys.ORDER_ACTUAL_TOTAL_AMOUNT)) {
            OrderRefundQuery refundQuery = query.toOrderRefundQuery();
            vo.setOrderRefundAmount(orderDashboard.selectRefundAmount(refundQuery));
        }
        // 店铺数量
        if (keys.contains(StatKeys.STORE_COUNT)) {
            vo.setStoreCount(storeDashboard.selectCount(query.toStoreQuery()));
        }
        // 设备数量
        if (keys.contains(StatKeys.DEVICE_COUNT)) {
            vo.setDeviceCount(deviceDashboard.selectCount(query.toDeviceQuery()));
        }
        //设备状态数量
        if (keys.contains(StatKeys.DEVICE_STATUS_COUNT)) {
            vo.setDeviceStatusMap(deviceDashboard.selectStatusCount(query.toDeviceQuery()));
        }
        // 设备在线状态数量
        if (keys.contains(StatKeys.DEVICE_ONLINE_STATUS_COUNT)) {
            vo.setDeviceOnlineStatusMap(deviceDashboard.selectOnlineStatusCount(query.toDeviceQuery()));
        }
        // 爆灯次数
        if (keys.contains(StatKeys.LIGHTING_NUM_COUNT)) {
            vo.setUserLightingNum(lightingNumDashboard.selectCount(query.toLightingNumQuery()));
        }
        // 用户充值金额
        if (keys.contains(StatKeys.USER_RECHARGE_AMOUNT)) {
            vo.setUserRechargeAmount(orderDashboard.selectSumOfActualTotalAmount(query.toUserOrderQuery()));
        }
        // 用户退款金额
        if (keys.contains(StatKeys.USER_REFUND_AMOUNT)) {
            vo.setUserRefundAmount(orderDashboard.selectRefundAmount(query.toUserOrderRefundQuery()));
        }
        // 用户所属店铺
        return vo;
    }

}
