package com.ruoyi.test.seriver.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.test.domain.Answer;
import com.ruoyi.test.domain.Vo.AnswerVo;
import com.ruoyi.test.mapper.AnswerMapper;
import com.ruoyi.test.seriver.IAnswerService;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AnswerServiceImpl extends ServiceImpl<AnswerMapper, Answer> implements IAnswerService {

    @Autowired
    private AnswerMapper answerMapper;

    @Override
    public int answer(Answer answer) {
        return answerMapper.answer(answer);
    }

    @Override
    public Answer selectByTestId(String sender,Long testid) {
        LambdaQueryWrapper<Answer> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Answer::getTestid,testid);
        queryWrapper.eq(Answer::getSender,sender);
        queryWrapper.orderByDesc(Answer::getFinishtime).last("LIMIT 1");
        return answerMapper.selectOne(queryWrapper);
    }

    @Override
    public List<Answer> selectBySender(String sender) {
        return answerMapper.selectBySender(sender);
    }
}
