MerchantCustomerInfoMapper.xml
14.9 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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<?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.customer.mapper.MerchantCustomerInfoMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.dj.customer.model.MerchantCustomerInfo">
<id column="ID" jdbcType="BIGINT" property="id" />
<result column="MERCHANT_ID" jdbcType="INTEGER" property="merchantId" />
<result column="ACCOUNT_ID" jdbcType="INTEGER" property="accountId" />
<result column="PHONE" jdbcType="VARCHAR" property="phone" />
<result column="USER_NAME" jdbcType="VARCHAR" property="userName" />
<result column="GENDER" jdbcType="CHAR" property="gender" />
<result column="BIZ_OPEN_ID" jdbcType="VARCHAR" property="bizOpenId" />
<result column="WEAPP_OPEN_ID" jdbcType="VARCHAR" property="weappOpenId" />
<result column="UNION_ID" jdbcType="VARCHAR" property="unionId" />
<result column="BIND_DEVICE" jdbcType="CHAR" property="bindDevice" />
<result column="OUTER_IMPORT" jdbcType="CHAR" property="outerImport" />
<result column="STAND_NO" jdbcType="VARCHAR" property="standNo" />
<result column="SOURCES_DETAIL" jdbcType="VARCHAR" property="sourcesDetail" />
<result column="LAST_LOGIN_TIME" jdbcType="TIMESTAMP" property="lastLoginTime" />
<result column="CREATED_BY" jdbcType="VARCHAR" property="createdBy" />
<result column="CREATED_DATE" jdbcType="TIMESTAMP" property="createdDate" />
<result column="UPDATED_BY" jdbcType="VARCHAR" property="updatedBy" />
<result column="UPDATED_DATE" jdbcType="TIMESTAMP" property="updatedDate" />
<result column="DELETED_FLAG" jdbcType="CHAR" property="deletedFlag" />
</resultMap>
<resultMap id="BaseResultVOMap" type="cn.com.glsx.dj.customer.vo.MerchantCustomerRefVO">
<result column="haveDeviceCount" jdbcType="INTEGER" property="haveDeviceCount" />
<result column="noDeviceCount" jdbcType="INTEGER" property="noDeviceCount" />
<result column="shopCount" jdbcType="INTEGER" property="shopCount" />
<result column="outerImportCount" jdbcType="INTEGER" property="outerImportCount" />
<result column="webAppOpenIdCount" jdbcType="INTEGER" property="webAppOpenIdCount" />
<result column="merchantCustomerCount" jdbcType="INTEGER" property="merchantCustomerCount" />
<result column="haveDevicePercentage" jdbcType="DOUBLE" property="haveDevicePercentage" />
<result column="noDevicePercentage" jdbcType="DOUBLE" property="noDevicePercentage" />
</resultMap>
<resultMap type="cn.com.glsx.dj.customer.dto.MerchantCustomerDTO" id="DTOMap" extends="BaseResultMap">
<result column="RECEIVED_COUPON_NUM" jdbcType="INTEGER" property="receivedCouponNum" />
<result column="VERIFIED_COUPON_NUM" jdbcType="INTEGER" property="verifiedCouponNum" />
<result column="SUCCESSED_ORDER_NUM" jdbcType="INTEGER" property="successedOrderNum" />
<result column="SUCCESSED_ORDER_PAID" jdbcType="DOUBLE" property="successedOrderPaid" />
<result column="has_binded_eapp" jdbcType="CHAR" property="hasBindedWeapp"/>
<result column="has_orderd" jdbcType="CHAR" property="hasOrderd"/>
<result column="merchant_name" jdbcType="VARCHAR" property="merchantName"/>
<result column="sn" jdbcType="VARCHAR" property="sn"/>
</resultMap>
<sql id="Base_Column_List">
ID, MERCHANT_ID, ACCOUNT_ID, PHONE, USER_NAME, GENDER, BIZ_OPEN_ID, WEAPP_OPEN_ID,
UNION_ID, BIND_DEVICE, OUTER_IMPORT, STAND_NO, SOURCES_DETAIL, LAST_LOGIN_TIME, CREATED_BY,
CREATED_DATE, UPDATED_BY, UPDATED_DATE, DELETED_FLAG
</sql>
<sql id="Alias_Column_List">
c.ID, c.MERCHANT_ID, c.ACCOUNT_ID, c.PHONE, c.USER_NAME, c.BIZ_OPEN_ID, c.WEAPP_OPEN_ID, c.UNION_ID,
c.BIND_DEVICE, c.OUTER_IMPORT, c.STAND_NO, c.GENDER, c.SOURCES_DETAIL, c.LAST_LOGIN_TIME,
c.CREATED_BY, c.CREATED_DATE, c.UPDATED_BY, c.UPDATED_DATE, c.DELETED_FLAG
</sql>
<sql id="Tables_Column_List">
ID, MERCHANT_ID, ACCOUNT_ID, PHONE, USER_NAME, GENDER, BIZ_OPEN_ID, WEAPP_OPEN_ID,
UNION_ID, BIND_DEVICE, OUTER_IMPORT, STAND_NO, SOURCES_DETAIL, LAST_LOGIN_TIME, CREATED_BY,
CREATED_DATE, UPDATED_BY, UPDATED_DATE, DELETED_FLAG, RECEIVED_COUPON_NUM, VERIFIED_COUPON_NUM,
SUCCESSED_ORDER_NUM,SUCCESSED_ORDER_PAID, has_binded_eapp,has_orderd,merchant_name
</sql>
<sql id="batchMergeSql">
INSERT INTO dj_merchant_customer_info (
MERCHANT_ID,
PHONE,
USER_NAME,
BIND_DEVICE,
OUTER_IMPORT,
STAND_NO,
GENDER,
SOURCES_DETAIL,
CREATED_BY,
CREATED_DATE,
UPDATED_BY,
UPDATED_DATE,
DELETED_FLAG
)
VALUES
<foreach collection="list" item="info" index="index" separator=",">
(
#{info.merchantId},
#{info.phone},
#{info.userName},
#{info.bindDevice},
#{info.outerImport},
#{info.standNo},
#{info.gender},
#{info.sourcesDetail},
#{info.phone},
<if test="info.createdDate != null">
#{info.createdDate},
</if>
<if test="info.createdDate == null">
NOW(),
</if>
#{info.phone},
NOW(),
'N'
)
</foreach>
ON DUPLICATE KEY
UPDATE
UPDATED_BY = VALUES(PHONE),
UPDATED_DATE = NOW(),
</sql>
<insert id="batchMergeForImportUser" parameterType="java.util.List">
<include refid="batchMergeSql"></include>
OUTER_IMPORT = 'Y',
USER_NAME = CASE BIND_DEVICE WHEN 'Y' THEN IFNULL(USER_NAME,VALUES(USER_NAME)) ELSE IFNULL(VALUES(USER_NAME), USER_NAME) END
</insert>
<insert id="batchMergeForHardwareUser" parameterType="java.util.List">
<include refid="batchMergeSql"></include>
STAND_NO = VALUES(STAND_NO),
GENDER = VALUES(GENDER),
USER_NAME = VALUES(USER_NAME),
BIND_DEVICE = IFNULL(VALUES(BIND_DEVICE), BIND_DEVICE)
</insert>
<select id="queryByMerchantId" parameterType="java.lang.Integer" resultMap="BaseResultVOMap">
select
sum(case when BIND_DEVICE ='Y' then 1 ELSE 0 end) AS haveDeviceCount,
sum(case when BIND_DEVICE ='N' or BIND_DEVICE is null then 1 ELSE 0 end) AS noDeviceCount,
sum(case when BIND_DEVICE is not null and (OUTER_IMPORT = 'N' or OUTER_IMPORT is null) and WEAPP_OPEN_ID is null then 1 ELSE 0 end) AS shopCount,
sum(case when OUTER_IMPORT = 'Y' AND WEAPP_OPEN_ID is NULL then 1 ELSE 0 end) AS outerImportCount,
sum(case when WEAPP_OPEN_ID is NOT NULL then 1 ELSE 0 end) AS webAppOpenIdCount,
sum(case when BIND_DEVICE is not null and (OUTER_IMPORT != 'Y' or OUTER_IMPORT is null) and WEAPP_OPEN_ID is null then 1 ELSE 0 end)+
SUM(case when OUTER_IMPORT = 'Y' AND WEAPP_OPEN_ID is NULL then 1 ELSE 0 end)+
SUM(case when WEAPP_OPEN_ID is NOT NULL then 1 ELSE 0 end) AS merchantCustomerCount,
cast(sum(case when BIND_DEVICE ='Y' then 1 ELSE 0 end)/count(id)*100 as decimal(18,2)) AS haveDevicePercentage,
cast(100-sum(case when BIND_DEVICE ='Y' then 1 ELSE 0 end)/count(id)*100 as decimal(18,2)) AS noDevicePercentage
from dj_merchant_customer_info
WHERE DELETED_FLAG = 'N'
<if test="merchantId != null">
and MERCHANT_ID = #{merchantId, jdbcType=INTEGER}
</if>
</select>
<select id="pageMerchanrCustomer" parameterType="cn.com.glsx.dj.customer.dto.MerchantCustomerDTO"
resultMap="DTOMap">
select <include refid="Tables_Column_List"/>
from (
select <include refid="Alias_Column_List" /> ,(if(c.WEAPP_OPEN_ID is null,'N','Y')) has_binded_eapp
,(if(c.BIND_DEVICE='Y', 'Y','N')) has_orderd, s.merchant_name,
IF(m.RECEIVED_COUPON_NUM is null,0,m.RECEIVED_COUPON_NUM) as RECEIVED_COUPON_NUM,
IF(m.VERIFIED_COUPON_NUM is null,0,m.VERIFIED_COUPON_NUM) as VERIFIED_COUPON_NUM,
IF(m.SUCCESSED_ORDER_NUM is null,0,m.SUCCESSED_ORDER_NUM) as SUCCESSED_ORDER_NUM,
IF(m.SUCCESSED_ORDER_PAID is null,0.0,m.SUCCESSED_ORDER_PAID) as SUCCESSED_ORDER_PAID
from dj_merchant_customer_info c
left join dj_system_merchant s on c.merchant_id = s.merchant_id
left join dj_merchant_customer_marketing m on c.merchant_id = m.merchant_id and c.PHONE = m.PHONE
where c.DELETED_FLAG = 'N'
AND (c.WEAPP_OPEN_ID is NOT NULL OR c.BIND_DEVICE is NOT NULL OR c.OUTER_IMPORT = 'Y')
<if test="merchantId != null">
and c.MERCHANT_ID = #{merchantId, jdbcType=INTEGER}
</if>
<if test="merchantIds != null and merchantIds.size() > 0">
and c.MERCHANT_ID in
<foreach collection="merchantIds" index="index" item="item"
open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test='hasOrderd != null and hasOrderd == "N"'>
and (c.OUTER_IMPORT = 'Y' or c.WEAPP_OPEN_ID is not null)
</if>
<if test='hasOrderd != null and hasOrderd == "Y"'>
and c.BIND_DEVICE is not null and (c.OUTER_IMPORT != 'Y' or c.OUTER_IMPORT is null) and c.WEAPP_OPEN_ID is null
</if>
<if test='hasBindedWeapp != null and hasBindedWeapp == "Y"'>
and c.WEAPP_OPEN_ID is not null
</if>
<if test='hasBindedWeapp != null and hasBindedWeapp == "N"'>
and c.WEAPP_OPEN_ID is null
</if>
<if test="selectCondition != null and selectCondition != '' ">
and (
c.STAND_NO LIKE CONCAT('%', #{selectCondition, jdbcType=VARCHAR}, '%')
or
c.PHONE LIKE CONCAT('%', #{selectCondition, jdbcType=VARCHAR}, '%')
or
c.USER_NAME LIKE CONCAT('%', #{selectCondition, jdbcType=VARCHAR}, '%')
)
</if>
) as t
where 1=1
<if test="receivedCouponNumMin != null">
<![CDATA[and RECEIVED_COUPON_NUM >= #{receivedCouponNumMin, jdbcType=INTEGER}]]>
</if>
<if test="receivedCouponNumMax != null">
<![CDATA[and RECEIVED_COUPON_NUM <= #{receivedCouponNumMax, jdbcType=INTEGER}]]>
</if>
<if test="successedOrderNumMin != null">
<![CDATA[and SUCCESSED_ORDER_NUM >= #{successedOrderNumMin, jdbcType=INTEGER}]]>
</if>
<if test="successedOrderNumMax != null">
<![CDATA[and SUCCESSED_ORDER_NUM <= #{successedOrderNumMax, jdbcType=INTEGER}]]>
</if>
<if test="verifiedCouponNumMin != null">
<![CDATA[and VERIFIED_COUPON_NUM >= #{verifiedCouponNumMin, jdbcType=INTEGER}]]>
</if>
<if test="verifiedCouponNumMax != null">
<![CDATA[and VERIFIED_COUPON_NUM <= #{verifiedCouponNumMax, jdbcType=INTEGER}]]>
</if>
<if test="successedOrderPaidMin != null">
<![CDATA[and SUCCESSED_ORDER_PAID >= #{successedOrderPaidMin, jdbcType=DOUBLE}]]>
</if>
<if test="successedOrderPaidMax != null">
<![CDATA[and SUCCESSED_ORDER_PAID <= #{successedOrderPaidMax, jdbcType=DOUBLE}]]>
</if>
ORDER BY CREATED_DATE DESC
</select>
<select id="listMerchanrCustomer" parameterType="cn.com.glsx.dj.customer.dto.MerchantCustomerDTO"
resultMap="DTOMap">
select <include refid="Tables_Column_List"/>
from (
select <include refid="Alias_Column_List" /> ,(if(c.WEAPP_OPEN_ID is null,'N','Y')) has_binded_eapp
,(if(c.BIND_DEVICE='Y', 'Y','N')) has_orderd, s.merchant_name,
IF(m.RECEIVED_COUPON_NUM is null,0,m.RECEIVED_COUPON_NUM) as RECEIVED_COUPON_NUM,
IF(m.VERIFIED_COUPON_NUM is null,0,m.VERIFIED_COUPON_NUM) as VERIFIED_COUPON_NUM,
IF(m.SUCCESSED_ORDER_NUM is null,0,m.SUCCESSED_ORDER_NUM) as SUCCESSED_ORDER_NUM,
IF(m.SUCCESSED_ORDER_PAID is null,0.0,m.SUCCESSED_ORDER_PAID) as SUCCESSED_ORDER_PAID
from dj_merchant_customer_info c
left join dj_system_merchant s on c.merchant_id = s.merchant_id
left join dj_merchant_customer_marketing m on c.merchant_id = m.merchant_id and c.PHONE = m.PHONE
where c.DELETED_FLAG = 'N'
AND (c.WEAPP_OPEN_ID is NOT NULL OR c.BIND_DEVICE is NOT NULL OR c.OUTER_IMPORT = 'Y')
<if test="merchantId != null">
and c.MERCHANT_ID = #{merchantId, jdbcType=INTEGER}
</if>
<if test="merchantIds != null and merchantIds.size() > 0">
and c.MERCHANT_ID in
<foreach collection="merchantIds" index="index" item="item"
open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test='hasOrderd != null and hasOrderd == "N"'>
and (c.OUTER_IMPORT = 'Y' or c.WEAPP_OPEN_ID is not null)
</if>
<if test='hasOrderd != null and hasOrderd == "Y"'>
and c.BIND_DEVICE is not null and (c.OUTER_IMPORT != 'Y' or c.OUTER_IMPORT is null) and c.WEAPP_OPEN_ID is null
</if>
<if test='hasBindedWeapp != null and hasBindedWeapp == "Y"'>
and c.WEAPP_OPEN_ID is not null
</if>
<if test='hasBindedWeapp != null and hasBindedWeapp == "N"'>
and c.WEAPP_OPEN_ID is null
</if>
<if test="selectCondition != null and selectCondition != '' ">
and (
c.STAND_NO LIKE CONCAT('%', #{selectCondition, jdbcType=VARCHAR}, '%')
or
c.PHONE LIKE CONCAT('%', #{selectCondition, jdbcType=VARCHAR}, '%')
or
c.USER_NAME LIKE CONCAT('%', #{selectCondition, jdbcType=VARCHAR}, '%')
)
</if>
) as t
where 1=1
<if test="receivedCouponNumMin != null">
<![CDATA[and RECEIVED_COUPON_NUM >= #{receivedCouponNumMin, jdbcType=INTEGER}]]>
</if>
<if test="receivedCouponNumMax != null">
<![CDATA[and RECEIVED_COUPON_NUM <= #{receivedCouponNumMax, jdbcType=INTEGER}]]>
</if>
<if test="successedOrderNumMin != null">
<![CDATA[and SUCCESSED_ORDER_NUM >= #{successedOrderNumMin, jdbcType=INTEGER}]]>
</if>
<if test="successedOrderNumMax != null">
<![CDATA[and SUCCESSED_ORDER_NUM <= #{successedOrderNumMax, jdbcType=INTEGER}]]>
</if>
<if test="verifiedCouponNumMin != null">
<![CDATA[and VERIFIED_COUPON_NUM >= #{verifiedCouponNumMin, jdbcType=INTEGER}]]>
</if>
<if test="verifiedCouponNumMax != null">
<![CDATA[and VERIFIED_COUPON_NUM <= #{verifiedCouponNumMax, jdbcType=INTEGER}]]>
</if>
<if test="successedOrderPaidMin != null">
<![CDATA[and SUCCESSED_ORDER_PAID >= #{successedOrderPaidMin, jdbcType=DOUBLE}]]>
</if>
<if test="successedOrderPaidMax != null">
<![CDATA[and SUCCESSED_ORDER_PAID <= #{successedOrderPaidMax, jdbcType=DOUBLE}]]>
</if>
ORDER BY CREATED_DATE DESC
</select>
<select id="countAll" resultType="java.lang.Integer">
select count(*) from dj_merchant_customer_info
where DELETED_FLAG = 'N'
AND (WEAPP_OPEN_ID is NOT NULL OR BIND_DEVICE is not null OR OUTER_IMPORT = 'Y')
</select>
<select id="countMerchantIds" parameterType="java.util.List" resultType="java.lang.Integer">
select count(*) from dj_merchant_customer_info
where DELETED_FLAG = 'N'
AND (WEAPP_OPEN_ID is NOT NULL OR BIND_DEVICE is not null OR OUTER_IMPORT = 'Y')
AND MERCHANT_ID IN
<foreach collection="list" index="index" item="item"
open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="selectDeviceByMerchantId" parameterType="java.lang.Integer" resultMap="DTOMap">
SELECT o.sub_device_sn as sn
from dj_merchant_customer_info info left JOIN dj_insure_order o ON info.STAND_NO=o.stand_no
WHERE o.insurance_status=1 AND info.BIND_DEVICE = 'Y' AND info.DELETED_FLAG='N' AND o.deleted_flag='N' AND o.sub_device_sn is NOT NULL
<if test="merchantId != null">
and info.MERCHANT_ID = #{merchantId, jdbcType=INTEGER}
</if>
</select>
<select id="queryCustomerMerchantRef" resultType="cn.com.glsx.dj.customer.dto.CustomerMerchantRefDTO" parameterType="java.lang.Long">
SELECT
ID id,
PHONE mobile,
MERCHANT_ID merchantId
FROM
dj_merchant_customer_info
WHERE
ID > #{lastId}
AND PHONE IS NOT NULL
ORDER BY
ID
</select>
</mapper>