package jnpf.cultivate.controller.web.learn;


import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageInfo;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.cultivate.service.FtbCultivateLearnTaskInfoCountService;
import jnpf.cultivate.utils.CultivateLearnUtils;
import jnpf.model.cultivate.req.learn.QueryLearnTaskCountListReq;
import jnpf.model.cultivate.vo.learn.FtbCultivateLearnTaskInfoCountListVO;
import jnpf.model.cultivate.vo.learn.FtbCultivateLearnTaskInfoListVO;
import jnpf.model.cultivate.vo.learn.FtbExportCultivateLearnTaskInfoCountListVO;
import jnpf.util.FtbUtil;
import jnpf.util.excel.EasyExcelUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.List;

/**
 * web学习任务统计模块
 *
 * @Author: xuguilin
 * @create: 2024/9/9:11:20
 */
@RestController
@Slf4j
@RequestMapping("/web/learnTask/count")
public class FtbCultivateLearnTaskCountController {

    @Autowired
    private FtbCultivateLearnTaskInfoCountService countService;


    /**
     * 查询任务统计数据列表
     *
     * @param req
     * @return {@link ActionResult}<{@link FtbCultivateLearnTaskInfoListVO}>
     */
    @GetMapping("/queryCountList")
    public ActionResult<PageListVO<FtbCultivateLearnTaskInfoCountListVO>> queryCountList(@Validated QueryLearnTaskCountListReq req) {
        PageInfo<FtbCultivateLearnTaskInfoCountListVO> pageVo = countService.queryCountList(req);
        return ActionResult.page(pageVo.getList(), FtbUtil.getPagination(pageVo));
    }

    /**
     * 导出搜索的任务列表
     *
     * @param req
     * @param response
     * @throws IOException
     */
    @GetMapping("/exportSearchTaskList")
    public void exportSearchTaskList(@Validated QueryLearnTaskCountListReq req, HttpServletResponse response) throws IOException {
        req.setPageSize(-1);
        req.setCurrentPage(1);
        PageInfo<FtbCultivateLearnTaskInfoCountListVO> pageVo = countService.queryCountList(req);
        List<FtbCultivateLearnTaskInfoCountListVO> list = pageVo.getList();
        List<FtbExportCultivateLearnTaskInfoCountListVO> exportList = CultivateLearnUtils.convertFtbExportCultivateLearnTaskInfoCountListVO(list);
        EasyExcelUtils.exportExcel(response, "培训任务统计-"+ DateUtil.format(new Date(), "yyyyMMddHHmmss"), exportList, FtbExportCultivateLearnTaskInfoCountListVO.class);
    }




}
