package com.xhkjedu.sstudy.controller.subjectbook;

import com.xhkjedu.annotation.Action;
import com.xhkjedu.sstudy.model.subjectbook.TSubjectBook;
import com.xhkjedu.sstudy.model.subjectbook.TTeacherSubjectbook;
import com.xhkjedu.sstudy.service.subjectbook.TeacherSubjectbookService;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.vo.ResultVo;
import com.xhkjedu.sstudy.vo.subjectbook.TeacherSClassVo;
import com.xhkjedu.sstudy.vo.subjectbook.TeacherSubjectbookVo;
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;

/**
 * @author ywx
 * @classname TeacherSubjectbookController
 * @description 
 * @date 2020/6/5 15:38
 **/
@RestController
@RequestMapping("/tsubjectbook")
public class TeacherSubjectbookController {
    @Resource
    private TeacherSubjectbookService teacherSubjectbookService;

    @PostMapping("/add")
    @Action("教师教材-增加")
    public ResultVo add(@RequestBody TTeacherSubjectbook book) {
        Integer id = teacherSubjectbookService.save(book);
        return new ResultVo(0, "保存成功",id);
    }

    @PostMapping("/delete")
    @Action("教师教材-删除")
    public ResultVo delete(@RequestBody TTeacherSubjectbook book) {
        N_Utils.validation(new Object[]{book.getTbid(),"教师教材关系id",1});
        teacherSubjectbookService.deleteById(book.getTbid());
        return new ResultVo(0,"删除成功");
    }

    @PostMapping("/list")
    public ResultVo list(@RequestBody TTeacherSubjectbook book) {
        N_Utils.validation(new Object[]{book.getTeacherid(),"教师id",1});
        List<TeacherSubjectbookVo> list = teacherSubjectbookService.findAll(book);
        return new ResultVo(0,"获取列表成功",list);
    }

    @PostMapping("/update_selected")
    public ResultVo updateSelected(@RequestBody TTeacherSubjectbook book) {
        N_Utils.validation(new Object[]{book.getTbid(),"教师教材关系id",1});
        teacherSubjectbookService.updateSelected(book.getTbid());
        return new ResultVo(0,"更新教材是否选中成功");
    }

    @PostMapping("/list_stubook")
    public ResultVo listStuBook(@RequestBody TSubjectBook book) {
        String subjectid = book.getSubjectid();
        Integer studentid = book.getCreateid();
        N_Utils.validation(new Object[]{studentid,"学生id",1});
        List<TeacherSubjectbookVo> list = teacherSubjectbookService.listStuBook(subjectid,studentid);
        return new ResultVo(0,"获取学生教材列表成功",list);
    }

    @PostMapping("/list_book_class")
    public ResultVo listBookClass(@RequestBody TTeacherSubjectbook book) {
        Integer teacherid = book.getTeacherid();
        N_Utils.validation(new Object[]{teacherid,"教师id",1});
        TeacherSClassVo list = teacherSubjectbookService.listBookClass(teacherid, book.getClasstype());
        return new ResultVo(0,"获取教师年级下班级列表成功",list);
    }

    @PostMapping("/list_subject_lsb")
    public ResultVo listSubjectLsb(@RequestBody TTeacherSubjectbook book) {
        N_Utils.validation(new Object[]{book.getTeacherid(),"教师id",1});
        List<TeacherSubjectbookVo> list = teacherSubjectbookService.listSubjectLsb(book.getTeacherid());
        return new ResultVo(0,"获取教师权限教材科目下所有教材列表成功",list);
    }
}
