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.SsmProjectProgressDao;
import com.ssm.manage.entity.ProjectProgress;
import com.ssm.manage.mapper.ProjectProgressMapper;
import com.ssm.manage.query.ProjectProgressRequest;
import com.ssm.manage.utils.DateUtils;
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 SsmProjectProgressDaoImpl extends BaseDaoImpl<ProjectProgress> implements SsmProjectProgressDao {
    @Autowired
    private ProjectProgressMapper mapper;

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

    @Override
    public PageInfo<ProjectProgress> selectPage(ProjectProgressRequest progressRequest) {
        Example example = new Example(ProjectProgress.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotBlank(progressRequest.getProjectName())){
            criteria.andLike("projectName", "%" + progressRequest.getProjectName() + "%");
        }
        if (null != progressRequest.getDocDate()){
            criteria.andLike("docDate", "%" + DateUtils.ymdFormat(progressRequest.getDocDate()) + "%");
        }
        if (null != progressRequest.getMemberId()){
            criteria.andEqualTo("memberId", progressRequest.getMemberId());
        }
        if (StringUtils.isNotBlank(progressRequest.getStaffId())){
            criteria.andLike("staffIds", "%" + progressRequest.getStaffId() + "%");
        }
        criteria.andEqualTo("source", progressRequest.getSource());
        criteria.andEqualTo("storeId", progressRequest.getStoreId());
        PageHelper.startPage(progressRequest.getPageNum(),progressRequest.getPageSize(),progressRequest.getOrderAndSort());
        List<ProjectProgress> list = selectByExample(example);
        PageInfo<ProjectProgress> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
