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.SsmRechargeDemotioneingRunDao;
import com.ssm.manage.dao.SsmSalesmanDao;
import com.ssm.manage.entity.RechargeDemotioneingRun;
import com.ssm.manage.entity.Salesman;
import com.ssm.manage.mapper.RechargeDemotioneingRunMapper;
import com.ssm.manage.mapper.SalesmanMapper;
import com.ssm.manage.query.RechargeDemotioneingRunRequest;
import com.ssm.manage.query.SalesmanRequest;
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 SsmSalesmanDaoImpl extends BaseDaoImpl<Salesman> implements SsmSalesmanDao {
    @Autowired
    private SalesmanMapper mapper;

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

    @Override
    public List<Salesman> selectList(SalesmanRequest salesman) {
        Example example = new Example(Salesman.class);
        Example.Criteria criteria = example.createCriteria();
        if(null != salesman.getOrderId()){
            criteria.andLike("orderId","%"+salesman.getOrderId()+"%");
        }
        if(null != salesman.getOrderType()){
            criteria.andLike("orderType","%"+salesman.getOrderType()+"%");
        }
        if(null != salesman.getStoreName()){
            criteria.andLike("storeName","%"+salesman.getStoreName()+"%");
        }
        if(null != salesman.getStoreNum()){
            criteria.andLike("storeNum","%"+salesman.getStoreNum()+"%");
        }

        if(null != salesman.getStoreIds() && salesman.getStoreIds().size()>0){
            criteria.andIn("storeId",salesman.getStoreIds());
        }
//        if(null != salesman.getStoreNum()){
//            criteria.andEqualTo("storeNum",salesman.getStoreNum());
//        }
        if(null != salesman.getBrandNumber()){
            criteria.andEqualTo("brandNumber",salesman.getBrandNumber());
        }
        if(null != salesman.getStaffNum()){
            criteria.andLike("staffNum","%"+salesman.getStaffNum()+"%");
        }
        if(null != salesman.getStaffName()){
            criteria.andLike("staffName","%"+salesman.getStaffName()+"%");
        }
        if(null != salesman.getStaffType()){
            criteria.andEqualTo("staffType",salesman.getStaffType());
        }
        if(null != salesman.getStartDate() && null != salesman.getEndDate()){
            criteria.andBetween("orderDate",salesman.getStartDate(),salesman.getEndDate());
        }
        if(salesman.getStoreIdsOrder()!=null && salesman.getStoreIdsOrder().size()>0){
            criteria.andIn("storeIdOrder",salesman.getStoreIdsOrder());
        }
        criteria.andEqualTo("state",salesman.getState());
        List<Salesman> list = mapper.selectByExample(example);
        return list;
    }

    @Override
    public List<Salesman> selectList(Salesman salesman) {
        Example example = new Example(Salesman.class);
        Example.Criteria criteria = example.createCriteria();
        if(null != salesman.getOrderId()){
            criteria.andEqualTo("orderId",salesman.getOrderId());
        }
        if(null != salesman.getOrderNum()){
            criteria.andEqualTo("orderNum",salesman.getOrderNum());
        }
        if(null != salesman.getOrderType()){
            criteria.andEqualTo("orderType",salesman.getOrderType());
        }
        if(null != salesman.getStoreId()){
            criteria.andEqualTo("storeId",salesman.getStoreId());
        }
        if(null != salesman.getStaffType()){
            criteria.andEqualTo("staffType",salesman.getStaffType());
        }
        criteria.andEqualTo("state",salesman.getState());

        List<Salesman> list = mapper.selectByExample(example);
        return list;
    }

    @Override
    public void updateByDocNum(String initNum) {
        mapper.updateByDocNum(initNum);
    }

}
