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.SsmModifyCourseRecordDao;
import com.ssm.manage.entity.BaseStore;
import com.ssm.manage.entity.ModifyCourseRecord;
import com.ssm.manage.entity.ModifyRechargeRecord;
import com.ssm.manage.mapper.ModifyCourseRecordMapper;
import com.ssm.manage.query.ModifyCourseRecordRequest;
import com.ssm.manage.service.SsmBaseStoreService;
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 SsmModifyCourseRecordDaoImpl extends BaseDaoImpl<ModifyCourseRecord> implements SsmModifyCourseRecordDao {
    @Autowired
    private ModifyCourseRecordMapper mapper;
    @Autowired
    private SsmBaseStoreService ssmBaseStoreService;

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

    @Override
    public PageInfo<ModifyCourseRecord> selectPage(ModifyCourseRecordRequest modifyCourseRecordRequest) {
        Example example = new Example(ModifyCourseRecord.class);
        Example.Criteria criteria = example.createCriteria();
        BaseStore baseStore = ssmBaseStoreService.selectByPrimaryKey(modifyCourseRecordRequest.getStoreId());
        if(baseStore.getParentId()!=null){
            criteria.andEqualTo("storeId", modifyCourseRecordRequest.getStoreId());
        }
        if (null != modifyCourseRecordRequest.getMemberId()){
            criteria.andEqualTo("memberId", modifyCourseRecordRequest.getMemberId());
        }
        if (StringUtils.isNotBlank(modifyCourseRecordRequest.getCourseProjectName())){
            criteria.andLike("courseProjectName", "%" + modifyCourseRecordRequest.getCourseProjectName() + "%");
        }
        PageHelper.startPage(modifyCourseRecordRequest.getPageNum(), modifyCourseRecordRequest.getPageSize(), modifyCourseRecordRequest.getOrderAndSort());
        List<ModifyCourseRecord> list = selectByExample(example);
        PageInfo<ModifyCourseRecord> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
