package com.xhkjedu.smarking.controller.scan;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.smarking.model.scan.MsScanbatch;
import com.xhkjedu.smarking.model.scan.MsScanbatchPaper;
import com.xhkjedu.smarking.service.paper.MsPaperService;
import com.xhkjedu.smarking.service.scan.MsScanbatchService;
import com.xhkjedu.smarking.vo.scan.ScanParams;
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 auto
 * @Date 2024-10-15
 */
@RestController
@RequestMapping("/mscan")
public class MsScanbatchController {
    @Resource
    private MsScanbatchService msScanbatchService;
    @Resource
    private MsPaperService msPaperService;

    /**
     * @Description 新增试卷扫描批次
     * @Param [msScanbatch]
     * @Author auto
     * @Date 2024-10-15
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/save")
    public ResultVo save(@RequestBody MsScanbatch msScanbatch) {
        N_Utils.validation(new Object[]{msScanbatch.getMpid(), "试卷id", 1});
        return msScanbatchService.save(msScanbatch);
    }

    /*
     * @Description 扫描答卷-批次下试卷
     * @Date 2024/10/24 16:30:20
     * @Author WN
     * @Param [msScanbatch]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/papers")
    public ResultVo listPaperByBatchid(@RequestBody MsScanbatch msScanbatch) {
        Integer page = msScanbatch.getPage();
        Integer pageSize = msScanbatch.getPageSize();
        N_Utils.validation(new Object[]{page, "显示页码", 1, pageSize, "显示条数", 1,msScanbatch.getBatchid(), "批次id", 1});
        PageHelper.startPage(page, pageSize);
        List<MsScanbatchPaper> papers = msScanbatchService.listPaperByBatchid(msScanbatch.getBatchid());
        PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(papers));
        return new ResultVo(0, "获取成功", pageResult);
    }

    /*
     * @Description 扫描答卷-考试扫描信息
     * @Date 2024/10/24 15:12:56
     * @Author WN
     * @Param [msScanbatch]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/scan_paper")
    public ResultVo getExamScanPaper(@RequestBody MsScanbatch msScanbatch) {
        Integer mpid = msScanbatch.getMpid();
        N_Utils.validation(new Object[]{mpid, "试卷id", 1});
        Map<String, Object> map = msScanbatchService.getExamPaperScanInfo(mpid);
        return new ResultVo(0, "查询成功", map);
    }

    /*
     * @Description 扫描记录-扫描信息、考试班级、扫描批次
     * @Date 2024/10/25 14:49:07
     * @Author WN
     * @Param [msScanbatch]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/record_info")
    public ResultVo getScanPaperRecordInfo(@RequestBody MsScanbatch msScanbatch) {
        Integer mpid = msScanbatch.getMpid();
        N_Utils.validation(new Object[]{mpid, "试卷id", 1});
        Map<String, Object> map = msScanbatchService.getScanRecordAndClass(mpid);
        return new ResultVo(0, "查询成功", map);
    }

    /*
     * @Description 扫描记录-按班级
     * @Date 2024/10/25 16:51:59
     * @Author WN
     * @Param [params]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/record_class")
    public ResultVo listRecordClassStudents(@RequestBody ScanParams params) {
        Integer page = params.getPage();
        Integer pageSize = params.getPageSize();
        N_Utils.validation(new Object[]{params.getMpid(), "试卷id", 1,params.getExamid(), "考试id", 1,page, "显示页码", 1, pageSize, "显示条数", 1});
        PageHelper.startPage(page, pageSize);
        int examid = msPaperService.getExamidByMpid(params.getMpid());
        params.setExamid(examid);
        List<Map<String, Object>> list = msScanbatchService.listRecordClassStudents(params);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(list));
        return new ResultVo(0, "查询成功", pageResult);
    }

    /*
     * @Description 扫描记录-按班级-导出
     * @Date 2024/10/25 17:00:23
     * @Author WN
     * @Param [params]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/record_class_exp")
    public ResultVo listRecordClassStudentsExpport(@RequestBody ScanParams params) {
        N_Utils.validation(new Object[]{params.getMpid(), "试卷id", 1});
        int examid = msPaperService.getExamidByMpid(params.getMpid());
        params.setExamid(examid);
        List<Map<String, Object>> list = msScanbatchService.listRecordClassStudents(params);
        return new ResultVo(0, "查询成功", list);
    }

    /*
     * @Description 扫描记录-按班级
     * @Date 2024/10/25 16:55:40
     * @Author WN
     * @Param [params]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/record_batch")
    public ResultVo listRecordBatchStudents(@RequestBody ScanParams params) {
        Integer page = params.getPage();
        Integer pageSize = params.getPageSize();
        N_Utils.validation(new Object[]{params.getMpid(), "试卷id", 1,page, "显示页码", 1, pageSize, "显示条数", 1});
        PageHelper.startPage(page, pageSize);
        List<Map<String, Object>> list = msScanbatchService.listRecordBatchStudents(params);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(list));
        return new ResultVo(0, "查询成功", pageResult);
    }

    /*
     * @Description 扫描记录-按班级-导出
     * @Date 2024/10/25 17:01:09
     * @Author WN
     * @Param [params]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/record_batch_exp")
    public ResultVo listRecordBatchStudentsExport(@RequestBody ScanParams params) {
        N_Utils.validation(new Object[]{params.getMpid(), "试卷id", 1});
        List<Map<String, Object>> list = msScanbatchService.listRecordBatchStudents(params);
        return new ResultVo(0, "查询成功", list);
    }
}
