<?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.amms.mapper.CarouselMapper">

    <resultMap type="com.amms.domain.Carousel" id="CarouselResult">
        <result property="id"    column="id"    />
        <result property="title"    column="title"    />
        <result property="imageUrl"    column="image_url"    />
        <result property="link"    column="link"    />
        <result property="sort"    column="sort"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectCarouselVo">
        select id, title, image_url, link, sort, status, create_time, update_time from carousel
    </sql>

    <select id="selectCarouselList" parameterType="com.amms.domain.Carousel" resultMap="CarouselResult">
        <include refid="selectCarouselVo"/>
        <where>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="imageUrl != null  and imageUrl != ''"> and image_url = #{imageUrl}</if>
            <if test="link != null  and link != ''"> and link = #{link}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>

    <select id="selectCarouselById" parameterType="Long" resultMap="CarouselResult">
        <include refid="selectCarouselVo"/>
        where id = #{id}
    </select>

    <insert id="insertCarousel" parameterType="com.amms.domain.Carousel" useGeneratedKeys="true" keyProperty="id">
        insert into carousel
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">title,</if>
            <if test="imageUrl != null and imageUrl != ''">image_url,</if>
            <if test="link != null">link,</if>
            <if test="sort != null">sort,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">#{title},</if>
            <if test="imageUrl != null and imageUrl != ''">#{imageUrl},</if>
            <if test="link != null">#{link},</if>
            <if test="sort != null">#{sort},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateCarousel" parameterType="com.amms.domain.Carousel">
        update carousel
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="imageUrl != null and imageUrl != ''">image_url = #{imageUrl},</if>
            <if test="link != null">link = #{link},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCarouselById" parameterType="Long">
        delete from carousel where id = #{id}
    </delete>
</mapper>
