package com.ssm.manage.dao.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.core.impl.BaseDaoImpl;
import com.ssm.manage.dao.SsmSysMenuDao;
import com.ssm.manage.entity.SysMenu;
import com.ssm.manage.mapper.SysMenuMapper;
import com.ssm.manage.query.MenuRequest;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Component
public class SsmSysMenuDaoImpl extends BaseDaoImpl<SysMenu> implements SsmSysMenuDao {
    @Autowired
    private SysMenuMapper mapper;

    @Override
    public SysMenuMapper getMapper() {
        return mapper;
    }


    @Override
    public PageInfo<SysMenu> selectPage(MenuRequest menuRequest) {
        Example example = new Example(SysMenu.class);
        Example.Criteria criteria = example.createCriteria();
        if(StringUtils.isNotBlank(menuRequest.getMenuName())) {
            criteria.orLike("menuName", "%" + menuRequest.getMenuName() + "%");
        }
        PageHelper.startPage(menuRequest.getPageNum(),menuRequest.getPageSize(),menuRequest.getOrderAndSort());
        List<SysMenu> list = mapper.selectByExample(example);
        PageInfo<SysMenu> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
