<?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="adGroupPlaceSqlMapper">
	<sql id="base_column">
		id,
		adgroup_id  as adGroupId,
		place_id as placeId
	</sql>

	<insert id="addPlace" parameterType="com.cloudcross.ssp.model.AdGroupPlace">
		insert into
		t_adgroup_place (adgroup_id,place_id,supdated,status)
		values (#{adGroupId},#{placeId},#{supdated},#{status})
	</insert>

	<select id="findAll" parameterType="long" resultType="com.cloudcross.ssp.model.AdGroupPlace">
		select
		<include refid="base_column"/>
		from t_adgroup_place
		<where>
		adgroup_id = #{adGroupId}
		</where>
	</select>
	
	<delete id="delete" parameterType="long"> 
	delete from t_adgroup_place where adgroup_id = #{adGroupId} 
	</delete>
	
	<update id="updatedSupdate" parameterType="java.util.Map">
		update t_adgroup_place set supdated=#{supdated} where adgroup_id= #{adGroupId}
	</update>
	
	<select id="findAllByAdGroupId" parameterType="long" resultType="com.cloudcross.ssp.model.AdGroupPlace">
		select
		<include refid="base_column"/>
		from t_adgroup_place
		where adgroup_id = #{adGroupId}
	</select>
	
	<!-- 批量插入 -->
	<insert id="addAdGroupPlaceBatch" parameterType="java.util.Map">
		insert into t_adgroup_place 
		(adgroup_id,place_id,status,supdated)
		values
		<foreach collection="placeIdList" item="placeId" index="index" separator=",">
			(#{adgroupPlace.adGroupId},#{placeId},#{adgroupPlace.status},#{adgroupPlace.supdated})
		</foreach>
	</insert>
	
	<select id="queryPlaceByAdgroupId" parameterType="java.lang.Long" resultType="java.lang.Long">
		select place_id as placeId from t_adgroup_place where status=0 and adgroup_id = #{adgroupId}
	</select>
	
	<update id="updateAdgroupPlaceByAdgroupId" parameterType="java.util.Map">
		update t_adgroup_place set status=-1,supdated=#{supdated} where adgroup_id= #{adgroupId}
	</update>
</mapper>