<?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="KafkaBillDao">
    <resultMap id="KafkaBillMap" type="com.xiaojukeji.kafka.manager.common.entity.pojo.KafkaBillDO">
        <id column="id" property="id" />
        <result column="cluster_id" property="clusterId" />
        <result column="topic_name" property="topicName" />
        <result column="principal"  property="principal" />
        <result column="quota"      property="quota" />
        <result column="cost"       property="cost" />
        <result column="gmt_day"    property="gmtDay" />
        <result column="gmt_create" property="gmtCreate" />
    </resultMap>

    <insert id="replace" parameterType="com.xiaojukeji.kafka.manager.common.entity.pojo.KafkaBillDO" >
      REPLACE INTO kafka_bill (
        cluster_id,
        topic_name,
        principal,
        quota,
        cost,
        gmt_day
      )
      VALUES (
        #{clusterId},
        #{topicName},
        #{principal},
        #{quota},
        #{cost},
        #{gmtDay}
      )
    </insert>

    <select id="getByTopicName" parameterType="java.util.Map" resultMap="KafkaBillMap">
        SELECT * FROM kafka_bill
        WHERE cluster_id=#{clusterId}
          AND topic_name=#{topicName}
          AND gmt_create>=#{startTime} AND #{endTime} >= gmt_create
    </select>

    <select id="getByPrincipal" parameterType="java.util.Map" resultMap="KafkaBillMap">
        SELECT * FROM kafka_bill
        WHERE principal=#{principal}
          AND gmt_create>=#{startTime} AND #{endTime} >= gmt_create
    </select>

    <select id="getByTimeBetween" parameterType="java.util.Map" resultMap="KafkaBillMap">
        SELECT * FROM kafka_bill
        WHERE gmt_create>=#{startTime} AND #{endTime} >= gmt_create
    </select>

    <select id="getByGmtDay" parameterType="java.util.Map" resultMap="KafkaBillMap">
        SELECT * FROM kafka_bill
        WHERE gmt_day=#{gmtDay}
    </select>
</mapper>