<?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.AppClientValueStatDao">
	<sql id="columns">
		app_id,collect_time,update_time,command,distribute_type,count
	</sql>

	<insert id="batchSave">
		insert into app_client_value_minute_stats(<include refid="columns" />)
		values
		<foreach collection="appClientValueDistriStatTotalList" item="valueDistri" separator=",">
        	(#{valueDistri.appId},#{valueDistri.collectTime},#{valueDistri.updateTime},#{valueDistri.command},#{valueDistri.distributeType},#{valueDistri.count})
	    </foreach>
	    on duplicate key update
	    count = count + #{valueDistri.count}, update_time=now()
	</insert>
	
	<insert id="save">
		insert into app_client_value_minute_stats(<include refid="columns" />)
		values(#{appId},#{collectTime},#{updateTime},#{command},#{distributeType},#{count})
	    on duplicate key update
	    count = count + #{count}, update_time=now()
	</insert>
	
	<select id="getAppValueDistriList" resultType="AppClientValueDistriSimple">
    	select distribute_type, sum(count) as count
    	from app_client_value_minute_stats
    	where app_id=#{appId} and collect_time between #{startTime} and #{endTime}
        group by distribute_type order by distribute_type
    </select>
    
    <delete id="deleteBeforeCollectTime">
    	delete from app_client_value_minute_stats where collect_time &lt;#{collectTime}
    </delete>
    

</mapper>