WeEmpleCodeMapper.xml
11.1 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
<?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.linkwechat.wecom.mapper.WeEmpleCodeMapper">
<resultMap type="WeEmpleCode" id="WeEmpleCodeResult">
<result property="id" column="id"/>
<result property="codeType" column="code_type"/>
<result property="skipVerify" column="skip_verify"/>
<result property="scenario" column="scenario"/>
<result property="welcomeMsg" column="welcome_msg"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="delFlag" column="del_flag"/>
<result property="configId" column="config_id"/>
<result property="qrCode" column="qr_code"/>
<result property="mediaId" column="media_id"/>
<result property="scanTimes" column="scan_times" />
<result property="state" column="state" />
<result property="isJoinConfirmFriends" column="is_join_confirm_friends" />
<collection property="weEmpleCodeUseScops" ofType="com.linkwechat.wecom.domain.WeEmpleCodeUseScop">
<result property="businessId" column="business_id"/>
<result property="businessName" column="business_name"/>
<result property="mobile" column="mobile"/>
</collection>
<collection property="weEmpleCodeTags" ofType="com.linkwechat.wecom.domain.WeEmpleCodeTag">
<result property="tagId" column="tag_id"/>
<result property="tagName" column="tag_name"/>
</collection>
</resultMap>
<sql id="selectWeEmpleCodeVo">
select id, code_type, skip_verify, scenario, welcome_msg, create_by, create_time, del_flag, config_id,qr_code, state, scan_times from we_emple_code
</sql>
<sql id="getQrcodeByUserIdVo">
select
wec.id,
wec.code_type,
wec.skip_verify,
wec.scenario,
wec.welcome_msg,
wec.create_by,
wec.create_time,
wec.del_flag,
wec.config_id,
wec.state,
wec.qr_code,
wec.scan_times
from we_emple_code wec
left join we_emple_code_use_scop wecus on wec.id = wecus.emple_code_id
and wecus.business_id_type = 2
and wecus.del_flag = 0
</sql>
<sql id="selectWeEmpleCodeLsit">
select
wecode.id,
wecode.code_type,
wecode.media_id,
wecode.skip_verify,
wecode.scenario,
wecode.welcome_msg,
wecode.create_by,
wecode.create_time,
wecode.del_flag,
wecode.config_id,
wecode.qr_code,
wecode.state,
wecode.scan_times,
wecusn.business_id,
wecusn.business_name,
wecusn.mobile,
wect.tag_id,
wect.tag_name,
wecode.is_join_confirm_friends
from
we_emple_code wecode
left join (
SELECT
wecus.emple_code_id, wecus.business_id, wecus.business_name,wu.mobile
FROM
we_emple_code_use_scop wecus
LEFT JOIN we_user wu ON
wu.user_id = wecus.business_id
WHERE
wecus.del_flag = 0
) as wecusn on
wecode.id = wecusn.emple_code_id
left join we_emple_code_tag wect on
wecode.id = wect.emple_code_id
where 1=1 and wecode.del_flag = 0
</sql>
<select id="selectWeEmpleCodeList" parameterType="WeEmpleCode" resultType="com.linkwechat.wecom.domain.WeEmpleCode">
<include refid="selectWeEmpleCodeLsit"/>
<if test="codeType != null ">and wecode.code_type = #{codeType}</if>
<if test="skipVerify != null ">and wecode.skip_verify = #{skipVerify}</if>
<if test="scenario != null and scenario != ''">
and wecode.scenario like concat('%', #{scenario}, '%')
</if>
<if test="welcomeMsg != null ">and wecode.welcome_msg = #{welcomeMsg}</if>
<if test="createBy != null and createBy !=''">
AND wecode.create_by like concat('%', #{createBy}, '%')
</if>
<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
AND date_format(wecode.create_time,'%y%m%d') >= date_format(#{beginTime},'%y%m%d')
</if>
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
AND date_format(wecode.create_time,'%y%m%d') <= date_format(#{endTime},'%y%m%d')
</if>
<if test="mobile != null and mobile !=''">
AND wecusn.mobile like concat('%', #{mobile}, '%')
</if>
<if test="useUserName != null and useUserName !=''">
AND wecusn.business_name like concat('%', #{useUserName}, '%')
</if>
group by wecode.id
</select>
<select id="selectWeEmpleCodeById" parameterType="Long" resultMap="WeEmpleCodeResult">
<include refid="selectWeEmpleCodeLsit"/>
<if test="id != null and id !=''">
and wecode.id = #{id}
</if>
</select>
<select id="selectWeEmpleCodeByIds" parameterType="java.util.ArrayList" resultMap="WeEmpleCodeResult">
<include refid="selectWeEmpleCodeLsit"/>
<if test="ids != null and ids.size > 0">
and wecode.id in
<foreach collection="ids" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</if>
</select>
<insert id="insertWeEmpleCode" parameterType="WeEmpleCode">
insert into we_emple_code
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="codeType != null">code_type,</if>
<if test="skipVerify != null">skip_verify,</if>
<if test="scenario != null">scenario,</if>
<if test="welcomeMsg != null">welcome_msg,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="delFlag != null">del_flag,</if>
<if test="configId != null">config_id,</if>
<if test="qrCode != null">qr_code,</if>
<if test="mediaId != null">media_id,</if>
<if test="state != null">state,</if>
<if test="scanTimes != null">scan_times,</if>
<if test="isJoinConfirmFriends != null">is_join_confirm_friends,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="codeType != null">#{codeType},</if>
<if test="skipVerify != null">#{skipVerify},</if>
<if test="scenario != null">#{scenario},</if>
<if test="welcomeMsg != null">#{welcomeMsg},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="delFlag != null">#{delFlag},</if>
<if test="configId != null">#{configId},</if>
<if test="qrCode != null">#{qrCode},</if>
<if test="mediaId != null">#{mediaId},</if>
<if test="state != null">#{state},</if>
<if test="scanTimes != null">#{scanTimes},</if>
<if test="isJoinConfirmFriends != null">#{isJoinConfirmFriends},</if>
</trim>
</insert>
<update id="updateWeEmpleCode" parameterType="WeEmpleCode">
update we_emple_code
<trim prefix="SET" suffixOverrides=",">
<if test="codeType != null">code_type = #{codeType},</if>
<if test="skipVerify != null">skip_verify = #{skipVerify},</if>
<if test="scenario != null">scenario = #{scenario},</if>
<if test="welcomeMsg != null">welcome_msg = #{welcomeMsg},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
<if test="configId != null">config_id = #{configId},</if>
<if test="qrCode != null">qr_code = #{qrCode},</if>
<if test="mediaId != null">media_id = #{mediaId},</if>
<if test="state != null">state = #{state},</if>
<if test="scanTimes != null">scan_times = #{scanTimes},</if>
<if test="isJoinConfirmFriends != null"> is_join_confirm_friends =#{isJoinConfirmFriends},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteWeEmpleCodeById" parameterType="Long">
delete from we_emple_code where id = #{id}
</delete>
<delete id="deleteWeEmpleCodeByIds" parameterType="String">
delete from we_emple_code where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<update id="batchRemoveWeEmpleCodeIds">
update we_emple_code set
del_flag = 1
where id in
<foreach collection="ids" item="id" index="index"
separator="," open="(" close=")">
#{id}
</foreach>
</update>
<select id="selectWelcomeMsgByScenario" parameterType="String"
resultType="com.linkwechat.wecom.domain.dto.WeEmpleCodeDto">
select
wecode.id as emple_code_id,
wecode.welcome_msg ,
wm.category_id,
wm.material_url,
wm.content,
wm.material_name,
wm.digest,
wm.cover_url
from
we_emple_code wecode
left join we_emple_code_use_scop wecus on
wecode.id = wecus.emple_code_id
left join we_material wm on
wm .id = wecode.media_id
where
wecode.del_flag = 0
<if test="scenario != null and scenario != ''">
and wecode.scenario = #{scenario}
</if>
<if test="userId != null and userId != ''">
and wecus.business_id = #{userId}
</if>
</select>
<select id="selectWelcomeMsgByState" parameterType="String" resultType="com.linkwechat.wecom.domain.dto.WeEmpleCodeDto">
select
wecode.id as emple_code_id,
wecode.welcome_msg ,
wm.category_id,
wm.material_url,
wm.content,
wm.material_name,
wm.digest,
wm.cover_url
from
we_emple_code wecode
left join we_emple_code_use_scop wecus on
wecode.id = wecus.emple_code_id
left join we_material wm on
wm .id = wecode.media_id
where
wecode.del_flag = 0
<if test="state != null and state != ''">
and wecode.state = #{state}
</if>
</select>
<select id="getQrcodeByUserId" parameterType="java.lang.String" resultType="com.linkwechat.wecom.domain.WeEmpleCode">
<include refid="getQrcodeByUserIdVo"/>
<where>
<if test="userId != null and userId != ''">
and wecus.business_id = #{userId}
</if>
</where>
</select>
<update id="updateScanTimesByState" parameterType="String">
update we_emple_code
set scan_times = scan_times + 1
where state = #{state}
</update>
</mapper>