package com.gyee.frame.controller.health;

import com.gyee.frame.common.conf.AjaxStatus;
import com.gyee.frame.common.domain.AjaxResult;
import com.gyee.frame.service.health.HealthMainService;
import com.gyee.frame.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.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.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/healthmain")
@Api(value = "健康管理主页面" ,tags =  "健康管理主页面")
public class HealthMainController {

    @Resource
    private HealthMainService healthMainService;


    @PostMapping("/findAllChart")
    @ResponseBody
    @ApiOperation(value = "获得健康状态情况图表", notes = "获得健康状态情况图表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "num", value = "结果数量", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "类型", required = true, dataType = "string", paramType = "query")})
    public AjaxResult findAllChart(String wpId, String num, String type) throws Exception {


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

        if(StringUtils.notEmp(wpId) && StringUtils.notEmp(num) && StringUtils.notEmp(type))
        {
            map = healthMainService.findAllChart(wpId,Integer.valueOf(num), Integer.valueOf(type));
        }

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

    }

    @PostMapping("/findAllMap")
    @ResponseBody
    @ApiOperation(value = "获得全省健康状态基础数据", notes = "获得全省健康状态基础数据")
    @ApiImplicitParams({
           })
    public AjaxResult findAllMap() throws Exception {


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

        map = healthMainService.findAllMap();

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

    }

    @PostMapping("/findWpMap")
    @ResponseBody
    @ApiOperation(value = "获得场站健康状态基础数据", notes = "获得场站健康状态基础数据")
    @ApiImplicitParams({
    })
    public AjaxResult findWpMap(String wpId) throws Exception {


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


        if(StringUtils.notEmp(wpId))
        {
            map = healthMainService.findWpMap(wpId);
        }


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

    }


    @PostMapping("/findHealthMatrixMap")
    @ResponseBody
    @ApiOperation(value = "获得健康矩阵", notes = "获得健康矩阵")
    @ApiImplicitParams({
    })
    public AjaxResult findHealthMatrixMap() throws Exception {


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


        map = healthMainService.findHealthMatrixMap();


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

    }
}
