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.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qmth.teachcloud.mark.entity.MarkHeaderTag;
import com.qmth.teachcloud.mark.mapper.MarkHeaderTagMapper;
import com.qmth.teachcloud.mark.service.MarkHeaderTagService;

/**
 * <p>
 * 组长特殊标记表 服务实现类
 * </p>
 *
 * @author xf
 * @since 2023-11-01
 */
@Service
public class MarkHeaderTagServiceImpl extends ServiceImpl<MarkHeaderTagMapper, MarkHeaderTag>
		implements MarkHeaderTagService {

	@Override
	public void deleteByStudentIdAndGroupNumber(Long studentId, Integer groupNumber) {
		UpdateWrapper<MarkHeaderTag> updateWrapper = new UpdateWrapper<>();
		LambdaUpdateWrapper<MarkHeaderTag> lambdaUpdateWrapper = updateWrapper.lambda();
		lambdaUpdateWrapper.eq(MarkHeaderTag::getStudentId, studentId);
		if (groupNumber != null) {
			lambdaUpdateWrapper.eq(MarkHeaderTag::getGroupNumber, groupNumber);
		}
		this.remove(updateWrapper);
	}

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

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

	@Override
	public void deleteByExamIdAndPaperNumberAndGroupNumberAndStudentId(Long examId, String paperNumber,
			Integer groupNumber, Long studentId) {
		UpdateWrapper<MarkHeaderTag> updateWrapper = new UpdateWrapper<>();
		LambdaUpdateWrapper<MarkHeaderTag> lambdaUpdateWrapper = updateWrapper.lambda();
		lambdaUpdateWrapper.eq(MarkHeaderTag::getExamId, examId);
		lambdaUpdateWrapper.eq(MarkHeaderTag::getStudentId, studentId);
		lambdaUpdateWrapper.eq(MarkHeaderTag::getPaperNumber, paperNumber);
		lambdaUpdateWrapper.eq(MarkHeaderTag::getGroupNumber, groupNumber);
		this.remove(updateWrapper);
	}
}
