<?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="cn.reghao.tnb.content.app.data.db.mapper.AudioPostMapper">
    <insert id="save" useGeneratedKeys="true" keyProperty="id">
        insert into audio_post
        (`audio_id`,`audio_file_id`,`audio_url`,`title`,`duration`,`codec`,`scope`,`publish_at`,`publish_by`)
        values 
        (#{audioId},#{audioFileId},#{audioUrl},#{title},#{duration},#{codec},#{scope},#{publishAt},#{publishBy})
    </insert>

    <update id="updateAudioScope">
        update audio_post
        set scope=#{scope}
        where audio_id=#{audioId}
    </update>

    <select id="countByUserId" resultType="java.lang.Integer">
        select count(*)
        from audio_post
        where publish_by=${userId}
    </select>
    <select id="findAudioCardByUserIdAndByPage" resultType="cn.reghao.tnb.content.app.data.model.vo.UserAudioCard">
        select audio_id,title,audio_url,duration,codec,publish_at,scope
        from audio_post
        where publish_by=#{userId}
        order by publish_at desc
    </select>
    <select id="findAudioInfo" resultType="cn.reghao.tnb.content.app.data.model.vo.UserAudioCard">
        select audio_id,title,audio_url,duration,codec,publish_at,scope
        from audio_post
        where audio_id=#{audioId}
    </select>
    <select id="findByAudioId" resultType="cn.reghao.tnb.content.app.data.model.po.AudioPost">
        select *
        from audio_post
        where audio_id=#{audioId}
    </select>
</mapper>
