package com.gyee.runeconomy.controller.monitor;

import com.gyee.runeconomy.dto.AjaxResult;
import com.gyee.runeconomy.dto.DataVo;
import com.gyee.runeconomy.dto.PowercurveVo;
import com.gyee.runeconomy.dto.ProjectplanVo;
import com.gyee.runeconomy.service.monitor.*;
import com.gyee.runeconomy.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 监视中心首页
 */

@Controller
@RequestMapping("/cockpit")
@Api(value = "驾驶舱", tags = "驾驶舱")

public class MonitorController {
    @Autowired
    private MonitorService monitorService;

    @Autowired
    private ProjectPlanService planService;

    @Autowired
    private GroupRealtimeService groupRealtimeService;

    @Resource
    private HourpowerService hourpowerService;

    @Resource
    private MonitorprojectplanService monitorprojectplanService;

    @Resource
    private MonitorvalueService hoursvalue;

    @GetMapping("/monitor")
    @ResponseBody
    @ApiOperation(value = "首页", notes = "首页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "场站编号", required = true, dataType = "string", paramType = "query")})

    public AjaxResult getinformation(String wpId) throws Exception {

        Map<String, String> map = new HashMap<>();
        if (!wpId.isEmpty()) {
            map = monitorService.getcockpit(wpId);
        }
        if (null != map) {
            return AjaxResult.successData(200, map);
        } else {
            return AjaxResult.error(500, "操作失败");
        }

    }

    @GetMapping("/Powercurve24")
    @ResponseBody
    @ApiOperation(value = "24小时功率曲线", notes = "24小时功率曲线")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "场站编号", required = true, dataType = "string", paramType = "query")})
    public AjaxResult Powercurve24(String wpId) throws Exception {

        List<PowercurveVo> resultList = new ArrayList<>();
        if (StringUtils.notEmp(wpId)) {
            resultList = hourpowerService.Powercurve24(wpId);
        }

        if (null != resultList) {
            return AjaxResult.successData(200, resultList);
        } else {
            return AjaxResult.error(500, "操作失败");
        }

    }

    @GetMapping("/Realtime")
    @ResponseBody
    @ApiOperation(value = "实时数据", notes = "实时数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "场站编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "uniformCode", value = "统一编码", required = true, dataType = "string", paramType = "query")
    })
    public AjaxResult Realtime(String wpId, String uniformCode) throws Exception {

        List<PowercurveVo> resultList = new ArrayList<>();
        if (StringUtils.notEmp(wpId)) {
            resultList = monitorService.Realtimevalue(wpId, uniformCode);
        }

        if (null != resultList) {
            return AjaxResult.successData(200, resultList);
        } else {
            return AjaxResult.error(500, "操作失败");
        }

    }

    @GetMapping("/Utilizationhours")
    @ResponseBody
    @ApiOperation(value = "利用小时", notes = "利用小时")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "场站编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "timetype", value = "统一编码", required = true, dataType = "string", paramType = "query")
    })
    public AjaxResult Utilizationhours(String wpId, String timetype) throws Exception {

        List<PowercurveVo> resultList = new ArrayList<>();
        if (StringUtils.notEmp(wpId)) {
            resultList = hoursvalue.hoursvalue(wpId, timetype);
        }

        if (null != resultList) {
            return AjaxResult.successData(200, resultList);
        } else {
            return AjaxResult.error(500, "操作失败");
        }

    }

    @GetMapping("/Planproject")
    @ResponseBody
    @ApiOperation(value = "计划电量", notes = "计划电量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "场站编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "timetype", value = "统一编码", required = true, dataType = "string", paramType = "query")
    })
    public AjaxResult Planproject(String wpId, String timetype) throws Exception {

        List<ProjectplanVo> resultList = new ArrayList<>();
        if (StringUtils.notEmp(wpId)) {
            resultList = planService.planvalue(wpId, timetype);
        }

        if (null != resultList) {
            return AjaxResult.successData(200, resultList);
        } else {
            return AjaxResult.error(500, "操作失败");
        }

    }

    @GetMapping("/projectplan")
    @ResponseBody
    @ApiOperation(value = "首页计划电量", notes = "首页计划电量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "场站编号", required = true, dataType = "string", paramType = "query")})

    public AjaxResult projectplan(String wpId) throws Exception {

        Map<String, String> map = new HashMap<>();
        if (!wpId.isEmpty()) {
            map = monitorprojectplanService.plan(wpId);
        }
        if (null != map) {
            return AjaxResult.successData(200, map);
        } else {
            return AjaxResult.error(500, "操作失败");
        }

    }

    @GetMapping("/GroupRealtime")
    @ResponseBody
    @ApiOperation(value = "首页实时数据", notes = "首页实时数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "场站编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "uniformCode", value = "统一编码", required = true, dataType = "string", paramType = "query")
    })
    public AjaxResult GroupRealtime(String wpId, String uniformCode) throws Exception {

        List<DataVo> resultList = new ArrayList<>();
        if (StringUtils.notEmp(wpId)) {
            resultList = groupRealtimeService.GroupRealtimevalue(wpId, uniformCode);
        }

        if (null != resultList) {
            return AjaxResult.successData(200, resultList);
        } else {
            return AjaxResult.error(500, "操作失败");
        }

    }


}
