package com.sckw.report.controller;

import com.sckw.core.web.response.BaseResult;
import com.sckw.report.model.dto.SalesReportDTO;
import com.sckw.report.model.vo.SalesReportVO;
import com.sckw.report.model.vo.SalesReportSummaryVO;
import com.sckw.report.service.KwSalesReportService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/salesReport")
@Tag(name = "销售报表")
public class KwSalesReportController {

    @Autowired
    private KwSalesReportService salesReportService;

    /**
     * 获取销售报表数据
     * @param salesReportDTO 筛选参数
     * @return 报表数据列表
     */
    @PostMapping("/getSalesReportData")
    @Operation(summary = "获取销售报表数据", description = "根据筛选参数获取销售报表数据列表")
    public BaseResult<List<SalesReportVO>> getSalesReportData(@RequestBody SalesReportDTO salesReportDTO) {
        return BaseResult.success(salesReportService.getSalesReportData(salesReportDTO));
    }

    /**
     * 获取销售报表汇总数据
     * @param salesReportDTO 筛选参数
     * @return 汇总数据
     */
    @PostMapping("/summary")
    @Operation(summary = "获取销售报表汇总数据", description = "根据筛选参数获取销售报表汇总数据")
    public BaseResult<SalesReportSummaryVO> getSalesReportSummary(@RequestBody SalesReportDTO salesReportDTO) {
        return BaseResult.success(salesReportService.getSalesReportSummary(salesReportDTO));
    }

    /**
     * 导出销售报表
     * @param salesReportDTO 筛选参数
     * @param response 响应对象
     */
    @PostMapping("/export")
    @Operation(summary = "导出销售报表", description = "根据筛选参数导出销售报表")
    public void exportSalesReport(@RequestBody SalesReportDTO salesReportDTO, HttpServletResponse response) {
        salesReportService.exportSalesReport(salesReportDTO, response);
    }
}
