<?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.ImageFileMapper">
    <insert id="save" useGeneratedKeys="true" keyProperty="id">
        insert into image_file
        (`album_id`,`channel_code`,`image_file_id`,`object_id`,`format`,`url`,`width`,`height`,`horizontal`)
        values 
        (#{albumId},#{channelCode},#{imageFileId},#{objectId},#{format},#{url},#{width},#{height},#{horizontal})
    </insert>
    <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
        insert into image_file
        (`album_id`,`channel_code`,`image_file_id`,`object_id`,`format`,`url`,`width`,`height`,`horizontal`)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.albumId},#{item.channelCode},#{item.imageFileId},#{item.objectId},#{item.format},#{item.url},#{item.width},#{item.height},#{item.horizontal})
        </foreach>
    </insert>

    <select id="countByAlbumId" resultType="java.lang.Integer">
        select count(*)
        from image_file
        where album_id=#{albumId}
        group by image_file_id
    </select>
    <select id="findByUrl" resultType="cn.reghao.tnb.content.app.data.model.po.ImageFile">
        select *
        from image_file
        where url=#{url}
    </select>
    <select id="findImageFileIdsByPage" resultType="java.lang.String">
        select image_file_id
        from image_file
        where album_id=#{albumId}
        group by image_file_id
    </select>
    <select id="findByImageFileIds" resultType="cn.reghao.tnb.content.app.data.model.po.ImageFile">
        select *
        from image_file
        where image_file_id in
        <foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </select>
</mapper>
