package com.gyee.runeconomy.controller.Electricity;

import com.gyee.runeconomy.dto.AjaxResult;
import com.gyee.runeconomy.init.CacheContext;
import com.gyee.runeconomy.model.auto.ProBasicPowerstation;
import com.gyee.runeconomy.service.Comprehensive.ComprehensiveelectricityService;
import com.gyee.runeconomy.service.Electricity.Electricityservice;
import com.gyee.runeconomy.service.StudyElectricity.StudyElectricityService;
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.ResponseBody;

import javax.annotation.Resource;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Controller
@RequestMapping("/electricity")
@Api(value = "电量统计", tags = "电量统计")
public class ElectricityController {

    @Resource
    private Electricityservice electricityservice;

    @Resource
    private StudyElectricityService studyelectricity;

    @Resource
    private ComprehensiveelectricityService comprehensiveelectricityService;

    @GetMapping("/statistics")
    @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"),
            @ApiImplicitParam(name = "year", value = "场站编号", required = true, dataType = "string", paramType = "query")
    })

    public AjaxResult forecast(String wpId, String timetype, String year) throws Exception {


        Map<String, Object> resultList = new LinkedHashMap<>();
        if (StringUtils.notEmp(wpId)) {
            resultList = electricityservice.planvalue(wpId, timetype, year);
        }

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

    }


    @GetMapping("/coulometric")
    @ResponseBody
    @ApiOperation(value = "光伏电量分析", notes = "光伏电量分析")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "场站编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "year", value = "场站编号", required = true, dataType = "string", paramType = "query")
    })

    public AjaxResult coulometricgf(String wpId, String year) throws Exception {


        Map<String, Object> resultList = new LinkedHashMap<>();
        if (StringUtils.notEmp(wpId)) {
            resultList = electricityservice.coulometric(wpId, year);
        }

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

    }

    @GetMapping("/study")
    @ResponseBody
    @ApiOperation(value = "可研电量分析", notes = "可研电量分析")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "场站编号", required = true, dataType = "string", paramType = "query")
    })

    public AjaxResult studygf(String wpId) throws Exception {


        Map<String, Object> resultList = new LinkedHashMap<>();
        if (StringUtils.notEmp(wpId)) {
            resultList = studyelectricity.studyelectricity(wpId);
        }

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

    }

    @GetMapping("/Comprehensive2")
    @ResponseBody
    @ApiOperation(value = "综合厂用电量", notes = "综合厂用电量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "场站编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "year", value = "场站编号", required = true, dataType = "string", paramType = "query")
    })

    public AjaxResult cydlfx2(String wpId, String year) throws Exception {


        Map<String, Object> resultList = new LinkedHashMap<>();
        if (StringUtils.notEmp(wpId)) {
            resultList = comprehensiveelectricityService.Comprehensive2(wpId, year);
        }

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

    }


    @GetMapping("/Comprehensive")
    @ResponseBody
    @ApiOperation(value = "综合厂用电量", notes = "综合厂用电量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "场站编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "year", value = "场站编号", required = true, dataType = "string", paramType = "query")
    })

    public AjaxResult cydlfx(String wpId, String year) throws Exception {


        Map<String, Object> resultList = new LinkedHashMap<>();
        if (StringUtils.notEmp(wpId)) {
            resultList = comprehensiveelectricityService.Comprehensive(wpId, year);
        }

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

    }

    @GetMapping("/czlist")
    @ResponseBody
    @ApiOperation(value = "场站列表", notes = "场站列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "场站编号", required = false, dataType = "string", paramType = "query")
    })

    public AjaxResult czlb(String wpId) throws Exception {
        List<ProBasicPowerstation> list = null;
        if (wpId != null && wpId.isEmpty()) {
            String[] split = wpId.split(",");
            list = CacheContext.wpls.stream().filter(w -> wpId.equals(w.getId())).collect(Collectors.toList());
        } else {
            list = CacheContext.wpls;
        }
        if (null != list) {
            return AjaxResult.successData(200, list);
        } else {
            return AjaxResult.error(500, "操作失败");
        }
    }
}
