Helius
2022-02-21 f54f8a92c09a2cd76b3bbb796df680215b63ab8a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?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) &lt;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>