package com.xhkjedu.smarking.controller.paper;

import com.xhkjedu.smarking.model.exam.MsSubject;
import com.xhkjedu.smarking.model.paper.MsPaper;
import com.xhkjedu.smarking.model.paper.MsPaperFile;
import com.xhkjedu.smarking.model.paper.MsPaperQtype;
import com.xhkjedu.smarking.model.paper.MsPaperQtypeQuestion;
import com.xhkjedu.smarking.service.paper.MsPaperQtypeService;
import com.xhkjedu.smarking.vo.paper.MsPaperParams;
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 java.util.List;
import java.util.Map;

/**
 * @Description 阅卷试卷题型表相关操作
 * @Author auto
 * @Date 2024-10-15
 */
@RestController
@RequestMapping("/pqtype")
public class MsPaperQtypeController {
    @Resource
    private MsPaperQtypeService msPaperQtypeService;

    /**
     * @Description 新增
     * @Param [msPaperQtype]
     * @Author auto
     * @Date 2024-10-15
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/save")
    public ResultVo save(@RequestBody MsPaper paper) {
        N_Utils.validation(new Object[]{paper.getMpid(),"试卷id",1});
        List<MsPaperQtype> qtypes = paper.getQtypes();
        if(qtypes == null || qtypes.isEmpty()){
            return new ResultVo(1,"未设置试题");
        }
        return msPaperQtypeService.savePaperQtype(paper,1);
    }

    /*
     * @Description 保存并提交
     * @Date 2024/10/30 14:40:09
     * @Author WN
     * @Param [paper]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/save_commit")
    public ResultVo saveAndCommit(@RequestBody MsPaper paper) {
        N_Utils.validation(new Object[]{paper.getMpid(),"试卷id",1});
        List<MsPaperQtype> qtypes = paper.getQtypes();
        if(qtypes == null || qtypes.isEmpty()){
            return new ResultVo(1,"未设置试题");
        }
        return msPaperQtypeService.savePaperQtype(paper,2);
    }

    /*
     * @Description 试卷答案-客观题
     * @Date 2024/10/17 15:47:05
     * @Author WN
     * @Param [qtype]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/answer_obj")
    public ResultVo answerObjective(@RequestBody MsPaperQtype qtype){
        N_Utils.validation(new Object[]{qtype.getMpid(),"试卷id",1});
        List<MsPaperQtypeQuestion> questions = qtype.getQuestions();
        if(questions == null || questions.isEmpty()){
            return new ResultVo(1,"未设置试题答案");
        }
        return msPaperQtypeService.answerObjective(qtype);
    }

    /*
     * @Description 试卷答案-主观题答案
     * @Date 2024/10/17 16:01:07
     * @Author WN
     * @Param [paper]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/answer_sub")
    public ResultVo answerSubjective(@RequestBody MsPaper paper){
        N_Utils.validation(new Object[]{paper.getMpid(),"试卷id",1});
        List<MsPaperFile> pfiles = paper.getPfiles();
        if(pfiles == null || pfiles.isEmpty()){
            return new ResultVo(1,"未上传文件");
        }
        msPaperQtypeService.answerSubjective(paper);
        return new ResultVo(0,"保存成功");
    }

    /*
     * @Description 试题知识点
     * @Date 2024/10/17 17:08:33
     * @Author WN
     * @Param [paper]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/save_point")
    public ResultVo saveQuestionPoint(@RequestBody MsPaper paper){
        N_Utils.validation(new Object[]{paper.getMpid(),"试卷id",1});
        List<MsPaperQtypeQuestion> questions = paper.getQuestions();
        if(questions == null || questions.isEmpty()){
            return new ResultVo(1,"未设置试题知识点");
        }
        msPaperQtypeService.saveQuestionPoints(paper);
        return new ResultVo(0,"保存成功");
    }

    /*
     * @Description 获取科目试卷详情
     * @Date 2024/10/18 9:32:00
     * @Author WN
     * @Param [subject]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/detail")
    public ResultVo paperDetailInfo(@RequestBody MsSubject subject){
        N_Utils.validation(new Object[]{subject.getMsid(),"考试科目id",1});
        Map<String,Object> map =msPaperQtypeService.getPaperDetail(subject.getMsid());
        return new ResultVo(0,"获取成功" ,map);
    }

    /*
     * @Description 试卷-客观题/主观题
     * @Date 2024/10/21 13:53:38
     * @Author WN
     * @Param [subject]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/paper_que")
    public ResultVo listObjOrSubQuesitons(@RequestBody MsPaperParams params){
        N_Utils.validation(new Object[]{params.getMpid(),"试卷id",1});
        List<Map<String,Object>> map =msPaperQtypeService.listPaperSubjectiveQuestions(params.getMpid(),params.getQtype());
        return new ResultVo(0,"获取成功" ,map);
    }

    /*
     * @Description 试卷文件-原卷或答案
     * @Date 2024/11/14 10:42:34
     * @Author WN
     * @Param [paper]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/paper_file")
    public ResultVo listSubjectiveQuesitons(@RequestBody MsPaperFile paper){
        N_Utils.validation(new Object[]{paper.getMpid(),"试卷id",1,paper.getFiletype(),"文件类型",1});
        List<Map<String,Object>> map =msPaperQtypeService.listFileByFiletype(paper.getMpid(),paper.getFiletype());
        return new ResultVo(0,"获取成功" ,map);
    }

    /*
     * @Description 线下试卷-保存题型及试题
     * @Date 2024/12/4 10:40:53
     * @Author WN
     * @Param [qtype]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/qtype_save")
    public ResultVo saveOfflineQtype(@RequestBody MsPaperQtype qtype) {
        N_Utils.validation(new Object[]{qtype.getMpid(),"试卷id",1});
        List<MsPaperQtypeQuestion> questions = qtype.getQuestions();
        if(questions == null || questions.isEmpty()){
            return new ResultVo(1,"未设置试题");
        }
        return msPaperQtypeService.saveQtypeQuestionOffline(qtype);
    }

    /*
     * @Description 线下试卷-修改题型及试题
     * @Date 2024/12/4 10:42:29
     * @Author WN
     * @Param [qtype]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/qtype_update")
    public ResultVo updateOfflineQtype(@RequestBody MsPaperQtype qtype) {
        N_Utils.validation(new Object[]{qtype.getMpid(),"试卷id",1,qtype.getMptid(),"题型id",1});
        List<MsPaperQtypeQuestion> questions = qtype.getQuestions();
        if(questions == null || questions.isEmpty()){
            return new ResultVo(1,"未设置试题");
        }
        return msPaperQtypeService.updateQtypeQuestionOffline(qtype);
    }

    /*
     * @Description 线下试卷-删除题型
     * @Date 2024/12/4 10:45:45
     * @Author WN
     * @Param [qtype]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/qtype_del")
    public ResultVo deleteOfflineQtype(@RequestBody MsPaperQtype qtype) {
        N_Utils.validation(new Object[]{qtype.getMpid(),"试卷id",1,qtype.getMptid(),"题型id",1});
        return msPaperQtypeService.deleteQtypeOffline(qtype);
    }

    /*
     * @Description 线下试卷-移动题型
     * @Date 2024/12/4 10:54:08
     * @Author WN
     * @Param [params]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/qtype_move")
    public ResultVo moveOfflineQtype(@RequestBody MsPaperParams params) {
        N_Utils.validation(new Object[]{params.getMpid(),"试卷id",1,params.getMptid(),"题型id",1,params.getMovetype(),"移动类型",1});
        msPaperQtypeService.updateQtypeOrderOffline(params);
        return new ResultVo(0,"保存成功");
    }

    /*
     * @Description 线下试卷-修改试题
     * @Date 2024/12/4 10:55:44
     * @Author WN
     * @Param [question]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/que_update")
    public ResultVo updateOfflineQuestion(@RequestBody MsPaperQtypeQuestion question) {
        N_Utils.validation(new Object[]{question.getMpid(),"试卷id",1,question.getMptid(),"题型id",1,question.getMptqid(),"试题id",1});
        msPaperQtypeService.updateQuestionOffline(question);
        return new ResultVo(0,"保存成功");
    }

    /*
     * @Description 线下试卷-删除试题
     * @Date 2024/12/4 10:56:59
     * @Author WN
     * @Param [question]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/que_del")
    public ResultVo deleteOfflineQuestion(@RequestBody MsPaperQtypeQuestion question) {
        N_Utils.validation(new Object[]{question.getMpid(),"试卷id",1,question.getMptid(),"题型id",1,question.getMptqid(),"试题id",1});
        msPaperQtypeService.deleteQuestionOffline(question);
        return new ResultVo(0,"保存成功");
    }

    /*
     * @Description 线下试卷-移动试题
     * @Date 2024/12/4 10:58:39
     * @Author WN
     * @Param [params]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/que_move")
    public ResultVo moveOfflineQuestion(@RequestBody MsPaperParams params) {
        N_Utils.validation(new Object[]{params.getMpid(),"试卷id",1,params.getMptqid(),"试题id",1,params.getMovetype(),"移动类型",1});
        msPaperQtypeService.updateQuestionOrderOffline(params);
        return new ResultVo(0,"保存成功");
    }




}
