package com.sifang.modules.order.dao;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.order.entity.CrmOrderDispatch;
import com.sifang.modules.sys.common.persistence.BaseDao;
import com.sifang.modules.sys.common.persistence.Parameter;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class CrmOrderDispatchDao extends BaseDao<CrmOrderDispatch> {


    /**
     * 查询出可派工的服务商
     * province、city
    */
    public List<Record> getDisOrderSite(String province,String city,String cate,String serviceType){
        StringBuilder sf = new StringBuilder();
        sf.append(" SELECT s.id,s.name,s.province,s.city,s.area,s.address,s.lnglat,s.name,s.site_type,ad.province as deprovince,ad.city as decity ,ad.area as dearea,ad.address as deaddress,ad.lnglat as delnglat  ");
        sf.append( "FROM crm_site s   ");
        sf.append( " left join crm_site_order_default_address ad  on ad.site_id = s.id ");
        sf.append( " left join crm_site_category ca  on ca.site_id = s.id ");
        sf.append("WHERE (s.province=? AND s.city=? AND s.status='0' OR s.check_flag='3' ) and ca.name like '%"+cate+"%' AND ca.service_type=? ");
        return Db.find(sf.toString(),province,city,serviceType);
    }

    public CrmOrderDispatch getByOrderId(String orderId){
        return getByLimit(orderId);
    }
}
