package com.yida.data.attendance.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yida.data.attendance.dto.ListRecordDTO;
import com.yida.data.attendance.vo.AttendanceResultVO;
import com.yida.data.attendance.vo.CountVO;
import com.yida.data.attendance.vo.InOutDormPageVO;
import com.yida.data.attendance.vo.RecordDetailVO;
import com.yida.data.common.core.entity.attendance.EduAttendanceRecord;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

import com.yida.data.common.core.entity.attendance.EduAttendanceRule;
import org.apache.ibatis.annotations.Param;

public interface EduAttendanceRecordMapper extends BaseMapper<EduAttendanceRecord> {

    List<InOutDormPageVO> listInOut(Page page,
        @Param("studentIds") List<Long> studentIds,
        @Param("zone") Integer zone,
        @Param("startTime") LocalDateTime startTime,
        @Param("endTime") LocalDateTime endTime);

    IPage<AttendanceResultVO> listAttendanceResultPage(Page page,
        @Param("studentIds") List<Long> studentIds,
        @Param("ruleId") Long ruleId,
        @Param("date") LocalDate date);


    List<AttendanceResultVO> listAttendanceResult(@Param("studentIds") List<Long> studentIds,
        @Param("ruleId") Long ruleId,
        @Param("date") LocalDate date);

    List<RecordDetailVO> listRecordDetail(@Param("userId") Long userId,
        @Param("date") String date);


    RecordDetailVO getRecordDetail(Long id);


    /**
     * 查询时间段内最后一条记录
     *
     * @param startTime
     * @param endTime
     * @param type      0-进入，1-离开
     * @return
     */
    EduAttendanceRecord getLastRecordByTime(@Param("startTime") LocalDateTime startTime,
        @Param("endTime") LocalDateTime endTime,
        @Param("type") Integer type,
        @Param("studentId") Long studentId);

    /**
     * 统计时段内迟到早退记录条数
     *
     * @param startTime
     * @param endTime
     * @return
     */
    CountVO countLateAndLeave(
        @Param("startTime") LocalDateTime startTime,
        @Param("endTime") LocalDateTime endTime,
        @Param("userId") Long userId);

    List<RecordDetailVO> listRecord(@Param("dto") ListRecordDTO dto);


    /**
     * @param startTime 规则开始时间
     * @param endTime   规则结束时间
     * @param nowDate   当前时间
     * @param studentId 学生ID
     * @param type      统计类型：0=正常打卡人数，1=迟到人数/晚归人数，2：旷课人数/旷宿人数，3：早退人数，4：请假人数
     * @return
     */
    Integer stasticTeacherData(@Param("startTime") LocalDateTime startTime,
        @Param("endTime") LocalDateTime endTime,
        @Param("nowDate") LocalDateTime nowDate,
        @Param("studentId") Long studentId,
        @Param("type") Integer type);


    EduAttendanceRecord getFirstByStudentIdAndRuleTimeId(@Param("studentId") Long studentId,
        @Param("ruleTimeId") Long ruleTimeId,
        @Param("date") String date,
        @Param("deviceIdList") List<Long> deviceIdList);

    EduAttendanceRecord getLastByStudentIdAndRuleTimeId(@Param("studentId") Long studentId,
        @Param("ruleTimeId") Long ruleTimeId,
        @Param("date") String date,
        @Param("deviceIdList") List<Long> deviceIdList);


    List<EduAttendanceRecord> getRecordByStudentIdAndMonth(@Param("studentId") Long studentId,
        @Param("month") String month,
        @Param("status") Integer status);


    EduAttendanceRecord getDormLastByStudentIdAndRuleTimeId(@Param("studentId") Long studentId,
        @Param("date") String date);

    EduAttendanceRecord getDormFirstByStudentIdAndRuleTimeId(@Param("studentId") Long studentId,
        @Param("date") String date);

}
