<?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.PostItemMapper">
    <insert id="save" useGeneratedKeys="true" keyProperty="id">
        insert into vod_post_item
        (`album_id`,`post_id`,`pos`,`added_at`)
        values
        (#{albumId},#{postId},#{pos},#{addedAt})
    </insert>
    <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
        insert into vod_post_item
        (`album_id`,`post_id`,`pos`,`added_at`)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.albumId},#{item.postId},#{item.pos},#{item.addedAt})
        </foreach>
    </insert>

    <delete id="deleteByAlbumIdAndPostId">
        delete from vod_post_item
        where album_id=#{albumId} and post_id=#{postId}
    </delete>

    <select id="countByAlbumId" resultType="java.lang.Integer">
        select count(*)
        from vod_post_item
        where album_id=#{albumId}
    </select>
    <select id="findByAlbumIdByPage" resultType="cn.reghao.tnb.content.app.vod.model.po.PostItem">
        select *
        from vod_post_item
        where album_id=#{albumId}
    </select>
    <select id="findByImagePost" resultType="cn.reghao.tnb.content.app.vod.model.po.PostItem">
        select *
        from vod_post_item
        where album_id in
              (
                  select album_id
                  from vod_post_album
                  where post_type=1 and create_by=#{createBy}
              )
          and post_id=#{imageFileId}
    </select>
</mapper>
