WeGroupMapper.xml 1.9 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`
        FROM
        we_group wg
        LEFT JOIN  we_user wu ON wg.`owner`=wu.user_id
        <where>
            <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>


</mapper>