package com.ag.web.docker.web;

import com.ag.secp.platform.common.DaoUtil;
import com.ag.secp.platform.common.DockerCommon;
import com.alibaba.dubbo.common.json.JSON;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by shaoqiang on 2017/5/11.
 */
@Controller
@RequestMapping("/webdocker")
public class WebController {

    @Autowired
    SqlSessionTemplate sqlSessionTemplate;
    @Autowired
    DockerCommon dockerCommon;
    /**
     * ??????
     *
     * @return
     */
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String dingcommit(Model model, HttpServletRequest request) {
        //DockerCommon commondocker = new DockerCommon();
        model.addAttribute("dockerlist", dockerCommon.listContainer());
        return "computemanage";

    }

    /**
     * ????
     *
     * @return
     */
    @RequestMapping(value = "/monitordetail", method = RequestMethod.GET)
    public String monitor(Model model, HttpServletRequest request) {

        String id=request.getParameter("id");
        model.addAttribute("cid",id);

        return "computemonitor";

    }

    @RequestMapping(value = "/cpumonitor", method = RequestMethod.POST)
    @ResponseBody
    public String getcpu(Model model, HttpServletRequest request) throws IOException {


        String cid=request.getParameter("cid");

        Map parame=new HashMap();
        parame.put("cid",cid);
        // List datalist=DaoUtil.selectList("agCommon.getcontainerinfo",parame);
        List datalist = sqlSessionTemplate.selectList("agCommon.getcontainerinfo",parame);
        /*Map dataMap = new HashMap();
        dataMap.put("elapsed", "2017-05-20");
        dataMap.put("value", "0.04");

        List datalist = new ArrayList();
        Map dataMap1 = new HashMap();
        dataMap1.put("elapsed", "2017-05-20");
        dataMap1.put("value", "0.06");

        Map dataMap2 = new HashMap();
        dataMap2.put("elapsed", "2017-05-20");
        dataMap2.put("value", "0.08");

        Map dataMap3 = new HashMap();
        dataMap3.put("elapsed", "2017-05-20");
        dataMap3.put("value", "0.10");


        datalist.add(dataMap);
        datalist.add(dataMap1);
        datalist.add(dataMap2);
        datalist.add(dataMap3);*/


        return JSON.json(datalist);

    }
}
