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.bo.ReportRebuildBo;
import com.ruoyi.web.report.service.IReportAggregateService;
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>提供手动补算入口，用于按时间窗重算离线聚合数据。</p>
 */
@RestController
@RequestMapping("/erp/report/aggregate")
public class ReportAggregateController extends BaseController {

    @Autowired
    private IReportAggregateService reportAggregateService;

    /**
     * 手动补算报表聚合数据。
     */
    @PreAuthorize("@ss.hasPermi('erp:report:publish')")
    @Log(title = "ERP报表聚合补算", businessType = BusinessType.UPDATE)
    @PostMapping("/{reportId}/rebuild")
    public AjaxResult rebuild(@PathVariable("reportId") Long reportId, @RequestBody ReportRebuildBo rebuildBo) {
        return toAjax(reportAggregateService.rebuild(reportId, rebuildBo));
    }
}
