<?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.xjlrl.XjlrlAdRecordMapper">
    <insert id="addOne">
        insert into yt_dyz_ad_record
        (
            record_id,
            user_id,
            nick_name,
            placement_id,
            ad_source_id,
            revenue,
            network_form_id,
            network_name,
            network_placement_id,
            begin_time,
            finish_time,
            result_json,
            ad_source_index,
            ad_source_type,
            ecpm,
            app_id
        )
        values
            (
                #{recordId},
                #{userId},
                #{nickName},
                #{placementId},
                #{adSourceId},
                #{revenue},
                #{networkFormId},
                #{networkName},
                #{networkPlacementId},
                ifnull(#{beginTime}, now()),
                ifnull(#{finishTime}, now()),
                #{resultJson},
                #{adSourceIndex},
                #{adSourceType},
                #{ecpm},
                #{appId}
            )
    </insert>
    <select id="getByUserId" resultType="com.ytpm.app.model.YtDyzAdRecord">
        select
        record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
        from yt_dyz_ad_record
        where user_id = #{userId}
        <if test="adsourceType != null">
            and ad_source_type = #{adsourceType}
        </if>
        order by finish_time desc
    </select>
    <select id="getByUserIds" resultType="com.ytpm.app.model.YtDyzAdRecord">
        select
        record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
        from yt_dyz_ad_record
        where user_id in
        <foreach collection="userIds.split(',')" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
        order by finish_time
    </select>
</mapper>