LibGeoLocationMapper.xml
7 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?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.laowu.mapper.LibGeoLocationMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.laowu.model.LibGeoLocationDO">
<id column="id" property="id" />
<result column="create_date" property="createDate" />
<result column="update_date" property="updateDate" />
<result column="delete_date" property="deleteDate" />
<result column="province" property="province" />
<result column="city" property="city" />
<result column="town" property="town" />
<result column="village" property="village" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
create_date,
update_date,
delete_date,
id, province, city, town, village
</sql>
<select id="provinces" resultType="string">
SELECT DISTINCT
t.province
FROM
lib_geo_location t
WHERE
t.delete_date IS NULL
AND t.province IS NOT NULL
</select>
<select id="cities" resultType="string">
SELECT DISTINCT
t.city
FROM
lib_geo_location t
WHERE
t.delete_date IS NULL
AND t.city IS NOT NULL
and t.province =#{province}
</select>
<select id="county" resultType="string">
SELECT DISTINCT
t.county
FROM
lib_geo_location t
WHERE
t.delete_date IS NULL
AND t.county IS NOT NULL
AND t.province = #{province}
AND t.city = #{city}
</select>
<select id="towns" resultType="string">
SELECT DISTINCT
t.town
FROM
lib_geo_location t
WHERE
t.delete_date IS NULL
AND t.county IS NOT NULL
AND t.province = #{province}
AND t.city = #{city}
AND t.county = #{county}
and town is not NULL
</select>
<select id="villages" resultType="string">
SELECT DISTINCT
t.village
FROM
lib_geo_location t
WHERE
t.delete_date IS NULL
AND t.county IS NOT NULL
AND t.province = #{province}
AND t.city = #{city}
AND t.county = #{county}
AND t.town = #{town}
and t.village is not null
</select>
<select id="geo" resultType="com.laowu.vo.geo.GeoVO">
SELECT
t1.province,
t1.city,
t1.county,
t1.town,
count(*) as cnt
FROM
lib_geo_location t1
WHERE
t1.delete_date IS NULL
<if test="province != null and province != ''">
AND t1.province = #{province}
</if>
<if test="city != null and city != ''">
AND t1.city = #{city}
</if>
<if test="county != null and county != ''">
AND t1.county = #{county}
</if>
<if test="town != null and town != ''">
AND ( t1.town LIKE concat('%', #{town}, '%') OR t1.village LIKE concat('%', #{town}, '%') )
</if>
GROUP BY
t1.province,
t1.city,
t1.county,
t1.town
</select>
<select id="localVillages" parameterType="com.laowu.model.LibGeoLocationDO" resultType="string">
SELECT
distinct t.county
FROM
lib_geo_location t
WHERE
t.delete_date IS NULL
AND t.province = #{province}
AND t.city = #{city}
</select>
<select id="countyCounts" resultType="com.laowu.vo.geo.CountyCountsVO">
SELECT
t4.county as name,
count( 0 ) as cnt
FROM
workstation_dict t1
LEFT JOIN workstation_member_mapping t3 ON t1.id = t3.station_id
LEFT JOIN member_dict t4 ON t3.member_id = t4.id
WHERE
t1.delete_date IS NULL
AND t3.delete_date IS NULL
AND t4.delete_date IS NULL
AND t1.id = #{workStationId}
GROUP BY
t4.county
</select>
<select id="townCounts" resultType="com.laowu.vo.geo.TownCountsVO">
SELECT
t1.town as name,
count( 0 ) as cnt
FROM
lib_geo_location t1
LEFT JOIN (
SELECT
t4.id,
t4.user_name AS NAME,
t4.province AS m_pr,
t4.city AS m_ci,
t4.county AS m_co,
t4.town AS m_to,
t4.village AS m_vi
FROM
workstation_dict t1
LEFT JOIN workstation_member_mapping t3 ON t1.id = t3.station_id
LEFT JOIN member_dict t4 ON t3.member_id = t4.id
WHERE
t1.delete_date IS NULL
AND t3.delete_date IS NULL
AND t4.delete_date IS NULL
AND t1.id = #{workStationId}
<if test="town != null and town != ''">
AND t4.town = #{town}
</if>
) t2 ON t1.province = t2.m_pr
AND t1.city = t2.m_ci
AND t1.county = t2.m_co
AND t1.town = t2.m_to
WHERE
t2.id IS NOT NULL
AND t1.delete_date IS NULL
GROUP BY
t1.town
</select>
<select id="villageCounts" resultType="com.laowu.vo.geo.VillageCountsVO">
SELECT
t1.village as name,
count(0) cnt
FROM
lib_geo_location t1
LEFT JOIN (
SELECT
t4.id,
t4.user_name AS NAME,
t4.province AS m_pr,
t4.city AS m_ci,
t4.county AS m_co,
t4.town AS m_to,
t4.village AS m_vi
FROM
workstation_dict t1
LEFT JOIN workstation_member_mapping t3 ON t1.id = t3.station_id
LEFT JOIN member_dict t4 ON t3.member_id = t4.id
AND t1.province = t4.province
AND t1.city = t4.city
AND t1.county = t4.county
WHERE
t1.delete_date IS NULL
AND t3.delete_date IS NULL
AND t4.delete_date IS NULL
AND t1.id = #{workStationId}
) t2 ON t1.province = t2.m_pr
AND t1.city = t2.m_ci
AND t1.county = t2.m_co
AND t1.town = t2.m_to
AND t1.village = t2.m_vi
WHERE
t1.delete_date is null
and t2.id IS NOT NULL
<if test="town != null and town != ''">
and t1.town = #{town}
</if>
<if test="village != null and village != ''">
and t1.village = #{village}
</if>
GROUP BY
t1.village
</select>
</mapper>