<?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.backendsys.modules.cms.banner.dao.BannerI18nDao">

    <!-- 批量插入 -->
    <insert id="insertBatch" parameterType="java.util.List">
        INSERT INTO cms_banner_i18n (
            banner_id, language, title, link, image, image_thumb
        )
        VALUES
        <foreach collection="translations" item="item" separator=",">
        (
            #{item.banner_id}, #{item.language}, #{item.title}, #{item.link}, #{item.image}, #{item.image_thumb}
        )
        </foreach>
    </insert>

    <!-- 批量更新 -->
    <update id="updateBatch" parameterType="com.backendsys.modules.cms.banner.entity.BannerI18n">
        <foreach collection="translations" item="item" separator=";">
            UPDATE cms_banner_i18n
            <set>
                <trim suffixOverrides="," suffix=" ">
                    title = #{item.title},
                    <if test="item.link != null and item.link != ''">
                        link = #{item.link},
                    </if>
                    <if test="item.image != null and item.image != ''">
                        image = #{item.image},
                    </if>
                    <if test="item.image_thumb != null and item.image_thumb != ''">
                        image_thumb = #{item.image_thumb},
                    </if>
                </trim>
            </set>
            WHERE banner_id = #{item.banner_id} AND language = #{item.language}
        </foreach>
    </update>

</mapper>
