package com.gyee.frame.controller.monitor;

import com.gyee.frame.common.conf.AjaxStatus;
import com.gyee.frame.common.domain.AjaxResult;
import com.gyee.frame.common.spring.InitialRunner;
import com.gyee.frame.model.custom.DataVo;
import com.gyee.frame.service.ForecastwindspeedService;
import com.gyee.frame.service.websocket.*;
import com.gyee.frame.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.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
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("/genreset")
@Api(value = "驾驶舱" ,tags =  "驾驶舱")
public class GenreSetPushController {

    @Resource
    private GenreSetPushService genreSetPushService;
    @Resource
    private GenreSetPushDetailLnService genreSetPushDetailLnService;
    @Resource
    private GenreSetPushDetailPjService genreSetPushDetailPjService;
    @Resource
    private GenreSetPushDetailWpService genreSetPushDetailWpService;
    @Resource
    private GenreSetPushDetailService genreSetPushDetailService;
    @Resource
    private RealPowerPushService realPowerPushService;
    @Resource
    private AgcService agcService;
    @Resource
    private ForecastwindspeedService forecastwindspeedService;
    @PostMapping("/getAgcValues")
    @ResponseBody
    @ApiOperation(value = "获取AGC信息", notes = "获取AGC信息")
    @ApiImplicitParams({})
    public AjaxResult getAgcValues() throws Exception {


        List<Map<String, Object>> vos=  new ArrayList<>();


        vos=agcService.getAgcValues();

        if (null!=vos){
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, vos);
        }

    }

    @PostMapping("/findBasicDataInfo")
    @ResponseBody
    @ApiOperation(value = "获取驾驶舱基础信息", notes = "获取驾驶舱基础信息")
    @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "对象编号", required = true, dataType = "string", paramType = "query")})
    public AjaxResult findBasicDataInfo(String id) throws Exception {

        Map<String, Object> map = new HashMap<String, Object>();

        if(StringUtils.notEmp(id))
        {
            map=genreSetPushService.findBasicDataInfo(id);
        }

        if (null!=map){
            return AjaxResult.successData(AjaxStatus.success.code, map);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, map);
        }

    }

    @PostMapping("/findPowerInfo")
    @ResponseBody
    @ApiOperation(value = "获取驾驶舱功率曲线图和电量柱状图信息", notes = "获取驾驶舱功率曲线图和电量柱状图信息")
    @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "对象编号", required = true, dataType = "string", paramType = "query")})
    public AjaxResult findPowerInfo(String id) throws Exception {

        Map<String, Object> map = new HashMap<String, Object>();

        if(StringUtils.notEmp(id))
        {
            map=genreSetPushService.findPowerInfo(id);
        }

        if (null!=map){
            return AjaxResult.successData(AjaxStatus.success.code, map);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, map);
        }

    }

    @PostMapping("/findDayInfo")
    @ResponseBody
    @ApiOperation(value = "获取钻取指标日信息", notes = "获取钻取指标日信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "钻取对象编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "targetName", value = "指标名称", required = true, dataType = "string", paramType = "query")})

    public AjaxResult findDayInfo(String id, String targetName) throws Exception {


        Map<String, Object> map = new HashMap<String, Object>();

        if (StringUtils.notEmp(id) && StringUtils.notEmp(targetName) ) {
            if (InitialRunner.wpmap.containsKey(id)) {

                map = genreSetPushDetailWpService.findDayInfo(id, targetName);
            } else if (InitialRunner.pjmap.containsKey(id)) {

                map = genreSetPushDetailPjService.findDayInfo(id, targetName);
            } else if (InitialRunner.lnmap.containsKey(id)) {

                map = genreSetPushDetailLnService.findDayInfo(id, targetName);
            } else {
                map = genreSetPushDetailService.findDayInfo(id, targetName);
            }
        }


        if (null!=map){
            return AjaxResult.successData(AjaxStatus.success.code, map);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, map);
        }

    }


    @PostMapping("/findMonthInfo")
    @ResponseBody
    @ApiOperation(value = "获取钻取指标月信息", notes = "获取钻取指标月信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "钻取对象编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "targetName", value = "指标名称", required = true, dataType = "string", paramType = "query")})

    public AjaxResult findMonthInfo(String id, String targetName) throws Exception {


        Map<String, Object> map = new HashMap<String, Object>();

        if (StringUtils.notEmp(id) && StringUtils.notEmp(targetName) ) {
            if (InitialRunner.wpmap.containsKey(id)) {

                map = genreSetPushDetailWpService.findMonthInfo(id, targetName);
            } else if (InitialRunner.pjmap.containsKey(id)) {

                map = genreSetPushDetailPjService.findMonthInfo(id, targetName);
            } else if (InitialRunner.lnmap.containsKey(id)) {

                map = genreSetPushDetailLnService.findMonthInfo(id, targetName);
            } else {
                map = genreSetPushDetailService.findMonthInfo(id, targetName);
            }
        }


        if (null!=map){
            return AjaxResult.successData(AjaxStatus.success.code, map);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, map);
        }

    }

    @PostMapping("/findYearInfo")
    @ResponseBody
    @ApiOperation(value = "获取钻取指标年信息", notes = "获取钻取指标年信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "钻取对象编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "targetName", value = "指标名称", required = true, dataType = "string", paramType = "query")})

    public AjaxResult findYearInfo(String id, String targetName) throws Exception {


        Map<String, Object> map = new HashMap<String, Object>();

        if (StringUtils.notEmp(id) && StringUtils.notEmp(targetName) ) {
            if (InitialRunner.wpmap.containsKey(id)) {

                map = genreSetPushDetailWpService.findYearInfo(id, targetName);
            } else if (InitialRunner.pjmap.containsKey(id)) {

                map = genreSetPushDetailPjService.findYearInfo(id, targetName);
            } else if (InitialRunner.lnmap.containsKey(id)) {

                map = genreSetPushDetailLnService.findYearInfo(id, targetName);
            } else {
                map = genreSetPushDetailService.findYearInfo(id, targetName);
            }
        }



        if (null!=map){
            return AjaxResult.successData(AjaxStatus.success.code, map);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, map);
        }

    }


    @PostMapping("/findProjectPlanPower")
    @ResponseBody
    @ApiOperation(value = "获取计划发电量钻取信息", notes = "获取计划发电量钻取信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "钻取对象编号", required = true, dataType = "string", paramType = "query")})

    public AjaxResult findProjectPlanPower(String id) throws Exception {


        List<DataVo> vos = new ArrayList<DataVo>();
        if (StringUtils.notEmp(id)  ) {
            if (InitialRunner.wpmap.containsKey(id)) {

                vos = genreSetPushDetailWpService.findProjectPlanPower(id);
            } else if (InitialRunner.pjmap.containsKey(id)) {

                vos = genreSetPushDetailPjService.findProjectPlanPower(id);
            } else if (InitialRunner.lnmap.containsKey(id)) {

                vos = genreSetPushDetailLnService.findProjectPlanPower(id);
            } else {
                vos = genreSetPushDetailService.findProjectPlanPower(id);
            }
        }



        if (null!=vos){
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, vos);
        }

    }


    @PostMapping("/findGLDetail")
    @ResponseBody
    @ApiOperation(value = "获取功率曲线钻取信息", notes = "获取功率曲线钻取信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "钻取对象编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "targetName", value = "指标名称", required = true, dataType = "string", paramType = "query")})

    public AjaxResult findGLDetail(String id, String targetName) throws Exception {


       List<Object> vos = new ArrayList<Object>();
 //       Map<String, List> vos = new HashMap<String, List>();

        if (StringUtils.notEmp(id) && StringUtils.notEmp(targetName) ) {
            vos = realPowerPushService.findGLDetail(id,targetName);
        }

        if (null!=vos){
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, vos);
        }

    }


