package com.kym.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.kym.common.R;
import com.kym.common.annotation.SysLog;
import com.kym.entity.queryParams.DailyStatQueryParam;
import com.kym.service.DailyStatService;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 日统计 前端控制器
 *
 * @author skyline
 * @since 2025-02-19
 */
@RestController
@RequestMapping("/daily-stat")
public class DailyStatController {

    private final DailyStatService dailyStatService;

    public DailyStatController(DailyStatService dailyStatService) {
        this.dailyStatService = dailyStatService;
    }

    @SaCheckPermission("dailyStat.list")
    @PostMapping("/list")
    public R<?> list(@RequestBody DailyStatQueryParam params) {
        return R.success(dailyStatService.listDailyStat(params));
    }

    @SaCheckPermission("dailyStat.sync")
    @SysLog("手动同步日统计")
    @PostMapping("/sync")
    public R<?> sync(@RequestBody Map<String, String> body) {
        String statDate = body.get("statDate");
        dailyStatService.syncDailyStat(statDate);
        return R.success();
    }

    @SaCheckPermission("dailyStat.sync")
    @SysLog("批量同步日统计")
    @PostMapping("/batch-sync")
    public R<?> batchSync(@RequestBody Map<String, String> body) {
        String startDate = body.get("startDate");
        String endDate = body.get("endDate");
        dailyStatService.syncDailyStatBatch(startDate, endDate);
        return R.success();
    }

    @SaCheckPermission("dailyStat.list")
    @PostMapping("/aggregate")
    public R<?> aggregate(@RequestBody DailyStatQueryParam params) {
        return R.success(dailyStatService.aggregateDailyStat(params));
    }
}
