package com.gyee.frame.controller.monitor;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

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 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.Windturbine;
import com.gyee.frame.service.websocket.WtInfoPushService;
import com.gyee.frame.service.websocket.WtWarnPushService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Controller
@RequestMapping("/monitorinverter")
@Api(value = "逆变器监视", tags = "逆变器监视")
public class MonitorInverterPushController {

	@Resource
	private WtInfoPushService wtInfoPushService;
	@Resource
	private WtWarnPushService wtWarnPushService;

	@PostMapping("/findInverterInfo")
	@ResponseBody
	@ApiOperation(value = "逆变器信息", notes = "逆变器AI点、报警点")
	@ApiImplicitParams({ @ApiImplicitParam(name = "wtId", value = "逆变器ID", required = true, dataType = "string", paramType = "query") })
	public AjaxResult findWtInfo(String wtId) throws Exception {
		List<Object> listAI = wtInfoPushService.findInverterInfo(wtId);
		Object listDI = wtInfoPushService.findInverterDI(wtId);
		Windturbine wt = InitialRunner.wtmap.get(wtId);
		Map<String, Object> map = Maps.newHashMap();
		map.put("listAI", listAI);
		map.put("listDI", listDI);
		map.put("info",wt);
		return AjaxResult.successData(AjaxStatus.success.code, map);
	}

    @PostMapping("/findInverterInfoList")
    @ResponseBody
    @ApiOperation(value = "逆变器信息列表", notes = "逆变器信息列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query")
    })

	public AjaxResult findWtInfoList(String wpId) throws Exception {
		List<Map<String, Object>> vos = new ArrayList<>();
		vos = wtInfoPushService.findInverterInfoList(wpId);
		if (null != vos) {
			return AjaxResult.successData(AjaxStatus.success.code, vos);
		} else {
			return AjaxResult.successData(AjaxStatus.error.code, vos);
		}
	}

	@PostMapping("/findInverterPowerLine")
	@ResponseBody
	@ApiOperation(value = "逆变器开网频率", notes = "逆变器当日0点至今功率，间隔30分钟")
	@ApiImplicitParams({ @ApiImplicitParam(name = "wtId", value = "逆变器ID", required = true, dataType = "string", paramType = "query") })
	public AjaxResult findInverterPowerLine(String wtId) throws Exception {
		List<Object> list = wtInfoPushService.findInverterPowerCurve(wtId);
		return AjaxResult.successData(AjaxStatus.success.code, list);
	}
}
