package com.gyee.runeconomy.controller.Windresourceanalysis;

import com.alibaba.fastjson.JSONObject;
import com.gyee.runeconomy.dto.AjaxResult;
import com.gyee.runeconomy.dto.DataVo;
import com.gyee.runeconomy.dto.WindspeedVo;
import com.gyee.runeconomy.dto.pewpVo;
import com.gyee.runeconomy.dto.result.JsonResult;
import com.gyee.runeconomy.dto.result.ResultCode;
import com.gyee.runeconomy.service.Windresourceanalysis.WindresourceanalysisService;
import com.gyee.runeconomy.service.Windresourceanalysis.WindresourceanalysisService2;
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.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

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

@Controller
@RequestMapping("//analysisfx")
@Api(value = "光伏系统效率计算", tags = "光伏系统效率计算")
public class WindresourceanalysisController {
    @Resource
    private WindresourceanalysisService windresourceanalysisService;

    @Resource
    private WindresourceanalysisService2 windresourceanalysisService2;

    @GetMapping("/fdanalysis")
    @ResponseBody
    @ApiOperation(value = "pr分析", notes = "pr分析")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Data", value = "日期", required = true, dataType = "string", paramType = "query")
    })

    public AjaxResult prfx(String Data) throws Exception {

        List<WindspeedVo> resultList = new ArrayList<>();
        if (StringUtils.notEmp(Data)) {
            resultList = windresourceanalysisService.Comprehensive(Data);
        }

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

    }

    @GetMapping("/gzanalysis")
    @ResponseBody
    @ApiOperation(value = "pr分析", notes = "pr分析")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Data", value = "日期", required = true, dataType = "string", paramType = "query")
    })

    public AjaxResult pgzfx(String Data) throws Exception {

        List<pewpVo> resultList = new ArrayList<>();
        if (StringUtils.notEmp(Data)) {
            resultList = windresourceanalysisService.gzComprehensive(Data);
        }

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

    }

    @GetMapping("/GFGroupRealtime")
    @ResponseBody
    @ApiOperation(value = "首页实时数据", notes = "首页实时数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpid", value = "场站", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "Data", value = "日期", required = true, dataType = "string", paramType = "query")
    })
    public AjaxResult GroupRealtime(String wpid, String Data) throws Exception {

        List<DataVo> resultList = new ArrayList<>();
        if (StringUtils.notEmp(wpid)) {
            resultList = windresourceanalysisService.GroupRealtimevalue(wpid, Data);
        }

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

    }

    @GetMapping("/FDGroupRealtime")
    @ResponseBody
    @ApiOperation(value = "首页实时数据", notes = "首页实时数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpid", value = "场站", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "Data", value = "日期", required = true, dataType = "string", paramType = "query")
    })
    public AjaxResult fdGroupRealtime(String wpid, String Data) throws Exception {

        List<DataVo> resultList = new ArrayList<>();
        if (StringUtils.notEmp(wpid)) {
            resultList = windresourceanalysisService.fdGroupRealtimevalue(wpid, Data);
        }

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

    }


    /***
     * 风速风向玫瑰图
     * @param wpid  预处理数据的id
     * @param mode 统计方式   0：单台统计   1：合并统计
     * @return
     */
    @GetMapping("/roses")
    @ResponseBody
    public JSONObject fsRoses(String wpid, @RequestParam(value = "mode", required = false) Integer mode, String Data) throws Exception {
        mode = mode == null ? 0 : mode;
//        Object o = windresourceanalysisService.fxRoses(wpid, mode, Data);
        Object o = windresourceanalysisService2.fxRoses(wpid, mode, Data);
        return JsonResult.successData(ResultCode.SUCCESS, o);
    }
}
