<?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.house.mapper.InfoMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*,
               b.nickname,b.avatar,b.grade_id,
               c.name as gradeName
        FROM house_info a
        LEFT JOIN sys_user b ON a.user_id = b.user_id
        LEFT JOIN shop_user_grade c ON b.grade_id = c.grade_id
        <where>
            <if test="param.houseId != null">
                AND a.house_id = #{param.houseId}
            </if>
            <if test="param.houseTitle != null">
                AND a.house_title LIKE CONCAT('%', #{param.houseTitle}, '%')
            </if>
            <if test="param.cityByHouse != null">
                AND a.city_by_house LIKE CONCAT('%', #{param.cityByHouse}, '%')
            </if>
            <if test="param.houseType != null">
                AND a.house_type LIKE CONCAT('%', #{param.houseType}, '%')
            </if>
            <if test="param.leaseMethod != null">
                AND a.lease_method LIKE CONCAT('%', #{param.leaseMethod}, '%')
            </if>
            <if test="param.rent != null">
                AND a.rent = #{param.rent}
            </if>
            <if test="param.monthlyRent != null">
                AND a.monthly_rent = #{param.monthlyRent}
            </if>
            <if test="param.extent != null">
                AND a.extent LIKE CONCAT('%', #{param.extent}, '%')
            </if>
            <if test="param.floor != null">
                AND a.floor LIKE CONCAT('%', #{param.floor}, '%')
            </if>
            <if test="param.roomNumber != null">
                AND a.room_number LIKE CONCAT('%', #{param.roomNumber}, '%')
            </if>
            <if test="param.realName != null">
                AND a.real_name LIKE CONCAT('%', #{param.realName}, '%')
            </if>
            <if test="param.phone != null">
                AND a.phone LIKE CONCAT('%', #{param.phone}, '%')
            </if>
            <if test="param.password != null">
                AND a.password LIKE CONCAT('%', #{param.password}, '%')
            </if>
            <if test="param.toward != null">
                AND a.toward LIKE CONCAT('%', #{param.toward}, '%')
            </if>
            <if test="param.houseLabel != null">
                AND a.house_label LIKE CONCAT('%', #{param.houseLabel}, '%')
            </if>
            <if test="param.files != null">
                AND a.files LIKE CONCAT('%', #{param.files}, '%')
            </if>
            <if test="param.content != null">
                AND a.content LIKE CONCAT('%', #{param.content}, '%')
            </if>
            <if test="param.expirationTime != null">
                AND a.expiration_time LIKE CONCAT('%', #{param.expirationTime}, '%')
            </if>
            <if test="param.province != null">
                AND a.province LIKE CONCAT('%', #{param.province}, '%')
            </if>
            <if test="param.city != null">
                AND a.city LIKE CONCAT('%', #{param.city}, '%')
            </if>
            <if test="param.region != null">
                AND a.region LIKE CONCAT('%', #{param.region}, '%')
            </if>
            <if test="param.area != null">
                AND a.area LIKE CONCAT('%', #{param.area}, '%')
            </if>
            <if test="param.address != null">
                AND a.address LIKE CONCAT('%', #{param.address}, '%')
            </if>
            <if test="param.comments != null">
                AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
            </if>
            <if test="param.authentication != null">
                AND a.authentication = #{param.authentication}
            </if>
            <if test="param.status != null">
                AND a.status = #{param.status}
            </if>
            <if test="param.sortNumber != null">
                AND a.sort_number = #{param.sortNumber}
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </if>
            <if test="param.deleted != null">
                AND a.deleted = #{param.deleted}
            </if>
            <if test="param.deleted == null">
                AND a.deleted = 0
            </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.house_title LIKE CONCAT('%', #{param.keywords}, '%')
            OR b.nickname = #{param.keywords}
            )
          </if>
        </where>
    </sql>

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

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

</mapper>
