package com.xhkjedu.suser.controller.gradeclass;

import com.xhkjedu.annotation.Action;
import com.xhkjedu.suser.model.gradeclass.TGrade;
import com.xhkjedu.suser.service.gradeclass.GradeService;
import com.xhkjedu.suser.vo.gradeclass.GradeVo;
import com.xhkjedu.utils.N_Utils;
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;
import java.util.Map;

/**
 * @author ywx
 * @classname TGradeController
 * @description
 * @date 2020/6/2 14:47
 **/
@RestController
@RequestMapping("/grade")
public class GradeController {
    @Resource
    private GradeService gradeService;

    @PostMapping("/add")
    @Action("年级管理-增加")
    public ResultVo add(@RequestBody TGrade tGrade) {
        Integer id = gradeService.save(tGrade);
        return new ResultVo(0, "保存成功",id);
    }

    @PostMapping("/delete")
    @Action("年级管理-删除")
    public ResultVo delete(@RequestBody TGrade tGrade) {
        N_Utils.validation(new Object[]{tGrade.getGradeid(),"年级id",1});
        gradeService.deleteById(tGrade.getGradeid());
        return new ResultVo(0,"删除成功");
    }

    @PostMapping("/update")
    @Action("年级管理-修改")
    public ResultVo update(@RequestBody TGrade tGrade) {
        N_Utils.validation(new Object[]{tGrade.getGradeid(),"年级id",1});
        gradeService.update(tGrade);
        return new ResultVo(0,"修改成功");
    }

    @PostMapping("/detail")
    public ResultVo detail(@RequestBody TGrade tGrade) {
        N_Utils.validation(new Object[]{tGrade.getGradeid(),"年级id",1});
        TGrade grade = gradeService.findById(tGrade.getGradeid());
        return new ResultVo(0,"获取详情成功",grade);
    }

    @PostMapping("/list")
    public ResultVo list(@RequestBody TGrade tGrade) {
        Integer schoolid = tGrade.getSchoolid();
        N_Utils.validation(new Object[]{schoolid,"学校id",1});
        List<TGrade> list = gradeService.findAll(schoolid);
        return new ResultVo(0,"获取列表成功",list);
    }

    @PostMapping("/list_class")
    public ResultVo listClass(@RequestBody TGrade tGrade) {
        Integer schoolid = tGrade.getSchoolid();
        N_Utils.validation(new Object[]{schoolid,"学校id",1});
        List<GradeVo> list = gradeService.listClass(schoolid,tGrade.getClasstype());
        return new ResultVo(0,"获取班级列表成功",list);
    }

    @PostMapping("/list_class_stu")
    public ResultVo listClassStu(@RequestBody TGrade tGrade) {
        Integer schoolid = tGrade.getSchoolid();
        N_Utils.validation(new Object[]{schoolid, "学校id", 1});
        List<Map> list = gradeService.listClassStu(schoolid, tGrade.getClasstype());
        return new ResultVo(0, "获取班级学生列表成功", list);
    }

    //教师设置班级权限
    @PostMapping("/lct")
    public ResultVo listClassForTeacher(@RequestBody TGrade tGrade) {
        Integer schoolid = tGrade.getSchoolid();
        N_Utils.validation(new Object[]{schoolid,"学校id",1});
        List<GradeVo> list = gradeService.listClassForTeacher(schoolid);
        return new ResultVo(0,"获取班级列表成功",list);
    }

    @PostMapping("/list_teacher")
    public ResultVo listTeacher(@RequestBody TGrade tGrade) {
        Integer schoolid = tGrade.getSchoolid();
        N_Utils.validation(new Object[]{schoolid,"学校id",1});
        List<GradeVo> list = gradeService.listTeacher(schoolid);
        return new ResultVo(0,"获取教师列表成功",list);
    }

    /**
     * @Description 集团校教师列表
     * @Param [tGrade]
     * @Author ywx
     * @Date 2023/7/21 16:16
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_jtteacher")
    public ResultVo listJtTeacher(@RequestBody TGrade tGrade) {
        Integer schoolid = tGrade.getSchoolid();
        N_Utils.validation(new Object[]{schoolid, "学校id", 1});
        List<Map<String, String>> list = gradeService.listJtTeacher(schoolid);
        return new ResultVo(0, "获取集团校教师列表成功", list);
    }


    /*
    * @Description 集团校管理班级
    * @Author WN
    * @Date 2023/4/10 15:09
    */
    @PostMapping("/listjtc")
    public ResultVo listJtClasses(@RequestBody TGrade tGrade) {
        Integer schoolid = tGrade.getSchoolid();
        N_Utils.validation(new Object[]{schoolid,"学校id",1});
        List<Map> list = gradeService.listJtClasses(schoolid);
        return new ResultVo(0,"获取集团校班级列表成功",list);
    }
}
