<?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.DmsOutsideAccommodationApplyMapper">

    <resultMap type="DmsOutsideAccommodationApply" id="DmsOutsideAccommodationApplyResult">
        <result property="id" column="id"/>
        <result property="applyNo" column="apply_no"/>
        <result property="studentId" column="student_id"/>
        <result property="studentNo" column="student_no"/>
        <result property="studentName" column="student_name"/>
        <result property="gender" column="gender"/>
        <result property="birthDate" column="birth_date"/>
        <result property="deptId" column="dept_id"/>
        <result property="deptName" column="dept_name"/>
        <result property="majorId" column="major_id"/>
        <result property="majorName" column="major_name"/>
        <result property="classId" column="class_id"/>
        <result property="className" column="class_name"/>
        <result property="originalDormitory" column="original_dormitory"/>
        <result property="accommodationFee" column="accommodation_fee"/>
        <result property="accommodationFeeStatus" column="accommodation_fee_status"/>
        <result property="applyReason" column="apply_reason"/>
        <result property="outsideAddress" column="outside_address"/>
        <result property="address" column="address"/>
        <result property="emergencyPhone" column="emergency_phone"/>
        <result property="emergencyContact" column="emergency_contact"/>
        <result property="parentOpinion" column="parent_opinion"/>
        <result property="parentSignAttachment" column="parent_sign_attachment"/>
        <result property="parentPhone" column="parent_phone"/>
        <result property="parentAddress" column="parent_address"/>
        <result property="parentDetailAddress" column="parent_detail_address"/>
        <result property="studentPromiseSign" column="student_promise_sign"/>
        <result property="promiseDate" column="promise_date"/>
        <result property="startDate" column="start_date"/>
        <result property="endDate" column="end_date"/>
        <result property="status" column="status"/>
        <result property="rejectReason" column="reject_reason"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="isValid" column="is_valid"/>
        <result property="teacherName" column="teacher_name"/>
        <result property="affixId" column="affix_id"/>
        <result property="deployId" column="deploy_id"/>
        <result property="processInstanceId" column="process_instance_id"/>
        <result property="idCard" column="idCard"/>
        <result property="studentPhone" column="studentPhone"/>
        <result property="studentSignature" column="student_signature"/>
        <result property="promiseContent"    column="promise_content"    />
    </resultMap>

    <sql id="selectDmsOutsideAccommodationApplyVo">
        select id,
               apply_no,
               student_id,
               student_no,
               student_name,
               gender,
               birth_date,
               dept_id,
               dept_name,
               major_id,
               major_name,
               class_id,
               class_name,
               original_dormitory,
               accommodation_fee,
               accommodation_fee_status,
               apply_reason,
               outside_address,
               address,
               emergency_phone,
               emergency_contact,
               parent_opinion,
               parent_sign_attachment,
               parent_phone,
               parent_address,
               parent_detail_address,
               student_promise_sign,
               promise_date,
               start_date,
               end_date,
               status,
               reject_reason,
               create_time,
               create_by,
               update_time,
               update_by,
               is_valid,
               teacher_name,
               affix_id,
               deploy_id,
               process_instance_id,
               idCard,
               studentPhone,
               student_signature,
               promise_content
        from dms_outside_accommodation_apply
    </sql>

    <select id="selectDmsOutsideAccommodationApplyList" parameterType="DmsOutsideAccommodationApply"
            resultMap="DmsOutsideAccommodationApplyResult">
        <include refid="selectDmsOutsideAccommodationApplyVo"/>
        <where>
            <if test="applyNo != null  and applyNo != ''">and apply_no = #{applyNo}</if>
            <if test="studentId != null ">and student_id = #{studentId}</if>
            <if test="studentNo != null  and studentNo != ''">and student_no = #{studentNo}</if>
            <if test="studentName != null  and studentName != ''">and student_name like concat('%', #{studentName},
                '%')
            </if>
            <if test="gender != null  and gender != ''">and gender = #{gender}</if>
            <if test="birthDate != null ">and birth_date = #{birthDate}</if>
            <if test="deptId != null ">and dept_id = #{deptId}</if>
            <if test="deptName != null  and deptName != ''">and dept_name like concat('%', #{deptName}, '%')</if>
            <if test="majorId != null ">and major_id = #{majorId}</if>
            <if test="majorName != null  and majorName != ''">and major_name like concat('%', #{majorName}, '%')</if>
            <if test="classId != null ">and class_id = #{classId}</if>
            <if test="className != null  and className != ''">and class_name like concat('%', #{className}, '%')</if>
            <if test="originalDormitory != null  and originalDormitory != ''">and original_dormitory =
                #{originalDormitory}
            </if>
            <if test="accommodationFee != null  and accommodationFee != ''">and accommodation_fee =
                #{accommodationFee}
            </if>
            <if test="accommodationFeeStatus != null ">and accommodation_fee_status = #{accommodationFeeStatus}</if>
            <if test="applyReason != null  and applyReason != ''">and apply_reason = #{applyReason}</if>
            <if test="outsideAddress != null  and outsideAddress != ''">and outside_address = #{outsideAddress}</if>
            <if test="address != null  and address != ''">and address = #{address}</if>
            <if test="emergencyPhone != null  and emergencyPhone != ''">and emergency_phone = #{emergencyPhone}</if>
            <if test="emergencyContact != null  and emergencyContact != ''">and emergency_contact =
                #{emergencyContact}
            </if>
            <if test="parentOpinion != null ">and parent_opinion = #{parentOpinion}</if>
            <if test="parentSignAttachment != null  and parentSignAttachment != ''">and parent_sign_attachment =
                #{parentSignAttachment}
            </if>
            <if test="parentPhone != null  and parentPhone != ''">and parent_phone = #{parentPhone}</if>
            <if test="parentAddress != null  and parentAddress != ''">and parent_address = #{parentAddress}</if>
            <if test="parentDetailAddress != null  and parentDetailAddress != ''">and parent_detail_address =
                #{parentDetailAddress}
            </if>
            <if test="studentPromiseSign != null  and studentPromiseSign != ''">and student_promise_sign =
                #{studentPromiseSign}
            </if>
            <if test="promiseDate != null ">and promise_date = #{promiseDate}</if>
            <if test="startDate != null ">and start_date = #{startDate}</if>
            <if test="endDate != null ">and end_date = #{endDate}</if>
            <if test="status != null ">and status = #{status}</if>
            <if test="rejectReason != null  and rejectReason != ''">and reject_reason = #{rejectReason}</if>
            <if test="isValid != null ">and is_valid = #{isValid}</if>
            <if test="teacherName != null  and teacherName != ''">and teacher_name like concat('%', #{teacherName},
                '%')
            </if>
            <if test="affixId != null  and affixId != ''">and affix_id = #{affixId}</if>
            <if test="deployId != null  and deployId != ''">and deploy_id = #{deployId}</if>
            <if test="processInstanceId != null  and processInstanceId != ''">and process_instance_id =
                #{processInstanceId}
            </if>
            <if test="idCard != null  and idCard != ''">and idCard = #{idCard}</if>
            <if test="studentPhone != null  and studentPhone != ''">and studentPhone = #{studentPhone}</if>
            <if test="studentSignature != null  and studentSignature != ''">and student_signature =
                #{studentSignature}
            </if>
        </where>
    </select>

    <select id="selectDmsOutsideAccommodationApplyById" parameterType="Long"
            resultMap="DmsOutsideAccommodationApplyResult">
        <include refid="selectDmsOutsideAccommodationApplyVo"/>
        where id = #{id}
    </select>

    <!--根据流程ID查询信息-->
    <select id="selectDmsOutsideAccommodationApplyByProcessInstanceId" parameterType="String"
            resultMap="DmsOutsideAccommodationApplyResult">
        <include refid="selectDmsOutsideAccommodationApplyVo"/>
        where processInstanceId = #{process_instance_id}
    </select>

    <!--根据学生姓名和学号查询申请表-->
    <select id="getAccommodationByStuNameAndStuNo" resultMap="DmsOutsideAccommodationApplyResult">
        select *
        from dms_outside_accommodation_apply
        <where>
            <if test="studentName != null and studentName != ''">
                and student_name = #{studentName}
            </if>
            <if test="studentNo != null and studentNo != ''">
                and student_no = #{studentNo}
            </if>
        </where>
    </select>


    <!--  根据学号查询辅导员信息  -->
    <select id="getCounselorInfo" resultType="com.srs.common.doman.vo.TeacherVo">
        SELECT d.user_id userId, d.dept_id deptId, d.user_name userName, d.nick_name nickName
        FROM srs_student a
                 LEFT JOIN srs_class b ON a.class_id = b.class_id
                 LEFT JOIN cph_teacher c ON b.teacher_id = c.teacher_id
                 LEFT JOIN sys_user d ON c.employee_id = d.user_name
        WHERE a.stu_no = #{stuNo}
    </select>

    <insert id="insertDmsOutsideAccommodationApply" parameterType="DmsOutsideAccommodationApply" useGeneratedKeys="true"
            keyProperty="id">
        insert into dms_outside_accommodation_apply
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="applyNo != null and applyNo != ''">apply_no,</if>
            <if test="studentId != null">student_id,</if>
            <if test="studentNo != null and studentNo != ''">student_no,</if>
            <if test="studentName != null and studentName != ''">student_name,</if>
            <if test="gender != null">gender,</if>
            <if test="birthDate != null">birth_date,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="deptName != null and deptName != ''">dept_name,</if>
            <if test="majorId != null">major_id,</if>
            <if test="majorName != null and majorName != ''">major_name,</if>
            <if test="classId != null">class_id,</if>
            <if test="className != null and className != ''">class_name,</if>
            <if test="originalDormitory != null and originalDormitory != ''">original_dormitory,</if>
            <if test="accommodationFee != null and accommodationFee != ''">accommodation_fee,</if>
            <if test="accommodationFeeStatus != null">accommodation_fee_status,</if>
            <if test="applyReason != null and applyReason != ''">apply_reason,</if>
            <if test="outsideAddress != null and outsideAddress != ''">outside_address,</if>
            <if test="address != null and address != ''">address,</if>
            <if test="emergencyPhone != null and emergencyPhone != ''">emergency_phone,</if>
            <if test="emergencyContact != null and emergencyContact != ''">emergency_contact,</if>
            <if test="parentOpinion != null">parent_opinion,</if>
            <if test="parentSignAttachment != null and parentSignAttachment != ''">parent_sign_attachment,</if>
            <if test="parentPhone != null and parentPhone != ''">parent_phone,</if>
            <if test="parentAddress != null and parentAddress != ''">parent_address,</if>
            <if test="parentDetailAddress != null and parentDetailAddress != ''">parent_detail_address,</if>
            <if test="studentPromiseSign != null and studentPromiseSign != ''">student_promise_sign,</if>
            <if test="promiseDate != null">promise_date,</if>
            <if test="startDate != null">start_date,</if>
            <if test="endDate != null">end_date,</if>
            <if test="status != null">status,</if>
            <if test="rejectReason != null">reject_reason,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="isValid != null">is_valid,</if>
            <if test="teacherName != null and teacherName != ''">teacher_name,</if>
            <if test="affixId != null">affix_id,</if>
            <if test="deployId != null">deploy_id,</if>
            <if test="processInstanceId != null">process_instance_id,</if>
            <if test="idCard != null and idCard != ''">idCard,</if>
            <if test="studentPhone != null">studentPhone,</if>
            <if test="studentSignature != null">student_signature,</if>
            <if test="promiseContent != null">promise_content,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="applyNo != null and applyNo != ''">#{applyNo},</if>
            <if test="studentId != null">#{studentId},</if>
            <if test="studentNo != null and studentNo != ''">#{studentNo},</if>
            <if test="studentName != null and studentName != ''">#{studentName},</if>
            <if test="gender != null">#{gender},</if>
            <if test="birthDate != null">#{birthDate},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="deptName != null and deptName != ''">#{deptName},</if>
            <if test="majorId != null">#{majorId},</if>
            <if test="majorName != null and majorName != ''">#{majorName},</if>
            <if test="classId != null">#{classId},</if>
            <if test="className != null and className != ''">#{className},</if>
            <if test="originalDormitory != null and originalDormitory != ''">#{originalDormitory},</if>
            <if test="accommodationFee != null and accommodationFee != ''">#{accommodationFee},</if>
            <if test="accommodationFeeStatus != null">#{accommodationFeeStatus},</if>
            <if test="applyReason != null and applyReason != ''">#{applyReason},</if>
            <if test="outsideAddress != null and outsideAddress != ''">#{outsideAddress},</if>
            <if test="address != null and address != ''">#{address},</if>
            <if test="emergencyPhone != null and emergencyPhone != ''">#{emergencyPhone},</if>
            <if test="emergencyContact != null and emergencyContact != ''">#{emergencyContact},</if>
            <if test="parentOpinion != null">#{parentOpinion},</if>
            <if test="parentSignAttachment != null and parentSignAttachment != ''">#{parentSignAttachment},</if>
            <if test="parentPhone != null and parentPhone != ''">#{parentPhone},</if>
            <if test="parentAddress != null and parentAddress != ''">#{parentAddress},</if>
            <if test="parentDetailAddress != null and parentDetailAddress != ''">#{parentDetailAddress},</if>
            <if test="studentPromiseSign != null and studentPromiseSign != ''">#{studentPromiseSign},</if>
            <if test="promiseDate != null">#{promiseDate},</if>
            <if test="startDate != null">#{startDate},</if>
            <if test="endDate != null">#{endDate},</if>
            <if test="status != null">#{status},</if>
            <if test="rejectReason != null">#{rejectReason},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="isValid != null">#{isValid},</if>
            <if test="teacherName != null and teacherName != ''">#{teacherName},</if>
            <if test="affixId != null">#{affixId},</if>
            <if test="deployId != null">#{deployId},</if>
            <if test="processInstanceId != null">#{processInstanceId},</if>
            <if test="idCard != null and idCard != ''">#{idCard},</if>
            <if test="studentPhone != null">#{studentPhone},</if>
            <if test="studentSignature != null">#{studentSignature},</if>
            <if test="promiseContent != null">#{promiseContent},</if>
        </trim>
    </insert>

    <update id="updateDmsOutsideAccommodationApply" parameterType="DmsOutsideAccommodationApply">
        update dms_outside_accommodation_apply
        <trim prefix="SET" suffixOverrides=",">
            <if test="applyNo != null and applyNo != ''">apply_no = #{applyNo},</if>
            <if test="studentId != null">student_id = #{studentId},</if>
            <if test="studentNo != null and studentNo != ''">student_no = #{studentNo},</if>
            <if test="studentName != null and studentName != ''">student_name = #{studentName},</if>
            <if test="gender != null">gender = #{gender},</if>
            <if test="birthDate != null">birth_date = #{birthDate},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
            <if test="majorId != null">major_id = #{majorId},</if>
            <if test="majorName != null and majorName != ''">major_name = #{majorName},</if>
            <if test="classId != null">class_id = #{classId},</if>
            <if test="className != null and className != ''">class_name = #{className},</if>
            <if test="originalDormitory != null and originalDormitory != ''">original_dormitory =
                #{originalDormitory},
            </if>
            <if test="accommodationFee != null and accommodationFee != ''">accommodation_fee = #{accommodationFee},</if>
            <if test="accommodationFeeStatus != null">accommodation_fee_status = #{accommodationFeeStatus},</if>
            <if test="applyReason != null and applyReason != ''">apply_reason = #{applyReason},</if>
            <if test="outsideAddress != null and outsideAddress != ''">outside_address = #{outsideAddress},</if>
            <if test="address != null and address != ''">address = #{address},</if>
            <if test="emergencyPhone != null and emergencyPhone != ''">emergency_phone = #{emergencyPhone},</if>
            <if test="emergencyContact != null and emergencyContact != ''">emergency_contact = #{emergencyContact},</if>
            <if test="parentOpinion != null">parent_opinion = #{parentOpinion},</if>
            <if test="parentSignAttachment != null and parentSignAttachment != ''">parent_sign_attachment =
                #{parentSignAttachment},
            </if>
            <if test="parentPhone != null and parentPhone != ''">parent_phone = #{parentPhone},</if>
            <if test="parentAddress != null and parentAddress != ''">parent_address = #{parentAddress},</if>
            <if test="parentDetailAddress != null and parentDetailAddress != ''">parent_detail_address =
                #{parentDetailAddress},
            </if>
            <if test="studentPromiseSign != null and studentPromiseSign != ''">student_promise_sign =
                #{studentPromiseSign},
            </if>
            <if test="promiseDate != null">promise_date = #{promiseDate},</if>
            <if test="startDate != null">start_date = #{startDate},</if>
            <if test="endDate != null">end_date = #{endDate},</if>
            <if test="status != null">status = #{status},</if>
            <if test="rejectReason != null">reject_reason = #{rejectReason},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="isValid != null">is_valid = #{isValid},</if>
            <if test="teacherName != null and teacherName != ''">teacher_name = #{teacherName},</if>
            <if test="affixId != null">affix_id = #{affixId},</if>
            <if test="deployId != null">deploy_id = #{deployId},</if>
            <if test="processInstanceId != null">process_instance_id = #{processInstanceId},</if>
            <if test="idCard != null and idCard != ''">idCard = #{idCard},</if>
            <if test="studentPhone != null">studentPhone = #{studentPhone},</if>
            <if test="studentSignature != null">student_signature = #{studentSignature},</if>
            <if test="promiseContent != null">promise_content = #{promiseContent},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDmsOutsideAccommodationApplyById" parameterType="Long">
        delete
        from dms_outside_accommodation_apply
        where id = #{id}
    </delete>

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