package com.qmth.teachcloud.mark.service.impl;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.qmth.teachcloud.common.enums.mark.SubjectiveStatus;
import com.qmth.teachcloud.mark.entity.MarkGroupStudent;
import com.qmth.teachcloud.mark.mapper.MarkGroupStudentMapper;
import com.qmth.teachcloud.mark.service.MarkGroupStudentService;

/**
 * <p>
 * 考生分组状态表 服务实现类
 * </p>
 *
 * @author xf
 * @since 2023-09-22
 */
@Service
public class MarkGroupStudentServiceImpl extends MppServiceImpl<MarkGroupStudentMapper, MarkGroupStudent> implements MarkGroupStudentService {

    @Override
    public long countByStudentIdAndStatus(Long studentId, SubjectiveStatus marked) {
        QueryWrapper<MarkGroupStudent> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(MarkGroupStudent::getStudentId, studentId)
                .eq(MarkGroupStudent::getStatus, marked);
        return this.count(queryWrapper);
    }

    @Override
    public void deleteByStudentId(Long studentId) {
        UpdateWrapper<MarkGroupStudent> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().eq(MarkGroupStudent::getStudentId, studentId);
        this.remove(updateWrapper);
    }

    @Override
    public void deleteByExamIdAndPaperNumberAndGroupNumber(Long examId, String paperNumber, Integer groupNumber) {
        UpdateWrapper<MarkGroupStudent> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().eq(MarkGroupStudent::getExamId, examId)
                .eq(MarkGroupStudent::getPaperNumber, paperNumber)
                .eq(MarkGroupStudent::getGroupNumber, groupNumber);
        this.remove(updateWrapper);
    }

	@Override
	public MarkGroupStudent getByStudentIdAndGroupNumber(Long studentId, Integer groupNumber) {
		QueryWrapper<MarkGroupStudent> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(MarkGroupStudent::getStudentId, studentId)
                .eq(MarkGroupStudent::getGroupNumber, groupNumber);
        return this.getOne(queryWrapper);
	}
}
