package com.ruoyi.web.report.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.report.domain.design.ReportDesignSaveBo;
import com.ruoyi.web.report.service.IReportDesignService;
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.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>开发端通过该控制器读取和保存字段、关联、自定义 SQL、
 * 聚合策略等低代码配置数据。</p>
 */
@RestController
@RequestMapping("/erp/report/design")
public class ReportDesignController extends BaseController {

    @Autowired
    private IReportDesignService reportDesignService;

    /**
     * 查询报表设计详情。
     */
    @PreAuthorize("@ss.hasPermi('erp:report:query')")
    @GetMapping("/{reportId}")
    public AjaxResult getDesign(@PathVariable("reportId") Long reportId) {
        return success(reportDesignService.getDesign(reportId));
    }

    /**
     * 保存报表设计配置。
     */
    @PreAuthorize("@ss.hasPermi('erp:report:edit')")
    @Log(title = "ERP报表设计", businessType = BusinessType.UPDATE)
    @PostMapping("/{reportId}")
    public AjaxResult saveDesign(@PathVariable("reportId") Long reportId, @RequestBody ReportDesignSaveBo saveBo) {
        return toAjax(reportDesignService.saveDesign(reportId, saveBo));
    }
}
