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.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.test.domain.Task;
import com.ruoyi.test.domain.Vo.TaskVo;
import com.ruoyi.test.mapper.TaskMapper;
import com.ruoyi.test.seriver.ITaskService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements ITaskService {
    @Autowired
    private TaskMapper taskMapper;
    @Override
    public IPage<Task> selectList(int pagenum,int pagesize) {
        Page<Task> page = new Page<>(pagenum,pagesize);
        LambdaQueryWrapper<Task> queryWrapper = new LambdaQueryWrapper<>();
        IPage<Task> iPage = taskMapper.selectPage(page,queryWrapper);
        return iPage;
    }

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

    @Override
    public int addTask(TaskVo taskVo,String username) {
        return taskMapper.addTask(taskVo,username);
    }

    @Override
    public int deleteTask(Long id) {
        return taskMapper.deleteTask(id);
    }

    @Override
    public IPage<Task> selectListBySubject(String subject, int pagenum) {
        Page<Task> page = new Page<>(pagenum,10);
        LambdaQueryWrapper<Task> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Task::getSubject,subject);
        IPage<Task> iPage = taskMapper.selectPage(page,queryWrapper);
        return iPage;
    }

    @Override
    public IPage<Task> selectListByGradeAndSubject(String grade, String subject, int pagenum, int pagesize) {
        Page<Task> page = new Page<>(pagenum,pagesize);
        LambdaQueryWrapper<Task> queryWrapper = new LambdaQueryWrapper<>();
        if(grade!=null){
            queryWrapper.eq(Task::getGrade,grade);
        }
        if(subject!=null){
            queryWrapper.eq(Task::getSubject,subject);
        }
        IPage<Task> iPage = taskMapper.selectPage(page,queryWrapper);
        return iPage;
    }
}
