package com.tuoheng.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tuoheng.admin.entity.domain.Report;
import com.tuoheng.admin.entity.request.ReportRequest;
import com.tuoheng.admin.entity.vo.ReportInfoVO;
import com.tuoheng.admin.entity.vo.ReportVO;
import com.tuoheng.admin.service.IReportService;
import com.tuoheng.common.common.OperationEnum;
import com.tuoheng.common.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spring.web.json.Json;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 巡检报告表 前端控制器
 *
 * @author qiujinyang
 * @since 2021-09-29
 */
@RestController
@RequestMapping("/report")
public class ReportController {

    @Autowired
    private IReportService reportService;

    /**
     * 提交并生成报告
     *
     * @param missionId 任务ID
     * @return
     */
    @PostMapping("/generate/{missionId}")
    public JsonResult generateReport(@PathVariable("missionId") Integer missionId) {
        return reportService.generateReport(missionId);
    }

    /**
     * 获取报告列表(分页)
     *
     * @param request 查询条件
     * @return
     */
    @GetMapping("/page")
    public JsonResult<IPage<Report>> queryPage(ReportRequest request) {
        return reportService.queryPage(request);
    }

    /**
     * 报告详情
     *
     * @param reportId 任务Id
     * @return
     */
    @GetMapping("/{reportId}")
    public JsonResult<ReportInfoVO> detail(@PathVariable("reportId") Integer reportId) {
        return JsonResult.success(reportService.detail(reportId));
    }


    /**
     * 导出报告word并下载
     *
     * @param reportId 报告ID
     * @return
     */
    @GetMapping(value = "{reportId}/word")
    public JsonResult<String> exportReportWord(@PathVariable("reportId") Integer reportId, HttpServletRequest request, HttpServletResponse response) throws Exception{
        return JsonResult.success(reportService.exportReportWord(reportId, request, response));
    }

    /**
     * 导出处理报告word并下载
     *
     * @param reportId 报告ID
     * @return
     */
    @GetMapping(value = "{reportId}/handleWord")
    public JsonResult<String> exportReportHandleWord(@PathVariable("reportId") Integer reportId, HttpServletRequest request, HttpServletResponse response) throws Exception{
        return JsonResult.success(reportService.exportReportHandleWord(reportId, request, response));
    }

}
