package com.ruoyi.web.controller.clock;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.clock.domain.bo.AnalysisQueryBo;
import com.ruoyi.clock.domain.vo.*;
import com.ruoyi.clock.service.IClockRecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
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 pengc
 * @date 2026-03-04
 */
@Validated
@Api(value = "统计分析控制器", tags = {"统计分析"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/clock/analysis")
public class AnalysisController extends BaseController {

    private final IClockRecordService iClockRecordService;

    /**
     * 查询统计分析概览数据
     * 包括：总参与人数、门店数、代理商数、打卡次数、产品销量
     */
    @ApiOperation("查询统计分析概览数据")
    @SaCheckPermission("clock:analysis:overview")
    @GetMapping("/overview")
    public R<AnalysisOverviewVo> overview() {
        return R.ok(iClockRecordService.queryAnalysisOverview());
    }

    /**
     * 查询门店活跃度排行
     */
    @ApiOperation("门店活跃度排行")
    @SaCheckPermission("clock:analysis:rank")
    @GetMapping("/shopActivityRank")
    public R<List<ShopActivityRankVo>> shopActivityRank(AnalysisQueryBo bo) {
        return R.ok(iClockRecordService.queryShopActivityRank(bo));
    }

    /**
     * 查询参与人数与销量趋势（最近30天）
     */
    @ApiOperation("参与人数与销量趋势")
    @SaCheckPermission("clock:analysis:trend")
    @GetMapping("/trend")
    public R<List<TrendVo>> trend(AnalysisQueryBo bo) {
        return R.ok(iClockRecordService.queryTrend(bo));
    }

    /**
     * 查询月度参与人数与销量对比（最近6个月）
     */
    @ApiOperation("月度参与人数与销量对比")
    @SaCheckPermission("clock:analysis:monthly")
    @GetMapping("/monthlyComparison")
    public R<List<MonthlyComparisonVo>> monthlyComparison(AnalysisQueryBo bo) {
        return R.ok(iClockRecordService.queryMonthlyComparison(bo));
    }

    /**
     * 查询门店销量排行榜 TOP 6
     */
    @ApiOperation("门店销量排行榜 TOP 6")
    @SaCheckPermission("clock:analysis:rank")
    @GetMapping("/shopSalesRank")
    public R<List<ShopSalesRankVo>> shopSalesRank() {
        return R.ok(iClockRecordService.queryShopSalesRank());
    }

}
