<?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.pcloudkeyword.dao.impl.PcloudClassifyTemplateDaoImpl" >
  <resultMap id="BaseResultMap" type="PcloudClassifyTemplate" >
      <id column="id" jdbcType="BIGINT" property="id" />
      <result column="classify_id" jdbcType="INTEGER" property="classifyId" />
      <result column="template_code" jdbcType="VARCHAR" property="templateCode" />
      <result column="audio_file_url" jdbcType="VARCHAR" property="audioFileUrl" />
      <result column="audio_file_size" jdbcType="BIGINT" property="audioFileSize" />
      <result column="is_open" jdbcType="BIT" property="isOpen" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, classify_id, template_code, audio_file_url, audio_file_size, is_open
  </sql>

    <insert id="insert" parameterType="PcloudClassifyTemplate"  useGeneratedKeys="true" keyProperty="id">
        insert into pcloud_classify_template (classify_id, template_code, audio_file_url,
        audio_file_size, is_open)
        values (#{classifyId,jdbcType=INTEGER}, #{templateCode,jdbcType=VARCHAR}, #{audioFileUrl,jdbcType=VARCHAR},
        #{audioFileSize,jdbcType=BIGINT}, 1)
    </insert>

    <select id="getById" parameterType="long" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from pcloud_classify_template
        where id = #{id}
    </select>

    <select id="getTemplateByClassifyId" parameterType="int" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from pcloud_classify_template
        where classify_id = #{classifyId}
        and is_open = 1
        limit 1
    </select>

    <select id="listClassifyTemplate" parameterType="map" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from pcloud_classify_template
        where 1 = 1
        <if test="classifyId != null">
            and classify_id = #{classifyId}
        </if>

    </select>

    <update id="updateOpenStateByClassifyId" parameterType="PcloudClassifyTemplate">
        update pcloud_classify_template
        set
        is_open = #{isOpen}
        where classify_id = #{classifyId}
    </update>

    <update id="updateOpenStateById" parameterType="PcloudClassifyTemplate">
        update pcloud_classify_template
        set
        is_open = #{isOpen}
        where classify_id = #{classifyId}
        and id = #{id}
    </update>

    <update id="update" parameterType="PcloudClassifyTemplate">
        update pcloud_classify_template
        <set>
            <if test="classifyId != null">
                classify_id = #{classifyId,jdbcType=INTEGER},
            </if>
            <if test="templateCode != null">
                template_code = #{templateCode,jdbcType=VARCHAR},
            </if>
            <if test="audioFileUrl != null">
                audio_file_url = #{audioFileUrl,jdbcType=VARCHAR},
            </if>
            <if test="audioFileSize != null">
                audio_file_size = #{audioFileSize,jdbcType=BIGINT},
            </if>
            <if test="isOpen != null">
                is_open = #{isOpen,jdbcType=TINYINT},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>

</mapper>