package com.xhkjedu.sstudy.controller.paper;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.annotation.Action;
import com.xhkjedu.sstudy.model.paper.TPaper;
import com.xhkjedu.sstudy.model.paperstudent.TPaperClass;
import com.xhkjedu.sstudy.service.paperreport.PaperReportService;
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;

/**
 * @Description 作业报告
 * @Author ywx
 * Date 2023/4/18 15:41
 **/
@RestController
@RequestMapping("/pr")
public class PaperReportController {
    @Resource
    private PaperReportService paperReportService;

    /**
     * @Description 生成报告
     * @Param [paper]
     * @Author ywx
     * @Date 2023/4/18 15:46
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("gpr")
    @Action("作业管理-生成报告")
    public ResultVo generatePaperReport(@RequestBody TPaperClass paper) {
        Integer paperid = paper.getPaperid();
        N_Utils.validation(new Object[]{paperid, "作业id", 1});
        paperReportService.generatePaperReport(paperid);
        return new ResultVo(0, "生成报告成功");
    }

    /**
     * @Description 作业概况
     * @Param [paper]
     * @Author ywx
     * @Date 2023/4/18 15:48
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("po")
    public ResultVo getPaperOverview(@RequestBody TPaperClass paper) {
        Integer paperid = paper.getPaperid();
        Integer classid = paper.getClassid();
        N_Utils.validation(new Object[]{paperid, "作业id", 1, classid, "班级id", 1});
        Map map = paperReportService.getPaperOverview(paperid, classid);
        return new ResultVo(0, "获取作业概况成功", map);
    }

    /**
     * @Description 作业详情
     * @Param [paper]
     * @Author ywx
     * @Date 2023/4/19 9:01
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("pd")
    public ResultVo getPaperDetail(@RequestBody TPaperClass paper) {
        Integer paperid = paper.getPaperid();
        Integer classid = paper.getClassid();
        N_Utils.validation(new Object[]{paperid, "作业id", 1, classid, "班级id", 1});
        Map map = paperReportService.getPaperDetail(paperid, classid);
        return new ResultVo(0, "获取作业详情成功", map);
    }

    /**
     * @Description 未提交学生列表
     * @Param [paper]
     * @Author ywx
     * @Date 2023/4/19 11:27
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("list_wtjstu")
    public ResultVo listWtjStu(@RequestBody TPaperClass paper) {
        Integer paperid = paper.getPaperid();
        Integer classid = paper.getClassid();
        N_Utils.validation(new Object[]{paperid, "作业id", 1, classid, "班级id", 1});
        List<Map> list = paperReportService.listWtjStu(paperid, classid);
        return new ResultVo(0, "获取未提交学生列表成功", list);
    }

    /**
     * @Description 已提交学生列表
     * @Param [paper]
     * @Author ywx
     * @Date 2023/4/19 14:10
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("list_tjstu")
    public ResultVo listTjStu(@RequestBody TPaper paper) {
        Integer paperid = paper.getPaperid();
        Integer classid = paper.getClassid();
        Integer page = paper.getPage();
        N_Utils.validation(new Object[]{paperid, "作业id", 1, classid, "班级id", 1});
        if (N_Utils.isEmptyInteger(page)) {
            List<Map> list = paperReportService.listTjStu(paper);
            return new ResultVo(0, "获取已提交学生列表成功", list);
        } else {
            PageHelper.startPage(page, paper.getPageSize());
            List<Map> list = paperReportService.listTjStu(paper);
            PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(list));
            return new ResultVo(0, "获取已提交学生列表成功", pageResult);
        }
    }

    /**
     * @Description 作业基本信息
     * @Param [paper]
     * @Author ywx
     * @Date 2023/4/19 17:16
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("p")
    public ResultVo getPaper(@RequestBody TPaperClass paper) {
        Integer paperid = paper.getPaperid();
        N_Utils.validation(new Object[]{paperid, "作业id", 1});
        Map map = paperReportService.getPaper(paperid);
        return new ResultVo(0, "获取作业基本信息成功", map);
    }

    /**
     * @Description 优秀作答班级
     * @Param [paper]
     * @Author ywx
     * @Date 2023/6/26 9:58
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("gac")
    public ResultVo listGoodAnswerClass(@RequestBody TPaperClass paper) {
        Integer paperid = paper.getPaperid();
        Integer schoolid = paper.getSchoolid();
        Integer papertype = paper.getPapertype();
        N_Utils.validation(new Object[]{paperid, "作业id", 1, schoolid, "学校id", 1, papertype, "作业类型", 1});
        List<Map> list = paperReportService.listGoodAnswerClass(paperid, schoolid, papertype);
        return new ResultVo(0, "获取优秀作答班级成功", list);
    }

    /**
     * @Description 作业提交详情
     * @Date 2024/6/19 10:32
     * @Author YWX
     * @Param [paper]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("list_stu")
    public ResultVo listStu(@RequestBody TPaper paper) {
        Integer paperid = paper.getPaperid();
        Integer classid = paper.getClassid();
        N_Utils.validation(new Object[]{paperid, "作业id", 1, classid, "班级id", 1});
        List<Map> list = paperReportService.listStu(paper);
        return new ResultVo(0, "获取成功", list);
    }
}
