<?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.ma.mapper.LabelBindMapper">
    <resultMap type="com.bonus.material.ma.domain.LabelBind" id="LabelBindResult">
        <result property="id"    column="id"    />
        <result property="maId"    column="ma_id"    />
        <result property="labelCode"    column="label_code"    />
        <result property="typeId"    column="type_id"    />
        <result property="bindTime"    column="bind_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="binder"    column="binder"    />
        <result property="status"    column="status"    />
        <result property="labelType"    column="label_type"    />
        <result property="companyId"    column="company_id"    />
    </resultMap>

    <sql id="selectLabelBindVo">
        select id, ma_id, label_code, type_id, bind_time, create_time, update_time, binder, status, label_type, company_id from ma_label_bind
    </sql>

    <select id="selectLabelBindList" parameterType="com.bonus.material.ma.domain.LabelBind" resultMap="LabelBindResult">
        <include refid="selectLabelBindVo"/>
        <where>  
            <if test="maId != null "> and ma_id = #{maId}</if>
            <if test="labelCode != null  and labelCode != ''"> and label_code = #{labelCode}</if>
            <if test="typeId != null  and typeId != ''"> and type_id = #{typeId}</if>
            <if test="bindTime != null "> and bind_time = #{bindTime}</if>
            <if test="binder != null  and binder != ''"> and binder = #{binder}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="labelType != null "> and label_type = #{labelType}</if>
            <if test="companyId != null  and companyId != ''"> and company_id = #{companyId}</if>
        </where>
    </select>
    
    <select id="selectLabelBindById" parameterType="Long" resultMap="LabelBindResult">
        <include refid="selectLabelBindVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertLabelBind" parameterType="com.bonus.material.ma.domain.LabelBind" useGeneratedKeys="true" keyProperty="id">
        insert into ma_label_bind
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="maId != null">ma_id,</if>
            <if test="labelCode != null">label_code,</if>
            <if test="typeId != null">type_id,</if>
            <if test="bindTime != null">bind_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="binder != null">binder,</if>
            <if test="status != null">status,</if>
            <if test="labelType != null">label_type,</if>
            <if test="companyId != null">company_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="maId != null">#{maId},</if>
            <if test="labelCode != null">#{labelCode},</if>
            <if test="typeId != null">#{typeId},</if>
            <if test="bindTime != null">#{bindTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="binder != null">#{binder},</if>
            <if test="status != null">#{status},</if>
            <if test="labelType != null">#{labelType},</if>
            <if test="companyId != null">#{companyId},</if>
         </trim>
    </insert>

    <update id="updateLabelBind" parameterType="com.bonus.material.ma.domain.LabelBind">
        update ma_label_bind
        <trim prefix="SET" suffixOverrides=",">
            <if test="maId != null">ma_id = #{maId},</if>
            <if test="labelCode != null">label_code = #{labelCode},</if>
            <if test="typeId != null">type_id = #{typeId},</if>
            <if test="bindTime != null">bind_time = #{bindTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="binder != null">binder = #{binder},</if>
            <if test="status != null">status = #{status},</if>
            <if test="labelType != null">label_type = #{labelType},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteLabelBindById" parameterType="Long">
        delete from ma_label_bind where id = #{id}
    </delete>

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