<?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.vod.db.mapper.PostAlbumMapper">
    <insert id="save" useGeneratedKeys="true" keyProperty="id">
        insert into vod_post_album
        (`album_id`,`album_name`,`cover_url`,`post_type`,`total`,`scope`,`create_by`)
        values
        (#{albumId},#{albumName},#{coverUrl},#{postType},#{total},#{scope},#{createBy})
    </insert>

    <update id="updateAlbumCover">
        update vod_post_album
        set cover_url=#{coverUrl}
        where album_id=#{albumId}
    </update>

    <select id="countByCriteria" resultType="java.lang.Integer">
        select count(*)
        from vod_post_album
        <where>
            deleted=0
            <if test="scope != null">
                and scope in
                <foreach collection="scope" item="id" index="index" open="(" close=")" separator=",">
                    #{id}
                </foreach>
            </if>
            <if test="postType != null">
                and post_type=#{postType}
            </if>
            <if test="createBy != null">
                and create_by=#{createBy}
            </if>
        </where>
    </select>
    <select id="findAlbumByPage" resultType="cn.reghao.tnb.content.app.vod.model.po.PostAlbum">
        select *
        from vod_post_album
        <where>
            deleted=0
            <if test="albumQuery.scope != null">
                and scope in
                <foreach collection="albumQuery.scope" item="item" index="index" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="albumQuery.postType != null">
                and post_type=#{albumQuery.postType}
            </if>
            <if test="albumQuery.createBy != null">
                and create_by=#{albumQuery.createBy}
            </if>
            <if test="albumQuery.albumId != null">
                and album_id=#{albumQuery.albumId}
            </if>
        </where>
        order by create_time desc
    </select>
</mapper>