<?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.lz.modules.flow.dao.FlowChangeMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.lz.modules.flow.entity.FlowChange">
        <id column="id" property="id"/>
        <result column="is_delete" property="isDelete"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="approval_id" property="approvalId"/>
        <result column="to_approval_id" property="toApprovalId"/>
        <result column="opt_id" property="optId"/>
        <result column="flow_record_id" property="flowRecordId"/>
        <result column="record_id" property="recordId"/>
        <result column="staff_id" property="staffId"/>
        <result column="type" property="type"/>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, approval_id AS approvalId, to_approval_id AS toApprovalId, opt_id AS optId, flow_record_id AS flowRecordId, record_id AS recordId, staff_id AS staffId, type AS type
    </sql>




    <select id="selectFlowChangeById" resultType="FlowChange" >
        select * from lz_flow_change  where id=#{id} and is_delete = 0 limit 1 
    </select>


    <insert id="insertFlowChange" parameterType="FlowChange" useGeneratedKeys="true" keyProperty="id" >
        insert into lz_flow_change(
            <if test="approvalId != null">approval_id, </if>
            <if test="toApprovalId != null">to_approval_id, </if>
            <if test="optId != null">opt_id, </if>
            <if test="flowRecordId != null">flow_record_id, </if>
            <if test="recordId != null">record_id, </if>
            <if test="staffId != null">staff_id, </if>
            <if test="type != null">type, </if>
            is_delete,
            gmt_create,
            gmt_modified
        )values(
            <if test="approvalId != null">#{ approvalId}, </if>
            <if test="toApprovalId != null">#{ toApprovalId}, </if>
            <if test="optId != null">#{ optId}, </if>
            <if test="flowRecordId != null">#{ flowRecordId}, </if>
            <if test="recordId != null">#{ recordId}, </if>
            <if test="staffId != null">#{ staffId}, </if>
            <if test="type != null">#{ type}, </if>
            0,
            now(),
            now()
        )
    </insert>


    <update id="updateFlowChangeById" parameterType="FlowChange" >
        update
            lz_flow_change
        <trim prefix="set" suffixOverrides=",">
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="gmtCreate != null">gmt_create = #{gmtCreate},</if>
            <if test="approvalId != null">approval_id = #{approvalId},</if>
            <if test="toApprovalId != null">to_approval_id = #{toApprovalId},</if>
            <if test="optId != null">opt_id = #{optId},</if>
            <if test="flowRecordId != null">flow_record_id = #{flowRecordId},</if>
            <if test="recordId != null">record_id = #{recordId},</if>
            <if test="staffId != null">staff_id = #{staffId},</if>
            <if test="type != null">type = #{type}</if>                
        </trim>
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="updateCoverFlowChangeById" parameterType="FlowChange" >
        update
            lz_flow_change    
        set     
            is_delete = #{isDelete},
            gmt_create = #{gmtCreate},
            approval_id = #{approvalId},
            to_approval_id = #{toApprovalId},
            opt_id = #{optId},
            flow_record_id = #{flowRecordId},
            record_id = #{recordId},
            staff_id = #{staffId},
            type = #{type}                
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="deleteFlowChangeById" parameterType="java.lang.Long">
        update lz_flow_change set is_delete = 1 where id=#{id} limit 1  
    </update>

</mapper>

