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.SsmSysCompanyDao;
import com.ssm.manage.entity.SysCompany;
import com.ssm.manage.mapper.SysCompanyMapper;
import com.ssm.manage.query.SysCompanyRequest;
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 SsmSysCompanyDaoImpl extends BaseDaoImpl<SysCompany> implements SsmSysCompanyDao {

    @Autowired
    private SysCompanyMapper mapper;

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

    @Override
    public PageInfo<SysCompany> selectPage(SysCompanyRequest sysCompanyRequest) {
        Example example = new Example(SysCompany.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotBlank(sysCompanyRequest.getCompanyCode())){
            criteria.andLike("companyCode;","%" + sysCompanyRequest.getCompanyCode()+ "%");
        }
        if (StringUtils.isNotBlank(sysCompanyRequest.getCompanyName())){
            criteria.andLike("companyName;","%" + sysCompanyRequest.getCompanyName()+ "%");
        }
        //排序
        sysCompanyRequest.setSort("companyId");
        PageHelper.startPage(sysCompanyRequest.getPageNum(),sysCompanyRequest.getPageSize(),sysCompanyRequest.getOrderAndSort());
        List<SysCompany> list = mapper.selectByExample(example);
        PageInfo<SysCompany> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

}
