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.SsmStoreMonthTaskDao;
import com.ssm.manage.entity.StoreMonthTask;
import com.ssm.manage.mapper.StoreMemberListMapper;
import com.ssm.manage.mapper.StoreMonthTaskMapper;
import com.ssm.manage.query.StoreMonthTaskRequest;
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 SsmStoreMonthTaskDaoImpl extends BaseDaoImpl<StoreMonthTask> implements SsmStoreMonthTaskDao {
    @Autowired
    private StoreMonthTaskMapper mapper;

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

    @Override
    public PageInfo<StoreMonthTask> selectPage(StoreMonthTaskRequest storeMonthTaskRequest) {
        Example example = new Example(StoreMonthTask.class);
        Example.Criteria criteria = example.createCriteria();
        if (storeMonthTaskRequest.getDate() != null) {
            criteria.andLike("date", storeMonthTaskRequest.getDate() + "%");
        }
        if (storeMonthTaskRequest.getState() != null) {
            criteria.andEqualTo("state", storeMonthTaskRequest.getState());
        }
        criteria.andEqualTo("storeId", storeMonthTaskRequest.getStoreId());
        PageHelper.startPage(storeMonthTaskRequest.getPageNum(),storeMonthTaskRequest.getPageSize(),storeMonthTaskRequest.getOrderAndSort());
        List<StoreMonthTask> list = selectByExample(example);
        PageInfo<StoreMonthTask> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
