package com.ruoyi.test.seriver.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.test.domain.Video;
import com.ruoyi.test.domain.Vo.VideoVo;
import com.ruoyi.test.mapper.VideoMapper;
import com.ruoyi.test.seriver.IVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class VideoServiceImpl extends ServiceImpl<VideoMapper, Video> implements IVideoService {

    @Autowired
    private VideoMapper videoMapper;

    @Override
    public IPage<Video> selectList(int pagenum) {
        Page<Video> page = new Page<>(pagenum,10);
        LambdaQueryWrapper<Video> queryWrapper = new LambdaQueryWrapper<>();
        IPage<Video> iPage = videoMapper.selectPage(page,queryWrapper);
        return iPage;
    }

    @Override
    public IPage<Video> selectListByGrate(String grade, int pagenum) {
        Page<Video> page = new Page<>(pagenum,10);
        LambdaQueryWrapper<Video> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Video::getGrade,grade);
        IPage<Video> iPage = videoMapper.selectPage(page,queryWrapper);
        return iPage;
    }

    @Override
    public int deleteVideo(Long id) {
        return videoMapper.deleteVideo(id);
    }

    @Override
    public int addVideo(VideoVo videoVo) {
        return videoMapper.addVideo(videoVo);
    }

    @Override
    public Video video(Long id) {
        LambdaQueryWrapper<Video> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Video::getId,id);
        return videoMapper.selectOne(queryWrapper);
    }
}
