<?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="dspAgentSqlMapper">

	<sql id="base_column">
		id,token,name,ip,port,updated
	</sql>

	<insert id="add" parameterType="java.util.List">
		insert into t_dsp_agent(token,name,ip,port,updated) values
		<foreach collection="dspAgentList" item="item" index="index" separator=",">
	    	( #{item.token},#{item.name}, #{item.ip}, #{item.port}, NOW() )
        </foreach>
	</insert>
	
	<update id="update" parameterType="java.util.List">
	 	<foreach collection="dspAgentList" item="item" index="index" open="" close="" separator=";">
	        update t_dsp_agent set token = #{item.token}, name = #{item.name},ip = #{item.ip},port = #{item.port},updated = NOW()
	        where id = #{item.id}
         </foreach>
	</update>
	
	<select id="getAll" parameterType="java.util.Map" resultType="com.cloudcross.ssp.model.DspAgent">
		select <include refid="base_column"/> from t_dsp_agent
	</select>
	
	<select id="get" parameterType="java.util.List" resultType="com.cloudcross.ssp.model.DspAgent">
		select 
		<include refid="base_column"/>
		from t_dsp_agent where id in
		<foreach item="id" collection="idList" open="(" separator="," close=")">
			#{id}
		</foreach>
	</select>
	
	<select id="isCheck" parameterType="com.cloudcross.ssp.model.DspAgent" resultType="java.lang.Integer">
		select count(*) from t_dsp_agent where name = #{name} and token = #{token}
	</select>
	
	<select id="selectMaxId" parameterType="java.util.Map" resultType="java.lang.Long">
		select id from t_dsp_agent where token = #{token} and name = #{name}
		<if test="dspId != null and dspId != '' ">
	    	and id != #{dspId}
	    </if>
	</select>
	
</mapper>