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

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yonge.cooleshow.biz.dal.dao.CourseScheduleStudentPaymentDao;
import com.yonge.cooleshow.biz.dal.entity.CourseScheduleStudentPayment;
import com.yonge.cooleshow.biz.dal.enums.CourseScheduleEnum;
import com.yonge.cooleshow.biz.dal.service.CourseScheduleStudentPaymentService;
import com.yonge.cooleshow.biz.dal.vo.LiveCourseInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.CollectionUtils;

import java.util.Collection;
import java.util.List;

/**
 * 课程学生缴费表(CourseScheduleStudentPayment)表服务实现类
 *
 * @author hgw
 * @since 2022-03-18 15:29:12
 */
@Service("courseScheduleStudentPaymentService")
public class CourseScheduleStudentPaymentServiceImpl extends ServiceImpl<CourseScheduleStudentPaymentDao, CourseScheduleStudentPayment> implements CourseScheduleStudentPaymentService {

    private final static Logger log = LoggerFactory.getLogger(CourseScheduleStudentPaymentServiceImpl.class);

    @Override
    public CourseScheduleStudentPaymentDao getDao() {
        return this.baseMapper;
    }

    /**
     * 根据课程组id查询学员信息
     *
     * @param groupId 课程组id
     */
    @Override
    public List<LiveCourseInfoVo.CourseBuyStudentVo> queryStudentInfoByGroupId(Long groupId) {
        return baseMapper.queryStudentInfoByGroupId(groupId);
    }

    @Override
    public CourseScheduleStudentPayment getByCourseId(Long courseId) {
        List<CourseScheduleStudentPayment> list = this.lambdaQuery()
                                                      .eq(CourseScheduleStudentPayment::getCourseId, courseId)
                                                      .eq(CourseScheduleStudentPayment::getCourseType,
                                                          CourseScheduleEnum.PRACTICE.getCode())
                                                      .isNotNull(CourseScheduleStudentPayment::getUserId)
                                                      .list();
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        return list.get(0);

    }


}

