<?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.BranchCompanyMapper" >
  <resultMap id="BaseResultMap" type="com.xxfc.platform.vehicle.entity.BranchCompany" >
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="branch_type" property="branchType" jdbcType="INTEGER" />
    <result column="subordinate_branch" property="subordinateBranch" jdbcType="INTEGER" />
    <result column="location" property="location" jdbcType="VARCHAR" />
    <result column="addr_province" property="addrProvince" jdbcType="INTEGER" />
    <result column="addr_city" property="addrCity" jdbcType="INTEGER" />
    <result column="addr_town" property="addrTown" jdbcType="INTEGER" />
    <result column="addr_detail" property="addrDetail" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
  </resultMap>

  <select id="search" resultType="com.xxfc.platform.vehicle.pojo.CompanySearchVO">
    select *
        <if test="lon != null and lat != null">
          , st_distance_sphere(point(#{lon}, #{lat}), point(longitude, latitude)) as distance
        </if>
    from branch_company
        <where>
            <if test="addrCity != null">
                and addr_city = #{addrCity}
            </if>
            <if test="lon != null and lat != null">
                and longitude is not null and latitude is not null
            </if>
        </where>
        <if test="lon != null and lat != null">
            order by distance asc
        </if>
  </select>
</mapper>