<?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="cn.com.countrygarden.bi.main.dao.phoenix.PhoenixSalesRoomMapper">
    <resultMap id="BaseResultMap" type="cn.com.countrygarden.bi.main.model.phoenix.PhoenixSalesRoom">
        <!--
          WARNING - @mbg.generated
        -->
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="areaid" jdbcType="VARCHAR" property="areaid"/>
        <result column="bldid" jdbcType="VARCHAR" property="bldid"/>
        <result column="bldname" jdbcType="VARCHAR" property="bldname"/>
        <result column="roomid" jdbcType="VARCHAR" property="roomid"/>
        <result column="roomname" jdbcType="VARCHAR" property="roomname"/>
        <result column="unit" jdbcType="VARCHAR" property="unit"/>
        <result column="stair" jdbcType="VARCHAR" property="stair"/>
        <result column="roomno" jdbcType="VARCHAR" property="roomno"/>
        <result column="cjarea" jdbcType="DECIMAL" property="cjarea"/>
        <result column="inarea" jdbcType="DECIMAL" property="inarea"/>
        <result column="gtarea" jdbcType="DECIMAL" property="gtarea"/>
        <result column="hyscmj" jdbcType="DECIMAL" property="hyscmj"/>
        <result column="bjj_dxsarea" jdbcType="DECIMAL" property="bjjDxsarea"/>
        <result column="gtb" jdbcType="DECIMAL" property="gtb"/>
        <result column="stru" jdbcType="VARCHAR" property="stru"/>
        <result column="huxing" jdbcType="VARCHAR" property="huxing"/>
        <result column="cg" jdbcType="VARCHAR" property="cg"/>
        <result column="ownershiptype" jdbcType="VARCHAR" property="ownershiptype"/>
        <result column="usenature" jdbcType="VARCHAR" property="usenature"/>
        <result column="state" jdbcType="VARCHAR" property="state"/>
        <result column="roomtype" jdbcType="VARCHAR" property="roomtype"/>
        <result column="usestate" jdbcType="VARCHAR" property="usestate"/>
        <result column="hycode" jdbcType="VARCHAR" property="hycode"/>
        <result column="htsldate" jdbcType="DATE" property="htsldate"/>
        <result column="roomsort" jdbcType="VARCHAR" property="roomsort"/>
        <result column="manageFeeDate" jdbcType="DATE" property="managefeedate"/>
        <result column="timestamp" jdbcType="BIGINT" property="timestamp"/>
    </resultMap>


    <insert id="persistence" useGeneratedKeys="true">
        REPLACE INTO phoenix_sales_room
        (areaid, bldid, bldname, roomid, roomname, unit, stair,
        roomno, cjarea, inarea, gtarea, hyscmj,
        bjj_dxsarea, gtb, stru, huxing, cg,
        ownershiptype, usenature, state, roomtype, usestate,
        hycode, htsldate, roomsort, manageFeeDate, timestamp)
        VALUES
        <foreach collection="items" index="index" item="item" separator=",">
            (#{areaId}, #{item.bldid}, #{item.bldname}, #{item.roomid}, #{item.roomname}, #{item.unit}, #{item.stair},
            #{item.roomno}, #{item.cjarea}, #{item.inarea}, #{item.gtarea}, #{item.hyscmj},
            #{item.bjjDxsarea}, #{item.gtb}, #{item.stru}, #{item.huxing}, #{item.cg},
            #{item.ownershiptype}, #{item.usenature}, #{item.state}, #{item.roomtype}, #{item.usestate},
            #{item.hycode}, #{item.htsldate}, #{item.roomsort}, #{item.managefeedate}, #{item.timestamp})
        </foreach>
    </insert>

    <delete id="truncate">
    TRUNCATE phoenix_sales_room
  </delete>

    <select id="findLastTimestamp"
            parameterType="map"
            resultMap="BaseResultMap">
        <![CDATA[
SELECT * FROM phoenix_sales_room WHERE areaid = #{areaId} ORDER BY timestamp DESC limit 1
        ]]>
    </select>
</mapper>