<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.xxfc.platform.vehicle.mapper.CompanyBaseMapper" >

  <select id="getList"  parameterType="com.xxfc.platform.vehicle.pojo.vo.CompanyVo"  resultType="com.xxfc.platform.vehicle.pojo.vo.CompanyVo">
     SELECT
      c.id as companyId,
      c.`name` as companyName,
      c.addr_detail as addrDetail,
      c.state,
      c.status,
      c.is_show as isShow,
      c.leader,
      c.leader_contact_info as leaderContactInfo,
      c.latitude,
      c.longitude,
      c.vehice_service_phone as vehiceServicePhone,
      c.tour_service_phone as tourServicePhone,
      b.zone_id as zoneId,
      a.name as zoneName,
      b.addr_province as addrProvince,
      b.province_name as provinceName,
      b.addr_city as addrCity,
      b.city_name as cityName,
      b.addr_town as addrTown,
      b.town_name as townName,
      b.cover,
      b.id,
      b.`name`,
      r.id as stockId,
      r.balance,
      r.rank,
      r.stock_state as stockState,
      r.total,
      r.type,
      r.price
      FROM  company_base b
      LEFT JOIN branch_company c ON c.company_base_id=b.id
      LEFT JOIN branch_company_stock_info_right r ON b.id=r.company_base_id
      LEFT JOIN area a ON b.zone_id=a.id
        <where>
            b.is_del=0
            <if test="zoneId != null and zoneId !='' ">
                and b.zone_id = #{zoneId}
            </if>
            <if test="addrProvince != null and addrProvince != ''">
                and b.addr_province =#{addrProvince}
            </if>
            <if test="addrCity != null and addrCity != ''">
                and b.addr_city =#{addrCity}
            </if>
            <if test="name != null and name != ''">
                and (b.`name` like CONCAT('%',#{name},'%') or c.`name` like CONCAT('%',#{name},'%') )
            </if>
        </where>
       order by b.upd_time desc
  </select>
</mapper>