package com.gyee.runeconomy.controller.EarlyWarning;

import com.alibaba.fastjson.JSONObject;

import com.gyee.runeconomy.dto.result.JsonResult;
import com.gyee.runeconomy.dto.result.ResultCode;
import com.gyee.runeconomy.service.EarlyWarning.EarlyWarningReliableService;
import com.gyee.runeconomy.service.EarlyWarning.EarlyWarninggetService;
import com.gyee.runeconomy.service.EarlyWarning.ReportService;
import com.gyee.runeconomy.service.Weather.WertherForecast;
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.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/WarningReport")
public class EarlyWarningController {

    @Autowired
    private EarlyWarningReliableService earlyWarningReliableService;

    @Autowired
    private EarlyWarninggetService earlyWarninggetService;

    @Autowired
    private ReportService reportService;

    @Autowired
    private WertherForecast wertherForecast;

    @GetMapping(value = "/reporkkxwt")
    @ApiOperation(value = "预警分析报告-可靠性问题", notes = "预警分析报告—可靠性问题")
    public JSONObject getinformationkkx() throws Exception {

        earlyWarningReliableService.Electricity();

        return JsonResult.success();
    }


    @GetMapping(value = "/report")
    @ApiOperation(value = "预警分析报告", notes = "预警分析报告")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "time", value = "时间", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "wpid", value = "场站", required = true, dataType = "string", paramType = "query")})
    public JSONObject getreportinformation(String time, String wpid) throws Exception {

        Map<String, String> map = new HashMap<>();
        if (!time.isEmpty()) {
            map = earlyWarninggetService.Electricity(time, wpid);
        }
        if (map.size() > 0) {
            return JsonResult.successData(ResultCode.SUCCESS, map);
        } else {
            return JsonResult.error(500, "该月份没有数据");
        }

    }

    @GetMapping(value = "/econreport")
    @ApiOperation(value = "经济运行分析报告", notes = "经济运行分析报告")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wtid", value = "风机", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "time", value = "时间", required = true, dataType = "string", paramType = "query")
    })
    public JSONObject geteconreportinformation(String wtid,String time) throws Exception {

        Map<String, String> map = new HashMap<>();
        if (!wtid.isEmpty()) {
            map = reportService.Electricity(wtid,time);
        }
        if (map.size() > 0) {
            return JsonResult.successData(ResultCode.SUCCESS, map);
        } else {
            return JsonResult.error(500, "该月份没有数据");
        }

    }

    @GetMapping(value = "/weather")
    @ApiOperation(value = "天气", notes = "天气")
    public JSONObject getweather() throws Exception {
        wertherForecast.doTaskWeatherForecast();
        return JsonResult.success();
    }

}
