<?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.ningdatech.pmapi.meeting.mapper.MeetingExpertEvaluationMapper">

    <select id="countExpertAttend" resultType="com.ningdatech.pmapi.common.model.entity.CountGroupByDTO">
        select count(1) total, expert_id groupKey from meeting_expert_evaluation
        where expert_id
        <foreach collection="expertIds" separator="," close=")" open=" in (" item="expertId">#{expertId}</foreach>
        <if test="isAttended != null">
            and is_attended = #{isAttended}
        </if>
        group by expert_id order by total desc
    </select>

    <select id="pageExpertEvaluationToDo"
            resultType="com.ningdatech.pmapi.meeting.entity.domain.MeetingExpert">
        select * from (SELECT ROW_NUMBER() OVER ( PARTITION BY expert_id ORDER BY update_on DESC )
        rowNumber, ID, expert_id, status, meeting_id FROM meeting_expert
        where meeting_id <foreach collection="meetingIds" item="item" open=" in (" close=")" separator=",">
        #{item}</foreach>) em
        WHERE rowNumber = 1 and status = 3 and not exists (select 1 from meeting_expert_evaluation where
        expert_meeting_id = em.id)
    </select>

</mapper>
