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.SsmSysPowerDao;
import com.ssm.manage.entity.SysPower;
import com.ssm.manage.mapper.SysPowerMapper;
import com.ssm.manage.query.PowerRequest;
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 SsmSysPowerDaoImpl extends BaseDaoImpl<SysPower> implements SsmSysPowerDao {
    @Autowired
    SysPowerMapper mapper;

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


    @Override
    public PageInfo<SysPower> selectPage(PowerRequest powerRequest) {
        Example example = new Example(SysPower.class);
        Example.Criteria criteria = example.createCriteria();
        //分页条件
        if(StringUtils.isNotBlank(powerRequest.getPowerName())) {
            criteria.orLike("powerName","%" + powerRequest.getPowerName() + "%");
        }
        //分页大小设置 必须有
        PageHelper.startPage(powerRequest.getPageNum(),powerRequest.getPageSize(),powerRequest.getOrderAndSort());
        //分页查询
        List<SysPower> list = mapper.selectByExample(example);
        PageInfo<SysPower> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public void deleteByPowerId(Integer powerId) {
        mapper.deleteByPowerId(powerId);
    }
}
