<?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.AppClientCostTimeStatDao">
	<sql id="columns">
		app_id,collect_time,client_ip,report_time,create_time,command,
		median,mean,ninety_percent_max,ninety_nine_percent_max,hundred_max,
		count,instance_host,instance_port,instance_id
	</sql>

	<insert id="save" parameterType="AppClientCostTimeStat"
		keyProperty="id" useGeneratedKeys="true">
		insert into app_client_costtime_minute_stat(<include refid="columns"/>)
		values(#{appId},#{collectTime},#{clientIp},#{reportTime},#{createTime},#{command},
		       #{median},#{mean},#{ninetyPercentMax},#{ninetyNinePercentMax},#{hundredMax},
		       #{count},#{instanceHost},#{instancePort},#{instanceId})
	</insert>
	
	<insert id="batchSave">
		insert into app_client_costtime_minute_stat(<include refid="columns" />)
		values
		<foreach collection="appClientCostTimeStatList" item="clientCostTime" separator=",">
			(#{clientCostTime.appId},#{clientCostTime.collectTime},#{clientCostTime.clientIp},#{clientCostTime.reportTime},#{clientCostTime.createTime},#{clientCostTime.command},
		       #{clientCostTime.median},#{clientCostTime.mean},#{clientCostTime.ninetyPercentMax},#{clientCostTime.ninetyNinePercentMax},#{clientCostTime.hundredMax},
		       #{clientCostTime.count},#{clientCostTime.instanceHost},#{clientCostTime.instancePort},#{clientCostTime.instanceId})
	    </foreach>
	</insert>
	
    <select id="getAppCommandClientToInstanceStat" resultType="AppClientCostTimeStat">
    	select id,<include refid="columns"/>
    	from app_client_costtime_minute_stat
    	where app_id=#{appId} and instance_id=#{instanceId} and client_ip=#{clientIp} and collect_time between #{startTime} and #{endTime} and command=#{command};
    </select>
    
    <select id="getTableMinimumId" resultType="long">
    	select id from app_client_costtime_minute_stat order by id limit 1
    </select>
    
    <select id="getMinimumIdByCollectTime" resultType="long">
    	select id from app_client_costtime_minute_stat where collect_time = #{collectTime} order by id limit 1
    </select>
    
    <delete id="deleteByIds">
    	delete from app_client_costtime_minute_stat where id>=#{startId} and id &lt;#{endId}
    </delete>

</mapper>