package com.xhkjedu.suser.controller.system;

import com.xhkjedu.annotation.Action;
import com.xhkjedu.suser.service.system.TeacherRoleService;
import com.xhkjedu.suser.vo.gradeclass.GradeVo;
import com.xhkjedu.suser.vo.system.TeacherRoleParam;
import com.xhkjedu.suser.vo.system.TeacherRoleVo;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
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 java.util.List;
import java.util.Map;

/**
 * @ClassName TeacherRoleController
 * Description 教师设置权限
 * Author WN
 * Date 2020/6/18 9:43
 **/
@RestController
@RequestMapping("/trole")
public class TeacherRoleController {

    @Autowired
    private TeacherRoleService teacherRoleService;

    /**
     *功能描述  保存教师权限
     * @author WN
     * @date 2020/6/18
     * @param  * @param trole
     * @return com.xhkjedu.vo.ResultVo
     */
    @PostMapping("/save")
    @Action("教师权限-增加")
    public ResultVo saveTeacherRole(@RequestBody TeacherRoleParam trole){
        N_Utils.validation(new Object[]{
                trole.getTeacherid(),"用户id",1
        });
        teacherRoleService.checkSubjectAndGrade(trole);//校验权限科目和年级
        try {
            teacherRoleService.save(trole);
        } catch (Exception e) {
            return new ResultVo(1,"保存失败");
        }
        return new ResultVo(0,"保存成功");
    }

    /**
     *功能描述 修改时获取已有权限
     * @author WN
     * @date 2020/6/18
     * @param  * @param trole
     * @return com.xhkjedu.vo.ResultVo
     */
    @PostMapping("/toup")
    @Action("教师权限-修改")
    public ResultVo toUpdate(@RequestBody TeacherRoleParam trole){
        N_Utils.validation(new Object[]{
                trole.getTeacherid(),"用户id",1
        });
        Map trvo = teacherRoleService.getTeacherRoles(trole);
        return new ResultVo(0,"获取教师权限成功",trvo);
    }

    /**
     * 教师权限教材列表
     * @Param [trole]
     * @Author ywx
     * @Date 2020/7/1 10:42
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_book")
    public ResultVo listBook(@RequestBody TeacherRoleParam trole){
        Integer teacherid = trole.getTeacherid();
        N_Utils.validation(new Object[]{teacherid,"教师id",1});
        TeacherRoleVo trvo = teacherRoleService.listBook(teacherid);
        return new ResultVo(0,"获取教师权限教材列表成功",trvo);
    }

    /**
     * 教师权限科目
     * @Param [trole]
     * @Author ywx
     * @Date 2020/7/24 9:27
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_subject")
    public ResultVo listSubject(@RequestBody TeacherRoleParam trole){
        Integer teacherid = trole.getTeacherid();
        N_Utils.validation(new Object[]{teacherid,"教师id",1});
        List<Map> subject = teacherRoleService.listSubject(teacherid);
        return new ResultVo(0,"获取教师权限科目列表成功",subject);
    }

    /**
     *功能描述 教师权限科目下教材
     * @author WN
     * @date 2020/8/11
     * @param  * @param trole
     * @return com.xhkjedu.vo.ResultVo
     */
    @PostMapping("/list_sbook")
    public ResultVo listSubjectBook(@RequestBody TeacherRoleParam trole){
        Integer teacherid = trole.getTeacherid();
        String subjectid = trole.getSubjectid();
        N_Utils.validation(new Object[]{teacherid,"教师id",1,subjectid,"科目id",2});
        List<Map> subject = teacherRoleService.listBookBySubjectid(teacherid, subjectid);
        return new ResultVo(0,"获取科目下权限教材列表成功",subject);
    }

    //班级错题、添加通知、我的班级用
    @PostMapping("/list_class")
    public ResultVo listClass(@RequestBody TeacherRoleParam trole){
        Integer teacherid = trole.getTeacherid();
        N_Utils.validation(new Object[]{teacherid,"教师id",1});
        List<GradeVo> list = teacherRoleService.listGradeClassesByUserid(trole);
        return new ResultVo(0,"获取教师权限班级列表成功",list);
    }

    /**
     * @Description 教师权限班级学生
     * @Date 2023/12/19 10:41
     * @Author YWX
     * @Param [trole]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_class_stu")
    public ResultVo listClassStu(@RequestBody TeacherRoleParam trole) {
        Integer teacherid = trole.getTeacherid();
        N_Utils.validation(new Object[]{teacherid, "教师id", 1});
        List<Map> list = teacherRoleService.listClassStu(trole);
        return new ResultVo(0, "获取教师权限班级学生列表成功", list);
    }

    //直播巡课、作业统计、预习统计搜索用
    @PostMapping("/list_class2")
    public ResultVo listClass2(@RequestBody TeacherRoleParam trole){
        Integer teacherid = trole.getTeacherid();
        N_Utils.validation(new Object[]{teacherid,"教师id",1});
        List<GradeVo> list = teacherRoleService.listGradeClassesByUserid2(trole);
        return new ResultVo(0,"获取教师权限班级列表成功",list);
    }

    /**
     * @Description 获取教师权限年级下所有班级
     * @Param [trole]
     * @Return com.xhkjedu.vo.ResultVo
     * @Author wn
     * @Date 2022/6/28 9:33
     **/
    @PostMapping("/list_allclass")
    public ResultVo listRoleGradeAllClass(@RequestBody TeacherRoleParam trole){
        Integer teacherid = trole.getTeacherid();
        N_Utils.validation(new Object[]{teacherid,"教师id",1});
        List<GradeVo> list = teacherRoleService.listRoleGradeAllClass(trole);
        return new ResultVo(0,"获取教师权限年级下班级列表成功",list);
    }

}
