<?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="cn.reghao.tnb.content.app.vod.db.mapper.VideoStatisticMapper">
    <insert id="save" useGeneratedKeys="true" keyProperty="id">
        insert into vod_video_statistic
        (`video_id`,`view`,`danmaku`,`comment`,`favorite`,`share`,`thumb_up`,`thumb_down`,`coin`)
        values 
        (#{videoId},#{view},#{danmaku},#{comment},#{favorite},#{share},#{thumbUp},#{thumbDown},#{coin})
    </insert>
    <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
        insert into vod_video_statistic
        (`video_id`,`view`,`danmaku`,`comment`,`favorite`,`share`,`thumb_up`,`thumb_down`,`coin`)
        values
        (#{item.videoId},#{item.view},#{item.danmaku},#{item.comment},#{item.favorite},#{item.share},#{item.thumbUp},#{item.thumbDown},#{item.coin})
    </insert>

    <update id="update">
        update vod_video_statistic
        set `view`=#{view},danmaku=#{danmaku},`comment`=#{comment},favorite=#{favorite},`share`=#{share},thumb_up=#{thumbUp},coin=#{coin}
        where video_id=#{videoId}
    </update>
    <update id="updateSetDelete">
        update vod_video_statistic
        set `deleted`=1
        where video_id=#{videoId}
    </update>
    <update id="updateIncrView">
        update vod_video_statistic
        set update_time=now(),`view`=`view`+1
        where video_id=#{videoId}
    </update>

    <select id="findAll" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoStatistic">
        SELECT *
        FROM vod_video_statistic
        limit 1000
    </select>
    <select id="findByVideoId" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoStatistic">
        SELECT *
        FROM vod_video_statistic
        where video_id=#{videoId}
    </select>
    <select id="findAllById" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoStatistic">
        select *
        FROM vod_video_statistic
        where `deleted`=0 and id > #{nextId}
        limit #{pageSize}
    </select>
</mapper>
