<?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.GroupChatActivityRewardMapper">
    <resultMap type="com.gic.haoban.manage.service.entity.chat.TabGroupChatActivityReward" id="TabHaobanGroupChatActivityRewardMap">
        <result property="chatActivityRewardId" column="chat_activity_reward_id" jdbcType="INTEGER"/>
        <result property="chatActivityId" column="chat_activity_id" jdbcType="INTEGER"/>
        <result property="inviteNumber" column="invite_number" jdbcType="INTEGER"/>
        <result property="inviteLevel" column="invite_level" jdbcType="INTEGER"/>
        <result property="rewardInvite" column="reward_invite" jdbcType="INTEGER"/>
        <result property="rewardType" column="reward_type" jdbcType="INTEGER"/>
        <result property="limitReward" column="limit_reward" jdbcType="INTEGER"/>
        <result property="rewardValue" column="reward_value" jdbcType="VARCHAR"/>
        <result property="rewardName" column="reward_name" jdbcType="VARCHAR"/>
        <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>

    <!--查询单个-->
    <select id="queryById" resultMap="TabHaobanGroupChatActivityRewardMap">
        select chat_activity_reward_id, chat_activity_id, invite_number, invite_level, reward_invite, reward_type, limit_reward, reward_value, reward_name, enterprise_id, wx_enterprise_id, create_time, update_time, delete_flag
        from tab_haoban_group_chat_activity_reward
        where chat_activity_reward_id = #{chatActivityRewardId}
    </select>

    <select id="queryByChatActivityIds" resultMap="TabHaobanGroupChatActivityRewardMap">
        select chat_activity_reward_id, chat_activity_id, invite_number, invite_level, reward_invite, reward_type, limit_reward, reward_value, reward_name, enterprise_id, wx_enterprise_id, create_time, update_time, delete_flag
        from tab_haoban_group_chat_activity_reward
        where delete_flag = 0 and chat_activity_id in
      <foreach collection="chatActivityIds" open="(" close=")" separator="," item="item">
          #{item}
      </foreach>
        order by reward_invite asc,invite_level asc,reward_type asc
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="TabHaobanGroupChatActivityRewardMap">
        select
        chat_activity_reward_id, chat_activity_id, invite_number, invite_level, reward_invite, reward_type, limit_reward, reward_value, reward_name, enterprise_id, wx_enterprise_id, create_time, update_time, delete_flag
        from tab_haoban_group_chat_activity_reward
        <where>
            <if test="chatActivityRewardId != null">
                and chat_activity_reward_id = #{chatActivityRewardId}
            </if>
            <if test="chatActivityId != null">
                and chat_activity_id = #{chatActivityId}
            </if>
            <if test="inviteNumber != null">
                and invite_number = #{inviteNumber}
            </if>
            <if test="inviteLevel != null">
                and invite_level = #{inviteLevel}
            </if>
            <if test="rewardInvite != null">
                and reward_invite = #{rewardInvite}
            </if>
            <if test="rewardType != null">
                and reward_type = #{rewardType}
            </if>
            <if test="limitReward != null">
                and limit_reward = #{limitReward}
            </if>
            <if test="rewardValue != null and rewardValue != ''">
                and reward_value = #{rewardValue}
            </if>
            <if test="rewardName != null and rewardName != ''">
                and reward_name = #{rewardName}
            </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>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from tab_haoban_group_chat_activity_reward
        <where>
            <if test="chatActivityRewardId != null">
                and chat_activity_reward_id = #{chatActivityRewardId}
            </if>
            <if test="chatActivityId != null">
                and chat_activity_id = #{chatActivityId}
            </if>
            <if test="inviteNumber != null">
                and invite_number = #{inviteNumber}
            </if>
            <if test="inviteLevel != null">
                and invite_level = #{inviteLevel}
            </if>
            <if test="rewardInvite != null">
                and reward_invite = #{rewardInvite}
            </if>
            <if test="rewardType != null">
                and reward_type = #{rewardType}
            </if>
            <if test="limitReward != null">
                and limit_reward = #{limitReward}
            </if>
            <if test="rewardValue != null and rewardValue != ''">
                and reward_value = #{rewardValue}
            </if>
            <if test="rewardName != null and rewardName != ''">
                and reward_name = #{rewardName}
            </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="chatActivityRewardId" useGeneratedKeys="true">
        insert into tab_haoban_group_chat_activity_reward(chat_activity_reward_id,chat_activity_id, invite_number, invite_level, reward_invite, reward_type, limit_reward, reward_value, reward_name, enterprise_id, wx_enterprise_id)
        values (#{chatActivityRewardId},#{chatActivityId}, #{inviteNumber}, #{inviteLevel}, #{rewardInvite}, #{rewardType}, #{limitReward}, #{rewardValue}, #{rewardName}, #{enterpriseId}, #{wxEnterpriseId})
    </insert>


    <!--通过主键修改数据-->
    <update id="update">
        update tab_haoban_group_chat_activity_reward
        <set>
            <if test="chatActivityId != null">
                chat_activity_id = #{chatActivityId},
            </if>
            <if test="inviteNumber != null">
                invite_number = #{inviteNumber},
            </if>
            <if test="inviteLevel != null">
                invite_level = #{inviteLevel},
            </if>
            <if test="rewardInvite != null">
                reward_invite = #{rewardInvite},
            </if>
            <if test="rewardType != null">
                reward_type = #{rewardType},
            </if>
            <if test="limitReward != null">
                limit_reward = #{limitReward},
            </if>
            <if test="rewardValue != null and rewardValue != ''">
                reward_value = #{rewardValue},
            </if>
            <if test="rewardName != null and rewardName != ''">
                reward_name = #{rewardName},
            </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_reward_id = #{chatActivityRewardId}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        update tab_haoban_group_chat_activity_reward set delete_flag = 1
        where chat_activity_reward_id = #{chatActivityRewardId}
    </delete>
</mapper>

