package com.gyee.frame.controller.health;

import com.gyee.frame.common.conf.AjaxStatus;
import com.gyee.frame.common.domain.AjaxResult;
import com.gyee.frame.model.custom.SimpleVo;
import com.gyee.frame.service.ShutdowneventService;
import com.gyee.frame.service.WarningRecordsService;
import com.gyee.frame.service.health.HealthOperationService;
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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

    @Resource
    private HealthOperationService healthOperationService;
    @Resource
    private ShutdowneventService shutdowneventService;
    @Resource
    private WarningRecordsService warningRecordsService;


    @PostMapping("/countWpwarn")
    @ResponseBody
    @ApiOperation(value = "近7天报警事件统计 type 1风场2项目", notes = "近7天报警事件统计 ype 1风场2项目")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "类型", required = true, dataType = "string", paramType = "query")})
    public AjaxResult countWpwarn(String type) throws Exception {


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

        if(StringUtils.notEmp(type))
        {
            if(type.equals("1"))
            {
                vos = warningRecordsService.countWpwarnByWp();
            }else  if(type.equals("2"))
            {
                vos = warningRecordsService.countWpwarnByPj();
            }

        }

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

    }

    @PostMapping("/countStop")
    @ResponseBody
    @ApiOperation(value = "近7天停机事件统计 type 1风场2项目", notes = "近7天停机事件统计 ype 1风场2项目")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "类型", required = true, dataType = "string", paramType = "query")})
    public AjaxResult countStop(String type) throws Exception {


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

        if(StringUtils.notEmp(type))
        {
            if(type.equals("1"))
            {
                vos = shutdowneventService.countStopByWp();
            }else  if(type.equals("2"))
            {
                vos = shutdowneventService.countStopByPj();
            }

        }

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

    }
    @PostMapping("/countWpOrProStatus")
    @ResponseBody
    @ApiOperation(value = "健康状态占比图表 type 1风场2项目", notes = "健康状态占比图表 type 1风场2项目")
    @ApiImplicitParams({
                @ApiImplicitParam(name = "type", value = "类型", required = true, dataType = "string", paramType = "query")})
    public AjaxResult countWpOrProStatus(String type) throws Exception {


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

        if(StringUtils.notEmp(type))
        {
            map = healthOperationService.countWpOrProStatus(type);
        }

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

    }

    @PostMapping("/findWpOrProStatusForHistory")
    @ResponseBody
    @ApiOperation(value = "健康状态曲线图表 type 1风场2项目 status 1良好2注意", notes = "健康状态曲线图表 type 1风场2项目 status 1良好2注意")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "类型", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态", required = true, dataType = "string", paramType = "query")})
    public AjaxResult findWpOrProStatusForHistory(String type, String status) throws Exception {


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

        if(StringUtils.notEmp(type) && StringUtils.notEmp(status))
        {
            map = healthOperationService.findWpOrProStatusForHistory(type,status);
        }

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

    }
}
