<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd" >
<mapper namespace="com.pcloud.book.rightsSetting.dao.impl.RightsNowPicDaoImpl">

    <resultMap  id="BaseResultMap" type="com.pcloud.book.rightsSetting.entity.RightsNowPic">
        <id property="id" column="id" jdbcType="BIGINT"/>
        <result property="picUrl" column="pic_url" jdbcType="VARCHAR"/>
        <result property="defaultPic" column="default_pic" jdbcType="BOOLEAN"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="type" column="type" jdbcType="INTEGER"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, pic_url, default_pic, create_time, type
    </sql>

    <select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List"/>
        from rights_now_pic
        where id = #{id,jdbcType=BIGINT}
    </select>

    <delete id="deleteById" parameterType="long">
        delete from rights_now_pic
        where id = #{id,jdbcType=BIGINT}
    </delete>

    <insert id="insert" parameterType="com.pcloud.book.rightsSetting.entity.RightsNowPic" useGeneratedKeys="true" keyProperty="id">
        insert into rights_now_pic
        <trim prefix="(" suffix=")" suffixOverrides=",">
            pic_url, default_pic, create_time, type
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{picUrl,jdbcType=VARCHAR},
            #{defaultPic,jdbcType=BOOLEAN},
            NOW(),
            #{type}
        </trim>
    </insert>

    <insert id="batchInsert"  parameterType="com.pcloud.book.rightsSetting.entity.RightsNowPic" useGeneratedKeys="true" keyProperty="id">
        insert into rights_now_pic (
        pic_url, default_pic, create_time, type
        ) values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.picUrl,jdbcType=VARCHAR},
            #{item.defaultPic,jdbcType=BOOLEAN},
            NOW(),
            #{type}
            )
        </foreach>
    </insert>

    <select id="getAllDefaultRightsNowPics" resultMap="BaseResultMap" parameterType="map">
        select <include refid="Base_Column_List"/>
        from rights_now_pic
        where default_pic=1
        <if test="type != null">
            and type = #{type}
        </if>
    </select>

    <select id="getRightsNowPics" parameterType="map" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from rights_now_pic
        where default_pic=0
        <if test="type != null">
            and type = #{type}
        </if>
        order by create_time desc
    </select>

</mapper>