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

import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.qmth.boot.core.exception.ParameterException;
import com.qmth.teachcloud.mark.bean.archivescore.ScanPaperPageVo;
import com.qmth.teachcloud.mark.entity.ScanPaperPage;
import com.qmth.teachcloud.mark.mapper.ScanPaperPageMapper;
import com.qmth.teachcloud.mark.service.ScanPaperPageService;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author xf
 * @since 2023-09-22
 */
@Service
public class ScanPaperPageServiceImpl extends MppServiceImpl<ScanPaperPageMapper, ScanPaperPage>
		implements ScanPaperPageService {

	@Override
	public ScanPaperPage findPaperIdAndIndex(Long paperId, Integer index) {
		if (paperId == null) {
			throw new ParameterException("paperId不能为空");
		}
		if (index == null) {
			throw new ParameterException("index不能为空");
		}
		QueryWrapper<ScanPaperPage> wrapper = new QueryWrapper<>();
		LambdaQueryWrapper<ScanPaperPage> lw = wrapper.lambda();
		lw.eq(ScanPaperPage::getPaperId, paperId);
		lw.eq(ScanPaperPage::getPageIndex, index);
		return this.getOne(wrapper);
	}

	@Override
	public List<ScanPaperPage> listByPaperId(Long paperId) {
		if (paperId == null) {
			throw new ParameterException("paperId不能为空");
		}
		QueryWrapper<ScanPaperPage> wrapper = new QueryWrapper<>();
		LambdaQueryWrapper<ScanPaperPage> lw = wrapper.lambda();
		lw.eq(ScanPaperPage::getPaperId, paperId);
		lw.orderByAsc(ScanPaperPage::getPageIndex);
		return baseMapper.selectList(wrapper);
	}

	@Override
	public List<ScanPaperPage> listByPaperList(List<Long> paperIds) {
		QueryWrapper<ScanPaperPage> wrapper = new QueryWrapper<>();
		LambdaQueryWrapper<ScanPaperPage> lw = wrapper.lambda();
		lw.in(ScanPaperPage::getPaperId, paperIds);
		wrapper.orderByAsc("paper_id", "page_index");
		return this.list(wrapper);
	}

	@Override
	public List<ScanPaperPageVo> listByStudentIds(List<Long> studentIds) {
		return baseMapper.listByStudentIds(studentIds);
	}

}
