package com.czg.controller.admin;

import com.czg.log.annotation.OperationLog;
import com.czg.order.entity.ShopProdStatistic;
import com.czg.order.param.SaleSummaryCountParam;
import com.czg.order.service.ShopProdStatisticService;
import com.czg.order.vo.SaleSummaryCountVo;
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 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 {
    @Resource
    private ShopProdStatisticService prodStatisticService;

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

    /**
     * 分页
     */
    @GetMapping("page")
    @OperationLog("分页")
    //@SaAdminCheckPermission("saleSummary:page")
    public CzgResult<List<ShopProdStatistic>> summaryPage(SaleSummaryCountParam param) {
        if (param.getShopId() == null) {
            param.setShopId(StpKit.USER.getShopId());
        }
        List<ShopProdStatistic> list = prodStatisticService.getArchiveTradeData(param);
        return CzgResult.success(list);
    }

    @ResponseExcel(name = "销售统计明细")
    @GetMapping("/export")
    public List<ShopProdStatistic> summaryExport(SaleSummaryCountParam param) {
        if (param.getShopId() == null) {
            param.setShopId(StpKit.USER.getShopId());
        }
        return prodStatisticService.getArchiveTradeData(param);
    }

}
