<?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="directSqlMapper">
	<sql id="base_column">
		id ,
		adgroup_id  as adGroupId,
		targettype as directType,
		targetshow as backShow,
		targetdata as data,
		updated
	</sql>

	<insert id="addDirect" parameterType="com.cloudcross.ssp.model.Direct">
		insert into
		t_target_show (adgroup_id,targettype,targetshow,targetdata,updated)
		values (#{adGroupId},#{directType},#{backShow},#{data},#{updated})
	</insert>

	<select id="findByAdGroupId" parameterType="map"  resultType="com.cloudcross.ssp.model.Direct">
		select
		<include refid="base_column" />
		from t_target_show
		where adgroup_id=#{adGroupId}  
			<if test="directType!=null">
				and  targettype=#{directType} 
			</if>
	</select>

	<update id="editDirect" parameterType="com.cloudcross.ssp.model.Direct">
		UPDATE t_target_show
		SET
		targetshow =#{backShow},
		targetdata = #{data},
		updated = #{updated}
		WHERE adgroup_id=#{adGroupId}  and targettype = #{directType}
	</update>

	<delete id="deleteDirect" parameterType="map" >
	    delete from t_target_show where adgroup_id=#{adGroupId}  and targettype = #{directType}
	</delete>

</mapper>