package com.xhkjedu.sexam.controller.exam;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.sexam.model.exam.ESubjectBadstudent;
import com.xhkjedu.sexam.service.exam.ESubjectBadstudentService;
import com.xhkjedu.utils.PageUtil;
import com.xhkjedu.vo.PageResult;
import com.xhkjedu.vo.ResultVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/e_badstudent")
public class ESubjectBadstudentController {
    @Resource
    private ESubjectBadstudentService eSubjectBadstudentService;

    @PostMapping("/add")
    public ResultVo add(@RequestBody ESubjectBadstudent eSubjectBadstudent) {
        eSubjectBadstudentService.save(eSubjectBadstudent);
        return new ResultVo(0,"保存成功");
    }

    @PostMapping("/delete")
    public ResultVo delete(@RequestBody ESubjectBadstudent eSubjectBadstudent) {
        eSubjectBadstudentService.deleteById(eSubjectBadstudent.getId());
        return new ResultVo(0,"删除成功");
    }

    @PostMapping("/update")
    public ResultVo update(@RequestBody ESubjectBadstudent eSubjectBadstudent) {
        eSubjectBadstudentService.update(eSubjectBadstudent);
        return new ResultVo(0,"修改成功");
    }

    @PostMapping("/list")
    public ResultVo list(@RequestBody ESubjectBadstudent eSubjectBadstudent) {
        PageHelper.startPage(eSubjectBadstudent.getPage(), eSubjectBadstudent.getPageSize());
        List<ESubjectBadstudent> list = eSubjectBadstudentService.listAll();
        PageResult pageResult = PageUtil.getPageResult(new PageInfo(list));
        return new ResultVo(0,"获取列表成功",pageResult);
    }
}
