<?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.sohu.cache.dao.InstanceSlowLogDao">

    <sql id="instance_slow_log_columns">
        instance_id,app_id,ip,port,slow_log_id,cost_time,command,execute_time,create_time
    </sql>

    <insert id="batchSave">
        insert ignore into instance_slow_log(<include refid="instance_slow_log_columns"/>)
        values
        <foreach collection="instanceSlowLogList" item="instanceSlowLog" separator=",">
        	(#{instanceSlowLog.instanceId},#{instanceSlowLog.appId},#{instanceSlowLog.ip},#{instanceSlowLog.port},#{instanceSlowLog.slowLogId},#{instanceSlowLog.costTime},#{instanceSlowLog.command},#{instanceSlowLog.executeTime},#{instanceSlowLog.createTime})
	    </foreach>
    </insert>
    
    <select id="getByAppId" resultType="InstanceSlowLog">
        select id,<include refid="instance_slow_log_columns"/>
        from instance_slow_log where app_id = #{appId}
    </select>
    
    
    <select id="search" resultType="InstanceSlowLog">
        select id,<include refid="instance_slow_log_columns"/>
        from instance_slow_log where app_id = #{appId} and create_time between DATE_FORMAT(#{startDate}, '%Y-%m-%d') and DATE_FORMAT(#{endDate}, '%Y-%m-%d')
    </select>
    
    <select id="getInstanceSlowLogCountMapByAppId" resultType="hashmap">
        select concat(ip,":",port) as hostPort,count(*) as count
        from instance_slow_log where app_id = #{appId} and create_time between DATE_FORMAT(#{startDate}, '%Y-%m-%d') and DATE_FORMAT(#{endDate}, '%Y-%m-%d') group by hostPort order by count desc
    </select>
    
    <select id="getAppSlowLogCount" resultType="int">
        select count(*) as count
        from instance_slow_log where app_id = #{appId} and create_time between DATE_FORMAT(#{startDate}, '%Y-%m-%d') and DATE_FORMAT(#{endDate}, '%Y-%m-%d')
    </select>

</mapper>