<?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.GroupChatActivityMapper">
    <resultMap type="com.gic.haoban.manage.service.entity.chat.TabGroupChatActivity" id="TabHaobanGroupChatActivityMap">
        <result property="chatActivityId" column="chat_activity_id" jdbcType="INTEGER"/>
        <result property="activityName" column="activity_name" jdbcType="VARCHAR"/>
        <result property="startDate" column="start_date" jdbcType="TIMESTAMP"/>
        <result property="endDate" column="end_date" jdbcType="TIMESTAMP"/>
        <result property="limitDate" column="limit_date" jdbcType="TIMESTAMP"/>
        <result property="activityImg" column="activity_img" jdbcType="VARCHAR"/>
        <result property="activityInviteImg" column="activity_invite_img" jdbcType="VARCHAR"/>
        <result property="activityDesc" column="activity_desc" jdbcType="VARCHAR"/>
        <result property="activityShareTitle" column="activity_share_title" jdbcType="VARCHAR"/>
        <result property="activityShareImg" column="activity_share_img" jdbcType="VARCHAR"/>
        <result property="activityPosterImg" column="activity_poster_img" jdbcType="VARCHAR"/>
        <result property="status" column="status" jdbcType="INTEGER"/>
        <result property="inviteRewardType" column="invite_reward_type" jdbcType="INTEGER"/>
        <result property="joinType" column="join_type" jdbcType="INTEGER"/>
        <result property="joinRule" column="join_rule" jdbcType="VARCHAR"/>
        <result property="joinChatHmId" column="join_chat_hm_id" jdbcType="INTEGER"/>
        <result property="inviteType" column="invite_type" jdbcType="INTEGER"/>
        <result property="inviteMemberType" column="invite_member_type" jdbcType="INTEGER"/>
        <result property="labelFlag" column="label_flag" jdbcType="INTEGER"/>
        <result property="labelJson" column="label_json" jdbcType="VARCHAR"/>
        <result property="exceptionNotice" column="exception_notice" jdbcType="INTEGER"/>
        <result property="exceptionNoticeNum" column="exception_notice_num" 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="creatorId" column="creator_id" jdbcType="VARCHAR"/>
        <result property="creatorName" column="creator_name" jdbcType="VARCHAR"/>
        <result property="deleteFlag" column="delete_flag" jdbcType="INTEGER"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="TabHaobanGroupChatActivityMap">
        select *
        from tab_haoban_group_chat_activity
        where chat_activity_id = #{chatActivityId} and delete_flag = 0
    </select>

    <select id="queryByIds" resultMap="TabHaobanGroupChatActivityMap">
        select *
        from tab_haoban_group_chat_activity
        where delete_flag = 0 and chat_activity_id in
        <foreach collection="chatActivityIds" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
        order by create_time desc
    </select>

    <select id="queryByIdsDel" resultMap="TabHaobanGroupChatActivityMap">
        select *
        from tab_haoban_group_chat_activity
        where chat_activity_id in
        <foreach collection="chatActivityIds" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
        order by create_time desc
    </select>

    <select id="listActivity" resultMap="TabHaobanGroupChatActivityMap">
        select
        a.*
        from tab_haoban_group_chat_activity a
        where a.enterprise_id = #{enterpriseId} and a.delete_flag = 0
        <if test="search.search != null and search.search != ''">
            and (a.activity_name like concat('%',#{search.search},'%') or a.chat_activity_id = #{search.search})
        </if>
        <if test="search.wxEnterpriseId != null">
            and a.wx_enterprise_id = #{search.wxEnterpriseId}
        </if>
        <if test="search.status != null">
            and a.status = #{search.status}
        </if>
        <if test="search.joinType != null">
            and a.join_type = #{search.joinType}
        </if>
        <if test="search.inviteRewardType != null">
            and a.invite_reward_type = #{search.inviteRewardType}
        </if>
        <if test="search.beginDate != null">
            and a.create_time >= #{search.beginDate}
        </if>
        <if test="search.endDate != null">
            and a.create_time <![CDATA[<=]]> #{search.endDate}
        </if>
        <if test="search.creatorIdList != null and search.creatorIdList.size > 0 ">
            and a.creator_id in
            <foreach collection="search.creatorIdList" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        order by a.create_time desc,a.chat_activity_id desc
    </select>

    <select id="listActivityByDate" resultMap="TabHaobanGroupChatActivityMap">
        select
        a.*
        from tab_haoban_group_chat_activity a
        where a.delete_flag = 0
        <if test="enterpriseId != null and enterpriseId != ''">
            and enterprise_id = #{enterpriseId}
        </if>
        <if test="status != null">
            and status = #{status}
        </if>
        <if test="startDate != null">
            and start_date <![CDATA[<=]]> #{startDate}
        </if>
        <if test="endDate != null">
            and end_date <![CDATA[<=]]> #{endDate}
        </if>
        order by a.create_time desc,a.chat_activity_id desc
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from tab_haoban_group_chat_activity
        <where>
            <if test="chatActivityId != null">
                and chat_activity_id = #{chatActivityId}
            </if>
            <if test="activityName != null and activityName != ''">
                and activity_name = #{activityName}
            </if>
            <if test="startDate != null">
                and start_date = #{startDate}
            </if>
            <if test="endDate != null">
                and end_date = #{endDate}
            </if>
            <if test="limitDate != null">
                and limit_date = #{limitDate}
            </if>
            <if test="activityImg != null and activityImg != ''">
                and activity_img = #{activityImg}
            </if>
            <if test="activityInviteImg != null and activityInviteImg != ''">
                and activity_invite_img = #{activityInviteImg}
            </if>
            <if test="activityDesc != null and activityDesc != ''">
                and activity_desc = #{activityDesc}
            </if>
            <if test="activityShareTitle != null and activityShareTitle != ''">
                and activity_share_title = #{activityShareTitle}
            </if>
            <if test="activityShareImg != null and activityShareImg != ''">
                and activity_share_img = #{activityShareImg}
            </if>
            <if test="activityPosterImg != null and activityPosterImg != ''">
                and activity_poster_img = #{activityPosterImg}
            </if>
            <if test="status != null">
                and status = #{status}
            </if>
            <if test="inviteRewardType != null">
                and invite_reward_type = #{inviteRewardType}
            </if>
            <if test="joinType != null">
                and join_type = #{joinType}
            </if>
            <if test="joinRule != null and joinRule != ''">
                and join_rule = #{joinRule}
            </if>
            <if test="joinChatHmId != null">
                and join_chat_hm_id = #{joinChatHmId}
            </if>
            <if test="inviteType != null">
                and invite_type = #{inviteType}
            </if>
            <if test="inviteMemberType != null">
                and invite_member_type = #{inviteMemberType}
            </if>
            <if test="labelFlag != null">
                and label_flag = #{labelFlag}
            </if>
            <if test="labelJson != null and labelJson != ''">
                and label_json = #{labelJson}
            </if>
            <if test="exceptionNotice != null">
                and exception_notice = #{exceptionNotice}
            </if>
            <if test="exceptionNoticeNum != null">
                and exception_notice_num = #{exceptionNoticeNum}
            </if>
            <if test="enterpriseId != null and enterpriseId != ''">
                and enterprise_id = #{enterpriseId}
            </if>
            <if test="wxEnterpriseId != null and wxEnterpriseId != ''">
                and wx_enterprise_id = #{wxEnterpriseId}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="chatActivityId" useGeneratedKeys="true">
        insert into tab_haoban_group_chat_activity(
            chat_activity_id,
            activity_name,
            start_date,
            end_date,
            limit_date,
            activity_img,
            activity_invite_img,
            activity_desc,
            activity_share_title,
            activity_share_img,
            activity_poster_img,
            status,
            invite_reward_type,
            join_type,
            join_rule,
            join_chat_hm_id,
            invite_type,
            invite_member_type,
            label_flag,
            label_json,
            exception_notice,
            exception_notice_num,
            enterprise_id,
            wx_enterprise_id,
            creator_id,
            creator_name)
        values (
                    #{chatActivityId},
                   #{activityName},
                   #{startDate},
                   #{endDate},
                   #{limitDate},
                   #{activityImg},
                   #{activityInviteImg},
                   #{activityDesc},
                   #{activityShareTitle},
                   #{activityShareImg},
                   #{activityPosterImg},
                   #{status},
                   #{inviteRewardType},
                   #{joinType},
                   #{joinRule},
                   #{joinChatHmId},
                   #{inviteType},
                   #{inviteMemberType},
                   #{labelFlag},
                   #{labelJson},
                   #{exceptionNotice},
                   #{exceptionNoticeNum},
                   #{enterpriseId},
                   #{wxEnterpriseId},
                   #{creatorId},
                   #{creatorName})
    </insert>


    <!--通过主键修改数据-->
    <update id="update">
        update tab_haoban_group_chat_activity
        <set>
            <if test="activityName != null and activityName != ''">
                activity_name = #{activityName},
            </if>
            <if test="startDate != null">
                start_date = #{startDate},
            </if>
            <if test="endDate != null">
                end_date = #{endDate},
            </if>
            <if test="limitDate != null">
                limit_date = #{limitDate},
            </if>
            <if test="activityImg != null and activityImg != ''">
                activity_img = #{activityImg},
            </if>
            <if test="activityInviteImg != null and activityInviteImg != ''">
                activity_invite_img = #{activityInviteImg},
            </if>
            <if test="activityDesc != null and activityDesc != ''">
                activity_desc = #{activityDesc},
            </if>
            <if test="activityShareTitle != null and activityShareTitle != ''">
                activity_share_title = #{activityShareTitle},
            </if>
            <if test="activityShareImg != null and activityShareImg != ''">
                activity_share_img = #{activityShareImg},
            </if>
            <if test="activityPosterImg != null and activityPosterImg != ''">
                activity_poster_img = #{activityPosterImg},
            </if>
            <if test="status != null">
                status = #{status},
            </if>
            <if test="inviteRewardType != null">
                invite_reward_type = #{inviteRewardType},
            </if>
            <if test="joinType != null">
                join_type = #{joinType},
            </if>
            <if test="joinRule != null and joinRule != ''">
                join_rule = #{joinRule},
            </if>
            <if test="joinChatHmId != null">
                join_chat_hm_id = #{joinChatHmId},
            </if>
            <if test="inviteType != null">
                invite_type = #{inviteType},
            </if>
            <if test="inviteMemberType != null">
                invite_member_type = #{inviteMemberType},
            </if>
            <if test="labelFlag != null">
                label_flag = #{labelFlag},
            </if>
            <if test="labelJson != null and labelJson != ''">
                label_json = #{labelJson},
            </if>
            <if test="exceptionNotice != null">
                exception_notice = #{exceptionNotice},
            </if>
            <if test="exceptionNoticeNum != null">
                exception_notice_num = #{exceptionNoticeNum},
            </if>
            <if test="enterpriseId != null and enterpriseId != ''">
                enterprise_id = #{enterpriseId},
            </if>
            <if test="wxEnterpriseId != null and wxEnterpriseId != ''">
                wx_enterprise_id = #{wxEnterpriseId},
            </if>
        </set>
        where chat_activity_id = #{chatActivityId}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        update tab_haoban_group_chat_activity set delete_flag = 1
        where enterprise_id = #{enterpriseId} and chat_activity_id = #{chatActivityId} and delete_flag = 0
    </delete>
</mapper>

