package com.czg.controller.admin;

import com.czg.handel.ExcelMergeHandler;
import com.czg.handel.TableRefundCellHandel;
import com.czg.log.annotation.OperationLog;
import com.czg.order.param.TableSummaryParam;
import com.czg.order.service.TableSummaryService;
import com.czg.order.vo.TableSummaryExportVo;
import com.czg.order.vo.TableSummaryInfoVo;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 台桌统计
 *
 * @author tankaikai
 * @since 2025-03-07 15:25
 */
@AllArgsConstructor
@RestController
@RequestMapping("/admin/table/summary")
public class TableSummaryController {
    private final TableSummaryService tableSummaryService;

    /**
     * 统计
     */
    @GetMapping("list")
    @OperationLog("统计")
    //@SaAdminCheckPermission("tableSummary:list")
    public CzgResult<List<TableSummaryInfoVo>> summaryList(TableSummaryParam param) {
        Long shopId = StpKit.USER.getShopId(0L);
        if (param.getShopId() == null) {
            param.setShopId(shopId);
        }
        List<TableSummaryInfoVo> data = tableSummaryService.summaryList(param);
        return CzgResult.success(data);
    }

    /**
     * 导出
     */
    @ResponseExcel(name = "台桌统计", writeHandler = {ExcelMergeHandler.class, TableRefundCellHandel.class})
    @GetMapping("export")
    @OperationLog("导出")
    //@SaAdminCheckPermission("tableSummary:export")
    public List<TableSummaryExportVo> summaryExport(TableSummaryParam param) {
        Long shopId = StpKit.USER.getShopId(0L);
        if (param.getShopId() == null) {
            param.setShopId(shopId);
        }
        return tableSummaryService.summaryExportList(param);
    }

}
