package jnpf.cultivate.v2.controller.web.promotion;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.cultivate.v2.service.V2CultivatePromotionService;
import jnpf.model.cultivate.CultivatePage;
import jnpf.model.cultivate.v2.promotion.req.V2PromotionOrgStatisticReq;
import jnpf.model.cultivate.v2.promotion.req.V2PromotionPersonStatisticReq;
import jnpf.model.cultivate.v2.promotion.vo.V2CultivatePromotionOrgStatisticVo;
import jnpf.model.cultivate.v2.promotion.vo.V2CultivatePromotionPersonStatisticVo;
import jnpf.util.EasyExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
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.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * web学习地图统计模块
 *
 * @author xgl
 */
@RestController
@RequestMapping("/v2/web/promotion/statistic")
public class V2CultivatePromotionStatisticController {
    /**
     * 服务对象
     */
    @Autowired
    private V2CultivatePromotionService promotionService;

    /**
     * 地图维度统计
     *
     * @param req 请求参数
     * @return 学习地图分页列表
     */
    @PostMapping("/map-statistics")
    public ActionResult<PageListVO<V2CultivatePromotionOrgStatisticVo>> mapStatistics(@RequestBody V2PromotionOrgStatisticReq req) {
        return ActionResult.success(CultivatePage.coverPageList(promotionService.organizationStatistics(req)));
    }

    /**
     * 地图维度统计 导出
     *
     * @param req 请求参数
     */
    @PostMapping("/map-statistics/export")
    public void mapStatisticsExport(@RequestBody V2PromotionOrgStatisticReq req, HttpServletResponse response) throws IOException {
        Page<V2CultivatePromotionOrgStatisticVo> listVO = promotionService.organizationStatistics(req);
        EasyExcelUtil.simpleWrite(listVO.getRecords(), "组织维度统计", V2CultivatePromotionOrgStatisticVo.class, response);
    }

    /**
     * 个人维度统计
     *
     * @param req 请求参数
     * @return 学习地图分页列表
     */
    @PostMapping("/person-statistics")
    public ActionResult<PageListVO<V2CultivatePromotionPersonStatisticVo>> personStatistics(@RequestBody V2PromotionPersonStatisticReq req) {
        return ActionResult.success(promotionService.personStatistics(req));
    }

    /**
     * 个人维度统计导出信息
     *
     * @param req      请求参数
     * @param response 响应
     */
    @PostMapping("/person-statistics/export")
    public void personStatisticsExport(@RequestBody V2PromotionPersonStatisticReq req, HttpServletResponse response) throws IOException {
        PageListVO<V2CultivatePromotionPersonStatisticVo> listVO = promotionService.personStatistics(req);
        EasyExcelUtil.simpleWrite(listVO.getList(), "个人维度统计", V2CultivatePromotionPersonStatisticVo.class, response);
    }
}
