<?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.pcloud.book.applet.dao.impl.AppletSubscribeRecordDaoImpl">

    <resultMap id="BaseResultMap" type="com.pcloud.book.applet.entity.AppletSubscribeRecord">
        <id column="id" property="id" jdbcType="OTHER"/>
        <result column="wechat_user_id" property="wechatUserId" jdbcType="OTHER"/>
        <result column="record_type" property="recordType" jdbcType="OTHER"/>
        <result column="count_type" property="countType" jdbcType="OTHER"/>
        <result column="create_time" property="createTime" jdbcType="OTHER"/>
        <result column="update_time" property="updateTime" jdbcType="OTHER"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, wechat_user_id, record_type, count_type, create_time, update_time
    </sql>

    <select id="getById" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM applet_subscribe_record
        WHERE id = #{id}
    </select>

    <select id="getList" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM applet_subscribe_record
    </select>

    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        INSERT INTO applet_subscribe_record(
            wechat_user_id, 
            record_type, 
            count_type,
            create_time,
            update_time
        ) VALUES (
            #{wechatUserId, jdbcType=OTHER}, 
            #{recordType, jdbcType=OTHER}, 
            #{countType, jdbcType=OTHER},
           now(),
           now()
        )
    </insert>

    <insert id="batchInsert">
        INSERT INTO applet_subscribe_record (
        wechat_user_id,
        record_type,
        count_type,
        create_time,
        update_time
        ) VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.wechatUserId, jdbcType=OTHER},
            #{item.recordType, jdbcType=OTHER},
            #{item.countType, jdbcType=OTHER},
            #{item.createTime, jdbcType=OTHER},
            #{item.updateTime, jdbcType=OTHER}
            )
        </foreach>
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        UPDATE applet_subscribe_record
        <set>
            <if test="wechatUserId != null">
                wechat_user_id = #{wechatUserId},
            </if>
            <if test="recordType != null">
                record_type = #{recordType},
            </if>
            <if test="countType != null">
                count_type = #{countType},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
        </set>
        WHERE id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        DELETE FROM applet_subscribe_record where id = #{id}
    </delete>

    <!--通过主键软删除-->
    <delete id="softDeleteById">
        update applet_subscribe_record set is_delete  = 1, update_time = now() where id = #{id}
    </delete>


</mapper>