<?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.skill.dao.impl.PcloudSubRemindDaoImpl">
    <resultMap id="BaseResultMap" type="com.pcloud.book.skill.entity.PcloudSubRemind">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="wx_user_id" property="wxUserId" jdbcType="VARCHAR"/>
        <result column="robot_wx_id" property="robotWxId" jdbcType="VARCHAR"/>
        <result column="skill_type" property="skillType" jdbcType="TINYINT"/>
        <result column="rel_skill_id" property="relSkillId" jdbcType="BIGINT"/>
        <result column="subscribe_state" property="subscribeState" jdbcType="TINYINT"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="skill_id" property="skillId" jdbcType="INTEGER"/>
    </resultMap>
    <sql id="Base_Column_List">
        id, wx_user_id, robot_wx_id, skill_type, rel_skill_id, subscribe_state, create_time,update_time,skill_id
    </sql>




    <insert id="insert" parameterType="com.pcloud.book.skill.entity.PcloudSubRemind" useGeneratedKeys="true"
            keyProperty="id">
        insert into pcloud_sub_remind
        <trim prefix="(" suffix=")" suffixOverrides=",">
            wx_user_id, robot_wx_id, skill_type, rel_skill_id, subscribe_state, create_time,update_time,skill_id
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{wxUserId},
            #{robotWxId},
            #{skillType},
            #{relSkillId},
            #{subscribeState},
            now(),
            NOW(),
            #{skillId}
        </trim>
    </insert>

    <select id="updateSubState" parameterType="map">
        update pcloud_sub_remind
        set
        subscribe_state=1,
        update_time=now()
        where
        wx_user_id=#{wxUserId}
        and rel_skill_id=#{relSkillId}
        and skill_type=#{skillType}
        <if test="skillId !=null">
            and skill_id=#{skillId}
        </if>
    </select>

    <select id="getUnSubRecord" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from pcloud_sub_remind
        where subscribe_state=0
    </select>

    <select id="getByMap" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from pcloud_sub_remind
        where
        wx_user_id=#{wxUserId}
        and rel_skill_id=#{relSkillId}
        and skill_type=#{skillType}
        <if test="skillId !=null">
            and skill_id=#{skillId}
        </if>
        limit 1
    </select>
</mapper>