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.SsmStaffLoginDao;
import com.ssm.manage.entity.BaseStaff;
import com.ssm.manage.entity.SysCompanyStore;
import com.ssm.manage.mapper.BaseStaffMapper;
import com.ssm.manage.query.StaffRequest;
import com.ssm.manage.query.SysCompanyStoreRequest;
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.ArrayList;
import java.util.List;

@Component
public class SsmStaffLoginDaoImpl extends BaseDaoImpl<BaseStaff> implements SsmStaffLoginDao {
    @Autowired
    private BaseStaffMapper mapper;

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

    @Override
    public List<BaseStaff> list(BaseStaff baseStaff){
        Example example = new Example(BaseStaff.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("state",baseStaff.getState());
        criteria.andEqualTo("mobilePhone",baseStaff.getMobilePhone());
        if(StringUtils.isNotBlank(baseStaff.getStoreName())){
            criteria.andLike("storeName","%" + baseStaff.getStoreName()+ "%");
        }
        if (StringUtils.isNotBlank(String.valueOf(baseStaff.getStoreId()))){
            criteria.andEqualTo("storeId",baseStaff.getStoreId());
        }
        List<BaseStaff> baseStaffs = mapper.selectByExample(example);
        return baseStaffs;
    }

    @Override
    public List<BaseStaff> selectBy(BaseStaff baseStaff){
        Example example = new Example(BaseStaff.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("state",baseStaff.getState());
        criteria.andEqualTo("mobilePhone",baseStaff.getMobilePhone());
        List<BaseStaff> baseStaffs = mapper.selectByExample(example);
        return baseStaffs;
    }

    @Override
    public List<StaffRequest> liststarfall(StaffRequest baseStaff){
        List<StaffRequest> baseStaffs = new ArrayList<>();
        if("99eeb974dcae1233b457b336d641ad98".equals(baseStaff.getMobilePhone())){
            baseStaffs = mapper.liststarfallRoot(baseStaff);
            for (StaffRequest staff : baseStaffs) {
                staff.setStoreId(staff.getId());
            }
        }else{
            baseStaffs = mapper.liststarfall(baseStaff);
        }
        return baseStaffs;
    }
}
