package cn.com.liandisys.ycjt.ggcx.taximan.service.impl;


import javax.annotation.Resource;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import cn.com.liandisys.ycjt.ggcx.busline.model.BusLineEntity;
import cn.com.liandisys.ycjt.ggcx.common.util.StringUtil;
import cn.com.liandisys.ycjt.ggcx.taximan.dao.TaxiManDao;
import cn.com.liandisys.ycjt.ggcx.taximan.model.TaxiMan;
import cn.com.liandisys.ycjt.ggcx.taximan.service.TaxiManService;
import cn.com.liandisys.ycjt.ggcx.taximan.vo.TaxiManVo;
@Service("TaxiManService")
public class TaxiManServiceImpl implements TaxiManService {
    
    private Logger logger = LoggerFactory.getLogger(TaxiManServiceImpl.class);

    @Resource(name = "taxiManDao")
    private TaxiManDao taxiManDao;

    @Override
    public Specification<TaxiMan> getSpecification(TaxiManVo queryParam) {
        final String localId = queryParam.getId();
        
        final String  localtaxiCompany = queryParam.getTaxiCompany();
        
        return new Specification<TaxiMan>() {

            @Override
            public Predicate toPredicate(Root<TaxiMan> root, CriteriaQuery<?> query, CriteriaBuilder cb) {

                Predicate predicate = cb.conjunction();
                //通过监督卡号查找
                if (!StringUtil.isEmpty(localId)) {
                    predicate.getExpressions().add(cb.like((root.get("id").as(String.class)),"%" + localId + "%"));
                }
                //通过监督卡号查找
                if (!StringUtil.isEmpty(localtaxiCompany)) {
                    predicate.getExpressions().add(cb.like((root.get("taxiCompany").as(String.class)),"%" + localtaxiCompany + "%"));
                }
                return predicate;
            }
        };
    }

    @Override
    public Page<TaxiMan> findAll(Specification<TaxiMan> spec, Pageable pageable) {
        return taxiManDao.findAll(spec, pageable);
    }

}
