package com.gyee.runeconomy.controller.goodness;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gyee.common.model.StringUtils;
import com.gyee.common.vo.threerate.PvVo;
import com.gyee.runeconomy.dto.R;
import com.gyee.runeconomy.dto.ResultMsg;
import com.gyee.runeconomy.init.CacheContext;
import com.gyee.runeconomy.model.auto.ProBasicEquipment;
import com.gyee.runeconomy.model.auto.ProEconWindturbineGoodness;
import com.gyee.runeconomy.model.auto.ProEconWtAlysisDay;
import com.gyee.runeconomy.service.WtAlysisDayService;
import com.gyee.runeconomy.service.goodness.WindturbinegoodnessService;
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.*;

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

/**
 * 单机性能分析列表
 */
@Controller
@RequestMapping("/goodness")
@Api(value = "单机信息总览首页", tags = "单机信息总览首页")
public class WindturbinegoodnessController {
    @Resource
    private WindturbinegoodnessService windturbinegoodnessService;
    @Resource
    private WtAlysisDayService wtAlysisDayService;


    /**
     * 获得单机性能总览列表信息
     *
     * @return
     */
    @PostMapping("/windturbinegoodness")
    @ResponseBody
    @ApiOperation(value = "获得单机性能总览列表信息", notes = "获得单机性能总览列表信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "cmId", value = "公司编号或者区域编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "0全部、光伏(-2)、风场(-1)", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "wpId", value = "风场编号", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "recorddate", value = "日期", required = true, dataType = "string", paramType = "query")})

    public R windturbinegoodness(Integer pageNum, Integer pageSize, String cmId, String type, String wpId, String recorddate) {

        Page<ProEconWindturbineGoodness> resultList = windturbinegoodnessService.windturbinegoodnessList(pageNum, pageSize, cmId, type, wpId, recorddate);

        if (resultList != null && !resultList.getRecords().isEmpty()) {

            for (ProEconWindturbineGoodness pwg : resultList.getRecords()) {
                if (CacheContext.wtmap.containsKey(pwg.getWindturbineId())) {
                    ProBasicEquipment wt = CacheContext.wtmap.get(pwg.getWindturbineId());
                    pwg.setWtcode(wt.getAname());

                    if (CacheContext.modelMap.containsKey(wt.getModelId())) {
                        pwg.setModelId(CacheContext.modelMap.get(wt.getModelId()).getAname());
                    }
                }

            }
        }
        return R.data(ResultMsg.ok(resultList));
    }


    /**
     * 获得单机性能总览历史列表信息
     */
    @PostMapping("/goodhistorylist")
    @ResponseBody
    @ApiOperation(value = "获得单机性能总览历史列表信息", notes = "获得单机性能总览历史列表信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "wtId", value = "风机编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "beginDate", value = "开始日期", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", required = true, dataType = "string", paramType = "query")})

    public R goodhistorylist(Integer pageNum, Integer pageSize, String wtId, String beginDate, String endDate) {

        Page<ProEconWtAlysisDay> resultList = wtAlysisDayService.wtAlysisDayList(pageNum, pageSize, wtId, beginDate, endDate);

        if (resultList != null && !resultList.getRecords().isEmpty()) {

            for (ProEconWtAlysisDay pwg : resultList.getRecords()) {
                if (CacheContext.wtmap.containsKey(pwg.getWindturbineId())) {
                    ProBasicEquipment wt = CacheContext.wtmap.get(pwg.getWindturbineId());
                    pwg.setWtcode(wt.getAname());

                }

            }
        }
        return R.data(ResultMsg.ok(resultList));

    }


    @GetMapping("/pvgoodness")
    @ResponseBody
    @ApiOperation(value = "光伏性能分析", notes = "光伏性能分析")
    public R pvgoodness(@RequestParam(value = "companys", required = true) String companys,
                        @RequestParam(value = "wpid", required = true) String wpid,
                        @RequestParam(value = "recorddate", required = true) String recorddate,
                        @RequestParam(value = "target", required = true) String target,
                        @RequestParam(value = "sort", required = true) String sort
    ) {
        List<PvVo> resultList = windturbinegoodnessService.pvgoodness(companys, wpid, recorddate, target, sort);

        if (StringUtils.isNotNull(resultList)) {
            return R.data(ResultMsg.ok(resultList));
        } else {
            return R.error(ResultMsg.error());
        }
    }

    @GetMapping("/pvgoodnesshis")
    @ResponseBody
    @ApiOperation(value = "光伏性能分析历史", notes = "光伏性能分析历史")
    public R pvgoodness(
            @RequestParam(value = "wpid", required = true) String wpid,
            @RequestParam(value = "wtid", required = true) String wtid,
            @RequestParam(value = "beginDate", required = true) String beginDate,
            @RequestParam(value = "endDate", required = true) String endDate,
            @RequestParam(value = "target", required = true) String target,
            @RequestParam(value = "sort", required = true) String sort
    ) {
        List<PvVo> resultList = windturbinegoodnessService.pvgoodnesshis(wpid, wtid, beginDate, endDate, target, sort);

        if (StringUtils.isNotNull(resultList)) {
            return R.data(ResultMsg.ok(resultList));
        } else {
            return R.error(ResultMsg.error());
        }
    }

}
