package cn.com.countrygarden.bi.main.controller.datav.wo;

import cn.com.countrygarden.bi.main.core.Response;
import com.eegrid.webapi.Device;
import com.eegrid.webapi.Energy;
import com.eegrid.webapi.Project;
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.*;

@Controller("datavEnergyController")
@RequestMapping("/api/datav/energy")
public class EnergyController {

    /**
     * 上线项目数
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    public Object energy() {
        List<Map<String, Object>> resultList = new ArrayList<>();

        Energy energy = new Energy();
        Map<String, Object> item = new HashMap<>();
        item.put("energy", energy.getEnergyQuantity());
        resultList.add(item);

        return Response.response(resultList);
    }

    /**
     * 上线项目数
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/project", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    public Object project() {
        List<Map<String, Object>> resultList = new ArrayList<>();
        Project project = new Project();
        Map<String, Object> item = new HashMap<>();
        item.put("project", project.getProjectQuantity());
        resultList.add(item);
        return Response.response(resultList);
    }

    /**
     * 上线设备数
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/device", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    public Object device() {
        List<Map<String, Object>> resultList = new ArrayList<>();
        Device device = new Device();
        Map<String, Object> item = new HashMap<>();
        item.put("device", device.getDeviceQuantity());
        resultList.add(item);
        return Response.response(resultList);
    }

    /**
     * 上线设备类型统计
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/device/types", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    public Object deviceTypes() {
        List<Map<String, Object>> resultList = new ArrayList<>();

        Device device = new Device();

        Map<String, Integer> deviceTypes;
        deviceTypes = device.getDeviceQuantityByDeviceType();

        for (String key : deviceTypes.keySet()) {
            Map<String, Object> item = new HashMap<>();
            item.put("type", key);
            item.put("value", deviceTypes.getOrDefault(key, 0));
            resultList.add(item);
        }

        return Response.response(resultList);
    }
}
