package com.xhkjedu.sstudy.controller.paperstudent;

import com.xhkjedu.sstudy.model.paperstudent.TPaperGroup;
import com.xhkjedu.sstudy.service.paperstudent.PaperGroupService;
import com.xhkjedu.sstudy.vo.paperstudent.PaperGroupParam;
import com.xhkjedu.sstudy.vo.paperstudent.PaperGroupVo;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
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 java.util.List;
import java.util.Map;

/**
 * @ClassName PaperGroupController
 * Description 作业--班级分组
 * Author WN
 * Date 2020/6/9 11:01
 **/
@RestController
@RequestMapping("/pg")
public class PaperGroupController {
    @Autowired
    private PaperGroupService paperGroupService;

    /**
     *功能描述  发布作业
     * @author WN
     * @date 2020/6/9
     * @param  * @param paperGroupParam
     * @return com.xhkjedu.vo.ResultVo
     */
    @PostMapping("/save")
    public ResultVo save(@RequestBody PaperGroupParam paperGroupParam){
        N_Utils.validation(new Object[]{paperGroupParam.getPaperid(),"作业id",1,paperGroupParam.getShowtype(),"公布答案",1,paperGroupParam.getClasslst(),"班级",1});
        return paperGroupService.savePaperGroup(paperGroupParam);
    }

    //发布作业（兼容靶向作业）
    @PostMapping("/save2")
    public ResultVo save2(@RequestBody PaperGroupParam paperGroupParam){
        N_Utils.validation(new Object[]{paperGroupParam.getPaperid(),"作业id",1,paperGroupParam.getShowtype(),"公布答案",1,paperGroupParam.getSelclass(),"班级",1});
        return paperGroupService.savePaperClassStu(paperGroupParam);
    }


    @PostMapping("/paper_student_list")
    public ResultVo listPaperStudent(@RequestBody TPaperGroup group) {
        Integer paperid = group.getPaperid();
        N_Utils.validation(new Object[]{paperid, "作业id", 1});
        List<PaperGroupVo> list = paperGroupService.listPaperStudent(paperid);
        return new ResultVo(0, "获取参与作业学生列表成功", list);
    }

    //作业发布对象
    @PostMapping("/list_object")
    public ResultVo listObject(@RequestBody TPaperGroup group) {
        Integer paperid = group.getPaperid();
        Integer createid = group.getCreateid();
        Integer papertype = group.getPapertype();
        N_Utils.validation(new Object[]{paperid, "试卷id", 1, createid, "发布人id", 1, papertype, "作业类型", 1});
        Map list = paperGroupService.listObject(paperid, createid, papertype);
        return new ResultVo(0, "获取发布对象成功", list);
    }
}
