package com.ichangzuo.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ichangzuo.system.mapper.StatisticsMapper;
import com.ichangzuo.system.model.entity.Statistics;
import com.ichangzuo.system.model.query.StatisticsPageQuery;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StatisticsServiceImpl extends ServiceImpl<StatisticsMapper, Statistics> {
    public void statistics(int iClient, String sOp, int num){
        baseMapper.callStatistics(iClient, sOp, num);
    }

    public IPage<Statistics> page(StatisticsPageQuery queryParams){
        int pageNum = queryParams.getPageNum();
        int pageSize = queryParams.getPageSize();

        LambdaQueryWrapper<Statistics> lqw = null;
        List<Integer> range =  queryParams.getRange();
        if(range!=null && range.size()==2){
            lqw = new LambdaQueryWrapper<>();
            lqw.ge(Statistics::getStatisticsDate, range.get(0))
                    .le(Statistics::getStatisticsDate, range.get(1));
        }

        return baseMapper.selectPage(new Page<Statistics>(pageNum, pageSize), lqw);
    }
}
