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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.lz.modules.flow.entity.FlowRecord">
        <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="department_id" property="departmentId"/>
        <result column="department_level" property="departmentLevel"/>
        <result column="record_id" property="recordId"/>
        <result column="approval_staff_id" property="approvalStaffId"/>
        <result column="approval_staff_name" property="approvalStaffName"/>
        <result column="role_id" property="roleId"/>
        <result column="flow_name" property="flowName"/>
        <result column="record_staff_id" property="recordStaffId"/>
        <result column="flow_id" property="flowId"/>
        <result column="flow_index" property="flowIndex"/>
        <result column="relation_index" property="relationIndex"/>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, department_id AS departmentId, department_level AS departmentLevel, record_id AS recordId, approval_staff_id AS approvalStaffId, approval_staff_name AS approvalStaffName, role_id AS roleId, flow_name AS flowName, record_staff_id AS recordStaffId, flow_id AS flowId, flow_index AS flowIndex, relation_index AS relationIndex
    </sql>




    <select id="selectFlowRecordById" resultType="FlowRecord" >
        select * from lz_flow_record  where id=#{id} and is_delete = 0 limit 1 
    </select>


    <insert id="insertFlowRecord" parameterType="FlowRecord" useGeneratedKeys="true" keyProperty="id" >
        insert into lz_flow_record(
            <if test="departmentId != null">department_id, </if>
            <if test="departmentLevel != null">department_level, </if>
            <if test="recordId != null">record_id, </if>
            <if test="approvalStaffId != null">approval_staff_id, </if>
            <if test="approvalStaffName != null">approval_staff_name, </if>
            <if test="roleId != null">role_id, </if>
            <if test="flowName != null">flow_name, </if>
            <if test="recordStaffId != null">record_staff_id, </if>
            <if test="flowId != null">flow_id, </if>
            <if test="flowIndex != null">flow_index, </if>
            <if test="relationIndex != null">relation_index, </if>
            is_delete,
            gmt_create,
            gmt_modified
        )values(
            <if test="departmentId != null">#{ departmentId}, </if>
            <if test="departmentLevel != null">#{ departmentLevel}, </if>
            <if test="recordId != null">#{ recordId}, </if>
            <if test="approvalStaffId != null">#{ approvalStaffId}, </if>
            <if test="approvalStaffName != null">#{ approvalStaffName}, </if>
            <if test="roleId != null">#{ roleId}, </if>
            <if test="flowName != null">#{ flowName}, </if>
            <if test="recordStaffId != null">#{ recordStaffId}, </if>
            <if test="flowId != null">#{ flowId}, </if>
            <if test="flowIndex != null">#{ flowIndex}, </if>
            <if test="relationIndex != null">#{ relationIndex}, </if>
            0,
            now(),
            now()
        )
    </insert>


    <update id="updateFlowRecordById" parameterType="FlowRecord" >
        update
            lz_flow_record
        <trim prefix="set" suffixOverrides=",">
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="gmtCreate != null">gmt_create = #{gmtCreate},</if>
            <if test="departmentId != null">department_id = #{departmentId},</if>
            <if test="departmentLevel != null">department_level = #{departmentLevel},</if>
            <if test="recordId != null">record_id = #{recordId},</if>
            <if test="approvalStaffId != null">approval_staff_id = #{approvalStaffId},</if>
            <if test="approvalStaffName != null">approval_staff_name = #{approvalStaffName},</if>
            <if test="roleId != null">role_id = #{roleId},</if>
            <if test="flowName != null">flow_name = #{flowName},</if>
            <if test="recordStaffId != null">record_staff_id = #{recordStaffId},</if>
            <if test="flowId != null">flow_id = #{flowId},</if>
            <if test="flowIndex != null">flow_index = #{flowIndex},</if>
            <if test="relationIndex != null">relation_index = #{relationIndex}</if>                
        </trim>
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="updateCoverFlowRecordById" parameterType="FlowRecord" >
        update
            lz_flow_record    
        set     
            is_delete = #{isDelete},
            gmt_create = #{gmtCreate},
            department_id = #{departmentId},
            department_level = #{departmentLevel},
            record_id = #{recordId},
            approval_staff_id = #{approvalStaffId},
            approval_staff_name = #{approvalStaffName},
            role_id = #{roleId},
            flow_name = #{flowName},
            record_staff_id = #{recordStaffId},
            flow_id = #{flowId},
            flow_index = #{flowIndex},
            relation_index = #{relationIndex}                
        ,gmt_modified = now()
        where id = #{id}
    </update>


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

</mapper>

