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.MonthStatQueryParam;
import com.kym.service.MonthStatService;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 月统计 前端控制器
 *
 * @author skyline
 * @since 2025-04-03
 */
@RestController
@RequestMapping("/month-stat")
public class MonthStatController {

    private final MonthStatService monthStatService;

    public MonthStatController(MonthStatService monthStatService) {
        this.monthStatService = monthStatService;
    }

    @SaCheckPermission("monthStat.list")
    @PostMapping("/list")
    public R<?> list(@RequestBody MonthStatQueryParam params) {
        return R.success(monthStatService.listMonthStat(params));
    }

    @SaCheckPermission("monthStat.sync")
    @SysLog("手动同步月统计")
    @PostMapping("/sync")
    public R<?> sync(@RequestBody Map<String, String> body) {
        String statMonth = body.get("statMonth");
        monthStatService.syncMonthlyStat(statMonth);
        return R.success();
    }
}
