<?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.material.basic.mapper.BmConfigMapper">
    <resultMap type="com.bonus.material.basic.domain.BmConfig" id="BmConfigResult">
        <result property="id"    column="id"    />
        <result property="itemName"    column="item_name"    />
        <result property="itemValue"    column="item_value"    />
        <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="selectBmConfigVo">
        select id, item_name, item_value, create_by, create_time, update_by, update_time from bm_config
    </sql>

    <select id="selectBmConfigList" parameterType="com.bonus.material.basic.domain.BmConfig" resultMap="BmConfigResult">
        <include refid="selectBmConfigVo"/>
        <where>  
            <if test="itemName != null  and itemName != ''"> and item_name like concat('%', #{itemName}, '%')</if>
            <if test="itemValue != null  and itemValue != ''"> and item_value = #{itemValue}</if>
        </where>
    </select>
    
    <select id="selectBmConfigById" parameterType="Long" resultMap="BmConfigResult">
        <include refid="selectBmConfigVo"/>
        where id = #{id}
    </select>

    <select id="selectBmConfigByItemName" parameterType="String" resultMap="BmConfigResult">
        <include refid="selectBmConfigVo"/>
        where item_name = #{itemName}
    </select>
        
    <insert id="insertBmConfig" parameterType="com.bonus.material.basic.domain.BmConfig" useGeneratedKeys="true" keyProperty="id">
        insert into bm_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="itemName != null">item_name,</if>
            <if test="itemValue != null">item_value,</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="itemName != null">#{itemName},</if>
            <if test="itemValue != null">#{itemValue},</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="updateBmConfig" parameterType="com.bonus.material.basic.domain.BmConfig">
        update bm_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="itemName != null">item_name = #{itemName},</if>
            <if test="itemValue != null">item_value = #{itemValue},</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="deleteBmConfigById" parameterType="Long">
        delete from bm_config where id = #{id}
    </delete>

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

    <delete id="deleteBmConfigByName" parameterType="String">
        delete from bm_config where item_name = #{itemName}
    </delete>
</mapper>