package com.xhkjedu.slive.controller.liveplay;

import com.xhkjedu.slive.model.liveplay.LCourseSectionStudent;
import com.xhkjedu.slive.service.liveplay.CourseSectionStudentService;
import com.xhkjedu.slive.vo.liveplay.CSStudentVo;
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 javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
* @author ywx
* @classname LCourseSectionStudentController
* @description
* @date 2021/01/15 12:25
**/
@RestController
@RequestMapping("/section_student")
public class CourseSectionStudentController {
    @Resource
    private CourseSectionStudentService courseSectionStudentService;

    @PostMapping("/add")
    public ResultVo add(@RequestBody LCourseSectionStudent student, HttpServletRequest request) {
        courseSectionStudentService.save(student,request);
        return new ResultVo(0, "保存成功");
    }

    @PostMapping("/list")
    public ResultVo list(@RequestBody LCourseSectionStudent student) {
        Integer sectionid = student.getSectionid();
        N_Utils.validation(new Object[]{sectionid,"课节id",1});
        List<CSStudentVo> list = courseSectionStudentService.listBySectionId(sectionid);
        return new ResultVo(0,"获取课节学生列表成功",list);
    }

    @PostMapping("/in_section")
    public ResultVo inSection(@RequestBody LCourseSectionStudent student,HttpServletRequest request) {
        N_Utils.validation(new Object[]{student.getSectionid(),"课节id",1,student.getStudentid(),"学生id",1
                ,student.getDevice(),"设备类型",2});
        return courseSectionStudentService.inSection(student,request);
    }

    @PostMapping("/out_section")
    public ResultVo outSection(@RequestBody LCourseSectionStudent student) {
        N_Utils.validation(new Object[]{student.getSectionid(),"课节id",1,student.getStudentid(),"学生id",1
                ,student.getDevice(),"设备类型",2});
        courseSectionStudentService.outSection(student);
        return new ResultVo(0,"学生退出课节成功");
    }

    @PostMapping("/update_time")
    public ResultVo updateTime(@RequestBody LCourseSectionStudent student) {
        N_Utils.validation(new Object[]{student.getSectionid(),"课节id",1,student.getStudentid(),"学生id",1
                ,student.getDevice(),"设备类型",2});
        courseSectionStudentService.updateTime(student);
        return new ResultVo(0,"修改成功");
    }
}
