package com.gyee.frame.controller.monitor;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.gyee.frame.common.conf.AjaxStatus;
import com.gyee.frame.common.domain.AjaxResult;
import com.gyee.frame.common.spring.InitialRunner;
import com.gyee.frame.model.auto.Windpowerstation;
import com.gyee.frame.model.auto.Windturbine;
import com.gyee.frame.model.custom.MatrixVo;
import com.gyee.frame.service.websocket.*;
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;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/matrix")
@Api(value = "矩阵" ,tags =  "矩阵")
public class MatrixPushController {

    @Resource
    private MatrixPushService matrixPushService;
    @Resource
    private MatrixDetialPushService matrixDetialPushService;
    @Resource
    private MatrixDetialGfPushService matrixDetialGfPushService;
    @Resource
    private MatrixQfPushService matrixQfPushService;
    @Resource
    private MatrixPushByWpService matrixPushByWpService;

    @PostMapping("/matrixPush")
    @ResponseBody
    @ApiOperation(value = "基础矩阵", notes = "基础矩阵")
    @ApiImplicitParams({})
    public AjaxResult matrixPush() throws Exception {


        Map<String, Object> map=  new HashMap<>();


        map=matrixPushService.genreSetMap();

        if (null!=map) {
            return AjaxResult.successData(AjaxStatus.success.code, map);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, map);
        }

    }

    @PostMapping("/matrixDetialPush")
    @ResponseBody
    @ApiOperation(value = "明细矩阵", notes = "明细矩阵")
    @ApiImplicitParams({})
    public AjaxResult matrixDetialPush() throws Exception {


        Map<String, Object> map=  new HashMap<>();


        map=matrixDetialPushService.genreSetMap();

        if (null!=map) {
            return AjaxResult.successData(AjaxStatus.success.code, map);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, map);
        }

    }

    @PostMapping("/matrixDetialGfPush")
    @ResponseBody
    @ApiOperation(value = "光伏矩阵", notes = "光伏矩阵")
    @ApiImplicitParams({})
    public AjaxResult matrixDetialGfPush() throws Exception {


        Map<String, Object> map=  new HashMap<>();


        map=matrixDetialGfPushService.genreSetMap();

        if (null!=map) {
            return AjaxResult.successData(AjaxStatus.success.code, map);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, map);
        }

    }

    @PostMapping("/matrixQfPush")
    @ResponseBody
    @ApiOperation(value = "欠发矩阵", notes = "欠发矩阵")
    @ApiImplicitParams({})
    public AjaxResult matrixQfPush() throws Exception {


        Map<String, Object> map=  new HashMap<>();


        map=matrixQfPushService.genreSetMap();

        if (null!=map) {
            return AjaxResult.successData(AjaxStatus.success.code, map);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, map);
        }

    }


    @PostMapping("/matrixByWpIdPush")
    @ResponseBody
    @ApiOperation(value = "风场矩阵", notes = "风场矩阵")
    @ApiImplicitParams({ @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query")})
    public AjaxResult matrixByWpIdPush(String wpId) throws Exception {


        Map<String, Object> map=  new HashMap<>();


        map=matrixPushByWpService.findMatrixById(wpId);

        if (null!=map) {
            return AjaxResult.successData(AjaxStatus.success.code, map);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, map);
        }

    }

    @PostMapping("/findSimpleMatrix")
    @ResponseBody
    @ApiOperation(value = "风场简单矩阵", notes = "风场简单矩阵")
    @ApiImplicitParams({ @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query")})
    public AjaxResult findSimpleMatrix(String wpId) throws Exception {


        Map<String, Object> map=  new HashMap<>();


        map=matrixPushByWpService.findSimpleMatrix(wpId);

        if (null!=map) {
            return AjaxResult.successData(AjaxStatus.success.code, map);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, map);
        }

    }


    @PostMapping("/findSimpleMatrixAll")
    @ResponseBody
    @ApiOperation(value = "全风场简单矩阵", notes = "全风场简单矩阵")
    @ApiImplicitParams({ @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query")})
    public AjaxResult findSimpleMatrixAll(String wpId) throws Exception {


        List<Object> vos=new ArrayList<>();


        for(Windpowerstation wp: InitialRunner.wpls)
        {
            Map<String, Object> map=  new HashMap<>();
            map.put("wpName",wp.getName());
            List<List<MatrixVo>> fjvos=matrixPushByWpService.findSimpleMatrixList(wp.getId());
            map.put("fjls",fjvos);
            vos.add(map);
        }


        if (null!=vos) {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, vos);
        }

    }

    @PostMapping("/findPVSimpleMatrixAll")
    @ResponseBody
    @ApiOperation(value = "全光伏场简单矩阵", notes = "全光伏场简单矩阵")
	public AjaxResult findPVSimpleMatrixAll() throws Exception {
		List<Object> vos = new ArrayList<>();
		for (Windpowerstation wp : InitialRunner.spls) {
			Map<String, Object> map = new HashMap<>();
			List<List<MatrixVo>> inverterls = matrixPushByWpService.findSimpleMatrixList(wp.getId());
			map.put("wpName", wp.getName());
			map.put("inverterls", inverterls.get(0));
			vos.add(map);
		}
		return AjaxResult.successData(AjaxStatus.success.code, vos);
	}
}
