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.service.IReportMetaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 报表设计器元数据控制器。
 */
@RestController
@RequestMapping("/erp/report/meta")
public class ReportMetaController extends BaseController {

    @Autowired
    private IReportMetaService reportMetaService;

    /**
     * 查询当前库可选表。
     */
    @PreAuthorize("@ss.hasPermi('erp:report:query')")
    @GetMapping("/tables")
    public AjaxResult tables() {
        return success(reportMetaService.listTables());
    }

    /**
     * 查询指定表可选字段。
     */
    @PreAuthorize("@ss.hasPermi('erp:report:query')")
    @GetMapping("/fields")
    public AjaxResult fields(@RequestParam("table") String tableName) {
        return success(reportMetaService.listColumns(tableName));
    }

    /**
     * 查询资产中心模板列表。
     */
    @PreAuthorize("@ss.hasPermi('erp:report:list')")
    @GetMapping("/assets/templates")
    public AjaxResult assetTemplates() {
        return success(reportMetaService.listAssetTemplates());
    }

    /**
     * 查询资产中心指标列表。
     */
    @PreAuthorize("@ss.hasPermi('erp:report:query')")
    @GetMapping("/assets/metrics")
    public AjaxResult assetMetrics() {
        return success(reportMetaService.listAssetMetrics());
    }
}
