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

  <!-- 关联查询sql -->
  <sql id="selectSql">
    SELECT a.*,
    b.nickname,b.avatar,b.grade_id
    FROM house_info a
    LEFT JOIN gxwebsoft_core.sys_user b ON a.user_id = b.user_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.extentStart != null">
        AND a.extent &gt;= #{param.extentStart}
      </if>
      <if test="param.extentEnd != null">
        AND a.extent &lt;= #{param.extentEnd}
      </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.salePrice != null">
        AND a.sale_price = #{param.salePrice}
      </if>
      <if test="param.totalPrice != null">
        AND a.total_Price = #{param.totalPrice}
      </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.recommend != null">
        AND a.recommend = #{param.recommend}
      </if>
      <if test="param.mustSee != null">
        AND a.must_see = #{param.mustSee}
      </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 a.house_id = #{param.keywords}
        OR b.nickname = #{param.keywords}
        OR a.room_number LIKE CONCAT('%', #{param.keywords}, '%')
        )
      </if>
    </where>
    <trim prefix="ORDER BY" suffixOverrides=",">
      <if test="param.sortScene == '综合排序'">
        a.sort_number asc,
      </if>
      <if test="param.sortScene == '最新发布'">
        a.create_time desc,
      </if>
      <if test="param.sortScene == '价格(低-高)'">
        a.monthly_rent asc,
      </if>
      <if test="param.sortScene == '价格(高-低)'">
        a.monthly_rent desc,
      </if>
      <if test="param.sortScene == '面积(小-大)'">
        a.extent asc,
      </if>
      <if test="param.sortScene == '面积(大-小)'">
        a.extent desc,
      </if>
      <if test="param.priceScene != null">
        ABS(a.monthly_rent - #{param.priceScene}),
      </if>

      <if test="param.extentScene != null">
        ABS(a.extent - #{param.extentScene}),
      </if>
    </trim>

  </sql>

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

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

</mapper>
