package com.xhkjedu.suser.controller.gradeclass;

import com.xhkjedu.annotation.Action;
import com.xhkjedu.suser.model.gradeclass.TGroup;
import com.xhkjedu.suser.model.subjectbook.TTeacherPowersb;
import com.xhkjedu.suser.service.gradeclass.GroupService;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.vo.ResultVo;
import com.xhkjedu.suser.vo.gradeclass.ClassGroupVo;
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 TGroupController
 * @description
 * @date 2020/6/2 14:58
 **/
@RestController
@RequestMapping("/group")
public class GroupController {
    @Resource
    private GroupService groupService;

    @PostMapping("/add")
    @Action("分组管理-增加")
    public ResultVo add(@RequestBody TGroup tGroup) {
        if (N_Utils.isListEmpty(tGroup.getStudents())){
            return new ResultVo(1,"分组学生不能为空");
        }
        Integer id = groupService.save(tGroup);
        return new ResultVo(0, "保存成功",id);
    }

    @PostMapping("/delete")
    @Action("分组管理-删除")
    public ResultVo delete(@RequestBody TGroup tGroup) {
        Integer grouptype = tGroup.getGrouptype();
        N_Utils.validation(new Object[]{tGroup.getGroupid(),"班级分组id",1,grouptype,"班级分组类型",1});
        if (grouptype == 1){
            return new ResultVo(1,"全体分组禁止删除");
        }
        groupService.deleteById(tGroup.getGroupid());
        return new ResultVo(0,"删除成功");
    }

    @PostMapping("/update")
    @Action("分组管理-修改")
    public ResultVo update(@RequestBody TGroup tGroup) {
        N_Utils.validation(new Object[]{tGroup.getGroupid(),"班级分组id",1});
        groupService.update(tGroup);
        return new ResultVo(0,"修改成功");
    }

    @PostMapping("/list")
    public ResultVo list(@RequestBody TGroup tGroup) {
        N_Utils.validation(new Object[]{tGroup.getClassid(),"班级id",1});
        List<TGroup> list = groupService.findAll(tGroup.getClassid(), tGroup.getCreateid());
        return new ResultVo(0,"获取列表成功",list);
    }

    @PostMapping("/teacher_list")
    public ResultVo teacherList(@RequestBody TGroup tGroup) {
        N_Utils.validation(new Object[]{tGroup.getCreateid(),"教师id",1});
        List<ClassGroupVo> list = groupService.teacherList(tGroup.getCreateid());
        return new ResultVo(0,"获取列表成功",list);
    }

    /**
     * @Description 伙伴学校班级分组列表
     * @Param [powersb]
     * @Author ywx
     * @Date 2023/4/11 14:13
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/teacher_listjtc")
    public ResultVo teacherListJtClass(@RequestBody TTeacherPowersb powersb) {
        Integer schoolid = powersb.getSchoolid();
        String subjectid = powersb.getSubjectid();
        Integer teacherid = powersb.getTeacherid();
        N_Utils.validation(new Object[]{schoolid, "学校id", 1, subjectid, "科目id", 2
                , teacherid, "教师id", 1});
        List<Map> list = groupService.teacherListJtClass(schoolid, subjectid, teacherid);
        return new ResultVo(0, "获取列表成功", list);
    }
}
