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.SsmSysBusinessParaDao;
import com.ssm.manage.entity.SysBusinessParameters;
import com.ssm.manage.entity.SysGlobalParameters;
import com.ssm.manage.mapper.SysBusinessParametersMapper;
import com.ssm.manage.query.BusinessParaRequest;
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 SsmSysBusinessParaDaoImpl extends BaseDaoImpl<SysBusinessParameters> implements SsmSysBusinessParaDao {
    @Autowired
    private SysBusinessParametersMapper mapper;

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

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