<?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.tzld.piaoquan.api.dao.mapper.GhDetailMapperExt">

    <insert id="batchInsertGhDetailExt">
        insert into gh_detail_ext (gh_detail_id, video_id, page, title_id, title, cover_id, cover, sort,
                                   is_delete, create_time, update_time)
        values
        <foreach collection="records" item="record" separator=",">
            (#{record.ghDetailId}, #{record.videoId}, #{record.page}, #{record.titleId}, #{record.title},
             #{record.coverId}, #{record.cover}, #{record.sort}, #{record.isDelete},
             #{record.createTime}, #{record.updateTime})
        </foreach>
    </insert>

    <update id="deleteOldGhDetailExt">
        update gh_detail_ext
        set is_delete = 1
        where gh_detail_id in (
            select id from gh_detail where gh_id = #{ghId} and type = #{type}
        )
    </update>

    <select id="getGhDetailExtList" resultType="com.tzld.piaoquan.api.model.po.GhDetailExt">
        select gde.*
        from gh_detail_ext gde
        join gh_detail gd on gde.gh_detail_id = gd.id
        where gd.gh_id = #{ghId}
          and gd.type = #{type}
          and gde.is_delete = 0
    </select>

    <delete id="deleteGzhAutoreplyBehaviorUvTotal">
        delete from gzh_autoreply_behavior_uv_total where dt = #{dt}
    </delete>

    <insert id="batchInsertGzhAutoreplyBehaviorUvTotal">
        insert into gzh_autoreply_behavior_uv_total (dt, channel, gh_id, uv, first_level, create_timestamp)
        values
        <foreach collection="records" item="item" separator=",">
            (#{item.dt}, #{item.channel}, #{item.ghId}, #{item.uv}, #{item.firstLevel}, #{item.createTimestamp})
        </foreach>
    </insert>

</mapper>