package cn.reghao.devops.web.mgr.log.controller;

import cn.reghao.devops.web.mgr.log.service.LoggingService;
import cn.reghao.jutil.jdk.result.WebResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.util.List;

/**
 * @author reghao
 * @date 2023-11-02 13:39:54
 */
@Controller
public class AppLogController {
    private final LoggingService loggingService;

    public AppLogController(LoggingService loggingService) {
        this.loggingService = loggingService;
    }

    @ApiOperation(value = "应用实时日志页面")
    @GetMapping(value = "/app/log/online")
    public String appLogPage() {
        return "/devops/app/stat/log";
    }

    @ApiOperation(value = "应用历史日志页面")
    @GetMapping(value = "/app/log/offline")
    public String appLog() {
        return "/devops/app/stat/log1";
    }

    @ApiOperation(value = "Nginx 日志页面")
    @GetMapping(value = "/app/log/nginx")
    public String nginxLog() {
        return "/devops/app/stat/nginxlog";
    }

    @GetMapping(value = "/api/log/nginx/chart", produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public String nginxLogData() throws ParseException {
        List list = loggingService.getChartData();
        return WebResult.success(list);
    }
}
