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

import com.alibaba.fastjson.JSON;
import com.jay.monitor.data.server.enums.DataSplitType;
import com.jay.monitor.data.server.factory.IdGenerateService;
import com.jay.monitor.data.server.factory.generate.DayIdGenerate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ： liukx
 * @describe ：首页
 * @time ： 2019/3/1 - 16:31
 */
@Controller
@RequestMapping(value = "/debug/id")
public class DebugController {
    @Autowired
    private DayIdGenerate dayIdGenerate;

    @Autowired
    private List<IdGenerateService> idGenerateServiceList;

    @RequestMapping(value = "/restartTimeStrap", method = RequestMethod.GET)
    @ResponseBody
    public String index() throws Exception {
        dayIdGenerate.setM_timestamp(11110L);
        return "OK";
    }

    @RequestMapping(value = "/getCurrentDayId", method = RequestMethod.GET)
    @ResponseBody
    public String getCurrentDayId() throws Exception {
        Map<String, String> debugMap = new HashMap<>();
        idGenerateServiceList.forEach((id) -> {
            String current = id.getCurrent();
            DataSplitType dataSplitType = id.splitType();
            debugMap.put(dataSplitType.name(), current);
        });
        return JSON.toJSONString(debugMap);
    }
}
