<?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.AppClientVersionDao">
	<sql id="columns">
		app_id,client_ip,client_version,report_time
	</sql>

	<insert id="saveOrUpdateClientVersion" parameterType="AppClientVersion" keyProperty="id"
		useGeneratedKeys="true">
		insert into app_client_version_statistic(<include refid="columns"/>)
		values(#{appId},#{clientIp},#{clientVersion},#{reportTime})
		on duplicate key
		update client_version=#{clientVersion},report_time=#{reportTime}
	</insert>
	
	<select id="getByClientIp" resultType="AppClientVersion">
		select id,<include refid="columns"/> from app_client_version_statistic where client_ip=#{clientIp}
	</select>
	
	<select id="getAppAllClientVersion" resultType="AppClientVersion">
		select id,<include refid="columns"/> from app_client_version_statistic where app_id=#{appId}
	</select>
	
	<select id="getAll" resultType="AppClientVersion">
		select id,<include refid="columns"/> from app_client_version_statistic where 1=1
		<choose>
        	<when test="appId > 0">
        	 	and app_id=#{appId}
        	</when>
        </choose>
	</select>

</mapper>