package com.boman.report.controller;

import com.boman.common.core.web.controller.BaseController;
import com.boman.common.core.web.page.TableDataInfo;
import com.boman.domain.dto.AjaxResult;
import com.boman.report.service.StatisticReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;
import com.boman.domain.entity.StatisticReport;

import java.util.List;

@RestController
@RequestMapping("/statistic/report")
public class StatisticReportController extends BaseController {

    @Autowired
    private StatisticReportService statisticReportService;
    @Autowired
    private StatisticReportService reportService;

    /**
     * 获取报表id集合
     *
     * @return
     */
    @GetMapping("/datas")
    public AjaxResult datas(@Param("reportName") String reportName) {
        return AjaxResult.success(reportService.datas(reportName));
    }

    /**
     * 列表
     * @return
     */
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody StatisticReport report) {
        startPage();
        List<StatisticReport> list = reportService.selectList(report);
        return getDataTable(list);
    }

    @PostMapping("/saveOrUpdate")
    public AjaxResult saveOrUpdate(@RequestBody StatisticReport report) {
        return reportService.saveOrUpdate(report);
    }


    /**
     * 获取报表详情
     * @param id
     * @return
     */
    @GetMapping(value = "/reportInfo/{id}")
    public AjaxResult getReportInfo(@PathVariable Long id)
    {
        return statisticReportService.getReportInfo(id);
    }

    /**
     * 获取报表详情
     * @param id
     * @return
     */
    @GetMapping(value = "/detail/{id}")
    public AjaxResult getDetailById(@PathVariable Long id) {
        return AjaxResult.success(statisticReportService.getDetailById(id));
    }
}
