WeGroupMapper.xml 3.75 KB
<?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') &gt;= date_format(#{beginTime},'%y%m%d')
            </if>

            <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
                AND date_format(wg.create_time,'%y%m%d') &lt;= 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>