MerchantMapper.xml
15 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<?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="cn.com.glsx.dj.system.mapper.MerchantMapper" >
<resultMap id="BaseResultMap" type="cn.com.glsx.dj.system.model.Merchant" >
<!--
WARNING - @mbg.generated
-->
<id column="id" property="id" jdbcType="INTEGER" />
<result column="merchant_id" property="merchantId" jdbcType="INTEGER" />
<result column="account_name" property="accountName" jdbcType="VARCHAR" />
<result column="merchant_name" property="merchantName" jdbcType="VARCHAR" />
<result column="short_name" property="shortName" jdbcType="VARCHAR" />
<result column="user_type" property="userType" jdbcType="TINYINT" />
<result column="merchant_type" property="merchantType"/>
<result column="contact_name" property="contactName" jdbcType="VARCHAR" />
<result column="phone" property="phone" jdbcType="VARCHAR" />
<result column="channel_id" property="channelId"/>
<result column="address" property="address" jdbcType="VARCHAR" />
<result column="province_id" property="provinceId" jdbcType="INTEGER" />
<result column="province_name" property="provinceName" jdbcType="VARCHAR" />
<result column="city_id" property="cityId" jdbcType="INTEGER" />
<result column="city_name" property="cityName" jdbcType="VARCHAR" />
<result column="area_id" property="areaId" jdbcType="INTEGER" />
<result column="area_name" property="areaName" jdbcType="VARCHAR" />
<result column="shop_photo" property="shopPhoto" jdbcType="VARCHAR" />
<result column="business_hours" property="businessHours" jdbcType="VARCHAR" />
<result column="parent_merchant_id" property="parentMerchantId"/>
<result column="parent_merchant_name" property="parentMerchantName"/>
<result column="sap" property="sap"/>
<result column="region" property="region"/>
<result column="stay_contact_name" property="stayContactName"/>
<result column="stay_phone" property="stayPhone"/>
<result column="created_by" property="createdBy" jdbcType="VARCHAR" />
<result column="created_date" property="createdDate" jdbcType="TIMESTAMP" />
<result column="updated_by" property="updatedBy" jdbcType="VARCHAR" />
<result column="updated_date" property="updatedDate" jdbcType="TIMESTAMP" />
<result column="deleted_flag" property="deletedFlag" jdbcType="CHAR" />
</resultMap>
<resultMap id="DTOResultMap" type="cn.com.glsx.dj.system.dto.MerchantDTO" extends="BaseResultMap">
<result column="user_id" property="userId"/>
<result column="rescueTime" property="rescueTime"/>
<result column="rescueRange" property="rescueRange"/>
<result column="brand" property="brand"/>
<result column="collisionPhone" property="collisionPhone"/>
<result column="lng" property="lng"/>
<result column="lat" property="lat"/>
<result column="channel_type" property="channelType"/>
<result column="enabled_flag" property="enabledFlag"/>
<result column="beServed" property="beServed"/>
</resultMap>
<sql id="Base_Column_List" >
id, merchant_id, account_name, merchant_name, short_name, user_type,merchant_type, contact_name,
phone,channel_id, address, province_id, province_name, city_id, city_name, area_id,
area_name, shop_photo, business_hours,parent_merchant_id,parent_merchant_name,
sap,region,stay_contact_name,stay_phone,
created_by, created_date, updated_by, updated_date,deleted_flag
</sql>
<select id="list" parameterType="cn.com.glsx.dj.system.dto.MerchantDTO" resultMap="DTOResultMap">
select a.id, a.merchant_id, a.account_name, a.merchant_name, a.short_name, a.user_type,a.merchant_type,
a.contact_name,a.phone,a.channel_id, a.address, a.province_id, a.province_name, a.city_id, a.city_name,
a.area_id,a.area_name, a.shop_photo, a.business_hours,a.parent_merchant_id,a.parent_merchant_name,
a.created_by, a.created_date, a.updated_by, a.updated_date,a.deleted_flag,a.lng,a.lat,a.sap,
a.region,a.stay_contact_name,a.stay_phone,
b.id as user_id, b.enabled_flag, c.channel_type
from dj_system_merchant a
left join dj_system_user b on b.deleted_flag='N' and b.merchant_id=a.merchant_id and b.user_type=a.user_type
left join dj_system_channel_config c on c.id = a.channel_id and c.deleted_flag='N'
<where>
a.deleted_flag = 'N'
<if test="channelId != null">
and a.channel_id = #{channelId}
</if>
<if test="channelType != null">
and c.channel_type = #{channelType}
</if>
<if test="merchantId != null">
and a.merchant_id = #{merchantId}
</if>
<if test="merchantIdExcept != null">
and a.merchant_id != #{merchantIdExcept}
</if>
<if test="parentMerchantId != null">
and a.parent_merchant_id = #{parentMerchantId}
</if>
<if test="userType != null">
and a.user_type = #{userType}
</if>
<if test="merchantType != null">
and a.merchant_type = #{merchantType}
</if>
<if test="merchantTypeList != null">
and a.merchant_type in
<foreach collection="merchantTypeList" open="(" close=")" separator="," item="item">
#{item}
</foreach>
</if>
<if test="accountName != null and accountName !=''">
and a.account_name like CONCAT('%',#{accountName},'%')
</if>
<if test="merchantName != null and merchantName !=''">
and (
a.merchant_name like CONCAT('%',#{merchantName},'%')
or a.short_name like CONCAT('%',#{merchantName},'%')
)
</if>
<if test="parentMerchantName != null and parentMerchantName !=''">
and a.parent_merchant_name like CONCAT('%',#{parentMerchantName},'%')
</if>
<if test="shortName != null and shortName !=''">
and a.short_name like CONCAT('%',#{shortName},'%')
</if>
<if test="contactName != null and contactName !=''">
and a.contact_name like CONCAT('%',#{contactName},'%')
</if>
<if test="phone != null and phone !=''">
and a.phone like CONCAT('%',#{phone},'%')
</if>
<if test="createdBy != null and createdBy !=''">
and a.created_by = #{createdBy}
</if>
<if test="keyword != null and keyword !=''">
and (a.merchant_name like CONCAT('%',#{keyword},'%')
or a.merchant_id = #{keyword})
</if>
<if test="merchantIds != null and merchantIds.size() > 0">
and a.merchant_id in
<foreach collection="merchantIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="roleIds != null and roleIds.size() > 0">
and EXISTS(
select 1 from dj_system_user_role b
left join dj_system_user c on b.user_id = c.id
where a.merchant_id = c.merchant_id and a.deleted_flag = 'N' and b.deleted_flag = 'N' and c.deleted_flag = 'N'
and b.role_id in
<foreach collection="roleIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
)
</if>
<if test="loginPhone != null and loginPhone!=''">
and b.phone = #{loginPhone}
</if>
<if test="carBrandId != null">
and exists(
select 1 from dj_system_merchant_car_brand d
where d.merchant_id = a.merchant_id and d.deleted_flag = 'N'
and d.brand_id = #{carBrandId}
<if test="carChildsBrandId != null">
and d.childs_brand_id = #{carChildsBrandId}
</if>
)
</if>
<if test="null != merchantAddressType and merchantAddressType ==1">
and (a.address is not null and a.address != '')
</if>
<if test="null != merchantAddressType and merchantAddressType ==2">
and (a.address is null or a.address = '')
</if>
<if test="null != enabledFlag and enabledFlag !=''">
and b.enabled_flag = #{enabledFlag}
</if>
</where>
order by a.updated_date desc,a.id desc
</select>
<select id="listWithServedMark" parameterType="cn.com.glsx.dj.system.dto.MerchantDTO" resultMap="DTOResultMap">
select a.id, a.merchant_id, a.account_name, a.merchant_name, a.short_name, a.user_type,a.merchant_type,
a.contact_name,a.phone,a.channel_id, a.address, a.province_id, a.province_name, a.city_id, a.city_name,
a.area_id,a.area_name, a.shop_photo, a.business_hours,a.parent_merchant_id,a.parent_merchant_name,
a.region,a.stay_contact_name,a.stay_phone,
a.created_by, a.created_date, a.updated_by, a.updated_date,a.deleted_flag,a.lng,a.lat,
b.id as user_id, b.enabled_flag, c.channel_type, IF( d.id IS NULL, FALSE, TRUE ) AS beServed
from dj_system_merchant a
left join dj_system_user b on b.deleted_flag='N' and b.merchant_id=a.merchant_id and b.user_type=a.user_type
left join dj_system_channel_config c on c.id = a.channel_id and c.deleted_flag='N'
LEFT JOIN (
SELECT id
FROM dj_system_merchant
WHERE merchant_id IN
<foreach collection="beServedMerchantIds" item="item" open="(" separator="," close=")">
#{item}
</foreach>
) d ON a.id = d.id
<where>
a.deleted_flag = 'N'
<if test="channelId != null">
and a.channel_id = #{channelId}
</if>
<if test="channelType != null">
and c.channel_type = #{channelType}
</if>
<if test="merchantId != null">
and a.merchant_id = #{merchantId}
</if>
<if test="merchantIdExcept != null">
and a.merchant_id != #{merchantIdExcept}
</if>
<if test="parentMerchantId != null">
and a.parent_merchant_id = #{parentMerchantId}
</if>
<if test="userType != null">
and a.user_type = #{userType}
</if>
<if test="merchantType != null">
and a.merchant_type = #{merchantType}
</if>
<if test="merchantTypeList != null">
and a.merchant_type in
<foreach collection="merchantTypeList" open="(" close=")" separator="," item="item">
#{item}
</foreach>
</if>
<if test="accountName != null and accountName !=''">
and a.account_name like CONCAT('%',#{accountName},'%')
</if>
<if test="merchantName != null and merchantName !=''">
and (
a.merchant_name like CONCAT('%',#{merchantName},'%')
or a.short_name like CONCAT('%',#{merchantName},'%')
)
</if>
<if test="parentMerchantName != null and parentMerchantName !=''">
and a.parent_merchant_name like CONCAT('%',#{parentMerchantName},'%')
</if>
<if test="shortName != null and shortName !=''">
and a.short_name like CONCAT('%',#{shortName},'%')
</if>
<if test="contactName != null and contactName !=''">
and a.contact_name like CONCAT('%',#{contactName},'%')
</if>
<if test="phone != null and phone !=''">
and a.phone like CONCAT('%',#{phone},'%')
</if>
<if test="createdBy != null and createdBy !=''">
and a.created_by = #{createdBy}
</if>
<if test="keyword != null and keyword !=''">
and (a.merchant_name like CONCAT('%',#{keyword},'%')
or a.merchant_id = #{keyword})
</if>
<if test="merchantIds != null and merchantIds.size() > 0">
and a.merchant_id in
<foreach collection="merchantIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="roleIds != null and roleIds.size() > 0">
and EXISTS(
select 1 from dj_system_user_role b
left join dj_system_user c on b.user_id = c.id
where a.merchant_id = c.merchant_id and a.deleted_flag = 'N' and b.deleted_flag = 'N' and c.deleted_flag = 'N'
and b.role_id in
<foreach collection="roleIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
)
</if>
<if test="loginPhone != null and loginPhone!=''">
and b.phone = #{loginPhone}
</if>
<if test="carBrandId != null">
and exists(
select 1 from dj_system_merchant_car_brand d
where d.merchant_id = a.merchant_id and d.deleted_flag = 'N'
and d.brand_id = #{carBrandId}
<if test="carChildsBrandId != null">
and d.childs_brand_id = #{carChildsBrandId}
</if>
)
</if>
<if test="null != merchantAddressType and merchantAddressType ==1">
and (a.address is not null and a.address != '')
</if>
<if test="null != merchantAddressType and merchantAddressType ==2">
and (a.address is null or a.address = '')
</if>
<if test="null != enabledFlag and enabledFlag !=''">
and b.enabled_flag = #{enabledFlag}
</if>
</where>
order by beServed,a.updated_date desc,a.id desc
</select>
<select id="getListShopByCity" parameterType="java.lang.String"
resultMap="DTOResultMap">
SELECT c.merchant_id, c.lat, c.lng,c.merchant_name,
IFNULL(c.address, '') as address,a.service_hours as rescueTime,a.service_range as rescueRange,
GROUP_CONCAT(b.vehicle_brand) as brand, CONCAT_WS(',',a.collision_phone,
a.spare_phones) as collisionPhone
FROM dj_collision_notice_config a LEFT JOIN
dj_collision_notice_config_car_brand b ON
a.merchant_id = b.merchant_id and b.deleted_flag = 'N'
LEFT JOIN dj_system_merchant c ON
a.merchant_id = c.merchant_id
WHERE a.merchant_id in (SELECT merchant_id
FROM dj_system_merchant WHERE city_name = #{city} ) GROUP BY a.merchant_id;
</select>
<select id="listSummary" parameterType="cn.com.glsx.dj.system.dto.MerchantDTO" resultMap="DTOResultMap">
SELECT dsm.merchant_id, dsm.merchant_name, dscc.channel_type
FROM dj_system_merchant dsm
left join dj_system_channel_config dscc on dscc.id = dsm.channel_id and dscc.deleted_flag = 'N'
where dsm.deleted_flag = 'N'
<if test="merchantId != null">
and dsm.merchant_id = #{merchantId}
</if>
<if test="merchantIds != null and merchantIds.size() > 0">
and dsm.merchant_id in
<foreach collection="merchantIds" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="merchantType != null">
and dsm.merchant_type = #{merchantType}
</if>
</select>
</mapper>