<?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.zehong.system.mapper.shelf.TRackMaterialRelationMapper">
    
    <resultMap type="TRackMaterialRelation" id="TRackMaterialRelationResult">
        <result property="relationId"    column="relation_id"    />
        <result property="rackCode"    column="rack_code"    />
        <result property="materialCode"    column="material_code"    />
        <result property="materialName"    column="material_name"    />
        <result property="materialSpecifications"    column="material_specifications"    />
        <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="selectTRackMaterialRelationVo">
        select relation_id, rack_code, material_code, material_name, material_specifications, create_by, create_time, update_by, update_time from t_rack_material_relation
    </sql>

    <select id="selectTRackMaterialRelationList" parameterType="TRackMaterialRelation" resultMap="TRackMaterialRelationResult">
        <include refid="selectTRackMaterialRelationVo"/>
        <where>  
            <if test="rackCode != null  and rackCode != ''"> and rack_code like concat('%', #{rackCode}, '%')</if>
            <if test="materialCode != null  and materialCode != ''"> and material_code like concat('%', #{materialCode}, '%')</if>
            <if test="materialName != null  and materialName != ''"> and material_name like concat('%', #{materialName}, '%')</if>
            <if test="materialSpecifications != null  and materialSpecifications != ''"> and material_specifications = #{materialSpecifications}</if>
        </where>
    </select>
    
    <select id="selectTRackMaterialRelationById" parameterType="Long" resultMap="TRackMaterialRelationResult">
        <include refid="selectTRackMaterialRelationVo"/>
        where relation_id = #{relationId}
    </select>
        
    <insert id="insertTRackMaterialRelation" parameterType="TRackMaterialRelation" useGeneratedKeys="true" keyProperty="relationId">
        insert into t_rack_material_relation
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="rackCode != null and rackCode != ''">rack_code,</if>
            <if test="materialCode != null and materialCode != ''">material_code,</if>
            <if test="materialName != null">material_name,</if>
            <if test="materialSpecifications != null">material_specifications,</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="rackCode != null and rackCode != ''">#{rackCode},</if>
            <if test="materialCode != null and materialCode != ''">#{materialCode},</if>
            <if test="materialName != null">#{materialName},</if>
            <if test="materialSpecifications != null">#{materialSpecifications},</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="updateTRackMaterialRelation" parameterType="TRackMaterialRelation">
        update t_rack_material_relation
        <trim prefix="SET" suffixOverrides=",">
            <if test="rackCode != null and rackCode != ''">rack_code = #{rackCode},</if>
            <if test="materialCode != null and materialCode != ''">material_code = #{materialCode},</if>
            <if test="materialName != null">material_name = #{materialName},</if>
            <if test="materialSpecifications != null">material_specifications = #{materialSpecifications},</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 relation_id = #{relationId}
    </update>

    <delete id="deleteTRackMaterialRelationById" parameterType="Long">
        delete from t_rack_material_relation where relation_id = #{relationId}
    </delete>

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