package com.qxgmat.service.inline;

import com.github.pagehelper.Page;
import com.nuliji.tools.AbstractService;
import com.nuliji.tools.exception.ParameterException;
import com.nuliji.tools.exception.SystemException;
import com.nuliji.tools.mybatis.Example;
import com.qxgmat.data.dao.StatDayMapper;
import com.qxgmat.data.dao.entity.StatDay;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

@Service
public class StatDayService extends AbstractService {
    private static final Logger logger = LoggerFactory.getLogger(SettingService.class);

    @Resource
    private StatDayMapper statDayMapper;

    public StatDay add(StatDay day){
        int result = insert(statDayMapper, day);
        day = one(statDayMapper, day.getId());
        if(day == null){
            throw new SystemException("统计添加失败");
        }
        return day;
    }

    public StatDay edit(StatDay setting){
        StatDay in = one(statDayMapper, setting.getId());
        if(in == null){
            throw new ParameterException("统计不存在");
        }
        int result = update(statDayMapper, setting);
        return setting;
    }

    public boolean delete(Number id){
        StatDay in = one(statDayMapper, id);
        if(in == null){
            throw new ParameterException("统计不存在");
        }
        int result = delete(statDayMapper, id);
        return result > 0;
    }

    public StatDay get(Number id){
        StatDay in = one(statDayMapper, id);

        if(in == null){
            throw new ParameterException("统计不存在");
        }
        return in;
    }

    public Page<StatDay> select(int page, int pageSize){
        return select(statDayMapper, page, pageSize);
    }

    public List<StatDay> select(Collection ids){
        return select(statDayMapper, ids);
    }
}
