package com.jay.monitor.data.server.controllers;

import com.alibaba.fastjson.JSONObject;
import com.cat.file.message.MessageManagerProcess;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author ： liukx
 * @describe ：首页
 * @time ： 2019/3/1 - 16:31
 */
@Controller
@RequestMapping(value = "/")
public class IndexController {
    final static private String page = "/";

    @Autowired
    private MessageManagerProcess messageManagerProcess;

    @RequestMapping(value = "/index.html", method = RequestMethod.GET)
    public String index() throws Exception {
        return page + "index";
    }

    @RequestMapping(value = "/test", method = {RequestMethod.DELETE, RequestMethod.PUT}, produces = "application/json; charset=utf-8")
    @ResponseBody
    public JSONObject test(@RequestBody JSONObject jsonObject) throws Exception {
        return jsonObject;
    }

    @RequestMapping(value = "/getLogId", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String getLogId(@RequestParam("id") String logId) throws Exception {
        return messageManagerProcess.getMessage(logId);
    }

    @RequestMapping(value = "/storeDisk", method = RequestMethod.GET)
    @ResponseBody
    public String storeDisk() throws Exception {
        messageManagerProcess.closeAll();
        return "OK";
    }
}
