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.entity.ShopTableOrderStatistic;
import com.czg.order.param.DataSummaryTradeParam;
import com.czg.order.param.TableSummaryParam;
import com.czg.order.service.ShopTableOrderStatisticService;
import com.czg.order.service.TableSummaryService;
import com.czg.order.vo.TableSummaryExportVo;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
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;

    @Resource
    private ShopTableOrderStatisticService tableOrderStatisticService;

    /**
     * 统计
     */
    @GetMapping("list")
    @OperationLog("统计")
    //@SaAdminCheckPermission("tableSummary:list")
    public CzgResult<List<ShopTableOrderStatistic>> summaryList(@Validated DataSummaryTradeParam param) {
        Long shopId = StpKit.USER.getShopId();
        if (param.getShopId() == null) {
            param.setShopId(shopId);
        }
        List<ShopTableOrderStatistic> archiveTradeData = tableOrderStatisticService.getArchiveTradeData(param.getShopId(), param.getRangeType(), param.getBeginDate(), param.getEndDate());
        return CzgResult.success(archiveTradeData);
    }

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

}
