WeGroupMapper.xml
3.75 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
<?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.WeGroupMapper">
<select id="selectWeGroupList" parameterType="WeGroup" resultType="com.linkwechat.wecom.domain.WeGroup">
SELECT
wg.chat_id,
wg.group_name,
wg.create_time,
wg.notice,
wu.user_name as groupLeaderName,
(SELECT COUNT(*) FROM we_group_member wgm WHERE wgm.chat_id=wg.chat_id) as memberNum,
wg.status,
wg.`owner`,
(SELECT GROUP_CONCAT(wt.`name`) FROM we_group_tag_rel wgtr LEFT JOIN we_tag wt ON wt.tag_id=wgtr.tag_id WHERE wg.chat_id=wgtr.chat_id) as tags,
(SELECT GROUP_CONCAT(wt.`tag_id`) FROM we_group_tag_rel wgtr LEFT JOIN we_tag wt ON wt.tag_id=wgtr.tag_id WHERE wg.chat_id=wgtr.chat_id) as tagIds
FROM
we_group wg
LEFT JOIN we_user wu ON wg.`owner`=wu.user_id
<where>
<if test="delFlag !=null"> wg.del_flag=#{delFlag}</if>
<if test="groupName != null and groupName != ''"> and wg.group_name like concat('%', #{groupName}, '%')</if>
<if test="groupLeader != null and groupLeader != ''"> and wu.user_name like concat('%', #{groupLeader}, '%')</if>
<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
AND date_format(wg.create_time,'%y%m%d') >= date_format(#{beginTime},'%y%m%d')
</if>
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
AND date_format(wg.create_time,'%y%m%d') <= date_format(#{endTime},'%y%m%d')
</if>
<if test="userIds != null and userIds !=''">
<if test="userIds.indexOf(',') != -1">
AND wg.`owner` in
<foreach item="item" index="index" collection="userIds.split(',')" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="userIds.indexOf(',') == -1">
AND wg.`owner`=#{userIds}
</if>
</if>
</where>
</select>
<select id="findWeGroupByCustomer" resultType="com.linkwechat.wecom.domain.WeCustomerAddGroup">
SELECT
wg.chat_id,
wg.group_name,
wu.user_name as ownerName,
COUNT(wgm.id) as groupMemberNum,
wgm.join_time,
(SELECT count(*) FROM we_group_member wgmr WHERE wgmr.chat_id=wg.chat_id and wgmr.user_id=#{userId}) as commonGroup
FROM
`we_group` wg
LEFT JOIN we_group_member wgm ON wgm.chat_id=wg.chat_id
LEFT JOIN we_user wu ON wg.`owner`=wu.user_id
WHERE wgm.user_id=#{externalUserid}
GROUP BY wg.chat_id
</select>
<insert id="insertBatch">
insert into we_group (chat_id, group_name, owner, add_time, notice, status,admin_user_id, create_by, create_time,update_by, update_time,del_flag)
values
<foreach collection="weGroups" item="weGroup" index="index" separator=",">
(#{weGroup.chatId},#{weGroup.groupName},#{weGroup.owner},#{weGroup.addTime},#{weGroup.notice},#{weGroup.status},#{weGroup.adminUserId},
#{weGroup.createBy},#{weGroup.createTime},#{weGroup.updateBy},#{weGroup.updateTime},#{weGroup.delFlag})
</foreach>
on duplicate key update group_name= values(group_name),owner= values(owner),
notice= values(notice),status= values(status),admin_user_id= values(admin_user_id),
update_by= values(update_by),update_time= values(update_time),del_flag=values(del_flag)
</insert>
</mapper>