<?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.ximai.mes.tm.mapper.TmToolWarehouseMapper">

    <resultMap type="TmToolWarehouse" id="TmToolWarehouseResult">
        <result property="toolWarehouseId" column="tool_warehouse_id"/>
        <result property="toolWarehouseCode" column="tool_warehouse_code"/>
        <result property="createBy" column="create_by"/>
        <result property="updateBy" column="update_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectTmToolWarehouseVo">
        select tool_warehouse_id, tool_warehouse_code, create_by, update_by, create_time, update_time
        from tm_tool_warehouse
    </sql>

    <select id="selectTmToolWarehouseList" parameterType="TmToolWarehouse" resultMap="TmToolWarehouseResult">
        <include refid="selectTmToolWarehouseVo"/>
        <where>
            <if test="toolWarehouseCode != null  and toolWarehouseCode != ''">and tool_warehouse_code =
                #{toolWarehouseCode}
            </if>
        </where>
    </select>

    <select id="selectTmToolWarehouseByToolWarehouseId" parameterType="Long" resultMap="TmToolWarehouseResult">
        <include refid="selectTmToolWarehouseVo"/>
        where tool_warehouse_id = #{toolWarehouseId}
    </select>

    <insert id="insertTmToolWarehouse" parameterType="TmToolWarehouse" useGeneratedKeys="true"
            keyProperty="toolWarehouseId">
        insert into tm_tool_warehouse
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="toolWarehouseCode != null">tool_warehouse_code,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="toolWarehouseCode != null">#{toolWarehouseCode},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateTmToolWarehouse" parameterType="TmToolWarehouse">
        update tm_tool_warehouse
        <trim prefix="SET" suffixOverrides=",">
            <if test="toolWarehouseCode != null">tool_warehouse_code = #{toolWarehouseCode},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where tool_warehouse_id = #{toolWarehouseId}
    </update>

    <delete id="deleteTmToolWarehouseByToolWarehouseId" parameterType="Long">
        delete
        from tm_tool_warehouse
        where tool_warehouse_id = #{toolWarehouseId}
    </delete>

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