<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd" >
<mapper namespace="com.pcloud.book.push.dao.impl.PushGroupRecordDaoImpl">
    <resultMap id="BaseResultMap" type="com.pcloud.book.push.entity.PushGroupRecord">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="push_record_id" property="pushRecordId" jdbcType="BIGINT"/>
        <result column="push_id" property="pushId" jdbcType="BIGINT"/>
        <result column="classify_id" property="classifyId" jdbcType="BIGINT"/>
        <result column="book_id" property="bookId" jdbcType="BIGINT"/>
        <result column="book_group_qrcode_id" property="bookGroupQrcodeId" jdbcType="BIGINT"/>
        <result column="push_status" property="pushStatus" jdbcType="BIGINT"/>
        <result column="is_delete" property="isDelete" jdbcType="BOOLEAN"/>
        <result column="create_user" property="createUser" jdbcType="BIGINT"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_user" property="updateUser" jdbcType="BIGINT"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, push_record_id, push_id, classify_id, book_id, book_group_qrcode_id, push_status, is_delete, create_user, create_time, update_user, update_time
    </sql>

    <select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List"/>
        from push_group_record
        where id = #{id,jdbcType=BIGINT}
    </select>

    <delete id="deleteById" parameterType="java.lang.Long">
        update push_group_record set is_delete = 1
        where id = #{id,jdbcType=BIGINT} and is_delete = 0
    </delete>

    <insert id="insert" parameterType="com.pcloud.book.push.entity.PushGroupRecord" useGeneratedKeys="true" keyProperty="id">
        insert into push_group_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            push_record_id,
            push_id,
            classify_id,
            book_id,
            book_group_qrcode_id,
            push_status,
            is_delete,
            create_user,
            create_time,
            update_user,
            update_time,
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{pushRecordId,jdbcType=BIGINT},
            #{pushId,jdbcType=BIGINT},
            #{classifyId,jdbcType=BIGINT},
            #{bookId,jdbcType=BIGINT},
            #{bookGroupQrcodeId,jdbcType=BIGINT},
            #{pushStatus,jdbcType=BIGINT},
            0,
            #{createUser,jdbcType=BIGINT},
            NOW(),
            #{updateUser,jdbcType=BIGINT},
            NOW(),
        </trim>
    </insert>

    <update id="update" parameterType="com.pcloud.book.push.entity.PushGroupRecord">
        update push_group_record
        <set>
            <if test="pushRecordId != null">
                push_record_id = #{pushRecordId,jdbcType=BIGINT},
            </if>
            <if test="pushId != null">
                push_id = #{pushId,jdbcType=BIGINT},
            </if>
            <if test="classifyId != null">
                classify_id = #{classifyId,jdbcType=BIGINT},
            </if>
            <if test="bookId != null">
                book_id = #{bookId,jdbcType=BIGINT},
            </if>
            <if test="bookGroupQrcodeId != null">
                book_group_qrcode_id = #{bookGroupQrcodeId,jdbcType=BIGINT},
            </if>
            <if test="pushStatus != null">
                push_status = #{pushStatus,jdbcType=BIGINT},
            </if>
            <if test="isDelete != null">
                is_delete = #{isDelete,jdbcType=BOOLEAN},
            </if>
            <if test="updateUser != null">
                update_user = #{updateUser,jdbcType=BIGINT},
            </if>
                update_time = NOW(),
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>

    <!--批量插入-->
    <insert id="batchInsert"  parameterType="com.pcloud.book.push.entity.PushGroupRecord" useGeneratedKeys="true" keyProperty="id">
        insert into push_group_record (
            push_record_id,
            push_id,
            classify_id,
            book_id,
            book_group_qrcode_id,
            push_status,
            is_delete,
            create_user,
            create_time,
            update_user,
            update_time
        ) values
        <foreach collection="list" item="item" index="index" separator=",">
         (
            #{item.pushRecordId,jdbcType=BIGINT},
            #{item.pushId,jdbcType=BIGINT},
            #{item.classifyId,jdbcType=BIGINT},
            #{item.bookId,jdbcType=BIGINT},
            #{item.bookGroupQrcodeId,jdbcType=BIGINT},
            #{item.pushStatus,jdbcType=BIGINT},
            0,
            #{item.createUser,jdbcType=BIGINT},
            NOW(),
            #{item.updateUser,jdbcType=BIGINT},
            NOW()
         )
        </foreach>
    </insert>

    <!--更新记录状态-->
    <update id="updateStateById" parameterType="map" >
        update push_group_record set
        push_status = #{pushStatus}
        where id=#{pushGroupRecordId}
    </update>

    <!--获取记录集合-->
    <select id="getListByPushRecordId" parameterType="Long" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/> from push_group_record
        where push_record_id=#{pushRecordId}
    </select>

    <!--根据记录id更新记录状态-->
    <update id="updateStateByPushRecordId" parameterType="map">
        update push_group_record set
        push_status = #{pushStatus}
        where push_record_id=#{pushRecordId}
    </update>
</mapper>