<?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.TmToolMaintenanceProcessMapper">

    <resultMap type="TmToolMaintenanceProcess" id="TmToolMaintenanceProcessResult">
        <result property="processId"    column="process_id"    />
        <result property="toolMaintenanceId"    column="tool_maintenance_id"    />
        <result property="processPerson"    column="process_person"    />
        <result property="processStatus"    column="process_status"    />
        <result property="processTime"    column="process_time"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="remark"    column="remark"    />
        <result property="lifeTime"    column="life_Time"    />

    </resultMap>

    <sql id="selectTmToolMaintenanceProcessVo">
        select process_id, tool_maintenance_id, process_person, process_status, process_time, start_time, end_time, remark ,life_Time from tm_tool_maintenance_process
    </sql>

    <select id="selectTmToolMaintenanceProcessList" parameterType="TmToolMaintenanceProcess" resultMap="TmToolMaintenanceProcessResult">
        <include refid="selectTmToolMaintenanceProcessVo"/>
        <where>
            <if test="toolMaintenanceId != null "> and tool_maintenance_id = #{toolMaintenanceId}</if>
            <if test="processPerson != null  and processPerson != ''"> and process_person = #{processPerson}</if>
            <if test="lifeTime != null  and lifeTime != ''"> and life_Time = #{lifeTime}</if>
            <if test="processStatus != null  and processStatus != ''"> and process_status = #{processStatus}</if>
            <if test="processTime != null  and processTime != ''"> and process_time = #{processTime}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
        </where>
    </select>

    <select id="selectTmToolMaintenanceProcessByProcessId" parameterType="Long" resultMap="TmToolMaintenanceProcessResult">
        <include refid="selectTmToolMaintenanceProcessVo"/>
        where process_id = #{processId}
    </select>
    <select id="selectTmToolMaintenanceId" parameterType="Long" resultMap="TmToolMaintenanceProcessResult">
        <include refid="selectTmToolMaintenanceProcessVo"/>
        where tool_maintenance_id=#{toolMaintenanceId}
    </select>

    <insert id="insertTmToolMaintenanceProcess" parameterType="TmToolMaintenanceProcess" useGeneratedKeys="true" keyProperty="processId">
        insert into tm_tool_maintenance_process
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="toolMaintenanceId != null">tool_maintenance_id,</if>
            <if test="processPerson != null">process_person,</if>
            <if test="lifeTime != null ">life_Time,</if>
            <if test="processStatus != null">process_status,</if>
            <if test="processTime != null">process_time,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="toolMaintenanceId != null">#{toolMaintenanceId},</if>
            <if test="processPerson != null">#{processPerson},</if>
            <if test="lifeTime != null ">#{lifeTime},</if>
            <if test="processStatus != null">#{processStatus},</if>
            <if test="processTime != null">#{processTime},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateTmToolMaintenanceProcess" parameterType="TmToolMaintenanceProcess">
        update tm_tool_maintenance_process
        <trim prefix="SET" suffixOverrides=",">
            <if test="toolMaintenanceId != null">tool_maintenance_id = #{toolMaintenanceId},</if>
            <if test="processPerson != null">process_person = #{processPerson},</if>
            <if test="lifeTime != null ">life_Time = #{lifeTime},</if>
            <if test="processStatus != null">process_status = #{processStatus},</if>
            <if test="processTime != null">process_time = #{processTime},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where process_id = #{processId}
    </update>

    <delete id="deleteTmToolMaintenanceProcessByProcessId" parameterType="Long">
        delete from tm_tool_maintenance_process where process_id = #{processId}
    </delete>

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