//    @PostMapping("/tooltipAjax")
//    @ResponseBody
//    @ApiOperation(value = "场站悬停功能", notes = "场站悬停功能")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "wpId", value = "场站编号", required = true, dataType = "string", paramType = "query")})
//
//    public AjaxResult tooltipAjax(String wpId) throws Exception {
//
//
//        Map<String, Double> retValue = new HashMap<String, Double>();
//        if (StringUtils.notEmp(wpId) ) {
//            retValue = genreSetPushService.tooltipAjax(wpId);
//        }
//
//        if (null!=retValue){
//            return AjaxResult.successData(AjaxStatus.success.code, retValue);
//        } else {
//            return AjaxResult.successData(AjaxStatus.error.code, retValue);
//        }
//
//    }

    @PostMapping("/getWeatherRealDay5Info")
    @ResponseBody
    @ApiOperation(value = "未来5天天气预报功能", notes = "未来5天天气预报功能")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "场站编号", required = true, dataType = "string", paramType = "query")})

    public AjaxResult getWeatherRealDay5Info(String wpId) throws Exception {


        Map<String,Object> retValue = new HashMap<String, Object>();
        if (StringUtils.notEmp(wpId) ) {
            retValue = genreSetPushService.getWeatherRealDay5Info(wpId);
        }

        if (null!=retValue){
            return AjaxResult.successData(AjaxStatus.success.code, retValue);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, retValue);
        }

    }

    @PostMapping("/getForecastwindspeedInfo")
    @ResponseBody
    @ApiOperation(value = "预测风速电量", notes = "预测风速电量功能")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "场站编号", required = true, dataType = "string", paramType = "query")})

    public AjaxResult getForecastwindspeedInfo(String wpId) throws Exception {

        Map<String,Object> map=new HashMap<>();
        List<DataVo> retValue = new ArrayList<>();
        List<String> datels=new ArrayList<>();

        retValue = forecastwindspeedService.getForecastwindspeedInfo(wpId);
        datels = forecastwindspeedService.getDayInfo();

        map.put("retValue",retValue);
        map.put("datels",datels);
        if (null!=map){
            return AjaxResult.successData(AjaxStatus.success.code, map);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, map);
        }

    }

}
