<?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.bonus.canteen.core.basic.mapper.BasicCarouselImageMapper">
    <resultMap type="com.bonus.canteen.core.basic.domain.BasicCarouselImage" id="BasicCarouselImageResult">
        <result property="id"    column="id"    />
        <result property="imgName"    column="img_name"    />
        <result property="imgUrl"    column="img_url"    />
        <result property="externalUrl"    column="external_url"    />
        <result property="ifEnabled"    column="if_enabled"    />
        <result property="usageType"    column="usage_type"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectBasicCarouselImageVo">
        select id, img_name, img_url, external_url, if_enabled, usage_type, create_by, create_time, update_by, update_time from basic_carousel_image
    </sql>

    <select id="selectBasicCarouselImageList" parameterType="com.bonus.canteen.core.basic.domain.BasicCarouselImage" resultMap="BasicCarouselImageResult">
        <include refid="selectBasicCarouselImageVo"/>
        <where>  
            <if test="imgName != null  and imgName != ''"> and img_name like concat('%', #{imgName}, '%')</if>
            <if test="imgUrl != null  and imgUrl != ''"> and img_url = #{imgUrl}</if>
            <if test="externalUrl != null  and externalUrl != ''"> and external_url = #{externalUrl}</if>
            <if test="ifEnabled != null  and ifEnabled != ''"> and if_enabled = #{ifEnabled}</if>
            <if test="usageType != null  and usageType != ''"> and usage_type = #{usageType}</if>
        </where>
    </select>
    
    <select id="selectBasicCarouselImageById" parameterType="Long" resultMap="BasicCarouselImageResult">
        <include refid="selectBasicCarouselImageVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertBasicCarouselImage" parameterType="com.bonus.canteen.core.basic.domain.BasicCarouselImage" useGeneratedKeys="true" keyProperty="id">
        insert into basic_carousel_image
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="imgName != null">img_name,</if>
            <if test="imgUrl != null">img_url,</if>
            <if test="externalUrl != null">external_url,</if>
            <if test="ifEnabled != null">if_enabled,</if>
            <if test="usageType != null">usage_type,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="imgName != null">#{imgName},</if>
            <if test="imgUrl != null">#{imgUrl},</if>
            <if test="externalUrl != null">#{externalUrl},</if>
            <if test="ifEnabled != null">#{ifEnabled},</if>
            <if test="usageType != null">#{usageType},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateBasicCarouselImage" parameterType="com.bonus.canteen.core.basic.domain.BasicCarouselImage">
        update basic_carousel_image
        <trim prefix="SET" suffixOverrides=",">
            <if test="imgName != null">img_name = #{imgName},</if>
            <if test="imgUrl != null">img_url = #{imgUrl},</if>
            <if test="externalUrl != null">external_url = #{externalUrl},</if>
            <if test="ifEnabled != null">if_enabled = #{ifEnabled},</if>
            <if test="usageType != null">usage_type = #{usageType},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBasicCarouselImageById" parameterType="Long">
        delete from basic_carousel_image where id = #{id}
    </delete>

    <delete id="deleteBasicCarouselImageByIds" parameterType="String">
        delete from basic_carousel_image where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>