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

import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.qmth.teachcloud.common.contant.SystemConstant;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qmth.teachcloud.mark.entity.ScanBatch;
import com.qmth.teachcloud.mark.entity.ScanBatchPaper;
import com.qmth.teachcloud.mark.entity.ScanPaper;
import com.qmth.teachcloud.mark.mapper.ScanBatchPaperMapper;
import com.qmth.teachcloud.mark.service.ScanBatchPaperService;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xf
 * @since 2023-09-22
 */
@Service
public class ScanBatchPaperServiceImpl extends MppServiceImpl<ScanBatchPaperMapper, ScanBatchPaper> implements ScanBatchPaperService {

    @Override
    public ScanBatchPaper findByBatchIdAndStudentIdAndPaperNumber(Long batchId, Long studentId, Integer paperIndex) {
        QueryWrapper<ScanBatchPaper> wrapper = new QueryWrapper<>();
        LambdaQueryWrapper<ScanBatchPaper> lw = wrapper.lambda();
        lw.eq(ScanBatchPaper::getBatchId, batchId);
        lw.eq(ScanBatchPaper::getStudentId, studentId);
        lw.eq(ScanBatchPaper::getPaperIndex, paperIndex);
        return baseMapper.selectOne(wrapper);
    }
    
    @Override
    @Transactional
    public void update(ScanBatch batch, ScanPaper paper, Long studentId, Integer paperNumber) {
    	ScanBatchPaper batchPaperEntity = new ScanBatchPaper();
        batchPaperEntity.setBatchId(batch.getId());
        batchPaperEntity.setStudentId(studentId);
        batchPaperEntity.setPaperIndex(paperNumber);
        batchPaperEntity.setPaperId(paper.getId());
        batchPaperEntity.setCardNumber(paper.getCardNumber());
        batchPaperEntity.setAssigned(paper.getAssigned());
        saveOrUpdateByMultiId(batchPaperEntity);
    }
}
