/**
 * @ProjectName: 智慧评标-主观分助手
 * @Package: com.zhpb.gdyd_zhpb_zgf.controller
 * @ClassName: StatisticsController
 * @Description: API访问统计控制器，提供API调用次数统计查询接口
 * @Author: 张志锋
 * @Date: 2025-10-31
 * @Version: 1.0
 * @Copyright: © 2025 智慧评标-主观分助手
 */
package com.zhpb.gdyd_zhpb_zgf.controller;

import com.zhpb.gdyd_zhpb_zgf.service.ApiStatisticsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 统计数据控制器
 */
@RestController
@RequestMapping("/api/v1/statistics")
@Tag(name = "统计信息", description = "API访问统计相关接口")
public class StatisticsController {

    @Autowired
    private ApiStatisticsService apiStatisticsService;

    /**
     * 获取API访问总次数
     *
     * @return 总访问次数
     */
    @GetMapping("/total")
    @Operation(summary = "获取API总访问次数", description = "返回系统中所有API接口的总访问次数")
    public Map<String, Object> getTotalCount() {
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("message", "获取成功");
        result.put("data", apiStatisticsService.getTotalApiCount());
        return result;
    }

    /**
     * 获取特定接口的访问次数
     *
     * @param path 接口路径
     * @return 访问次数
     */
    @GetMapping("/count")
    @Operation(summary = "获取特定接口访问次数", description = "根据接口路径返回该接口的访问次数")
    public Map<String, Object> getApiCount(String path) {
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("message", "获取成功");
        Map<String, Object> data = new HashMap<>();
        data.put("path", path);
        data.put("count", apiStatisticsService.getApiCount(path));
        result.put("data", data);
        return result;
    }
}

