<?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.gxwebsoft.dormitory.mapper.DormitoryBedMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*, b.name AS buildingName, c.name AS floorName, d.name AS recordName, e.real_name AS realName, e.phone AS phone, e.avatar
        FROM dormitory_bed a
        LEFT JOIN dormitory_building b ON a.building_id = b.id
        LEFT JOIN dormitory_floor c ON a.floor_id = c.id
        LEFT JOIN dormitory_record d ON a.record_id = d.id
        LEFT JOIN shop_user e ON a.user_id = e.user_id
        <where>
            <if test="param.id != null">
                AND a.id = #{param.id}
            </if>
            <if test="param.name != null">
                AND a.name LIKE CONCAT('%', #{param.name}, '%')
            </if>
            <if test="param.code != null">
                AND a.code LIKE CONCAT('%', #{param.code}, '%')
            </if>
            <if test="param.buildingId != null">
                AND a.building_id = #{param.buildingId}
            </if>
            <if test="param.floorId != null">
                AND a.floor_id = #{param.floorId}
            </if>
            <if test="param.recordId != null">
              AND a.record_id = #{param.recordId}
            </if>
            <if test="param.userId != null">
              AND a.user_id = #{param.userId}
            </if>
            <if test="param.bunk != null">
                AND a.bunk = #{param.bunk}
            </if>
            <if test="param.chargingPort != null">
                AND a.charging_port = #{param.chargingPort}
            </if>
            <if test="param.sortNumber != null">
                AND a.sort_number = #{param.sortNumber}
            </if>
            <if test="param.comments != null">
                AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
            </if>
            <if test="param.status != null">
                AND a.status = #{param.status}
            </if>
            <if test="param.createTimeStart != null">
                AND a.create_time &gt;= #{param.createTimeStart}
            </if>
            <if test="param.createTimeEnd != null">
                AND a.create_time &lt;= #{param.createTimeEnd}
            </if>
            <if test="param.keywords != null">
                AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%')
                )
              </if>
        </where>
    </sql>

    <!-- 分页查询 -->
    <select id="selectPageRel" resultType="com.gxwebsoft.dormitory.entity.DormitoryBed">
        <include refid="selectSql"></include>
    </select>

    <!-- 查询全部 -->
    <select id="selectListRel" resultType="com.gxwebsoft.dormitory.entity.DormitoryBed">
        <include refid="selectSql"></include>
    </select>

</mapper>
