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.print.ReportPrintTemplateVo;
import com.ruoyi.web.report.service.IReportPrintTemplateService;
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;

/**
 * 报表打印模板控制器。
 */
@RestController
@RequestMapping("/erp/report/printTemplate")
public class ReportPrintTemplateController extends BaseController {

    @Autowired
    private IReportPrintTemplateService reportPrintTemplateService;

    /**
     * 查询报表打印模板。
     */
    @PreAuthorize("@ss.hasPermi('erp:report:query')")
    @GetMapping("/{reportId}")
    public AjaxResult getTemplate(@PathVariable("reportId") Long reportId) {
        return success(reportPrintTemplateService.getByReportId(reportId));
    }

    /**
     * 覆盖保存报表打印模板。
     */
    @PreAuthorize("@ss.hasPermi('erp:report:edit')")
    @Log(title = "ERP报表打印模板", businessType = BusinessType.UPDATE)
    @PostMapping("/{reportId}")
    public AjaxResult saveTemplate(@PathVariable("reportId") Long reportId, @RequestBody ReportPrintTemplateVo template) {
        return toAjax(reportPrintTemplateService.saveByReportId(reportId, template));
    }
}
