<?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.ruoyi.ehsDocTransfer.mapper.EhsDocTransferMapper">

    <resultMap type="EhsDocTransfer" id="EhsDocTransferResult">
            <result property="id"    column="id"    />
            <result property="transferUserId"    column="transfer_user_id"    />
            <result property="transferName"    column="transfer_name"    />
            <result property="transferTime"    column="transfer_time"    />
            <result property="docTransferStatus"    column="doc_transfer_status"    />
            <result property="documentId"    column="document_id"    />
            <result property="documentName"    column="document_name"    />

            <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="deptId"    column="dept_id"    />
            <result property="createUserId"    column="create_user_id"    />
            <result property="updateUserId"    column="update_user_id"    />
    </resultMap>

    <sql id="selectEhsDocTransferVo">
        select id, transfer_user_id, transfer_name, transfer_time, doc_transfer_status, document_id, document_name, create_by, create_time, update_by, update_time, remark, dept_id, create_user_id, update_user_id from ehs_doc_transfer
    </sql>

    <select id="selectEhsDocTransferList" parameterType="EhsDocTransfer" resultMap="EhsDocTransferResult">
        <include refid="selectEhsDocTransferVo"/>
        <where>
                        <if test="transferUserId != null "> and transfer_user_id = #{transferUserId}</if>
                        <if test="transferName != null  and transferName != ''"> and transfer_name like concat('%', #{transferName}, '%')</if>
                        <if test="transferTime != null "> and transfer_time = #{transferTime}</if>
                        <if test="docTransferStatus != null "> and doc_transfer_status = #{docTransferStatus}</if>
                        <if test="documentId != null "> and document_id = #{documentId}</if>
                        <if test="documentName != null and documentName != ''"> and document_name = #{documentName}</if>
        </where>
    </select>

    <select id="selectEhsDocTransferById" parameterType="Long" resultMap="EhsDocTransferResult">
            <include refid="selectEhsDocTransferVo"/>
            where id = #{id}
    </select>
    <select id="getTransferInfoByDocId" resultMap="EhsDocTransferResult">
        SELECT t.*
        FROM ehs_document d,ehs_doc_transfer t
        WHERE d.id = t.document_id AND d.id = #{id}
        order by t.transfer_time desc
    </select>


</mapper>