package com.younike.system.service.impl;

import com.younike.common.core.domain.AjaxResult;
import com.younike.system.domain.Merchant;
import com.younike.system.domain.vo.*;
import com.younike.system.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 运营后台管理首页统计Service
 *
 * @author dail
 * @date 2022-02-10
 */
@Service
public class OperationIndexServiceImpl implements IOperationIndexService {
    @Autowired
    private IOrderService orderService;

    @Autowired
    private IMemberService memberService;

    @Autowired
    private IMerchantService merchantService;

    @Autowired
    private IServerUserService serverUserService;


    /**
     * 查询运营后台管理首页统计数据
     *
     * @return
     */
    @Override
    public AjaxResult getIndexStatisticsInfo() {
        OperationIndexStatisticsVO operationIndexStatisticsVO = new OperationIndexStatisticsVO();
        // 1.查询用户数据
        UserCountStatisticsVO userCountStatisticsVO = new UserCountStatisticsVO();
        // 查询商家数量
//        int merchantCount = merchantService.getMerchantCountByMerchantType("0");
//        userCountStatisticsVO.setMerchantCount(merchantCount);
        //2022.05.10 徐产品要求商家数统计已审核通过的数据,审核中，审核失败的商家数
        Merchant merchant = new Merchant();
        merchant.setMerchantType(0);
        merchant.setShopState("002,004");
        int merchantCount =  merchantService.getMerchantCountBy(merchant);
        userCountStatisticsVO.setMerchantCount(merchantCount);
        merchant.setShopState("001,003");
        int merchantAiditCount = merchantService.getMerchantCountBy(merchant);
        userCountStatisticsVO.setMerchantAiditCount(merchantAiditCount);
        // 查询个人商家数量
        int personalMerchantCount = merchantService.getMerchantCountByMerchantType("1");
        userCountStatisticsVO.setPersonalMerchantCount(personalMerchantCount);
        // 查询服务人员数量
        int serverUserCount = serverUserService.getServerUserCount();
        userCountStatisticsVO.setServerUserCount(serverUserCount);
        // 查询会员数量
        int memberCount = memberService.getMemberCount();
        userCountStatisticsVO.setMemberCount(memberCount);
        operationIndexStatisticsVO.setUserCountStatisticsVO(userCountStatisticsVO);

        // 2.查询今日订单数据
        TodayOrderVO todayOrderVO = orderService.getTodayOrderData();
        operationIndexStatisticsVO.setTodayOrderVo(todayOrderVO);

        // 3.查询本周Top5商家订单数据对象
        List<MerchantOrderOfWeekVO> merchantOrderOfWeekVOList = orderService.getTopFiveMerchantOrderData();
        operationIndexStatisticsVO.setMerchantOrderOfWeekVOList(merchantOrderOfWeekVOList);

        // 4.统计近30天的订单数据
        List<OrderStatisticsVO> orderStatisticsVOList = orderService.getOrderDataByMonth();
        operationIndexStatisticsVO.setOrderStatisticsVOList(orderStatisticsVOList);

        return AjaxResult.success(operationIndexStatisticsVO);
    }
}
