package com.ym.mec.biz.event.listener;

import com.ym.mec.biz.dal.dao.CourseScheduleDao;
import com.ym.mec.biz.event.StudentCourseChangeEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @Author Joburgess
 * @Date 2020.09.24
 */
@Component
public class StudentEventListener{

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private CourseScheduleDao courseScheduleDao;

    @Async
    @EventListener
    public void onStudentCourseChangeEvent(StudentCourseChangeEvent studentCourseChangeEvent) {
        courseScheduleDao.countGroupFinishCourse(studentCourseChangeEvent.getGroupId(), studentCourseChangeEvent.getGroupType().getCode());
        logger.info("用户{}在{}({})团体的课程发生变化.", studentCourseChangeEvent.getUserId(), studentCourseChangeEvent.getGroupType().getDesc(), studentCourseChangeEvent.getGroupId());
    }
}
