package com.czg.controller.admin;

import com.czg.log.annotation.OperationLog;
import com.czg.order.param.SaleSummaryCountParam;
import com.czg.order.service.SaleSummaryService;
import com.czg.order.vo.SaleSummaryCountVo;
import com.czg.order.vo.SaleSummaryInfoVo;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.mybatisflex.core.paginate.Page;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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
 */
@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping("/admin/sale/summary")
public class SaleSummaryController {
    private final SaleSummaryService saleSummaryService;

    /**
     * 统计
     */
    @GetMapping("count")
    @OperationLog("统计")
    //@SaAdminCheckPermission("saleSummary:count")
    public CzgResult<SaleSummaryCountVo> summaryCount(SaleSummaryCountParam param) {
        Long shopId = StpKit.USER.getShopId(0L);
        if (param.getShopId() == null) {
            param.setShopId(shopId);
        }
        SaleSummaryCountVo data = saleSummaryService.summaryCount(param);
        return CzgResult.success(data);
    }

    /**
     * 分页
     */
    @GetMapping("page")
    @OperationLog("分页")
    //@SaAdminCheckPermission("saleSummary:page")
    public CzgResult<Page<SaleSummaryInfoVo>> summaryPage(SaleSummaryCountParam param) {
        Long shopId = StpKit.USER.getShopId(0L);
        if (param.getShopId() == null) {
            param.setShopId(shopId);
        }
        Page<SaleSummaryInfoVo> page = saleSummaryService.summaryPage(param);
        return CzgResult.success(page);
    }

    /**
     * 导出
     */
    @ResponseExcel(name = "销售统计明细")
    @GetMapping("/export")
    @OperationLog("导出")
    //@SaAdminCheckPermission("saleSummary:export")
    public List<SaleSummaryInfoVo> summaryExport(SaleSummaryCountParam param) {
        Long shopId = StpKit.USER.getShopId(0L);
        if (param.getShopId() == null) {
            param.setShopId(shopId);
        }
        return saleSummaryService.summaryList(param);
    }

}
