package com.xhkjedu.sexam.controller.paper;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.annotation.Action;
import com.xhkjedu.sexam.model.exam.ESubject;
import com.xhkjedu.sexam.model.paper.EPaper;
import com.xhkjedu.sexam.model.paper.EPaperBack;
import com.xhkjedu.sexam.model.paperstudent.EPaperStudent;
import com.xhkjedu.sexam.service.paper.EPaperService;
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.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Description 试卷信息
 * @Author WN
 * Date 2022/7/18 10:31
 **/
@RestController
@RequestMapping("/ep")
public class EPaperController {
    @Resource
    private EPaperService ePaperService;

    //考试各科目试卷设置（管理员）
    @PostMapping("/list")
    public ResultVo examPaperList(@RequestBody EPaper paper){
        N_Utils.validation(new Object[]{paper.getExamid(),"考试id",1});
        Map map = ePaperService.listExamPapers(paper.getExamid());
        return new ResultVo(0,"成功获取考试试卷信息",map);
    }

    //试卷分析
    @PostMapping("/an")
    public ResultVo examPaperAnalyze(@RequestBody EPaper paper){
        N_Utils.validation(new Object[]{paper.getEpid(),"试卷id",1});
        Map amap  = ePaperService.getPaperAnalzyeByEpid(paper.getEpid());
        return new ResultVo(0,"成功获取考试试卷分析",amap);
    }

    //退回试卷
    @PostMapping("/sb")
    @Action("考试测评-退回试卷")
    public ResultVo saveExamPaperBack(@RequestBody EPaperBack ePaperBack){
        N_Utils.validation(new Object[]{ePaperBack.getEpid(),"试卷id",1});
        ePaperService.savePaperBack(ePaperBack);
        return new ResultVo(0,"成功退回试卷",null);
    }

    //试卷退回列表
    @PostMapping("/bl")
    public ResultVo listPaperBacks(@RequestBody EPaperBack ePaperBack){
        N_Utils.validation(new Object[]{ePaperBack.getEpid(),"试卷id",1});
        List<Map> list = ePaperService.listPaperBacksByEpid(ePaperBack.getEpid());
        return new ResultVo(0,"成功获取试卷退回原因",list);
    }

    //教师出卷列表
    @PostMapping("/listt")
    public ResultVo examTeacherPaperList(@RequestBody ESubject subject){
        Integer page = subject.getPage();
        Integer pageSize = subject.getPageSize();
        N_Utils.validation(new Object[]{subject.getTeacherid(),"教师id",1,page,"显示页码",1,pageSize,"显示条数",1});
        PageHelper.startPage(page, pageSize);
        List<Map> rtnlst = ePaperService.listExamPapersByTeacherid(subject.getTeacherid(),subject.getEsstate());
        PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(rtnlst));
        return new ResultVo(0,"成功获取教师出卷信息",pageResult);
    }

    //获取试卷文件
    @PostMapping("/files")
    public ResultVo listPaperFiles(@RequestBody EPaperStudent ePaperStudent){
        N_Utils.validation(new Object[]{ePaperStudent.getEpsid(),"学生试卷id",1});
        List<Map> list = ePaperService.listExamPaperFiles(ePaperStudent.getEpsid());
        return new ResultVo(0,"成功获取试卷文件",list);
    }

    //获取试卷原文件
    @PostMapping("/yfiles")
    public ResultVo listPaperSourcefiles(@RequestBody EPaperStudent ePaperStudent){
        N_Utils.validation(new Object[]{ePaperStudent.getEpsid(),"学生试卷id",1});
        List<String> list = ePaperService.listPaperSourceFilesByEpsid(ePaperStudent.getEpsid());
        return new ResultVo(0,"成功获取试卷文件",list);
    }


}
