package com.xhkjedu.suser.controller.gradeclass;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.annotation.Action;
import com.xhkjedu.suser.model.gradeclass.TClass;
import com.xhkjedu.suser.model.gradeclass.TClassTeacher;
import com.xhkjedu.suser.service.gradeclass.ClassTeacherService;
import com.xhkjedu.suser.vo.gradeclass.ClassTeacherParams;
import com.xhkjedu.suser.vo.gradeclass.ClassTeacherVo;
import com.xhkjedu.suser.vo.gradeclass.ClassVo;
import com.xhkjedu.utils.N_Utils;
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;
import java.util.Map;

/**
 * @author ywx
 * @classname TClassTeacherController
 * @description 
 * @date 2020/6/2 16:27
 **/
@RestController
@RequestMapping("/class_teacher")
public class ClassTeacherController {
    @Resource
    private ClassTeacherService classTeacherService;

    @PostMapping("/add")
    @Action("班级教师-增加")
    public ResultVo add(@RequestBody TClassTeacher tClassTeacher) {
        Integer id = classTeacherService.save(tClassTeacher);
        return new ResultVo(0, "保存成功",id);
    }

    @PostMapping("/update")
    @Action("班级教师-修改")
    public ResultVo update(@RequestBody TClassTeacher tClassTeacher) {
        N_Utils.validation(new Object[]{tClassTeacher.getTeacherid(),"教师id",1});
        classTeacherService.update(tClassTeacher);
        return new ResultVo(0,"修改成功");
    }

    @PostMapping("/list")
    public ResultVo list(@RequestBody TClassTeacher tClassTeacher) {
        Integer schoolid = tClassTeacher.getSchoolid();
        N_Utils.validation(new Object[]{tClassTeacher.getPage(),"显示页码",1,
                tClassTeacher.getPageSize(),"显示条数",1,schoolid,"学校id",1});
        Integer year = classTeacherService.getYear(schoolid);
        PageHelper.startPage(tClassTeacher.getPage(),tClassTeacher.getPageSize());
        List<ClassTeacherVo> list = classTeacherService.findAll(tClassTeacher, year);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo(list));
        return new ResultVo(0,"获取列表成功",pageResult);
    }

    /**
     *功能描述  获取教师当前年份任教班级
     * @author WN
     * @date 2020/6/13
     * @param  * @param cl
     */
    @PostMapping("/tclist")
    public ResultVo teacherClass(@RequestBody TClass cl) {
        N_Utils.validation(new Object[]{cl.getCreateid(),"教师id",1});
        List<ClassVo> list = classTeacherService.listTeacherClass(cl.getCreateid(),cl.getClasstype());
        return new ResultVo(0,"获取教师任教班级",list);
    }

    @PostMapping("/tclist2")
    public ResultVo teacherClass2(@RequestBody TClass cl) {
        N_Utils.validation(new Object[]{cl.getCreateid(),"教师id",1});
        List<ClassVo> list = classTeacherService.listTeacherClass2(cl.getCreateid());
        return new ResultVo(0,"获取教师任教班级",list);
    }

    //作业学生集合
    @PostMapping("/paper_student_list")
    public ResultVo listPaperStudent(@RequestBody Map paper) {
        Integer paperid = (Integer) paper.get("paperid");
        N_Utils.validation(new Object[]{paperid,"作业id",1});
        List<Map> list = classTeacherService.listPaperStudent(paperid);
        return new ResultVo(0,"获取作业学生列表成功",list);
    }


    @PostMapping("/paper_teacher_list")
    public ResultVo listPaperTeacher(@RequestBody Map paper) {
        Integer paperid = (Integer) paper.get("paperid");
        String subjectid = paper.get("subjectid").toString();
        N_Utils.validation(new Object[]{paperid,"作业id",1,subjectid,"科目id",2});
        List<Map> list = classTeacherService.listPaperTeacher(paperid, subjectid);
        return new ResultVo(0,"获取作业教师列表成功",list);
    }

    //获取当前年份年级下教师
    @PostMapping("/listteachers")
    public ResultVo listTeachers(@RequestBody TClass cl){
        N_Utils.validation(new Object[]{cl.getSchoolid(),"学校id",1,cl.getGradeid(),"年级",1});
        List<ClassTeacherVo> list = classTeacherService.listTeachersByGradeid(cl.getSchoolid(),cl.getGradeid());
        return new ResultVo(0,"获取教师任教班级",list);
    }

    /**
     * 功能描述  获取年级科目下老师
     *
     * @param * @param
     * @return com.xhkjedu.vo.ResultVo
     * @author WN
     * @date 2021/1/29
     */
    @PostMapping("/tsc")
    public ResultVo listTeachersBySubjectClass(@RequestBody ClassTeacherParams ctp) {

        N_Utils.validation(new Object[]{ctp.getSchoolid(), "学校id", 1,
                ctp.getGradeid(), "年级", 1, ctp.getSubjectid(), "科目", 1});
        List<ClassTeacherVo> lst = classTeacherService.listTeahcersBySubjectGrade(ctp);
        return new ResultVo(0, "获取年级科目下教师", lst);
    }

    /**
     * 获取年级科目下老师(标识是否是本班教师)
     *
     * @param [ctp]
     * @return com.xhkjedu.vo.ResultVo
     * @author ywx
     * @date 2022/5/5 11:14
     */
    @PostMapping("/tsc2")
    public ResultVo listTeachersBySubjectClass2(@RequestBody ClassTeacherParams ctp) {
        N_Utils.validation(new Object[]{ctp.getSchoolid(), "学校id", 1,
                ctp.getGradeid(), "年级", 1, ctp.getSubjectid(), "科目", 1, ctp.getClassid(), "班级id", 1});
        List<Map> lst = classTeacherService.listTeahcersBySubjectGrade2(ctp);
        return new ResultVo(0, "获取年级科目下教师", lst);
    }
}
