<?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.material.TRackMaterialInfoMapper">
    
    <resultMap type="TRackMaterialInfo" id="TRackMaterialInfoResult">
        <result property="materialId"    column="material_id"    />
        <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"    />
        <result property="isDel"    column="is_del"    />
    </resultMap>

    <sql id="selectTRackMaterialInfoVo">
        select material_id, material_code, material_name, material_specifications, create_by, create_time, update_by, update_time from t_rack_material_info
    </sql>

    <select id="selectTRackMaterialInfoList" parameterType="TRackMaterialInfo" resultMap="TRackMaterialInfoResult">
        <include refid="selectTRackMaterialInfoVo"/>
        <where>
            is_del = '0'
            <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="selectTRackMaterialInfoById" parameterType="Long" resultMap="TRackMaterialInfoResult">
        <include refid="selectTRackMaterialInfoVo"/>
        where material_id = #{materialId}
    </select>
        
    <insert id="insertTRackMaterialInfo" parameterType="TRackMaterialInfo" useGeneratedKeys="true" keyProperty="materialId">
        insert into t_rack_material_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <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>
            <if test=" isDel != null and isDel != ''">is_del,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <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>
            <if test=" isDel != null and isDel != ''">#{isDel},</if>
         </trim>
    </insert>

    <update id="updateTRackMaterialInfo" parameterType="TRackMaterialInfo">
        update t_rack_material_info
        <trim prefix="SET" suffixOverrides=",">
            <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>
            <if test="isDel != null and isDel != ''">is_del = #{isDel},</if>
        </trim>
        where material_id = #{materialId}
    </update>

    <delete id="deleteTRackMaterialInfoById" parameterType="Long">
        delete from t_rack_material_info where material_id = #{materialId}
    </delete>

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