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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.lz.modules.flow.entity.RecordFile">
        <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="staff_id" property="staffId"/>
        <result column="staff_name" property="staffName"/>
        <result column="department_id" property="departmentId"/>
        <result column="file_name" property="fileName"/>
        <result column="file_url" property="fileUrl"/>
        <result column="record_id" property="recordId"/>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, staff_id AS staffId, staff_name AS staffName, department_id AS departmentId, file_name AS fileName, file_url AS fileUrl, record_id AS recordId
    </sql>

    <select id="selectRecordFileById" resultType="RecordFile" >
        select * from lz_record_file  where id=#{id} and is_delete = 0 limit 1 
    </select>

    <insert id="insertRecordFile" parameterType="RecordFile" useGeneratedKeys="true" keyProperty="id" >
        insert into lz_record_file(
            <if test="staffId != null">staff_id, </if>
            <if test="staffName != null">staff_name, </if>
            <if test="departmentId != null">department_id, </if>
            <if test="fileName != null">file_name, </if>
            <if test="fileUrl != null">file_url, </if>
            <if test="recordId != null">record_id, </if>
            is_delete,
            gmt_create,
            gmt_modified
        )values(
            <if test="staffId != null">#{ staffId}, </if>
            <if test="staffName != null">#{ staffName}, </if>
            <if test="departmentId != null">#{ departmentId}, </if>
            <if test="fileName != null">#{ fileName}, </if>
            <if test="fileUrl != null">#{ fileUrl}, </if>
            <if test="recordId != null">#{ recordId}, </if>
            0,
            now(),
            now()
        )
    </insert>


    <update id="updateRecordFileById" parameterType="RecordFile" >
        update
            lz_record_file
        <trim prefix="set" suffixOverrides=",">
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="gmtCreate != null">gmt_create = #{gmtCreate},</if>
            <if test="staffId != null">staff_id = #{staffId},</if>
            <if test="staffName != null">staff_name = #{staffName},</if>
            <if test="departmentId != null">department_id = #{departmentId},</if>
            <if test="fileName != null">file_name = #{fileName},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</if>
            <if test="recordId != null">record_id = #{recordId}</if>                
        </trim>
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="updateCoverRecordFileById" parameterType="RecordFile" >
        update
            lz_record_file    
        set     
            is_delete = #{isDelete},
            gmt_create = #{gmtCreate},
            staff_id = #{staffId},
            staff_name = #{staffName},
            department_id = #{departmentId},
            file_name = #{fileName},
            file_url = #{fileUrl},
            record_id = #{recordId}                
        ,gmt_modified = now()
        where id = #{id}
    </update>


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

    <select id="selectByCondition" resultType="com.lz.modules.flow.entity.RecordFile">
        select * from lz_record_file  where record_id = #{req.recordId} and is_delete = 0  order by id desc
    </select>
    <select id="selectRecordFileCountByRecordId" resultType="java.lang.Integer">
        select ifnull(count(*),0) from lz_record_file  where record_id = #{recordId} and is_delete = 0
    </select>


</mapper>

