<?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.ehsDocument.mapper.EhsDocumentMapper">

    <resultMap type="EhsDocument" id="EhsDocumentResult">
        <result property="id"    column="id"    />
        <result property="docName"    column="doc_name"    />
        <result property="docFont"    column="doc_font"    />
        <result property="draftDept"    column="draft_dept"    />
        <result property="docType"    column="doc_type"    />
        <result property="docNumber"    column="doc_number"    />
        <result property="receiveTime"    column="receive_time"    />
        <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="deptId"    column="dept_id"    />
        <result property="createUserId"    column="create_user_id"    />
        <result property="updateUserId"    column="update_user_id"    />
    </resultMap>

    <sql id="selectEhsDocumentVo">
         select e.*, d.dept_name from ehs_document e
           left join sys_dept d on e.dept_id = d.dept_id
    </sql>

    <select id="selectEhsDocumentList" parameterType="EhsDocument" resultMap="EhsDocumentResult">
        <include refid="selectEhsDocumentVo"/>
        <where>
            <if test="deptId != null "> and e.dept_Id = #{deptId}</if>
            <if test="docName != null  and docName != ''"> and doc_name like concat('%', #{docName}, '%')</if>
            <if test="docType != null "> and doc_type = #{docType}</if>
            <if test="status !=null">and status = #{status}</if>
        </where>
    </select>

    <select id="selectEhsDocumentById" parameterType="Long" resultMap="EhsDocumentResult">
        <include refid="selectEhsDocumentVo"/>
        where id = #{id}
    </select>

    <select id="getAllDraftDept" resultType="java.lang.String">
        select dept_name
        from sys_dept
    </select>


</mapper>