<?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.applet.mapper.AppletThirdResourcesPicMapper">

    <resultMap type="com.pcloud.book.applet.entity.AppletThirdResourcesPic" id="AppletThirdResourcesPicMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="thirdResourcesId" column="third_resources_id" jdbcType="INTEGER"/>
        <result property="picUrl" column="pic_url" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into book.applet_third_resources_pic(third_resources_id, pic_url, create_time)
        values (#{thirdResourcesId}, #{picUrl}, #{createTime})
    </insert>

    <insert id="batchInsert" parameterType="list">
        insert into book.applet_third_resources_pic(third_resources_id, pic_url, create_time)
        VALUES
        <foreach collection="list" separator="," item="item">
            (#{item.thirdResourcesId}, #{item.picUrl}, now())
        </foreach>
    </insert>

    <!--通过主键删除-->
    <delete id="deleteByThirdResourcesId">
        delete from book.applet_third_resources_pic where third_resources_id = #{thirdResourcesId}
    </delete>

    <select id="getPicList" parameterType="long" resultType="string">
        SELECT pic_url FROM
        book.applet_third_resources_pic
        WHERE third_resources_id = #{thirdResourcesId}
    </select>

    <select id="getPicListByResourceIds" parameterType="list" resultMap="AppletThirdResourcesPicMap">
        SELECT id, third_resources_id, pic_url FROM
        book.applet_third_resources_pic
        WHERE third_resources_id IN
        <foreach collection="list" item="item" separator="," open="(" close=")" index="index">
            #{item}
        </foreach>
    </select>

</mapper>