<?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.PhoenixSalesOnSaleRoomMapper">
    <resultMap id="BaseResultMap" type="cn.com.countrygarden.bi.main.model.phoenix.PhoenixSalesOnSaleRoom">
        <!--
          WARNING - @mbg.generated
        -->
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="areaid" jdbcType="VARCHAR" property="areaid"/>
        <result column="areaname" jdbcType="VARCHAR" property="areaname"/>
        <result column="roomid" jdbcType="VARCHAR" property="roomid"/>
        <result column="yname" jdbcType="VARCHAR" property="yname"/>
        <result column="bldname" jdbcType="VARCHAR" property="bldname"/>
        <result column="bldid" jdbcType="VARCHAR" property="bldid"/>
        <result column="room" jdbcType="VARCHAR" property="room"/>
        <result column="huxing" jdbcType="VARCHAR" property="huxing"/>
        <result column="bldarea" jdbcType="DECIMAL" property="bldarea"/>
        <result column="inarea" jdbcType="DECIMAL" property="inarea"/>
        <result column="hyarea" jdbcType="DECIMAL" property="hyarea"/>
        <result column="bjj_hyarea" jdbcType="DECIMAL" property="bjjHyarea"/>
        <result column="ytarea" jdbcType="DECIMAL" property="ytarea"/>
        <result column="zdarea" jdbcType="DECIMAL" property="zdarea"/>
        <result column="flatarea" jdbcType="DECIMAL" property="flatarea"/>
        <result column="zhtotal" jdbcType="DECIMAL" property="zhtotal"/>
        <result column="yjprice" jdbcType="DECIMAL" property="yjprice"/>
        <result column="yjsldate" jdbcType="DATE" property="yjsldate"/>
        <result column="htsldate" jdbcType="DATE" property="htsldate"/>
        <result column="usestate" jdbcType="VARCHAR" property="usestate"/>
    </resultMap>

    <insert id="persistence" useGeneratedKeys="true">
        REPLACE INTO phoenix_sales_on_sale_room
        (areaid, areaname, roomid, yname, bldname, bldid, room,
        huxing, bldarea, inarea, hyarea, bjj_hyarea,
        ytarea, zdarea, flatarea, zhtotal, yjprice,
        yjsldate, htsldate, usestate)
        VALUES
        <foreach collection="items" index="index" item="item" separator=",">
            (#{areaId}, #{item.areaname}, #{item.roomid}, #{item.yname}, #{item.bldname}, #{item.bldid}, #{item.room},
            #{item.huxing}, #{item.bldarea}, #{item.inarea}, #{item.hyarea}, #{item.bjjHyarea},
            #{item.ytarea}, #{item.zdarea}, #{item.flatarea}, #{item.zhtotal}, #{item.yjprice},
            #{item.yjsldate}, #{item.htsldate}, #{item.usestate})
        </foreach>
    </insert>

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

    <select id="findLastTimestamp"
            parameterType="map"
            resultMap="BaseResultMap">
    <![CDATA[

SELECT * FROM phoenix_sales_on_sale_room WHERE areaid = #{areaId} ORDER BY timestamp DESC limit 1

        ]]>
  </select>
</mapper>