package com.gyee.runeconomy.controller.PVSystemEfficiencyCalculator;

import com.gyee.runeconomy.dto.AjaxResult;
import com.gyee.runeconomy.dto.PrAnalysisVo;
import com.gyee.runeconomy.service.Comprehensive.PVSystemEfficiencyCalculator;
import com.gyee.runeconomy.service.Comprehensive.QNPVSystemEfficiencyCalculator;
import com.gyee.runeconomy.service.Pranalysis.PrAnalysisService;
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.scheduling.annotation.Scheduled;
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.List;

@Controller
@RequestMapping("//PVSystemEfficiency")
@Api(value = "光伏系统效率计算", tags = "光伏系统效率计算")
public class PVSystemEfficiencyCalculatorController {

    @Resource
    private PVSystemEfficiencyCalculator calculator;
    @Resource
    private QNPVSystemEfficiencyCalculator qncalculator;

    @Resource
    private PrAnalysisService prAnalysisService;

    //    @Scheduled(cron = "0 0 11 * * ?")
    @GetMapping("/statistics")
    @ResponseBody
    @ApiOperation(value = "光伏系统效率计算", notes = "光伏系统效率计算")

    public AjaxResult forecast() throws Exception {

        calculator.planvalue();

        return AjaxResult.success();
    }


    @GetMapping("/pranalysis")
    @ResponseBody
    @ApiOperation(value = "pr分析", notes = "pr分析")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "场站编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "month", value = "月份", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "target", value = "值", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "sort", value = "a", required = false, dataType = "String", paramType = "query")
    })

    public AjaxResult prfx(String wpId, String month, String target, String sort) throws Exception {

        List<PrAnalysisVo> resultList = new ArrayList<>();
        if (StringUtils.notEmp(wpId)) {
            resultList = prAnalysisService.Comprehensive(wpId, month, target, sort);
        }

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

    }
}
