<?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.ytpm.dao.AdSourceMapper">

    <insert id="insertOne">
        insert into yt_app_ad_source
        (
            ad_source_id,
            name,
            placement_id,
            type,
            mix_format,
            enabled
        )
        values
            (
                #{adSourceId},
                #{name},
                #{placementId},
                #{type},
                #{mixFormat},
                #{enabled}
            )
    </insert>

    <update id="update">
        update yt_app_ad_source
        <set>
            <if test="name !=null">
                name = #{name},
            </if>
            <if test="placementId !=null">
                placement_id = #{placementId},
            </if>
            <if test="type !=null">
                type = #{type},
            </if>
            <if test="mixFormat !=null">
                mix_format = #{mixFormat},
            </if>
            <if test="enabled !=null">
                enabled = #{enabled},
            </if>
        </set>
        where ad_source_id = #{adSourceId}
    </update>

    <select id="adSourceList" resultType="com.ytpm.agent.view.AgentAdSourceView">
        select
            ad_source_id, name, type, mix_format,placement_id
        from yt_app_ad_source
        <where>
            <if test="placementId != null">
                placement_id=#{placementId}
            </if>
            <if test="name != null and name != ''">
                AND name LIKE CONCAT('%', #{name}, '%')
            </if>
            and enabled=1
        </where>
    </select>

</mapper>