package com.ruoyi.system.service;

import com.ruoyi.system.domain.AccessCount;
import com.ruoyi.system.mapper.AccessCountMapper;
import com.ruoyi.system.mapper.InfoUserMapper;
import com.ruoyi.system.mapper.PosFoodMapper;
import com.ruoyi.system.mapper.PosOrderMapper;

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

import java.util.Date;

@Service
public class StatisticsService {

    @Autowired
    private InfoUserMapper infoUserMapper;

    @Autowired
    private PosFoodMapper posFoodMapper;

    @Autowired
    private PosOrderMapper posOrderMapper;

    @Autowired
    private AccessCountMapper accessCountMapper;

    // 用户总数
    public int countUsersByUserTypeAndCreatedAt(int userType, Date createdAt) {
        return infoUserMapper.countUsersByUserTypeAndCreatedAt(userType, createdAt);
    }

    // 产品总数
    public int countPosFoodByCreatedAt(Date createdAt) {
        return posFoodMapper.countPosFoodByCreatedAt(createdAt);
    }

    // 今年总订单数
    public int countOrderByNowYear(Date nowYearFirstDay) {
        return posOrderMapper.countOrderByNowYear(nowYearFirstDay);
    }

    // 今年成功订单数
    public int countOrderSuccessByNowYear(Date nowYearFirstDay) {
        return posOrderMapper.countOrderSuccessByNowYear(nowYearFirstDay);
    }

    // 今年失败订单数
    public int countOrderFailByNowYear(Date nowYearFirstDay) {
        return posOrderMapper.countOrderFailByNowYear(nowYearFirstDay);
    }

    // 今年总营业额
    public Double totalTurnoverByNowYear(Date nowYearFirstDay) {
        return posOrderMapper.totalTurnoverByNowYear(nowYearFirstDay);
    }

    // 今年访问次数
    public int getAccessCount(int Year) {
        AccessCount accessCount = accessCountMapper.selectByYear(Year);
        if (accessCount == null) {
            return 0;
        }
        return accessCount.getCount();
    }

}
