package com.xhkjedu.suser.controller.gradeclass;

import com.xhkjedu.annotation.Action;
import com.xhkjedu.suser.model.gradeclass.TGroup;
import com.xhkjedu.suser.model.gradeclass.TGroupStudent;
import com.xhkjedu.suser.service.gradeclass.GroupStudentService;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.vo.ResultVo;
import com.xhkjedu.suser.vo.gradeclass.GroupStudentVo;
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 TGroupStudentController
 * @description 
 * @date 2020/6/2 16:49
 **/
@RestController
@RequestMapping("/group_student")
public class GroupStudentController {
    @Resource
    private GroupStudentService groupStudentService;

    @PostMapping("/add")
    @Action("分组学生-增加")
    public ResultVo add(@RequestBody TGroup group) {
        groupStudentService.batchSave(group);
        return new ResultVo(0, "保存成功");
    }

    @PostMapping("/delete")
    @Action("分组学生-删除")
    public ResultVo delete(@RequestBody TGroupStudent group) {
        N_Utils.validation(new Object[]{group.getGroupid(),"分组id",1});
        groupStudentService.deleteById(group);
        return new ResultVo(0,"删除成功");
    }

    @PostMapping("/list")
    public ResultVo list(@RequestBody TGroupStudent tGroupStudent) {
        Integer groupid = tGroupStudent.getGroupid();
        N_Utils.validation(new Object[]{groupid,"分组id",1});
        List<GroupStudentVo> list = groupStudentService.findAll(groupid);
        return new ResultVo(0,"获取列表成功",list);
    }
}
