<?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.ChannelMapper">
    <insert id="insert">
        insert into yt_channel
            (
             channel_id,
             channel_name,
             login_type,
             channel_account,
             channel_pwd,
             channel_status,
             api_key,
             api_secret,
             remark,
             ad_platform_type
            )
        values
            (
                #{channelId},
                #{channelName},
                #{loginType},
                #{channelAccount},
                #{channelPwd},
                #{channelStatus},
                #{apiKey},
                #{apiSecret},
                #{remark},
                #{adPlatformType}
            )
    </insert>
    <update id="update">
        update yt_channel
        <set>
            <if test="channelName !=null">
                channel_name = #{channelName},
            </if>
            <if test="channelStatus !=null">
                channel_status = #{channelStatus},
            </if>
            <if test="apiKey !=null">
                api_key = #{apiKey},
            </if>
            <if test="apiSecret !=null">
                api_secret = #{apiSecret},
            </if>
            <if test="remark !=null">
                remark = #{remark},
            </if>
            <if test="enabled !=null">
                enabled = #{enabled},
            </if>
            <if test="adPlatformType !=null">
                ad_platform_type = #{adPlatformType},
            </if>
            <if test="channelAccount !=null">
                channel_account = #{channelAccount},
            </if>
            <if test="channelPwd !=null">
                channel_pwd = #{channelPwd},
            </if>
            <if test="loginType !=null">
                login_type = #{loginType},
            </if>
            <if test="networkId !=null">
                network_id=#{networkId}
            </if>
        </set>
        where channel_id = #{channelId}
    </update>

    <select id="channelList" resultType="com.ytpm.agent.view.AgentChannelView">
        select
            channel_id, channel_name, login_type, channel_account, channel_pwd, channel_status, api_key, api_secret, remark, enabled,ad_platform_type,network_id
        from yt_channel
        where enabled = 1
    </select>
    
    <select id="relativeChannel" resultType="com.ytpm.agent.view.AgentChannelView">
        select
            channel_id, channel_name, login_type, channel_account, channel_pwd, channel_status, api_key, api_secret, remark, enabled,ad_platform_type
        from yt_channel
        where enabled = 1 and  channel_id not in (select channel_id from yt_app_channel_relative where app_id=#{appId})
    </select>
</mapper>