<?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.jay.monitor.data.server.daos.JayMonitorMqMapperExt">
    <insert id="batchPartitionInsert" keyColumn="list.id" keyProperty="list.id"
            useGeneratedKeys="true">
        insert into jay_monitor_mq_${date} (application_name, application_ip, mq_type,
        invoke_type, topic, partition_name,
        msg_id, data_group_name, data_group_key,
        data_id, root_log_id, parent_log_id,
        log_id, `status`, source_time,
        created_time, request_time)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.applicationName,jdbcType=VARCHAR}, #{item.applicationIp,jdbcType=VARCHAR},
            #{item.mqType,jdbcType=VARCHAR},
            #{item.invokeType,jdbcType=VARCHAR}, #{item.topic,jdbcType=VARCHAR}, #{item.partitionName,jdbcType=VARCHAR},
            #{item.msgId,jdbcType=VARCHAR}, #{item.dataGroupName,jdbcType=VARCHAR},
            #{item.dataGroupKey,jdbcType=VARCHAR},
            #{item.dataId,jdbcType=VARCHAR}, #{item.rootLogId,jdbcType=VARCHAR}, #{item.parentLogId,jdbcType=VARCHAR},
            #{item.logId,jdbcType=VARCHAR}, #{item.status,jdbcType=INTEGER}, #{item.sourceTime,jdbcType=TIMESTAMP},
            #{item.createdTime,jdbcType=TIMESTAMP},
            #{item.requestTime,jdbcType=INTEGER}
            )
        </foreach>
    </insert>

    <sql id="Base_Column_List">
    id, application_name, application_ip, mq_type, invoke_type, topic, partition_name,
    msg_id, data_group_name, data_group_key, data_id, root_log_id, parent_log_id, log_id,
    `status`, source_time, created_time,request_time
  </sql>

    <select id="selectPartitionById" resultType="com.jay.monitor.data.server.models.entity.JayMonitorMq">
        select
        <include refid="Base_Column_List"/>
        from jay_monitor_mq_${date}
        where id = #{id,jdbcType=INTEGER}
    </select>


    <select id="selectPartitionByList" resultType="com.jay.monitor.data.server.models.entity.JayMonitorMq">
        select
        <include refid="Base_Column_List"/>
        from jay_monitor_mq_${date}
        <include refid="whereCondition"/>
    </select>

    <sql id="whereCondition">
        <where>
            1=1
            <if test="record.applicationName != null and record.applicationName != ''">
                AND application_name = #{record.applicationName,jdbcType=VARCHAR}
            </if>
            <if test="record.applicationIp != null and record.applicationIp != ''">
                AND application_ip = #{record.applicationIp,jdbcType=VARCHAR}
            </if>
            <if test="record.mqType != null and record.mqType != ''">
                AND mq_type = #{record.mqType,jdbcType=VARCHAR}
            </if>
            <if test="record.invokeType != null and record.invokeType != ''">
                AND invoke_type = #{record.invokeType,jdbcType=VARCHAR}
            </if>
            <if test="record.topic != null and record.topic != ''">
                AND topic = #{record.topic,jdbcType=VARCHAR}
            </if>
            <if test="record.partitionName != null and record.partitionName != ''">
                AND partition_name = #{record.partitionName,jdbcType=VARCHAR}
            </if>
            <if test="record.msgId != null and record.msgId != ''">
                AND msg_id = #{record.msgId,jdbcType=VARCHAR}
            </if>
            <if test="record.dataGroupName != null and record.dataGroupName != ''">
                AND data_group_name = #{record.dataGroupName,jdbcType=VARCHAR}
            </if>
            <if test="record.dataGroupKey != null and record.dataGroupKey != ''">
                AND data_group_key = #{record.dataGroupKey,jdbcType=VARCHAR}
            </if>
            <if test="record.dataId != null and record.dataId != ''">
                AND data_id = #{record.dataId,jdbcType=VARCHAR}
            </if>
            <if test="record.rootLogId != null and record.rootLogId != ''">
                AND root_log_id = #{record.rootLogId,jdbcType=VARCHAR}
            </if>
            <if test="record.parentLogId != null and record.parentLogId != ''">
                AND parent_log_id = #{record.parentLogId,jdbcType=VARCHAR}
            </if>
            <if test="record.logId != null and record.logId != ''">
                AND log_id = #{record.logId,jdbcType=VARCHAR}
            </if>
            <if test="record.status != null and record.status != ''">
                AND `status` = #{record.status,jdbcType=INTEGER}
            </if>
            <if test="record.sourceTime != null and record.sourceTime != ''">
                AND source_time = #{record.sourceTime,jdbcType=TIMESTAMP}
            </if>
            <if test="record.createdTime != null and record.createdTime != ''">
                AND created_time = #{record.createdTime,jdbcType=TIMESTAMP}
            </if>
            <if test="record.requestTime != null and record.requestTime != ''">
                AND request_time >= #{record.requestTime,jdbcType=INTEGER}
            </if>
        </where>
        order by id desc limit ${pageSize}
    </sql>
</mapper>