package com.dayou.controller;

import com.dayou.vo.ReportMainVO;
import com.dayou.vo.ReportSectionTreeVO;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.RestController;
import com.dayou.controller.BaseController;
import com.dayou.service.IReportMainService;
import com.dayou.entity.ReportMain;
import com.dayou.common.RestResponse;
import org.springframework.web.bind.annotation.*;
import com.dayou.utils.ConvertUtil;
import com.dayou.utils.HttpKit;
import com.dayou.exception.ErrorCode;
import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.http.MediaType;
import org.springframework.web.multipart.MultipartFile;
/**
 * 报告主表
 *
 * @author wucl
 * @since 2023-08-29
 */
@RestController
@RequestMapping("reportMain")
@Slf4j
public class ReportMainController extends BaseController {
    @Autowired
    private IReportMainService reportMainService;

    /**
    * 报告主表列表
    */
    @GetMapping("")
    public RestResponse<Page<ReportMainVO>> page(ReportMainVO reportMain, Page page){
        Page<ReportMainVO> pages=reportMainService.selectPage(page,reportMain);
        return RestResponse.data(pages);
    }

    /**
     * 报告主表详情
     */
    @GetMapping("/{id}")
    public RestResponse<ReportMainVO> detail(@PathVariable Long id){
        ReportMainVO xReportMain =reportMainService.detail(id);
        return RestResponse.data(xReportMain);
     }

    /**
     * 报告主表新增
     */
    @PostMapping("")
    public RestResponse<Boolean> save(@RequestBody ReportMain reportMain) {
        Boolean ret = reportMainService.add(reportMain);
        return RestResponse.data(ret);
    }

    /**
     * 报告主表更新
     */
    @PutMapping("")
    public RestResponse<Boolean> updateNouns(@RequestBody ReportMainVO reportMain) {
        Boolean ret = reportMainService.updateNouns(reportMain);
        return RestResponse.data(ret);
    }

    /**
     * 报告主表删除
     */
    @DeleteMapping("/{id}")
    public RestResponse<Boolean> delete(@PathVariable Long id) {
        Boolean ret = reportMainService.delete(id);
        return RestResponse.data(ret);
    }


    /**
     * 生成报告
     * @return
     */
    @GetMapping("/generate/{id}")
    public RestResponse<Boolean> generateReport(@PathVariable("id") Long id) throws Exception {
        Boolean ret = reportMainService.generateReport(id);
        return RestResponse.data(ret);
    }

    /**
     * 获取报告标题段落树
     * @param id 报告id
     * @return
     */
    @GetMapping("/tree/{id}")
    public RestResponse<List<ReportSectionTreeVO>> getReportHeadlineTree(@PathVariable("id") Long id){
        List<ReportSectionTreeVO> tree = reportMainService.getReportHeadlineTree(id);
        return RestResponse.data(tree);
    }
}

