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.SsmProjectTypeDao;
import com.ssm.manage.entity.BaseProjectType;
import com.ssm.manage.mapper.BaseProjectTypeMapper;
import com.ssm.manage.query.ProjectTypeRequest;
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 SsmProjectTypeDaoImpl extends BaseDaoImpl<BaseProjectType> implements SsmProjectTypeDao {
    @Autowired
    private BaseProjectTypeMapper mapper;

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

    @Override
    public PageInfo<BaseProjectType> selectPage(ProjectTypeRequest projectTypeRequest) {
        Example example = new Example(BaseProjectType.class);
        Example.Criteria criteria = example.createCriteria();
        example.setOrderByClause("project_type_num desc");
        if (StringUtils.isNotBlank(projectTypeRequest.getProjectTypeNum())){
            criteria.andLike("projectTypeNum", "%" + projectTypeRequest.getProjectTypeNum() + "%");
        }
        if (StringUtils.isNotBlank(projectTypeRequest.getProjectTypeName())){
            criteria.andLike("projectTypeName","%" + projectTypeRequest.getProjectTypeName() + "%");
        }
        if (projectTypeRequest.getState() != null){
            criteria.andEqualTo("state",projectTypeRequest.getState());
        }

        criteria.andEqualTo("storeId",projectTypeRequest.getStoreId());

        PageHelper.startPage(projectTypeRequest.getPageNum(),projectTypeRequest.getPageSize(),"project_type_num");
        List<BaseProjectType> list = selectByExample(example);
        PageInfo<BaseProjectType> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public int insertBatch(List<BaseProjectType> list) {
        return mapper.insertBatch(list);
    }

    @Override
    public List<ProjectTypeRequest> getMenu(ProjectTypeRequest projectTypeRequest) {
        List<ProjectTypeRequest> menu = mapper.getMenu(projectTypeRequest);
        return menu;
    }
    @Override
    public List<ProjectTypeRequest> getMenuId(ProjectTypeRequest projectTypeRequest) {
        List<ProjectTypeRequest> menu = mapper.getMenuId(projectTypeRequest);
        return menu;
    }
}
