<?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.cmeeting.mapper.primary.MeetingInfoMapper">
    <insert id="batchInsert" parameterType="list">
        INSERT IGNORE INTO cmt_meeting_info (subject, meeting_id, meeting_record_id, meeting_code, host, host_uid, participant_users, start_time,
        end_time, is_generated, email_generate_access,  email_push_access, is_pushed, sync_time, sub_meeting_id, record_content, record_xml, generate_retry,
        push_retry, record_file_id, status, email)
        VALUES
        <foreach collection="meetingSaveList" item="meeting" separator=",">
            (
            #{meeting.subject},
            #{meeting.meetingId},
            #{meeting.meetingRecordId},
            #{meeting.meetingCode},
            #{meeting.host},
            #{meeting.hostUid},
            #{meeting.participantUsers},
            #{meeting.startTime},
            #{meeting.endTime},
            #{meeting.isGenerated},
            #{meeting.emailGenerateAccess},
            #{meeting.emailPushAccess},
            #{meeting.isPushed},
            #{meeting.syncTime},
            #{meeting.subMeetingId},
            #{meeting.recordContent},
            #{meeting.recordXml},
            #{meeting.generateRetry},
            #{meeting.pushRetry},
            #{meeting.recordFileId},
            #{meeting.status},
            #{meeting.email}
            )
        </foreach>
    </insert>
    <select id="getAllMeetingIds" resultType="com.cmeeting.vo.TencentMeetingVO$SimpleMeetingInfo">
        select meeting_id,meeting_record_id,sub_meeting_id,record_file_id from cmt_meeting_info order by sync_time desc limit 20000;
    </select>

    <select id="statistics" resultType="java.util.LinkedHashMap">
        SELECT
            userid.wid as userId,
            t.host_uid,
            <foreach collection="dateList" item="d" separator=",">
                cast(MAX(CASE WHEN sync_time = #{d} THEN cnt ELSE 0 END) as char) AS `${d}`
            </foreach>
        FROM (
            SELECT
                host_uid,
                date_format(sync_time, '%Y-%m-%d') as sync_time,
                SUM(CASE WHEN is_pushed = 1 THEN 1 ELSE 0 END) AS cnt
            FROM
                cmt_meeting_info
            WHERE
                is_pushed = 1 and
                date_format(sync_time, '%Y-%m-%d') BETWEEN #{startTime} AND #{endTime}
                GROUP BY host_uid, date_format(sync_time, '%Y-%m-%d')
            ) AS t,
            userid
        where
            userid.tid COLLATE utf8mb4_general_ci = t.host_uid  COLLATE utf8mb4_general_ci
            GROUP BY t.host_uid, userid.wid
    </select>

    <delete id="deleteDataAfterThan2Days">
        update cmt_meeting_info set record_content = '', record_xml = '',clear = 1 where start_time &lt; DATE_SUB(#{date}, INTERVAL 1 DAY);
    </delete>

</mapper>
