<?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.PhoenixSalesCustomerMapper">
    <resultMap id="BaseResultMap" type="cn.com.countrygarden.bi.main.model.phoenix.PhoenixSalesCustomer">
        <!--
          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="cstname" jdbcType="VARCHAR" property="cstname"/>
        <result column="card" jdbcType="VARCHAR" property="card"/>
        <result column="cardid" jdbcType="VARCHAR" property="cardid"/>
        <result column="cstxb" jdbcType="VARCHAR" property="cstxb"/>
        <result column="csttel" jdbcType="VARCHAR" property="csttel"/>
        <result column="csthandtel" jdbcType="VARCHAR" property="csthandtel"/>
        <result column="cstaddr" jdbcType="VARCHAR" property="cstaddr"/>
        <result column="roomsort" jdbcType="VARCHAR" property="roomsort"/>
        <result column="timestamp" jdbcType="BIGINT" property="timestamp"/>
    </resultMap>

    <insert id="persistence" useGeneratedKeys="true">
        REPLACE INTO phoenix_sales_customer
        (areaid, bldid, bldname, roomid, cstname, card, cstxb,
        csttel, csthandtel, cstaddr, roomsort, timestamp)
        VALUES
        <foreach collection="items" index="index" item="item" separator=",">
            (#{areaId}, #{item.bldid}, #{item.bldname}, #{item.roomid}, #{item.cstname}, #{item.card}, #{item.cstxb},
            #{item.csttel}, #{item.csthandtel}, #{item.cstaddr}, #{item.roomsort}, #{item.timestamp})
        </foreach>
    </insert>

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

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

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

        ]]>
  </select>
</mapper>