package com.czg.controller.admin;

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.resp.CzgResult;
import com.czg.sa.StpKit;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
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);
    }

    /**
     * 导出
     */
    @GetMapping("export")
    @OperationLog("导出")
    //@SaAdminCheckPermission("tableSummary:export")
    public void summaryExport(TableSummaryParam param, HttpServletResponse response) {
        if (param.getShopId() == null) {
            param.setShopId(StpKit.USER.getShopId());
        }
        tableSummaryService.summaryExportList(param, response);
    }

}
