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.vo.StaffRecordVO;
import com.yida.data.common.core.entity.attendance.EduAttendanceStaffRecord;
import org.apache.ibatis.annotations.Param;

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

/**
 * 教职工考勤-进出记录 Mapper
 *
 * @author ZYJ
 * @date 2021-09-27 18:56:19
 */
public interface EduAttendanceStaffRecordMapper extends BaseMapper<EduAttendanceStaffRecord> {

    /**
     * 查询进出记录列表
     *
     * @param page
     * @param schoolId
     * @param start
     * @param end
     * @param staffId
     * @return
     */
    IPage<StaffRecordVO> findPageStaffRecord(@Param("page") Page page,
        @Param("schoolId") Long schoolId,
        @Param("start") String start,
        @Param("end") String end,
        @Param("staffId") List<Long> staffId);

    /**
     * 查询时间最近的一条进记录
     *
     * @param staffId
     * @return
     */
    EduAttendanceStaffRecord finMaxRecord(@Param("staffId") Long staffId, @Param("atDate") LocalDateTime atDate);


    /**
     * 查询时间最近的一条出记录
     *
     * @param staffId
     * @return
     */
    EduAttendanceStaffRecord finMinRecord(@Param("staffId") Long staffId, @Param("endStiTime") LocalDateTime endStiTime);


    /**
     * 查询开始时间后第一条进记录
     *
     * @param staffId
     * @param startStiTime
     * @return
     */
    EduAttendanceStaffRecord finMinInRecord(@Param("staffId") Long staffId, @Param("startStiTime") LocalDateTime startStiTime);

    /**
     * 查询结束时间最近的一条记录
     *
     * @param staffId
     * @param endStiTime
     * @return
     */
    EduAttendanceStaffRecord findMinOutRecord(@Param("staffId") Long staffId, @Param("endStiTime") LocalDateTime endStiTime);

    EduAttendanceStaffRecord findMaxOutRecord(@Param("staffId") Long staffId, @Param("startStiTime") LocalDateTime startStiTime);

    /**
     * 是否有出的记录
     *
     * @param staffId
     * @param startStiTime
     * @return
     */
    List<EduAttendanceStaffRecord> findOutRecord(@Param("staffId") Long staffId,
        @Param("startStiTime") LocalDateTime startStiTime);


    /**
     * 查询中间是否有进入的记录
     *
     * @param staffId
     * @param startStiTime
     * @param endStiTime
     * @return
     */
    List<EduAttendanceStaffRecord> findInRecord(@Param("staffId") Long staffId, @Param("startStiTime") LocalDateTime startStiTime,
        @Param("endStiTime") LocalDateTime endStiTime);

    /**
     * 查询进入的记录
     *
     * @param staffId
     * @param startStiTime
     * @param endStiTime
     * @return
     */
    EduAttendanceStaffRecord fintRecord(@Param("staffId") Long staffId, @Param("startStiTime") LocalDateTime startStiTime,
        @Param("endStiTime") LocalDateTime endStiTime);

    /**
     * 查询前一天的最后一次通行记录
     *
     * @param staffId 职工id
     * @param lastDay 前一天日期
     * @return com.yida.data.common.core.entity.attendance.EduAttendanceStaffRecord
     * @author ZYJ
     * @date 2022/9/13 19:55
     */
    EduAttendanceStaffRecord findLastDayLastRecord(@Param("staffId") Long staffId, @Param("lastDay") LocalDate lastDay);

    /**
     * 查询指定时间段是否有通行记录
     *
     * @return com.yida.data.common.core.entity.attendance.EduAttendanceStaffRecord
     * @author ZYJ
     * @date 2022/10/27 11:05
     */
    EduAttendanceStaffRecord findTimeStaffRecord(@Param("ruleId") Long ruleId, @Param("ruleTimeId") Long ruleTimeId,
                                                 @Param("startTime") LocalDateTime startTime,
                                                 @Param("endTime") LocalDateTime endTime);
}
