<?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.srs.dormitory.mapper.DmsForeignApplicationMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.srs.dormitory.domain.DmsForeignApplication">
        <id column="id" property="id" />
        <result column="applicant_name" property="applicantName" />
        <result column="id_card" property="idCard" />
        <result column="phone_number" property="phoneNumber" />
        <result column="campus_contact_id" property="campusContactId" />
        <result column="reason" property="reason" />
        <result column="start_date" property="startDate" />
        <result column="end_date" property="endDate" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
        <result column="status" property="status" />
        <result column="del_flag" property="delFlag" />
    </resultMap>
    <select id="getForeignApplicationInfo" resultType="java.util.Map">
        SELECT a.id,a.applicant_name `name`,a.applicant_gender gender,
               a.id_card idCard,a.phone_number phoneNumber,a.reason, a.start_date startDate,
               a.end_date endDate,a.create_time createTime,a.update_time updateTime,a.`status`,
               u.nick_name nickName,u.phonenumber phoneNumbaer
        FROM `dms_foreign_application` a
                 LEFT JOIN sys_user u ON u.user_id = a.campus_contact_id
        WHERE  a.id = #{id}
    </select>
    <select id="getForeignApplicationList" resultType="java.util.Map">
        SELECT a.id,a.applicant_name `name`,a.applicant_gender gender,
        a.id_card idCard,a.phone_number applicantPhone,a.reason, a.start_date startDate,
        a.end_date endDate,a.create_time createTime,a.update_time updateTime,a.`status`,
        u.nick_name contactName,u.phonenumber contactPhone
        FROM `dms_foreign_application` a
        LEFT JOIN sys_user u ON u.user_id = a.campus_contact_id
        <where>
            <if test="startTime != null">and a.create_time >= #{startTime}</if>
            <if test="endTime != null">and a.create_time &lt;= #{endTime}</if>
            <if test="userId != null">and u.user_id = #{userId}</if>
            <if test="gender != null">and a.applicant_gender = #{gender}</if>
            <if test="status != null">and a.status = #{status}</if>
        </where>
    </select>

</mapper>
