<?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.community.huiju.dao.TpRentalHouseMapper" >
  <resultMap id="BaseResultMap" type="com.community.huiju.model.TpRentalHouse" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="community_id" property="communityId" jdbcType="INTEGER" />
    <result column="house_name" property="houseName" jdbcType="VARCHAR" />
    <result column="rental_price" property="rentalPrice" jdbcType="VARCHAR" />
    <result column="area" property="area" jdbcType="VARCHAR" />
    <result column="rental_type" property="rentalType" jdbcType="VARCHAR" />
    <result column="house_type" property="houseType" jdbcType="VARCHAR" />
    <result column="house_status" property="houseStatus" jdbcType="VARCHAR" />
    <result column="house_level" property="houseLevel" jdbcType="VARCHAR" />
    <result column="house_label" property="houseLabel" jdbcType="VARCHAR" />
    <result column="sort" property="sort" jdbcType="INTEGER" />
    <result column="house_tel" property="houseTel" jdbcType="VARCHAR" />
    <result column="community_address" property="communityAddress" jdbcType="VARCHAR" />
    <result column="community_longitude" property="communityLongitude" jdbcType="VARCHAR" />
    <result column="community_latitude" property="communityLatitude" jdbcType="VARCHAR" />
    <result column="bed" property="bed" jdbcType="VARCHAR" />
    <result column="mattress" property="mattress" jdbcType="VARCHAR" />
    <result column="wardrobe" property="wardrobe" jdbcType="VARCHAR" />
    <result column="sofa" property="sofa" jdbcType="VARCHAR" />
    <result column="washing_machine" property="washingMachine" jdbcType="VARCHAR" />
    <result column="air_conditioning" property="airConditioning" jdbcType="VARCHAR" />
    <result column="fridge" property="fridge" jdbcType="VARCHAR" />
    <result column="TV" property="tv" jdbcType="VARCHAR" />
    <result column="smart_lock" property="smartLock" jdbcType="VARCHAR" />
    <result column="water_heater" property="waterHeater" jdbcType="VARCHAR" />
    <result column="desk" property="desk" jdbcType="VARCHAR" />
    <result column="chair" property="chair" jdbcType="VARCHAR" />
    <result column="WiFi" property="wifi" jdbcType="VARCHAR" />
    <result column="kitchen" property="kitchen" jdbcType="VARCHAR" />
    <result column="bathroom" property="bathroom" jdbcType="VARCHAR" />
    <result column="balcony" property="balcony" jdbcType="VARCHAR" />
    <result column="create_date" property="createDate" jdbcType="TIMESTAMP" />
    <result column="create_user" property="createUser" jdbcType="INTEGER" />
    <result column="update_date" property="updateDate" jdbcType="TIMESTAMP" />
    <result column="update_user" property="updateUser" jdbcType="INTEGER" />
  </resultMap>
  <resultMap id="ResultMapWithBLOBs" type="com.community.huiju.model.TpRentalHouse" extends="BaseResultMap" >
    <result column="house_introduction" property="houseIntroduction" jdbcType="LONGVARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, community_id, house_name, rental_price, area, rental_type, house_type, house_status,
    house_level, house_label, sort, house_tel, community_address, community_longitude,
    community_latitude, bed, mattress, wardrobe, sofa, washing_machine, air_conditioning,
    fridge, TV, smart_lock, water_heater, desk, chair, WiFi, kitchen, bathroom, balcony,
    create_date, create_user, update_date, update_user
  </sql>
  <sql id="Blob_Column_List" >
    house_introduction
  </sql>
  <select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.Integer" >
    select
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from tp_rental_house
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from tp_rental_house
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.community.huiju.model.TpRentalHouse" >
    insert into tp_rental_house (id, community_id, house_name,
      rental_price, area, rental_type,
      house_type, house_status, house_level,
      house_label, sort, house_tel,
      community_address, community_longitude, community_latitude,
      bed, mattress, wardrobe,
      sofa, washing_machine, air_conditioning,
      fridge, TV, smart_lock,
      water_heater, desk, chair,
      WiFi, kitchen, bathroom,
      balcony, create_date, create_user,
      update_date, update_user, house_introduction
      )
    values (#{id,jdbcType=INTEGER}, #{communityId,jdbcType=INTEGER}, #{houseName,jdbcType=VARCHAR},
      #{rentalPrice,jdbcType=VARCHAR}, #{area,jdbcType=VARCHAR}, #{rentalType,jdbcType=VARCHAR},
      #{houseType,jdbcType=VARCHAR}, #{houseStatus,jdbcType=VARCHAR}, #{houseLevel,jdbcType=VARCHAR},
      #{houseLabel,jdbcType=VARCHAR}, #{sort,jdbcType=INTEGER}, #{houseTel,jdbcType=VARCHAR},
      #{communityAddress,jdbcType=VARCHAR}, #{communityLongitude,jdbcType=VARCHAR}, #{communityLatitude,jdbcType=VARCHAR},
      #{bed,jdbcType=VARCHAR}, #{mattress,jdbcType=VARCHAR}, #{wardrobe,jdbcType=VARCHAR},
      #{sofa,jdbcType=VARCHAR}, #{washingMachine,jdbcType=VARCHAR}, #{airConditioning,jdbcType=VARCHAR},
      #{fridge,jdbcType=VARCHAR}, #{tv,jdbcType=VARCHAR}, #{smartLock,jdbcType=VARCHAR},
      #{waterHeater,jdbcType=VARCHAR}, #{desk,jdbcType=VARCHAR}, #{chair,jdbcType=VARCHAR},
      #{wifi,jdbcType=VARCHAR}, #{kitchen,jdbcType=VARCHAR}, #{bathroom,jdbcType=VARCHAR},
      #{balcony,jdbcType=VARCHAR}, #{createDate,jdbcType=TIMESTAMP}, #{createUser,jdbcType=INTEGER},
      #{updateDate,jdbcType=TIMESTAMP}, #{updateUser,jdbcType=INTEGER}, #{houseIntroduction,jdbcType=LONGVARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.community.huiju.model.TpRentalHouse" >
    insert into tp_rental_house
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="communityId != null" >
        community_id,
      </if>
      <if test="houseName != null" >
        house_name,
      </if>
      <if test="rentalPrice != null" >
        rental_price,
      </if>
      <if test="area != null" >
        area,
      </if>
      <if test="rentalType != null" >
        rental_type,
      </if>
      <if test="houseType != null" >
        house_type,
      </if>
      <if test="houseStatus != null" >
        house_status,
      </if>
      <if test="houseLevel != null" >
        house_level,
      </if>
      <if test="houseLabel != null" >
        house_label,
      </if>
      <if test="sort != null" >
        sort,
      </if>
      <if test="houseTel != null" >
        house_tel,
      </if>
      <if test="communityAddress != null" >
        community_address,
      </if>
      <if test="communityLongitude != null" >
        community_longitude,
      </if>
      <if test="communityLatitude != null" >
        community_latitude,
      </if>
      <if test="bed != null" >
        bed,
      </if>
      <if test="mattress != null" >
        mattress,
      </if>
      <if test="wardrobe != null" >
        wardrobe,
      </if>
      <if test="sofa != null" >
        sofa,
      </if>
      <if test="washingMachine != null" >
        washing_machine,
      </if>
      <if test="airConditioning != null" >
        air_conditioning,
      </if>
      <if test="fridge != null" >
        fridge,
      </if>
      <if test="tv != null" >
        TV,
      </if>
      <if test="smartLock != null" >
        smart_lock,
      </if>
      <if test="waterHeater != null" >
        water_heater,
      </if>
      <if test="desk != null" >
        desk,
      </if>
      <if test="chair != null" >
        chair,
      </if>
      <if test="wifi != null" >
        WiFi,
      </if>
      <if test="kitchen != null" >
        kitchen,
      </if>
      <if test="bathroom != null" >
        bathroom,
      </if>
      <if test="balcony != null" >
        balcony,
      </if>
      <if test="createDate != null" >
        create_date,
      </if>
      <if test="createUser != null" >
        create_user,
      </if>
      <if test="updateDate != null" >
        update_date,
      </if>
      <if test="updateUser != null" >
        update_user,
      </if>
      <if test="houseIntroduction != null" >
        house_introduction,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="communityId != null" >
        #{communityId,jdbcType=INTEGER},
      </if>
      <if test="houseName != null" >
        #{houseName,jdbcType=VARCHAR},
      </if>
      <if test="rentalPrice != null" >
        #{rentalPrice,jdbcType=VARCHAR},
      </if>
      <if test="area != null" >
        #{area,jdbcType=VARCHAR},
      </if>
      <if test="rentalType != null" >
        #{rentalType,jdbcType=VARCHAR},
      </if>
      <if test="houseType != null" >
        #{houseType,jdbcType=VARCHAR},
      </if>
      <if test="houseStatus != null" >
        #{houseStatus,jdbcType=VARCHAR},
      </if>
      <if test="houseLevel != null" >
        #{houseLevel,jdbcType=VARCHAR},
      </if>
      <if test="houseLabel != null" >
        #{houseLabel,jdbcType=VARCHAR},
      </if>
      <if test="sort != null" >
        #{sort,jdbcType=INTEGER},
      </if>
      <if test="houseTel != null" >
        #{houseTel,jdbcType=VARCHAR},
      </if>
      <if test="communityAddress != null" >
        #{communityAddress,jdbcType=VARCHAR},
      </if>
      <if test="communityLongitude != null" >
        #{communityLongitude,jdbcType=VARCHAR},
      </if>
      <if test="communityLatitude != null" >
        #{communityLatitude,jdbcType=VARCHAR},
      </if>
      <if test="bed != null" >
        #{bed,jdbcType=VARCHAR},
      </if>
      <if test="mattress != null" >
        #{mattress,jdbcType=VARCHAR},
      </if>
      <if test="wardrobe != null" >
        #{wardrobe,jdbcType=VARCHAR},
      </if>
      <if test="sofa != null" >
        #{sofa,jdbcType=VARCHAR},
      </if>
      <if test="washingMachine != null" >
        #{washingMachine,jdbcType=VARCHAR},
      </if>
      <if test="airConditioning != null" >
        #{airConditioning,jdbcType=VARCHAR},
      </if>
      <if test="fridge != null" >
        #{fridge,jdbcType=VARCHAR},
      </if>
      <if test="tv != null" >
        #{tv,jdbcType=VARCHAR},
      </if>
      <if test="smartLock != null" >
        #{smartLock,jdbcType=VARCHAR},
      </if>
      <if test="waterHeater != null" >
        #{waterHeater,jdbcType=VARCHAR},
      </if>
      <if test="desk != null" >
        #{desk,jdbcType=VARCHAR},
      </if>
      <if test="chair != null" >
        #{chair,jdbcType=VARCHAR},
      </if>
      <if test="wifi != null" >
        #{wifi,jdbcType=VARCHAR},
      </if>
      <if test="kitchen != null" >
        #{kitchen,jdbcType=VARCHAR},
      </if>
      <if test="bathroom != null" >
        #{bathroom,jdbcType=VARCHAR},
      </if>
      <if test="balcony != null" >
        #{balcony,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null" >
        #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="createUser != null" >
        #{createUser,jdbcType=INTEGER},
      </if>
      <if test="updateDate != null" >
        #{updateDate,jdbcType=TIMESTAMP},
      </if>
      <if test="updateUser != null" >
        #{updateUser,jdbcType=INTEGER},
      </if>
      <if test="houseIntroduction != null" >
        #{houseIntroduction,jdbcType=LONGVARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.community.huiju.model.TpRentalHouse" >
    update tp_rental_house
    <set >
      <if test="communityId != null" >
        community_id = #{communityId,jdbcType=INTEGER},
      </if>
      <if test="houseName != null" >
        house_name = #{houseName,jdbcType=VARCHAR},
      </if>
      <if test="rentalPrice != null" >
        rental_price = #{rentalPrice,jdbcType=VARCHAR},
      </if>
      <if test="area != null" >
        area = #{area,jdbcType=VARCHAR},
      </if>
      <if test="rentalType != null" >
        rental_type = #{rentalType,jdbcType=VARCHAR},
      </if>
      <if test="houseType != null" >
        house_type = #{houseType,jdbcType=VARCHAR},
      </if>
      <if test="houseStatus != null" >
        house_status = #{houseStatus,jdbcType=VARCHAR},
      </if>
      <if test="houseLevel != null" >
        house_level = #{houseLevel,jdbcType=VARCHAR},
      </if>
      <if test="houseLabel != null" >
        house_label = #{houseLabel,jdbcType=VARCHAR},
      </if>
      <if test="sort != null" >
        sort = #{sort,jdbcType=INTEGER},
      </if>
      <if test="houseTel != null" >
        house_tel = #{houseTel,jdbcType=VARCHAR},
      </if>
      <if test="communityAddress != null" >
        community_address = #{communityAddress,jdbcType=VARCHAR},
      </if>
      <if test="communityLongitude != null" >
        community_longitude = #{communityLongitude,jdbcType=VARCHAR},
      </if>
      <if test="communityLatitude != null" >
        community_latitude = #{communityLatitude,jdbcType=VARCHAR},
      </if>
      <if test="bed != null" >
        bed = #{bed,jdbcType=VARCHAR},
      </if>
      <if test="mattress != null" >
        mattress = #{mattress,jdbcType=VARCHAR},
      </if>
      <if test="wardrobe != null" >
        wardrobe = #{wardrobe,jdbcType=VARCHAR},
      </if>
      <if test="sofa != null" >
        sofa = #{sofa,jdbcType=VARCHAR},
      </if>
      <if test="washingMachine != null" >
        washing_machine = #{washingMachine,jdbcType=VARCHAR},
      </if>
      <if test="airConditioning != null" >
        air_conditioning = #{airConditioning,jdbcType=VARCHAR},
      </if>
      <if test="fridge != null" >
        fridge = #{fridge,jdbcType=VARCHAR},
      </if>
      <if test="tv != null" >
        TV = #{tv,jdbcType=VARCHAR},
      </if>
      <if test="smartLock != null" >
        smart_lock = #{smartLock,jdbcType=VARCHAR},
      </if>
      <if test="waterHeater != null" >
        water_heater = #{waterHeater,jdbcType=VARCHAR},
      </if>
      <if test="desk != null" >
        desk = #{desk,jdbcType=VARCHAR},
      </if>
      <if test="chair != null" >
        chair = #{chair,jdbcType=VARCHAR},
      </if>
      <if test="wifi != null" >
        WiFi = #{wifi,jdbcType=VARCHAR},
      </if>
      <if test="kitchen != null" >
        kitchen = #{kitchen,jdbcType=VARCHAR},
      </if>
      <if test="bathroom != null" >
        bathroom = #{bathroom,jdbcType=VARCHAR},
      </if>
      <if test="balcony != null" >
        balcony = #{balcony,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null" >
        create_date = #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="createUser != null" >
        create_user = #{createUser,jdbcType=INTEGER},
      </if>
      <if test="updateDate != null" >
        update_date = #{updateDate,jdbcType=TIMESTAMP},
      </if>
      <if test="updateUser != null" >
        update_user = #{updateUser,jdbcType=INTEGER},
      </if>
      <if test="houseIntroduction != null" >
        house_introduction = #{houseIntroduction,jdbcType=LONGVARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.community.huiju.model.TpRentalHouse" >
    update tp_rental_house
    set community_id = #{communityId,jdbcType=INTEGER},
      house_name = #{houseName,jdbcType=VARCHAR},
      rental_price = #{rentalPrice,jdbcType=VARCHAR},
      area = #{area,jdbcType=VARCHAR},
      rental_type = #{rentalType,jdbcType=VARCHAR},
      house_type = #{houseType,jdbcType=VARCHAR},
      house_status = #{houseStatus,jdbcType=VARCHAR},
      house_level = #{houseLevel,jdbcType=VARCHAR},
      house_label = #{houseLabel,jdbcType=VARCHAR},
      sort = #{sort,jdbcType=INTEGER},
      house_tel = #{houseTel,jdbcType=VARCHAR},
      community_address = #{communityAddress,jdbcType=VARCHAR},
      community_longitude = #{communityLongitude,jdbcType=VARCHAR},
      community_latitude = #{communityLatitude,jdbcType=VARCHAR},
      bed = #{bed,jdbcType=VARCHAR},
      mattress = #{mattress,jdbcType=VARCHAR},
      wardrobe = #{wardrobe,jdbcType=VARCHAR},
      sofa = #{sofa,jdbcType=VARCHAR},
      washing_machine = #{washingMachine,jdbcType=VARCHAR},
      air_conditioning = #{airConditioning,jdbcType=VARCHAR},
      fridge = #{fridge,jdbcType=VARCHAR},
      TV = #{tv,jdbcType=VARCHAR},
      smart_lock = #{smartLock,jdbcType=VARCHAR},
      water_heater = #{waterHeater,jdbcType=VARCHAR},
      desk = #{desk,jdbcType=VARCHAR},
      chair = #{chair,jdbcType=VARCHAR},
      WiFi = #{wifi,jdbcType=VARCHAR},
      kitchen = #{kitchen,jdbcType=VARCHAR},
      bathroom = #{bathroom,jdbcType=VARCHAR},
      balcony = #{balcony,jdbcType=VARCHAR},
      create_date = #{createDate,jdbcType=TIMESTAMP},
      create_user = #{createUser,jdbcType=INTEGER},
      update_date = #{updateDate,jdbcType=TIMESTAMP},
      update_user = #{updateUser,jdbcType=INTEGER},
      house_introduction = #{houseIntroduction,jdbcType=LONGVARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.community.huiju.model.TpRentalHouse" >
    update tp_rental_house
    set community_id = #{communityId,jdbcType=INTEGER},
      house_name = #{houseName,jdbcType=VARCHAR},
      rental_price = #{rentalPrice,jdbcType=VARCHAR},
      area = #{area,jdbcType=VARCHAR},
      rental_type = #{rentalType,jdbcType=VARCHAR},
      house_type = #{houseType,jdbcType=VARCHAR},
      house_status = #{houseStatus,jdbcType=VARCHAR},
      house_level = #{houseLevel,jdbcType=VARCHAR},
      house_label = #{houseLabel,jdbcType=VARCHAR},
      sort = #{sort,jdbcType=INTEGER},
      house_tel = #{houseTel,jdbcType=VARCHAR},
      community_address = #{communityAddress,jdbcType=VARCHAR},
      community_longitude = #{communityLongitude,jdbcType=VARCHAR},
      community_latitude = #{communityLatitude,jdbcType=VARCHAR},
      bed = #{bed,jdbcType=VARCHAR},
      mattress = #{mattress,jdbcType=VARCHAR},
      wardrobe = #{wardrobe,jdbcType=VARCHAR},
      sofa = #{sofa,jdbcType=VARCHAR},
      washing_machine = #{washingMachine,jdbcType=VARCHAR},
      air_conditioning = #{airConditioning,jdbcType=VARCHAR},
      fridge = #{fridge,jdbcType=VARCHAR},
      TV = #{tv,jdbcType=VARCHAR},
      smart_lock = #{smartLock,jdbcType=VARCHAR},
      water_heater = #{waterHeater,jdbcType=VARCHAR},
      desk = #{desk,jdbcType=VARCHAR},
      chair = #{chair,jdbcType=VARCHAR},
      WiFi = #{wifi,jdbcType=VARCHAR},
      kitchen = #{kitchen,jdbcType=VARCHAR},
      bathroom = #{bathroom,jdbcType=VARCHAR},
      balcony = #{balcony,jdbcType=VARCHAR},
      create_date = #{createDate,jdbcType=TIMESTAMP},
      create_user = #{createUser,jdbcType=INTEGER},
      update_date = #{updateDate,jdbcType=TIMESTAMP},
      update_user = #{updateUser,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <select id="getRentalHouse" resultMap="ResultMapWithBLOBs">
    select
    *
    from
    tp_rental_house rh
    <where>

      <if test="houseName !=null and houseName != ''" >
        AND rh.house_name like concat('%',#{houseName},'%')
      </if>
      <if test="rentalType == 1" >
        and rh.rental_type = '1'
      </if>
      <if test="rentalType == 2" >
        and rh.rental_type = '2'
      </if>

      <if test="houseType == 1" >
        and rh.house_type = '1'
      </if>

      <if test="houseType == 2" >
        and rh.house_type = '2'
      </if>

      <if test="houseType == 3" >
        and rh.house_type = '3'
      </if>

      <if test="houseType == 4" >
        and rh.house_type >= '4'
      </if>

      <if test="rentalPrice == 1" >
        and rh.rental_price <![CDATA[<= ]]> 1000
      </if>

      <if test="rentalPrice == 2" >
        and  rh.rental_price <![CDATA[>= ]]> 1000
        and  rh.rental_price <![CDATA[<= ]]> 1500
      </if>

      <if test="rentalPrice == 3" >
        and  rh.rental_price <![CDATA[>= ]]> 1500
        and  rh.rental_price <![CDATA[<= ]]> 2000
      </if>

      <if test="rentalPrice == 4" >
        and  rh.rental_price <![CDATA[>= ]]> 2000
        and  rh.rental_price <![CDATA[<= ]]> 3000
      </if>

      <if test="rentalPrice == 5" >
        and  rh.rental_price <![CDATA[>= ]]> 3000
        and  rh.rental_price<![CDATA[ <= ]]> 4000
      </if>

      <if test="rentalPrice == 6" >
        and  rh.rental_price >= 4000
      </if>
      and community_id = #{communityId}
      and rh.house_status = 1
    </where>
    <if test="priceFluctuate == 3">
      order by rh.sort desc, update_date desc
    </if>

    <if test="priceFluctuate == 1" >
      order by (rh.rental_price+0)  asc, rh.sort desc, update_date desc
    </if>

    <if test="priceFluctuate == 2" >
      order by (rh.rental_price+0)  desc, rh.sort desc, update_date desc
    </if>
  </select>
</mapper>