<?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.ff.common.mapper.LangMapper">
    
    <resultMap type="Lang" id="LangResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="country"    column="country"    />
        <result property="langCode"    column="lang_code"    />
        <result property="langStatus"    column="lang_status"    />
        <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="selectLangVo">
        select id, name, country, lang_code, lang_status, create_by, create_time, update_by, update_time from ff_lang
    </sql>

    <select id="selectLangList" parameterType="Lang" resultMap="LangResult">
        <include refid="selectLangVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="country != null  and country != ''"> and country = #{country}</if>
            <if test="langCode != null  and langCode != ''"> and lang_code = #{langCode}</if>
            <if test="langStatus != null "> and lang_status = #{langStatus}</if>
        </where>
    </select>
    
    <select id="selectLangById" parameterType="Long" resultMap="LangResult">
        <include refid="selectLangVo"/>
        where id = #{id}
    </select>

    <insert id="insertLang" parameterType="Lang" useGeneratedKeys="true" keyProperty="id">
        insert into ff_lang
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="country != null">country,</if>
            <if test="langCode != null">lang_code,</if>
            <if test="langStatus != null">lang_status,</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="name != null">#{name},</if>
            <if test="country != null">#{country},</if>
            <if test="langCode != null">#{langCode},</if>
            <if test="langStatus != null">#{langStatus},</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="updateLang" parameterType="Lang">
        update ff_lang
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="country != null">country = #{country},</if>
            <if test="langCode != null">lang_code = #{langCode},</if>
            <if test="langStatus != null">lang_status = #{langStatus},</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="deleteLangById" parameterType="Long">
        delete from ff_lang where id = #{id}
    </delete>

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