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

import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qmth.teachcloud.mark.entity.MarkTrack;
import com.qmth.teachcloud.mark.mapper.MarkTrackMapper;
import com.qmth.teachcloud.mark.service.MarkTrackService;

/**
 * <p>
 * 轨迹给分表 服务实现类
 * </p>
 *
 * @author xf
 * @since 2023-09-22
 */
@Service
public class MarkTrackServiceImpl extends ServiceImpl<MarkTrackMapper, MarkTrack> implements MarkTrackService {

    @Override
    public void deleteByTaskId(Long taskId) {
        UpdateWrapper<MarkTrack> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().eq(MarkTrack::getTaskId, taskId);
        this.remove(updateWrapper);
    }

    @Override
    public List<MarkTrack> listByTaskIdAndQuestionNumber(Long taskId, String questionNumber) {
        QueryWrapper<MarkTrack> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(MarkTrack::getTaskId, taskId)
                .eq(MarkTrack::getQuestionNumber, questionNumber);
        return this.list(queryWrapper);
    }

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

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

	@Override
	public List<MarkTrack> listByTaskId(Long taskId) {
		 QueryWrapper<MarkTrack> queryWrapper = new QueryWrapper<>();
	        queryWrapper.lambda().eq(MarkTrack::getTaskId, taskId);
	        return this.list(queryWrapper);
	}

	@Override
	public List<MarkTrack> findByStudentIdAndQuestionNumber(Long studentId, String questionNumber) {
		QueryWrapper<MarkTrack> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(MarkTrack::getStudentId, studentId)
                .eq(MarkTrack::getQuestionNumber, questionNumber)
                .orderByAsc(MarkTrack::getNumber);
        return this.list(queryWrapper);
	}

    @Override
    public List<MarkTrack> listByStudentId(Long studentId) {
        QueryWrapper<MarkTrack> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(MarkTrack::getStudentId, studentId)
                .orderByAsc(MarkTrack::getQuestionNumber);
        return this.list(queryWrapper);
    }
}
