package com.ruoyi.web.report.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.report.domain.bo.ErpReportQueryBo;
import com.ruoyi.web.report.service.IErpReportRuntimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
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;

/**
 * 报表运行态控制器。
 *
 * <p>统一提供预览和查询两个入口，前端无需关注实时/离线路由细节，
 * 由 Service 层按报表定义自动决策。</p>
 */
@RestController
@RequestMapping("/erp/report/runtime")
public class ErpReportRuntimeController extends BaseController {

    @Autowired
    private IErpReportRuntimeService erpReportRuntimeService;

    @PreAuthorize("@ss.hasPermi('erp:report:query')")
    @PostMapping("/{reportId}/preview")
    public AjaxResult preview(@PathVariable("reportId") Long reportId, @RequestBody(required = false) ErpReportQueryBo queryBo) {
        // 设计阶段预览：用于开发者在发布前验证字段、过滤、排序配置。
        return success(erpReportRuntimeService.preview(reportId, queryBo));
    }

    @PreAuthorize("@ss.hasPermi('erp:report:query')")
    @PostMapping("/{reportId}/query")
    public AjaxResult query(@PathVariable("reportId") Long reportId, @RequestBody(required = false) ErpReportQueryBo queryBo) {
        // 运行阶段查询：用于用户页面正式取数。
        return success(erpReportRuntimeService.query(reportId, queryBo));
    }
}
