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.SsmSysGlobalParaDao;
import com.ssm.manage.entity.SysGlobalParameters;
import com.ssm.manage.mapper.SysGlobalParametersMapper;
import com.ssm.manage.query.GlobalParaRequest;
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 SsmSysGlobalParaDaoImpl extends BaseDaoImpl<SysGlobalParameters> implements SsmSysGlobalParaDao {
    @Autowired
    private SysGlobalParametersMapper mapper;

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

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