<?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.VideoCategoryMapper">
    <insert id="save" useGeneratedKeys="true" keyProperty="id">
        insert into vod_video_category
        (`pid`,`name`,`region_id`,`icon`,`sort`,`vip`)
        values 
        (#{pid},#{name},#{regionId},#{icon},#{sort},#{vip})
    </insert>

    <select id="findAllCategoryIds" resultType="cn.reghao.tnb.content.api.dto.spider.BiliRegion">
        select region_id,pid as category_pid,id as category_id
        from vod_video_category
        where pid not in (0, 3, 11)
    </select>
    <select id="findById" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoCategory">
        select *
        from vod_video_category
        where id=#{id}
    </select>
    <select id="findByRid" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoCategory">
        select *
        from vod_video_category
        where region_id=#{rid}
    </select>
    <select id="findVideoCategoryByPage" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoCategory">
        select *
        from vod_video_category
        <where>
            deleted=0
            <if test="categoryQuery.categoryPid != null">
                and pid=#{categoryQuery.categoryPid}
            </if>
            <if test="categoryQuery.categoryId != null">
                and id=#{categoryQuery.categoryId}
            </if>
            <if test="categoryQuery.pid != null">
                and `pid` != 0
            </if>
        </where>
    </select>
</mapper>