package com.admin.major.quartz;


import com.admin.major.domain.MajorInfo;
import com.admin.major.domain.StudentCourse;
import com.admin.major.domain.StudentInfo;
import com.admin.major.service.IMajorInfoService;
import com.admin.major.service.ISyncTableService;
import com.admin.major.service.IStudentCourseService;
import com.admin.major.service.IStudentInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 同步学生信息数据f
 */
@Component("syncTableTask")
@Slf4j
public class SyncTableTask {

    @Autowired
    private ISyncTableService syncTableService;

    @Autowired
    private IStudentInfoService studentInfoService;

    @Autowired
    private IMajorInfoService majorInfoService;

    @Autowired
    private IStudentCourseService studentCourseService;


    public void sync()
    {
        log.info("同步任务测试======================");
    }


    public void syncStudentInfo(){
        log.info("同步学生任务 START ");
        //同步学生信息
        StudentInfo studentInfo = new StudentInfo();
        List<StudentInfo> studentInfoList = syncTableService.getStudentInfo(studentInfo);
        log.info("同步学生信息 {}",studentInfoList.size());
        studentInfoService.saveBatch(studentInfoList);

        //同步课程成绩信息
        List<StudentCourse> studentCourse = syncTableService.getStudentCourse(new StudentCourse());
        log.info("同步学生课程信息 {}",studentCourse.size());
        studentCourseService.saveBatch(studentCourse);

        log.info("计算相关信息 {}",studentCourse.size());
        //计算分数
        syncTableService.calcScore();
        //计算排名
        syncTableService.calcRank();
        log.info("同步学生任务 END ");
    }



    public void syncMajorInfo(){
        MajorInfo majorInfoParam = new MajorInfo();
        List<MajorInfo> majorInfoList = syncTableService.getMajorInfo(majorInfoParam);
        majorInfoService.saveBatch(majorInfoList);
    }

}
