<?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.sundot.airport.system.mapper.SysWorkingDocumentMapper">

    <resultMap type="SysWorkingDocument" id="SysWorkingDocumentResult">
        <result property="documentId" column="document_id"/>
        <result property="documentTitle" column="document_title"/>
        <result property="documentFileName" column="document_file_name"/>
        <result property="documentNewFileName" column="document_new_file_name"/>
        <result property="documentOriginalFileName" column="document_original_file_name"/>
        <result property="documentUrl" column="document_url"/>
        <result property="status" column="status"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
        <result property="createByUserId" column="create_by_user_id"/>
        <result property="updateByUserId" column="update_by_user_id"/>
    </resultMap>

    <sql id="selectSysWorkingDocumentVo">
        select document_id,
               document_title,
               document_file_name,
               document_new_file_name,
               document_original_file_name,
               document_url,
               status,
               create_by,
               create_time,
               update_by,
               update_time,
               remark,
               create_by_user_id,
               update_by_user_id
        from sys_working_document
    </sql>

    <select id="selectSysWorkingDocumentList" parameterType="SysWorkingDocument" resultMap="SysWorkingDocumentResult">
        <include refid="selectSysWorkingDocumentVo"/>
        <where>
            <if test="documentTitle != null  and documentTitle != ''">and document_title = #{documentTitle}</if>
            <if test="documentFileName != null  and documentFileName != ''">and document_file_name like concat('%',
                #{documentFileName}, '%')
            </if>
            <if test="documentNewFileName != null  and documentNewFileName != ''">and document_new_file_name like
                concat('%', #{documentNewFileName}, '%')
            </if>
            <if test="documentOriginalFileName != null  and documentOriginalFileName != ''">and
                document_original_file_name like concat('%', #{documentOriginalFileName}, '%')
            </if>
            <if test="documentUrl != null  and documentUrl != ''">and document_url = #{documentUrl}</if>
            <if test="status != null  and status != ''">and status = #{status}</if>
            <if test="createByUserId != null ">and create_by_user_id = #{createByUserId}</if>
            <if test="updateByUserId != null ">and update_by_user_id = #{updateByUserId}</if>
            <if test="createBy != null  and createBy != ''">and create_by like
                concat('%', #{createBy}, '%')
            </if>
            <if test="updateBy != null  and updateBy != ''">and update_by like
                concat('%', #{updateBy}, '%')
            </if>
        </where>
        order by create_time desc
    </select>

    <select id="selectSysWorkingDocumentByDocumentId" parameterType="Long" resultMap="SysWorkingDocumentResult">
        <include refid="selectSysWorkingDocumentVo"/>
        where document_id = #{documentId}
    </select>

    <insert id="insertSysWorkingDocument" parameterType="SysWorkingDocument" useGeneratedKeys="true"
            keyProperty="documentId">
        insert into sys_working_document
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="documentTitle != null and documentTitle != ''">document_title,</if>
            <if test="documentFileName != null and documentFileName != ''">document_file_name,</if>
            <if test="documentNewFileName != null">document_new_file_name,</if>
            <if test="documentOriginalFileName != null">document_original_file_name,</if>
            <if test="documentUrl != null">document_url,</if>
            <if test="status != null">status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="createByUserId != null">create_by_user_id,</if>
            <if test="updateByUserId != null">update_by_user_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="documentTitle != null and documentTitle != ''">#{documentTitle},</if>
            <if test="documentFileName != null and documentFileName != ''">#{documentFileName},</if>
            <if test="documentNewFileName != null">#{documentNewFileName},</if>
            <if test="documentOriginalFileName != null">#{documentOriginalFileName},</if>
            <if test="documentUrl != null">#{documentUrl},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createByUserId != null">#{createByUserId},</if>
            <if test="updateByUserId != null">#{updateByUserId},</if>
        </trim>
    </insert>

    <update id="updateSysWorkingDocument" parameterType="SysWorkingDocument">
        update sys_working_document
        <trim prefix="SET" suffixOverrides=",">
            <if test="documentTitle != null and documentTitle != ''">document_title = #{documentTitle},</if>
            <if test="documentFileName != null and documentFileName != ''">document_file_name = #{documentFileName},
            </if>
            <if test="documentNewFileName != null">document_new_file_name = #{documentNewFileName},</if>
            <if test="documentOriginalFileName != null">document_original_file_name = #{documentOriginalFileName},</if>
            <if test="documentUrl != null">document_url = #{documentUrl},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createByUserId != null">create_by_user_id = #{createByUserId},</if>
            <if test="updateByUserId != null">update_by_user_id = #{updateByUserId},</if>
        </trim>
        where document_id = #{documentId}
    </update>

    <delete id="deleteSysWorkingDocumentByDocumentId" parameterType="Long">
        delete
        from sys_working_document
        where document_id = #{documentId}
    </delete>

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