<?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.android.mapper.BaseSettingMapper">

    <resultMap type="com.bonus.canteen.core.android.domain.CarouselImage" id="CarouselImageResult">
        <result property="id"    column="id"    />
        <result property="imageName"    column="image_name"    />
        <result property="externalUrl"    column="external_url"    />
        <result property="imageUrl"    column="image_url"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isEnabled"    column="is_enabled"    />
    </resultMap>

    <insert id="addBaseSetting" parameterType="com.bonus.canteen.core.android.domain.BaseSetting">
        replace into acc_base_setting(`key`,`value`)
        values (#{key},#{value})
    </insert>

    <update id="updateBaseSettingByKey" parameterType="com.bonus.canteen.core.android.domain.BaseSetting">
        update acc_base_setting set `value`=#{value} where `key`=#{key}
    </update>

    <delete id="deleteBaseSettingByKey" parameterType="com.bonus.canteen.core.android.domain.BaseSetting">
        delete from acc_base_setting where `key`= #{key}
    </delete>

    <select id="getBaseSettingByKey" parameterType="com.bonus.canteen.core.android.domain.BaseSetting" resultType="com.bonus.canteen.core.android.domain.BaseSetting">
        select * from acc_base_setting where `key`=#{key}
    </select>


    <insert id="addCarouseImage" parameterType="com.bonus.canteen.core.android.domain.CarouselImage">
        insert into acc_carousel_image(`image_name`,`external_url`,`image_url`)
        values (#{imageName},#{externalUrl},#{imageUrl})
    </insert>

    <select id="getCarouselImage" parameterType="com.bonus.canteen.core.android.domain.CarouselImage" resultMap="CarouselImageResult">
        select * from acc_carousel_image
        <where>
            <if test="imageName != null and imageName !='' ">
                and image_name like concat('%', #{imageName}, '%')
            </if>
            <if test="externalUrl != null and externalUrl !='' ">
                and external_url like concat('%', #{externalUrl}, '%')
            </if>
            <if test="imageUrl != null and imageUrl !='' ">
                and image_url like concat('%', #{imageUrl}, '%')
            </if>
            <if test="isEnabled !=null and isEnabled !=''">
                and is_enabled =  #{isEnabled}
            </if>
        </where>
    </select>

    <update id="updateCarouseImageById" parameterType="com.bonus.canteen.core.android.domain.CarouselImage">
         update acc_carousel_image
            <set>
                <if test="imageName != null and imageName !=''">
                    image_name=#{imageName},
                </if>

                <if test="externalUrl != null and externalUrl !=''">
                    external_url=#{externalUrl},
                </if>

                <if test="imageUrl != null and imageUrl !=''">
                    image_url=#{imageUrl},
                </if>

                <if  test="isEnabled != null and isEnabled !=''">
                    is_enabled = #{isEnabled}
                </if>

            </set>
        where id=#{id}
    </update>

    <delete id="delCarouseImageById" parameterType="com.bonus.canteen.core.android.domain.CarouselImage">
        delete from acc_carousel_image where id=#{id}
    </delete>

</mapper>
