package com.gyee.runeconomy.controller.performance;


import com.gyee.common.vo.curve.CurveVo;
import com.gyee.runeconomy.dto.R;
import com.gyee.runeconomy.dto.ResultMsg;
import com.gyee.runeconomy.service.PerformanceCurvefittingService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 功率曲线拟合 前端控制器
 * </p>
 *
 * @author wang
 * @since 2022-11-22
 */
@RestController
@RequestMapping("//performance")
@Api(value = "功率曲线拟合", tags = "功率曲线拟合")
public class PerformanceCurvefittingController {


    @Autowired
    private PerformanceCurvefittingService performanceCurvefittingService;

    /**
     * 功率列表
     *
     * @param windturbineIds 风机ids
     * @param type           0：全部；-1：风电；-2：光伏(暂时默认 -1；没有光伏的功率曲线)
     * @param dateType       1:日；2：月；3：年
     * @return
     */
    @GetMapping("/curvefitting")
    @ResponseBody
    @CrossOrigin(origins = "*", maxAge = 3600)
    public R curvefittinglist(@RequestParam(value = "windturbineIds") String windturbineIds,
                              @RequestParam(value = "type") String type,
                              @RequestParam(value = "dateType") String dateType
    ) {
        Map<String, List<CurveVo>> curvefitting = null;
        try {
            curvefitting = performanceCurvefittingService.curveFittingList(windturbineIds, type, dateType);
            return R.data(ResultMsg.ok(curvefitting));
        } catch (Exception e) {
            e.printStackTrace();
            return R.data(ResultMsg.error());
        }
    }


    /**
     * 功率曲线拟合
     *
     * @param windturbineIds 风机ids
     * @param type           0：全部；-1：风电；-2：光伏(暂时默认 -1；没有光伏的功率曲线)
     * @param dateType       1:日；2：月；3：年
     * @return
     */
    @GetMapping("/curve-fitting")
    @ResponseBody
    @CrossOrigin(origins = "*", maxAge = 3600)
    public R curvefitting(@RequestParam(value = "windturbineIds", required = true) String windturbineIds,
                          @RequestParam(value = "type", required = true) String type,
                          @RequestParam(value = "dateType", required = true) String dateType
    ) {
        Map<String, List<CurveVo>> curvefitting = null;
        try {
            curvefitting = performanceCurvefittingService.curvefitting(windturbineIds, type, dateType);
            return R.data(ResultMsg.ok(curvefitting));
        } catch (Exception e) {
            e.printStackTrace();
            return R.data(ResultMsg.error());
        }
    }
}
