package com.ruoyi.interfaces.core.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.interfaces.core.CrudDao;

import java.util.List;

/**
 * @author LinQiLong
 * @date 3/31/2022 11:41 PM
 */
public class AbstractCrudService<T, P> implements CrudService<T, P> {
    private CrudDao<T, P> dao;

    public AbstractCrudService(CrudDao<T, P> dao) {
        this.dao = dao;
    }

    @Override
    public T get(P param) {
        return this.dao.get(param);
    }

    @Override
    public List<T> findList(P param) {
        return this.dao.findList(param);
    }

    @Override
    public List<T> findPage(P param) {
        PageHelper.startPage(param);
        return this.dao.findList(param);
    }

    @Override
    public PageInfo<T> findPageInfo(P param) {
        PageHelper.startPage(param);
        List<T> list = this.dao.findList(param);
        return new PageInfo<>(list);
    }

    @Override
    public int insert(T entity) {
        return this.dao.insert(entity);
    }

    @Override
    public int update(T entity) {
        return this.dao.update(entity);
    }

    @Override
    public int delete(T entity) {
        return this.dao.delete(entity);
    }
}
