package com.yonge.cooleshow.biz.dal.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yonge.cooleshow.biz.dal.enums.CourseScheduleEnum;
import org.springframework.stereotype.Service;
import com.yonge.cooleshow.biz.dal.entity.StudentAttendance;
import com.yonge.cooleshow.biz.dal.vo.StudentAttendanceVo;
import com.yonge.cooleshow.biz.dal.dto.search.StudentAttendanceSearch;
import com.yonge.cooleshow.biz.dal.dao.StudentAttendanceDao;
import com.yonge.cooleshow.biz.dal.service.StudentAttendanceService;
import org.springframework.util.CollectionUtils;

import java.util.List;


@Service
public class StudentAttendanceServiceImpl extends ServiceImpl<StudentAttendanceDao, StudentAttendance> implements StudentAttendanceService {

	@Override
    public StudentAttendanceVo detail(Long id) {
        StudentAttendanceVo detail = baseMapper.detail(id);
        return detail;
    }
    
     @Override
    public IPage<StudentAttendanceVo> selectPage(IPage<StudentAttendanceVo> page, StudentAttendanceSearch query){
        return page.setRecords(baseMapper.selectPage(page, query));
    }

    @Override
    public StudentAttendance getByCourseTypeAndScheduleId(CourseScheduleEnum courseType, Long courseScheduleId) {
        List<StudentAttendance> list = this.lambdaQuery()
                                           .eq(StudentAttendance::getCourseGroupType, courseType)
                                           .eq(StudentAttendance::getCourseScheduleId, courseScheduleId)
                                           .list();
        if (!CollectionUtils.isEmpty(list)) {
            return list.get(0);
        }
        return null;
    }

}