<?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.pro.mapper.proWorkOrder.ProWorkOrderChangeRecordMapper">

    <resultMap type="ProWorkOrderChangeRecord" id="ProWorkOrderChangeRecordResult">
        <result property="id" column="id"/>
        <result property="workorderId" column="workorder_id"/>
        <result property="workorderName" column="workorder_name"/>
        <result property="workorderCode" column="workorder_code"/>
        <result property="actionType" column="action_type"/>
        <result property="requestBody" column="request_body"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateBy" column="update_by"/>
    </resultMap>

    <sql id="selectProWorkOrderChangeRecordVo">
        select id,
               workorder_id,
               workorder_name,
               workorder_code,
               action_type,
               request_body,
               create_time,
               create_by,
               update_time,
               update_by
        from pro_work_order_change_record
    </sql>

    <select id="selectProWorkOrderChangeRecordList" parameterType="ProWorkOrderChangeRecord"
            resultMap="ProWorkOrderChangeRecordResult">
        <include refid="selectProWorkOrderChangeRecordVo"/>
        <where>
            <if test="workorderId != null ">and workorder_id = #{workorderId}</if>
            <if test="workorderName != null  and workorderName != ''">and workorder_name like concat('%',
                #{workorderName}, '%')
            </if>
            <if test="workorderCode != null  and workorderCode != ''">and workorder_code = #{workorderCode}</if>
            <if test="actionType != null  and actionType != ''">and action_type = #{actionType}</if>
            <if test="requestBody != null  and requestBody != ''">and request_body = #{requestBody}</if>
        </where>
    </select>

    <select id="selectProWorkOrderChangeRecordById" parameterType="Long" resultMap="ProWorkOrderChangeRecordResult">
        <include refid="selectProWorkOrderChangeRecordVo"/>
        where id = #{id}
    </select>

    <insert id="insertProWorkOrderChangeRecord" parameterType="ProWorkOrderChangeRecord" useGeneratedKeys="true"
            keyProperty="id">
        insert into pro_work_order_change_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="workorderId != null">workorder_id,</if>
            <if test="workorderName != null">workorder_name,</if>
            <if test="workorderCode != null">workorder_code,</if>
            <if test="actionType != null">action_type,</if>
            <if test="requestBody != null">request_body,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="workorderId != null">#{workorderId},</if>
            <if test="workorderName != null">#{workorderName},</if>
            <if test="workorderCode != null">#{workorderCode},</if>
            <if test="actionType != null">#{actionType},</if>
            <if test="requestBody != null">#{requestBody},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
        </trim>
    </insert>

    <update id="updateProWorkOrderChangeRecord" parameterType="ProWorkOrderChangeRecord">
        update pro_work_order_change_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="workorderId != null">workorder_id = #{workorderId},</if>
            <if test="workorderName != null">workorder_name = #{workorderName},</if>
            <if test="workorderCode != null">workorder_code = #{workorderCode},</if>
            <if test="actionType != null">action_type = #{actionType},</if>
            <if test="requestBody != null">request_body = #{requestBody},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteProWorkOrderChangeRecordById" parameterType="Long">
        delete
        from pro_work_order_change_record
        where id = #{id}
    </delete>

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