package com.ruoyi.test.seriver.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.test.domain.StudentClass;
import com.ruoyi.test.domain.TeacherManageClass;
import com.ruoyi.test.mapper.StudentClassMapper;
import com.ruoyi.test.seriver.IStudentClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentClassServiceImpl extends ServiceImpl<StudentClassMapper, StudentClass> implements IStudentClassService {

    @Autowired
    private StudentClassMapper studentClassMapper;

    @Override
    public Integer totalStudent(List<TeacherManageClass> list) {
        Integer total=0;
        for(TeacherManageClass teacherManageClass : list){
            LambdaQueryWrapper<StudentClass> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(StudentClass::getGrade,teacherManageClass.getGrade())
                    .eq(StudentClass::getClass1,teacherManageClass.getClass1());
            total += studentClassMapper.selectList(queryWrapper).size();
        }
        return total;
    }

    @Override
    public List<StudentClass> selectByGradeAndClass(String grade, String Class) {
        LambdaQueryWrapper<StudentClass> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StudentClass::getGrade,grade)
                .eq(StudentClass::getClass1,Class);
        return studentClassMapper.selectList(queryWrapper);
    }

    @Override
    public int deleteStudentClass(Long id) {
        return studentClassMapper.deleteStudentClass(id);
    }

    @Override
    public StudentClass selectById(Long id) {
        LambdaQueryWrapper<StudentClass> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StudentClass::getStudentid,id);
        return studentClassMapper.selectOne(queryWrapper);
    }


}
