package com.czg.controller;

import com.czg.task.StatisticTask;
import com.czg.utils.FunUtils;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

/**
 * @author ww
 * @description
 */
@RestController
@RequestMapping("/task")
public class StatisticTaskController {

    @Resource
    private StatisticTask statisticTask;

    /**
     * 基础统计 预留重置统计
     *
     * @param date 日期yyyy-MM-dd
     */
    @GetMapping("/base")
    public String baseStatistic(@RequestParam LocalDate date, @RequestParam Long shopId, @RequestParam String type) {
        if ("order".equals(type)) {
            statisticTask.statisticAndInsertOrder(shopId, date);
        } else if ("prod".equals(type)) {
            statisticTask.statisticAndInsertProd(shopId, date);
        } else if ("table".equals(type)) {
            statisticTask.statisticAndInsertTable(shopId, date);
        } else if ("all".equals(type)) {
            FunUtils.safeRunVoid(() -> statisticTask.statisticAndInsertOrder(shopId, date));
            FunUtils.safeRunVoid(() -> statisticTask.statisticAndInsertProd(shopId, date));
            FunUtils.safeRunVoid(() -> statisticTask.statisticAndInsertTable(shopId, date));
        }
        return "success";
    }
}
