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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.srs.dormitory.domain.DmsChangeLog">
        <id column="id" property="id" />
        <result column="stu_no" property="stuNo" />
        <result column="type" property="type" />
        <result column="current_dorm_id" property="currentDormId" />
        <result column="current_bed_id" property="currentBedId" />
        <result column="target_dorm_id" property="targetDormId" />
        <result column="target_bed_id" property="targetBedId" />
        <result column="money" property="money" />
        <result column="approver" property="approver" />
        <result column="create_time" property="createTime" />
        <result column="del_flag" property="delFlag" />
    </resultMap>
    <select id="getLogList" resultType="java.util.Map">
        SELECT log.id,log.type,log.money,log.approver,log.create_time createTime ,
               cdb.`name` AS currentBuilding,cdf.floor AS currentFloor,
               cd.room_no AS currentRoom, cbed.bed_code AS currentBed,
               tdb.`name` AS targetBuilding, tdf.floor AS targetFloor,
               td.room_no AS targetRoom, tbed.bed_code AS targetBed,
               s.`name` AS stuName,s.gender AS stuGender
        FROM dms_change_log log
                 LEFT JOIN dms_dormitory cd ON log.current_dorm_id = cd.id
                 LEFT JOIN dms_dormitory_bed cbed ON cbed.id = log.current_bed_id
                 LEFT JOIN dms_dormitory_floor cdf ON cd.floor_id = cdf.id
                 LEFT JOIN dms_dormitory_building cdb ON cdb.id = cdf.building_id
                 LEFT JOIN dms_dormitory td ON log.target_dorm_id = td.id
                 LEFT JOIN dms_dormitory_bed tbed ON tbed.id = log.target_bed_id
                 LEFT JOIN dms_dormitory_floor tdf ON td.floor_id = tdf.id
                 LEFT JOIN dms_dormitory_building tdb ON tdb.id = tdf.building_id
                 LEFT JOIN srs_student s ON log.stu_no = s.stu_no
        <where>
            <if test="classId != null">and s.class_id = #{classId}</if>
            <if test="stuId != null">and s.stu_id = #{stuId}</if>
            <if test="name != null">and s.name like '%' #{name} '%'</if>
            <if test="type != null">and log.type = #{type}</if>
        </where>
        order by s.name
    </select>

</mapper>
