<?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.sb.multi.mybatis.mapper.one.DataBlockMapper">
    <update id="updateSetDelete">
        update data_block
        set deleted=1
        where content_id=#{contentId}
    </update>
    <update id="updatePath">
        update data_block
        set absolute_path=#{absolutePath}
        where id=#{id}
    </update>
    <update id="updateReplica">
        update data_block
        set replica=1
        where id=#{id}
    </update>

    <delete id="delete">
        delete from data_block
        where id=#{id}
    </delete>
    <delete id="deleteDataBlocks">
        delete from data_block
        where deleted=1
    </delete>

    <select id="findAll" resultType="cn.reghao.tnb.sb.multi.mybatis.model.one.DataBlock">
        select *
        from data_block
        where deleted=0 and absolute_path like '/opt/oss/disk/40b2cf6e-1501-421a-b7b3-9cbf5b206d39%'
    </select>
    <select id="findByContentId" resultType="cn.reghao.tnb.sb.multi.mybatis.model.one.DataBlock">
        select *
        from data_block
        where deleted=0 and content_id=#{contentId}
    </select>
    <select id="findByDeleted" resultType="cn.reghao.tnb.sb.multi.mybatis.model.one.DataBlock">
        select *
        from data_block
        where deleted=1
    </select>
    <select id="findByDisk" resultType="cn.reghao.tnb.sb.multi.mybatis.model.one.DataBlock">
        select data_block.*
        from file_meta
        inner join data_block
        on file_meta.content_id=data_block.content_id and file_meta.object_name like 'video/cam/%' and data_block.absolute_path like '/disk/a/%'
    </select>
</mapper>
