package com.dayou.controller;

import com.dayou.report.dto.CalculateDataRequestDTO;
import com.dayou.report.dto.InputData;
import com.dayou.vo.ReportSectionTreeVO;
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 org.springframework.web.bind.annotation.RestController;
import com.dayou.service.IReportSectionService;
import com.dayou.entity.ReportSection;
import com.dayou.common.RestResponse;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
/**
 * 报告段落
 *
 * @author wucl
 * @since 2023-08-29
 */
@RestController
@RequestMapping("reportSection")
@Slf4j
public class ReportSectionController extends BaseController {
    @Autowired
    private IReportSectionService reportSectionService;

    /**
    * 报告段落列表
    */
    @GetMapping("")
    public RestResponse<Page<ReportSection>> page(ReportSection reportSection, Page page){
        Page<ReportSection> pages=reportSectionService.selectPage(page,reportSection);
        return RestResponse.data(pages);
    }

    /**
     * 报告段落详情
     */
    @GetMapping("/{id}")
    public RestResponse<ReportSection> detail(@PathVariable Long id){
        ReportSection xReportSection =reportSectionService.detail(id);
        return RestResponse.data(xReportSection);
     }

    /**
     * 报告段落新增
     */
    @PostMapping("")
    public RestResponse<Boolean> save(@RequestBody ReportSection reportSection) {
        Boolean ret = reportSectionService.add(reportSection);
        return RestResponse.data(ret);
    }

    /**
     * 报告段落更新
     */
    @PutMapping("")
    public RestResponse<String> update(@RequestBody ReportSectionTreeVO treeVO) {
        String ret = reportSectionService.updateSection(treeVO);
        return RestResponse.data(ret);
    }

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

    /**
     * 计算数据接收接口
     * @param calculateData
     * @return
     */
    @PostMapping("/calculate")
    public RestResponse<String> calculate(@RequestBody @Valid CalculateDataRequestDTO calculateData){
        String result = reportSectionService.calculate(calculateData);
        return RestResponse.data(result);
    }

    /**
     * 计算数据 结构
     * @param id sectionId
     * @return
     */
    @GetMapping("/structure/{id}")
    public RestResponse<InputData> inputDataStructure(@PathVariable("id") Long id){
        InputData structure = reportSectionService.inputDataStructure(id);
        return RestResponse.data(structure);
    }
}

