package com.gyee.runeconomy.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.ProEconInOrOutSpeedTotal;
import com.gyee.runeconomy.service.outputspeed.OutputSpeedService;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;


@Controller
@RequestMapping("/outputspeed")
@Api(value = "切入切出管理", tags = "切入切出管理")
public class OutputSpeedController {

    @Resource
    private OutputSpeedService outputSpeedService;

    /**
     * 切入切出列表
     **/
    @PostMapping("/outputSpeedlist")
    @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 outputSpeedlist(Integer pageNum, Integer pageSize, String cmId, String type, String wpId, String recorddate) {

        Page<ProEconInOrOutSpeedTotal> pageInfo = outputSpeedService.outputSpeedlist(pageNum, pageSize, cmId, type, wpId, recorddate);
        if (pageInfo != null && !pageInfo.getRecords().isEmpty()) {

            for (ProEconInOrOutSpeedTotal pwg : pageInfo.getRecords()) {
                if (CacheContext.wtmap.containsKey(pwg.getWindturbineId())) {
                    ProBasicEquipment wt = CacheContext.wtmap.get(pwg.getWindturbineId());
                    pwg.setWtcode(wt.getAname());
                    pwg.setModelId(wt.getModelId());
                }

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

    }

    /**
     * 切入切出历史列表
     **/
    @PostMapping("/outputspeedhistorylist")
    @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 = "wtId", value = "风机编号", required = false, 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 outputspeedhistorylist(Integer pageNum, Integer pageSize, String cmId, String type, String wpId, String wtId, String beginDate, String endDate) {


        Page<ProEconInOrOutSpeedTotal> pageInfo = outputSpeedService.outputspeedhistorylist(pageNum, pageSize, cmId, type, wpId, wtId, beginDate, endDate);

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

            for (ProEconInOrOutSpeedTotal pwg : pageInfo.getRecords()) {
                if (CacheContext.wtmap.containsKey(pwg.getWindturbineId())) {
                    ProBasicEquipment wt = CacheContext.wtmap.get(pwg.getWindturbineId());
                    pwg.setWtcode(wt.getAname());
                    pwg.setModelId(wt.getModelId());
                }

            }
        }
        return R.data(ResultMsg.ok(pageInfo));
        //        return AjaxResult.successData(ResultCode.SUCCESS, pageInfo);

    }


}
