package com.xhkjedu.smarking.controller.paper;

import com.xhkjedu.smarking.model.paper.MsPaper;
import com.xhkjedu.smarking.model.paper.MsTemplate;
import com.xhkjedu.smarking.service.paper.MsTemplateService;
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("/mtemplate")
public class MsTemplateController {
    @Resource
    private MsTemplateService msTemplateService;

    /*
     * @Description 试卷模板列表
     * @Date 2024/10/18 14:48:12
     * @Author WN
     * @Param [paper]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list")
    public ResultVo queryList(@RequestBody MsPaper paper) {
        N_Utils.validation(new Object[]{paper.getMpid(),"试卷id",1});
        Map<String,Object> rtnMap = msTemplateService.listTemplatesByMpid(paper.getMpid());
        return new ResultVo(0, "查询成功", rtnMap);
    }

    /**
     * @Description 模板-新增
     * @Param [msTemplate]
     * @Author auto
     * @Date 2024-10-15
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/save")
    public ResultVo save(@RequestBody MsTemplate msTemplate) {
        N_Utils.validation(new Object[]{msTemplate.getMpid(),"试卷id",1});
        return new ResultVo(0, "保存成功",msTemplateService.save(msTemplate));
    }

    /*
     * @Description 模板-设置
     * @Date 2024/10/21 10:55:50
     * @Author WN
     * @Param [msTemplate]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/update")
    public ResultVo updateTemplate(@RequestBody MsTemplate msTemplate) {
        N_Utils.validation(new Object[]{msTemplate.getMpid(),"试卷id",1,msTemplate.getMtid(),"模板id",1,msTemplate.getCurrstep(),"当前步骤",1});
        MsTemplate mt = msTemplateService.updateTemplate(msTemplate);
        return new ResultVo(0, "保存成功",mt);
    }

    /*
     * @Description 保存模板主观题框选
     * @Date 2024/10/21 17:44:35
     * @Author WN
     * @Param [params]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/save_sub")
    public ResultVo saveSubjective(@RequestBody MsPaperParams params) {
        N_Utils.validation(new Object[]{params.getMpid(),"试卷id",1,params.getMtid(),"模板id",1});
        msTemplateService.saveSubjectiveQuestion(params);
        return new ResultVo(0, "保存成功",params.getMtid());
    }

    /*
     * @Description 删除模板
     * @Date 2024/10/21 17:50:46
     * @Author WN
     * @Param [msTemplate]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/delete")
    public ResultVo delete(@RequestBody MsTemplate msTemplate) {
        N_Utils.validation(new Object[]{msTemplate.getMtid(),"模板id",1});
        msTemplateService.deleteTemplate(msTemplate.getMtid());
        return new ResultVo(0, "删除成功");
    }

    /*
     * @Description 模板详情
     * @Date 2024/10/23 14:06:38
     * @Author WN
     * @Param [msTemplate]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/detail")
    public ResultVo detail(@RequestBody MsTemplate msTemplate) {
        N_Utils.validation(new Object[]{msTemplate.getMtid(),"模板id",1});
        MsTemplate rtnObj = msTemplateService.getTemplateDetailByMtid(msTemplate);
        return new ResultVo(0, "查询成功",rtnObj);
    }

    /*
     * @Description 模板题块详情-主观题
     * @Date 2024/10/24 10:25:43
     * @Author WN
     * @Param [msTemplate]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/detail_sub")
    public ResultVo getSubjectiveBlocks(@RequestBody MsTemplate msTemplate) {
        N_Utils.validation(new Object[]{msTemplate.getMtid(),"模板id",1});
        List<Map<String,Object>> rtnObjs = msTemplateService.listTemplateBlocksByMtidAndType(msTemplate.getMtid());
        return new ResultVo(0, "查询成功",rtnObjs);
    }

    /*
     * @Description 主观题框选-题块模板
     * @Date 2024/12/27 16:54:30
     * @Author WN
     * @Param [msTemplate]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/block_temp")
    public ResultVo listBlockTemplates(@RequestBody MsTemplate msTemplate) {
        N_Utils.validation(new Object[]{msTemplate.getMpid(),"试卷id",1,msTemplate.getMtid(),"模板id",1});
        List<Map<String,Object>> rtnObjs = msTemplateService.listBlockTemplates(msTemplate.getMpid(),msTemplate.getMtid());
        return new ResultVo(0, "查询成功",rtnObjs);
    }


}
