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.SsmSysRoleDao;
import com.ssm.manage.entity.SysRole;
import com.ssm.manage.mapper.SysRoleMapper;
import com.ssm.manage.query.RoleRequest;
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 SsmSysRoleDaoImpl extends BaseDaoImpl<SysRole> implements SsmSysRoleDao {
    @Autowired
    private SysRoleMapper mapper;

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

    @Override
    public PageInfo<SysRole> selectPage(RoleRequest roleRequest) {
        Example example = new Example(SysRole.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotBlank(roleRequest.getRoleName())){
            criteria.andLike("roleName","%" + roleRequest.getRoleName() + "%");
        }
        if (null != roleRequest.getIndustry()){
            criteria.andEqualTo("industry",roleRequest.getIndustry());
        }
        criteria.andEqualTo("state",roleRequest.getState());
        PageHelper.startPage(roleRequest.getPageNum(),roleRequest.getPageSize(),"role_id desc");
        List<SysRole> list =  selectByExample(example);
        PageInfo<SysRole> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
