package com.yida.data.school.leave.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yida.data.common.core.entity.leave.EduLeaveRequest;
import com.yida.data.school.dto.leave.FindPageLeaveListDTO;
import com.yida.data.school.dto.leave.ListStudentRequestDetailDTO;
import com.yida.data.school.vo.leave.FindPageLeaveListVO;
import com.yida.data.school.vo.leave.LeaveRequestDetailVO;

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

import org.apache.ibatis.annotations.Param;

/**
 * 请假表 Mapper
 *
 * @author ccl
 * @date 2021-11-22 16:27:42
 */
public interface EduLeaveRequestMapper extends BaseMapper<EduLeaveRequest> {

    /**
     * 分页查询请假条
     *
     * @param page
     * @param studentIds
     * @param studentName
     * @param status
     * @return
     */
    Page<EduLeaveRequest> findRequestPage(@Param("page") Page<EduLeaveRequest> page, @Param("studentIds") List<Long> studentIds,
                                          @Param("studentName") String studentName, @Param("status") Integer status,
                                          @Param("teacherId") Long teacherId, @Param("now") LocalDateTime now);

    /**
     * 后台条件查询请假条
     *
     * @param dto
     * @param studentName
     * @param status
     * @param gradeList
     * @param page
     * @return
     */
    Page<FindPageLeaveListVO> findPageLeaveList(
                                                @Param("studentName") String studentName,
                                                @Param("status") Integer status,
                                                @Param("sectionId") Long sectionId,
                                                @Param("gradeId") Long gradeId,
                                                @Param("page") Page<FindPageLeaveListVO> page,
                                                @Param("reviewStatus") Integer reviewStatus,
                                                @Param("teacherName") String teacherName,
                                                @Param("schoolId") Long schoolId,
                                                @Param("all") Integer all,
                                                @Param("studentIds") List<Long> studentIds);

    /**
     * @param page
     * @param studentIds
     * @param status
     * @return
     */
    Page<EduLeaveRequest> findpage(@Param("page") Page<EduLeaveRequest> page, @Param("studentIds") List<Long> studentIds,
                                   @Param("status") Integer status, @Param("studentId") Long studentId, @Param("now") LocalDateTime now);

    /**
     * 查询学生以前的请假数据
     *
     * @param studentId
     * @return
     */
    List<EduLeaveRequest> findLastRequest(@Param("studentId") Long studentId, @Param("now") LocalDateTime now);

    /**
     * 查询学生请假条
     *
     * @param dto
     * @return 开始或结束时间落在时间区间内的请假条
     */
    List<LeaveRequestDetailVO> listStudentRequest(@Param("dto") ListStudentRequestDetailDTO dto,
                                                  @Param("studentIds") List<Long> studentIds);

    /**
     * 是否存在请假条
     *
     * @param dto
     * @return 1-存在，null-不存在
     */
    Integer existRequest(@Param("dto") ListStudentRequestDetailDTO dto);

    FindPageLeaveListVO findLeaveRequest(@Param("id") Long id);
}
