<?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.PcloudSubReplyDaoImpl">
    <resultMap id="BaseResultMap" type="com.pcloud.book.skill.entity.PcloudSubReply">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="pcloud_skill_id" property="pcloudSkillId" jdbcType="BIGINT"/>
        <result column="sub_type" property="subType" jdbcType="BIGINT"/>
        <result column="type" property="type" jdbcType="BIGINT"/>
        <result column="content" property="content" jdbcType="BIGINT"/>
        <result column="description" property="description" jdbcType="BIGINT"/>
        <result column="link_url" property="linkUrl" jdbcType="BIGINT"/>
        <result column="pic_url" property="picUrl" jdbcType="BIGINT"/>
        <result column="serve_id" property="serveId" jdbcType="BIGINT"/>
        <result column="serve_type" property="serveType" jdbcType="BIGINT"/>
        <result column="resource_id" property="resourceId" jdbcType="BIGINT"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="remind_interval_time" property="remindIntervalTime" jdbcType="INTEGER"/>
        <result column="sub_link_confirm" property="subLinkConfirm" jdbcType="INTEGER"/>
        <result column="sub_link_introduce" property="subLinkIntroduce" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id ,pcloud_skill_id ,sub_type ,type ,content ,description ,link_url ,pic_url ,serve_id ,serve_type ,resource_id ,create_time,remind_interval_time
        ,sub_link_confirm,sub_link_introduce
    </sql>

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

    <insert id="insert" parameterType="com.pcloud.book.skill.entity.PcloudSubReply" useGeneratedKeys="true" keyProperty="id">
        insert into pcloud_sub_reply
        <trim prefix="(" suffix=")" suffixOverrides=",">
            pcloud_skill_id ,
            sub_type ,
            type ,
            content ,
            description ,
            link_url ,
            pic_url ,
            serve_id ,
            serve_type ,
            resource_id ,
            create_time,
            remind_interval_time,
            sub_link_confirm,
            sub_link_introduce
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{pcloudSkillId,jdbcType=BIGINT},
            #{subType,jdbcType=INTEGER},
            #{type,jdbcType=INTEGER},
            #{content,jdbcType=VARCHAR},
            #{description,jdbcType=VARCHAR},
            #{linkUrl,jdbcType=VARCHAR},
            #{picUrl,jdbcType=VARCHAR},
            #{serveId,jdbcType=BIGINT},
            #{serveType,jdbcType=VARCHAR},
            #{resourceId,jdbcType=BIGINT},
            NOW(),
            #{remindIntervalTime},
            #{subLinkConfirm},
            #{subLinkIntroduce}
        </trim>
    </insert>
    <insert id="batchInsert"  parameterType="com.pcloud.book.skill.entity.PcloudSubReply" useGeneratedKeys="true" keyProperty="id">
        insert into pcloud_sub_reply (
        pcloud_skill_id ,
        sub_type ,
        type ,
        content ,
        description ,
        link_url ,
        pic_url ,
        serve_id ,
        serve_type ,
        resource_id ,
        create_time,
        remind_interval_time,
        sub_link_confirm,
        sub_link_introduce
        ) values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.pcloudSkillId,jdbcType=BIGINT},
            #{item.subType,jdbcType=INTEGER},
            #{item.type,jdbcType=INTEGER},
            #{item.content,jdbcType=VARCHAR},
            #{item.description,jdbcType=VARCHAR},
            #{item.linkUrl,jdbcType=VARCHAR},
            #{item.picUrl,jdbcType=VARCHAR},
            #{item.serveId,jdbcType=BIGINT},
            #{item.serveType,jdbcType=VARCHAR},
            #{item.resourceId,jdbcType=BIGINT},
            NOW(),
            #{item.remindIntervalTime,jdbcType=INTEGER},
            #{item.subLinkConfirm ,jdbcType=INTEGER},
            #{item.subLinkIntroduce,jdbcType=VARCHAR}
            )
        </foreach>
    </insert>

    <delete id="deleteByPcloudSkillId" parameterType="long">
        delete from pcloud_sub_reply
        where pcloud_skill_id=#{pcloudSkillId}
    </delete>

    <select id="getListByPcloudSkillId" parameterType="long" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from pcloud_sub_reply
        where pcloud_skill_id=#{pcloudSkillId}
    </select>

    <select id="getListByPcloudSkillIds" parameterType="map" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from pcloud_sub_reply
        where pcloud_skill_id in
        <foreach collection="pcloudSkillIds" item="item" open="(" separator="," close=")">
            ${item}
        </foreach>
    </select>

    <select id="getBySkillIdAndType" parameterType="map" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from pcloud_sub_reply
        where pcloud_skill_id=#{skillId} and sub_type = #{subType}
    </select>

    <select id="getResourceCountBySkillId" parameterType="integer" resultType="integer">
        select
        count(id)
        from pcloud_sub_reply
        where pcloud_skill_id = #{_parameter}
    </select>
</mapper>