<?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.file.app.zdisk.db.mapper.CamRecordMapper">
    <insert id="save" useGeneratedKeys="true" keyProperty="id">
        insert into disk_cam_record
        (`cam_id`,`record_id`,`video_file_id`,`start_at`,`duration`)
        values
        (#{camId},#{recordId},#{videoFileId},#{startAt},#{duration})
    </insert>

    <delete id="deleteByAlbumIdAndPostId">
        delete from disk_cam_record
        where album_id=#{albumId} and post_id=#{postId}
    </delete>
    
    <select id="findByCamId" resultType="cn.reghao.tnb.file.app.zdisk.model.po.CamRecord">
        select *
        from disk_cam_record
        where cam_id=#{camId}
    </select>
    <select id="findByCamIdAndStartAt" resultType="cn.reghao.tnb.file.app.zdisk.model.vo.CamRecordInfo">
        select cam_id,record_id,DATE_FORMAT(start_at,'%T') as startTime,duration
        from disk_cam_record
        where cam_id=#{camId} and DATE_FORMAT(start_at,'%Y-%m-%d')=#{dayStr}
        order by start_at asc
    </select>
    <select id="findByRecordId" resultType="cn.reghao.tnb.file.app.zdisk.model.po.CamRecord">
        select *
        from disk_cam_record
        where record_id=#{recordId}
    </select>
    <select id="findGroupByYearMonth" resultType="java.lang.String">
        select DATE_FORMAT(start_at,'%Y-%m-%d') as yearMonthDay
        from disk_cam_record
        where cam_id=#{camId} and DATE_FORMAT(start_at,'%Y-%m')=#{yearMonth}
        group by yearMonthDay
    </select>
</mapper>
