<?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.gic.haoban.manage.service.dao.mapper.chat.GroupChatActivityInviteLogMapper">
    <resultMap type="com.gic.haoban.manage.service.entity.chat.TabGroupChatActivityInviteLog"
               id="TabHaobanGroupChatActivityInviteLogMap">
        <result property="chatActivityInviteId" column="chat_activity_invite_id" jdbcType="INTEGER"/>
        <result property="chatActivityId" column="chat_activity_id" jdbcType="INTEGER"/>
        <result property="inviterMemberId" column="inviter_member_id" jdbcType="VARCHAR"/>
        <result property="inviteeMemberId" column="invitee_member_id" jdbcType="VARCHAR"/>
        <result property="inviteeUserId" column="invitee_user_id" jdbcType="VARCHAR"/>
        <result property="inviteeUnionId" column="invitee_union_id" jdbcType="VARCHAR"/>
        <result property="userName" column="user_name" jdbcType="VARCHAR"/>
        <result property="nickName" column="nick_name" jdbcType="VARCHAR"/>
        <result property="groupChatId" column="group_chat_id" jdbcType="INTEGER"/>
        <result property="inviteType" column="invite_type" jdbcType="INTEGER"/>
        <result property="invalidInviteType" column="invalid_invite_type" jdbcType="INTEGER"/>
        <result property="addMemberType" column="add_member_type" jdbcType="INTEGER"/>
        <result property="batchNumber" column="batch_number" jdbcType="INTEGER"/>
        <result property="enterpriseId" column="enterprise_id" jdbcType="VARCHAR"/>
        <result property="wxEnterpriseId" column="wx_enterprise_id" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="deleteFlag" column="delete_flag" jdbcType="INTEGER"/>
    </resultMap>

    <sql id="Base_Column_List">
        chat_activity_invite_id
        , chat_activity_id, inviter_member_id, invitee_member_id, invitee_user_id,invitee_union_id,
               user_name, nick_name, group_chat_id, invite_type, invalid_invite_type, add_member_type, batch_number,
               enterprise_id, wx_enterprise_id, create_time, update_time, delete_flag
    </sql>

    <!--查询单个-->
    <select id="queryById" resultMap="TabHaobanGroupChatActivityInviteLogMap">
        select
        <include refid="Base_Column_List"/>

        from tab_haoban_group_chat_activity_invite_log
        where chat_activity_invite_id = #{chatActivityInviteId}
    </select>

    <!--查询指定行数据-->
    <select id="queryAll" resultMap="TabHaobanGroupChatActivityInviteLogMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_group_chat_activity_invite_log
        <where>
            and enterprise_id = #{enterpriseId} and delete_flag = 0
            <if test="chatActivityInviteId != null">
                and chat_activity_invite_id = #{chatActivityInviteId}
            </if>
            <if test="chatActivityId != null">
                and chat_activity_id = #{chatActivityId}
            </if>
            <if test="inviterMemberId != null and inviterMemberId != ''">
                and inviter_member_id = #{inviterMemberId}
            </if>
            <if test="inviteeMemberId != null and inviteeMemberId != ''">
                and invitee_member_id = #{inviteeMemberId}
            </if>
            <if test="inviteeUserId != null and inviteeUserId != ''">
                and invitee_user_id = #{inviteeUserId}
            </if>
            <if test="userName != null and userName != ''">
                and user_name = #{userName}
            </if>
            <if test="nickName != null and nickName != ''">
                and nick_name = #{nickName}
            </if>
            <if test="groupChatId != null">
                and group_chat_id = #{groupChatId}
            </if>
            <if test="inviteType != null">
                and invite_type = #{inviteType}
            </if>
            <if test="invalidInviteType != null">
                and invalid_invite_type = #{invalidInviteType}
            </if>
            <if test="addMemberType != null">
                and add_member_type = #{addMemberType}
            </if>
            <if test="batchNumber != null">
                and batch_number = #{batchNumber}
            </if>
            <if test="wxEnterpriseId != null and wxEnterpriseId != ''">
                and wx_enterprise_id = #{wxEnterpriseId}
            </if>
        </where>
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from tab_haoban_group_chat_activity_invite_log
        <where>
            and enterprise_id = #{enterpriseId} and delete_flag = 0
            <if test="chatActivityInviteId != null">
                and chat_activity_invite_id = #{chatActivityInviteId}
            </if>
            <if test="chatActivityId != null">
                and chat_activity_id = #{chatActivityId}
            </if>
            <if test="inviterMemberId != null and inviterMemberId != ''">
                and inviter_member_id = #{inviterMemberId}
            </if>
            <if test="inviteeMemberId != null and inviteeMemberId != ''">
                and invitee_member_id = #{inviteeMemberId}
            </if>
            <if test="inviteeUserId != null and inviteeUserId != ''">
                and invitee_user_id = #{inviteeUserId}
            </if>
            <if test="userName != null and userName != ''">
                and user_name = #{userName}
            </if>
            <if test="nickName != null and nickName != ''">
                and nick_name = #{nickName}
            </if>
            <if test="groupChatId != null">
                and group_chat_id = #{groupChatId}
            </if>
            <if test="inviteType != null">
                and invite_type = #{inviteType}
            </if>
            <if test="invalidInviteType != null">
                and invalid_invite_type = #{invalidInviteType}
            </if>
            <if test="addMemberType != null">
                and add_member_type = #{addMemberType}
            </if>
            <if test="batchNumber != null">
                and batch_number = #{batchNumber}
            </if>
            <if test="wxEnterpriseId != null and wxEnterpriseId != ''">
                and wx_enterprise_id = #{wxEnterpriseId}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="chatActivityInviteId" useGeneratedKeys="true">
        insert into tab_haoban_group_chat_activity_invite_log(chat_activity_invite_id,chat_activity_id, inviter_member_id, invitee_member_id, invitee_user_id,invitee_union_id,
                                                              user_name, nick_name, group_chat_id, invite_type, invalid_invite_type, add_member_type, batch_number,
                                                              enterprise_id, wx_enterprise_id)
        values (#{chatActivityInviteId},#{chatActivityId}, #{inviterMemberId}, #{inviteeMemberId}, #{inviteeUserId},#{inviteeUnionId}, #{userName}, #{nickName},
                #{groupChatId}, #{inviteType}, #{invalidInviteType}, #{addMemberType}, #{batchNumber}, #{enterpriseId},
                #{wxEnterpriseId})
    </insert>


    <select id="queryMaxBatchByChatActivityIdAndInviterMemberId" resultType="integer">
        select max(batch_number)
        from tab_haoban_group_chat_activity_invite_log
        where chat_activity_id = #{chatActivityId}
          and inviter_member_id = #{inviterMemberId}
          and invite_type = 1
          and delete_flag = 0
    </select>

    <select id="queryList" resultMap="TabHaobanGroupChatActivityInviteLogMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_group_chat_activity_invite_log
        where delete_flag = 0
        <if test="enterpriseId != null and enterpriseId != '' ">
            and enterprise_id = #{enterpriseId}
        </if>
        <if test="chatActivityId != null">
            and chat_activity_id = #{chatActivityId}
        </if>
        <if test="inviterMemberId != null and inviterMemberId != ''">
            and inviter_member_id = #{inviterMemberId}
        </if>
        <if test="inviteeMemberId != null and inviteeMemberId != ''">
            and invitee_member_id = #{inviteeMemberId}
        </if>
        <if test="batchNumber != null">
            and batch_number = #{batchNumber}
        </if>
        <if test="inviteType != null">
            and invite_type = #{inviteType}
        </if>
        <if test="addMemberType != null">
            and add_member_type = #{addMemberType}
        </if>
        <if test="beginTime != null">
            and create_time &gt; #{beginTime}
        </if>
        <if test="endTime != null">
            and create_time &lt; #{endTime}
        </if>
        <if test="sortFiled != null">
            order by  ${sortFiled}  ${sortType}
        </if>
    </select>
</mapper>
