<?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.willalp.files.mapper.PersonnelHireApprovalMapper">

    <resultMap type="com.willalp.files.domain.PersonnelHireApproval" id="PersonnelHireApprovalResult">
        <result property="id" column="id"/>
        <result property="title" column="title"/>
        <result property="personnelId" column="personnel_id"/>
        <result property="applyUserId" column="apply_user_id"/>
        <result property="applyUserName" column="apply_user_name"/>
        <result property="applyTime" column="apply_time"/>
        <result property="dimissionType" column="dimission_type"/>
        <result property="hireOrDimission" column="hire_or_dimission"/>
        <result property="isDelete" column="is_delete"/>
        <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"/>
    </resultMap>

    <sql id="selectPersonnelHireApprovalVo">
        select pha.id,
               title,
               personnel_id,
               apply_user_id,
               apply_user_name,
               apply_time,
               hopf.user_name,
               (select dept_name from sys_dept where dept_id = hopf.department) department,
               hopf.job_title,
               dimission_type,
               hire_or_dimission,
               pha.is_delete,
               pha.create_by,
               pha.create_time,
               pha.update_by,
               pha.update_time,
               pha.remark
        from personnel_hire_approval pha
                 left join hs_org_personnel_files hopf on pha.personnel_id = hopf.id
    </sql>

    <select id="selectPersonnelHireApprovalList" parameterType="PersonnelHireApproval"
            resultMap="PersonnelHireApprovalResult">
        <include refid="selectPersonnelHireApprovalVo"/>
        <where>
            pha.is_delete = 0 and hire_or_dimission = #{hireOrDimission}
            <if test="title != null  and title != ''">
                and title = #{title}
            </if>
            <if test="personnelId != null ">
                and personnel_id = #{personnelId}
            </if>
            <if test="applyUserId != null  and applyUserId != ''">
                and apply_user_id = #{applyUserId}
            </if>
            <if test="applyUserName != null  and applyUserName != ''">
                and apply_user_name like concat('%', #{applyUserName}, '%')
            </if>
        </where>
    </select>
</mapper>
