| <?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.xzx.gc.user.mapper.UserScrapStoreMapper">  | 
|   <resultMap id="BaseResultMap" type="com.xzx.gc.entity.UserScrapStore">  | 
|     <id column="id" jdbcType="VARCHAR" property="id" />  | 
|     <result column="name" jdbcType="VARCHAR" property="name" />  | 
|     <result column="mobile_phone" jdbcType="VARCHAR" property="mobilePhone" />  | 
|     <result column="longitude" jdbcType="VARCHAR" property="longitude" />  | 
|     <result column="latitude" jdbcType="VARCHAR" property="latitude" />  | 
|     <result column="address_area" jdbcType="VARCHAR" property="addressArea" />  | 
|     <result column="detail_address" jdbcType="VARCHAR" property="detailAddress" />  | 
|     <result column="create_time" jdbcType="VARCHAR" property="createTime" />  | 
|     <result column="store_name" jdbcType="VARCHAR" property="storeName" />  | 
|     <result column="store_url" jdbcType="VARCHAR" property="storeUrl" />  | 
|     <result column="open_time" jdbcType="VARCHAR" property="openTime" />  | 
|     <result column="del_flag" jdbcType="SMALLINT" property="delFlag" />  | 
|     <result column="province_id" property="provinceId" />  | 
|     <result column="city_id" property="cityId" />  | 
|     <result column="township_id"  property="townshipId" />  | 
|     <result column="relation_user_id"  property="relationUserId" />  | 
|     <result column="relation_user_name"  property="relationUserName" />  | 
|     <result column="bussiess_area"  property="bussiessArea" />  | 
|   </resultMap>  | 
|   | 
|     <select id="list" resultMap="BaseResultMap">  | 
|         SELECT a.*,c.name as relation_user_name  | 
|       <if test="latitude != null and latitude != ''">  | 
|         ,ROUND(lat_lng_distance(#{latitude}, #{longitude} , a.latitude, a.longitude), 3) as distance  | 
|       </if>  | 
|       <if test="userId != null and userId != ''">  | 
|         ,count(b.order_id) as orderNum  | 
|       </if>  | 
|       FROM  | 
|           xzx_user_scrap_store a  | 
|           left join xzx_user_other_info c on a.relation_user_id=c.user_id  | 
|           <if test="userId != null and userId != ''">  | 
|             LEFT JOIN xzx_order_info b on a.id=b.scrap_id and b.create_user_id=#{userId}  | 
|           </if>  | 
|           where a.del_flag=0  | 
|           <if test="townShipId != null and townShipId != ''">  | 
|             and a.township_id=#{townShipId}  | 
|           </if>  | 
|           <if test="relationUserId != null and relationUserId != ''">  | 
|             and a.relation_user_id=#{relationUserId}  | 
|           </if>  | 
|             <if test="latitude != null and latitude != '' and locationFilter!=null">  | 
|                 and ROUND(lat_lng_distance(#{latitude}, #{longitude} , a.latitude, a.longitude), 3) <6  | 
|             </if>  | 
|             group by a.id  | 
|       <choose>  | 
|         <when test="latitude != null and latitude != ''">  | 
|             <choose>  | 
|                 <when test="filterType != null and filterType != ''">  | 
|                        <choose>  | 
|                            <when test="filterType==2">  | 
|                                 order by distance  | 
|                            </when>  | 
|                        </choose>  | 
|                         <choose>  | 
|                             <when test="filterOrder==1">  | 
|                                 asc  | 
|                             </when>  | 
|                             <otherwise>  | 
|                                 desc  | 
|                             </otherwise>  | 
|                         </choose>  | 
|                 </when>  | 
|                 <otherwise>  | 
|                     <choose>  | 
|                         <when test="userId != null and userId != ''">  | 
|                             order by orderNum desc,distance asc  | 
|                         </when>  | 
|                         <otherwise>  | 
|                             order by distance asc  | 
|                         </otherwise>  | 
|                     </choose>  | 
|                 </otherwise>  | 
|             </choose>  | 
|   | 
|         </when>  | 
|         <otherwise>  | 
|           order by a.create_time desc  | 
|         </otherwise>  | 
|       </choose>  | 
|   | 
|   | 
|     </select>  | 
| </mapper> |