package jnpf.cultivate.controller.web.chapter;

import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.cultivate.service.FtbCultivateChapterTestService;
import jnpf.model.cultivate.CultivatePage;
import jnpf.model.cultivate.vo.chapter.FtbCultivateChapterTestStatisticVO;
import jnpf.util.excel.EasyExcelUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Title: web随堂测试统计
 * @Author: peng.hao
 * @create: 2024/6/11:9:27
 */
@RestController
@RequestMapping("/chapter-test")
public class FtbCultivateChapterTestStatisticController {


    @Resource
    private FtbCultivateChapterTestService chapterTestService;

    /**
     * 获取随堂测试统计
     * @return
     */
    @RequestMapping("/get-chapter-test-statistic")
    public ActionResult<PageListVO<FtbCultivateChapterTestStatisticVO>> getChapterTestStatistic(@RequestParam(value =  "keyWords" ,required = false) String  keyWords,
                                                                                                CultivatePage page) {
        return ActionResult.success(chapterTestService.getChapterTestStatistic(keyWords, page));
    }

    /**
     * 导出随堂测试统计
     * @param keyWords 关键字
     * @return
     */
    @RequestMapping("/export-chapter-test-statistic")
    public void exportChapterTestStatistic(@RequestParam(value =  "keyWords" ,required = false) String  keyWords,
                                           HttpServletResponse response) throws Exception {
        CultivatePage cultivatePage = new CultivatePage();
        cultivatePage.setPageSize(999999);
        PageListVO<FtbCultivateChapterTestStatisticVO> statistic = chapterTestService.getChapterTestStatistic(keyWords, cultivatePage);
        List<FtbCultivateChapterTestStatisticVO> list = statistic.getList();
        EasyExcelUtils.exportExcel( response,"随堂测试统计",list,FtbCultivateChapterTestStatisticVO.class);
    }
}
