package cn.feast.coding.service.links.impl;

import cn.feast.coding.mapper.links.LinkMapper;
import cn.feast.coding.model.links.Link;
import cn.feast.coding.service.links.LinkService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;

/**
 * Created By FeastCoding.
 */
@Service
public class LinkServiceImpl implements LinkService {
    @Autowired
    private LinkMapper mapper;

    public int insert(Link model){
        return mapper.insert(model);
    }

    public int update(Link model){
        return mapper.update(model);
    }

    public int deleteByPrimaryKey(Integer id){
        return mapper.deleteByPrimaryKey(id);
    }

    public List<Link> selectAll(Link model){
        return mapper.selectAll(model);
    }

    public PageInfo<Link> queryPage(Link model, int pageNum, int pageSize) {
        if (pageSize < 1)
            pageSize = 10;
        PageHelper.startPage(pageNum, pageSize);
        List<Link> list = mapper.selectAll(model);
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }

    public Link selectByPrimaryKey(Integer id){
        return mapper.selectByPrimaryKey(id);
    }

    public List<Link> queryAll(){
        return mapper.queryAll();
    }

    @Override
    public List queryByType(Integer linkType) {
        Link link = new Link();
        link.setTypeid(linkType);
        return mapper.selectAll(link);
    }

    @Override
    public List queryByTypeTimes(Integer urlType) {
        return mapper.queryByTypeTimes(urlType);
    }
}
