package com.gyee.frame.controller.report;

import com.gyee.frame.common.base.BaseController;
import com.gyee.frame.common.conf.AjaxStatus;
import com.gyee.frame.common.domain.AjaxResult;
import com.gyee.frame.model.auto.WtReportMain;
import com.gyee.frame.model.auto.WtTragetReportChart;
import com.gyee.frame.service.report.WtHealthReportService;
import com.gyee.frame.util.DateUtils;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
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("/report")
@Api(value = "日健康报告",tags =  "日健康报告")
public class WtHealthReportController extends BaseController {
	private static Logger logger = LoggerFactory.getLogger(WtHealthReportController.class);

	@Resource
	private WtHealthReportService wtHealthReportService;

	/**
	 * 查询健康报告主表和子表数据
	 * @param wtId
	 * @param recorddate
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/healthReport")
	@ResponseBody
	@ApiOperation(value = "查询健康报告主表和子表数据", notes = "查询健康报告主表和子表数据")
	@ApiImplicitParams({

			@ApiImplicitParam(name = "wtId", value = "风机编号", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "recorddate", value = "日期", required = true, dataType = "string", paramType = "query")})

	public AjaxResult healthReport(String wtId, String recorddate) throws Exception {

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

		if(StringUtils.notEmp(wtId) && StringUtils.notEmp(recorddate))
		{

			map=wtHealthReportService.healthReport(wtId, recorddate);
		}

		return AjaxResult.successData(AjaxStatus.success.code, map);

	}

	/**
	 * 查询健康包括部件健康指数的历史图表
	 * @param wtId
	 * @param partId
	 * zk	主控
	 * clx	齿轮箱
	 * fdj	发电机
	 * bj	变桨
	 * @param recorddate
	 * @return
	 */
	@PostMapping("/healthReportChart")
	@ResponseBody
	@ApiOperation(value = "查询健康包括部件健康指数的历史图表", notes = "查询健康包括部件健康指数的历史图表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "wtId", value = "风机编号", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "partId", value = "部件编号 zk:主控,clx:齿轮箱,fdj:发电机,bj:变桨", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "recorddate", value = "日期", required = true, dataType = "string", paramType = "query")})

	public AjaxResult healthReportChart(String wtId,String partId, String recorddate)  {

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

		if(StringUtils.notEmp(wtId) && StringUtils.notEmp(recorddate))
		{
			vos=wtHealthReportService.healthReportChart(wtId,partId, recorddate);
		}



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


	}

	/**
	 * 获得健康报表相关列表信息
	 * @param wtId
	 * @param beginDate 必选项
	 * @param endDate
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/getReportList")
	@ResponseBody
	@ApiOperation(value = "获得健康报表相关列表信息", notes = "获得健康报表相关列表信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
			@ApiImplicitParam(name = "wtId", value = "风机编号", required = true, 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 AjaxResult getReportList(String wpId,String wtId, String beginDate,String endDate) throws Exception {

		List<WtReportMain> wtrmls=new ArrayList<>();

		if( StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate))
		{

			wtrmls=wtHealthReportService.getReportList(wpId,wtId, DateUtils.parseDate(beginDate), DateUtils.parseDate(endDate));
		}

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

	}

}
