package com.gyee.frame.service.report;

import com.gyee.frame.common.dataSources.DataSource;
import com.gyee.frame.common.dataSources.DataSourceType;
import com.gyee.frame.model.auto.Recommenmain;
import com.gyee.frame.model.auto.Windturbineinfodaytop2;
import com.gyee.frame.model.auto.Wobugeq;
import com.gyee.frame.model.auto.WtTragetReportChart;
import com.gyee.frame.model.custom.ValueVo;
import com.gyee.frame.service.RecommenmainService;
import com.gyee.frame.service.Windturbineinfodaytop2Service;
import com.gyee.frame.service.WobugeqService;
import com.gyee.frame.service.WtTragetReportChartService;
import com.gyee.frame.util.DateUtils;
import com.gyee.frame.util.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * 线路 LineService
 * @Title: LineService.java 
 * @Package com.gyee.frame.service 
 * @author gyee_自动生成
 * @email 1@qq.com
 * @date 2019-12-31 14:58:09  
 **/
@Service
public class WtHealthReportMonthService {

	@Resource
	private WtTragetReportChartService wtTragetReportChartService;
	@Resource
	private WobugeqService wobugeqService;
	@Resource
	private RecommenmainService recommenmainService;
	@Resource
	private Windturbineinfodaytop2Service windturbineinfodaytop2Service;


	/**
	 * 查询健康包括部件健康指数的历史图表
	 * @param wtId
	 * @param partId
	 * @param recorddate
	 * @return
	 */
	public List<WtTragetReportChart> healthReportChart(String wtId,String partId, String recorddate)  {

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

		if(StringUtils.notEmp(wtId) && StringUtils.notEmp(recorddate))
		{
			Date date= DateUtils.parseStrtoDate(recorddate);
			Calendar cal = Calendar.getInstance();
			cal.setTime(date);
			cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
			Date endDate = cal.getTime();
			cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
			Date beginDate = cal.getTime();
			vos=wtTragetReportChartService.healthReportChart(wtId,partId,beginDate,endDate);
		}

		return vos;
	}


	/**
	 * 查询生产系统月度风机检修情况
	 * @param wtId
	 * @return
	 */
	@DataSource(value = DataSourceType.TICKET)
	public List<Wobugeq> getWobugeqList(String wtId, String recorddate)  {

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

		if(StringUtils.notEmp(wtId) && StringUtils.notEmp(recorddate))
		{
			Date date= DateUtils.parseStrtoDate(recorddate);


			Calendar cal = Calendar.getInstance();
			cal.setTime(date);
			cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
			Date endDate = cal.getTime();
			cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
			Date beginDate = cal.getTime();

			vos=wobugeqService.getWobugeqList(wtId,beginDate,endDate);
		}

		return vos;
	}

	/**
	 * 查询生产系统月度风机检修情况
	 * @param wtId
	 * @return
	 */

	public List<Recommenmain> getRecommenmainList(String wtId, String recorddate)  {

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

		if(StringUtils.notEmp(wtId) && StringUtils.notEmp(recorddate))
		{
			Date date= DateUtils.parseStrtoDate(recorddate);


			Calendar cal = Calendar.getInstance();
			cal.setTime(date);
			cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
			Date endDate = cal.getTime();
			cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
			Date beginDate = cal.getTime();

			vos=recommenmainService.getRecommenmainList(wtId,beginDate,endDate);
		}

		return vos;
	}

	/**
	 * 查询风机等级评估信息
	 * 	 * @param wtId
	 * @return
	 */

	public Map<String,Object> gamonthlistByWtId(String wtId, String recorddate)  {

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

		if(StringUtils.notEmp(wtId) && StringUtils.notEmp(recorddate))
		{
			Date date= DateUtils.parseStrtoDate(recorddate);


			Calendar cal = Calendar.getInstance();
			cal.setTime(date);
			int year=cal.get(Calendar.YEAR);
			int month=cal.get(Calendar.MONTH)+1;


			List<Windturbineinfodaytop2> ls=windturbineinfodaytop2Service.gamonthlistByWtId(wtId,String.valueOf(year),String.valueOf(month));
			if (!ls.isEmpty())
			{
				Windturbineinfodaytop2 po=ls.get(0);

				map.put("wid",po);
				List<ValueVo> vos=windturbineinfodaytop2Service.wtchart(po);
				map.put("vos",vos);
			}
		}



		return map;
	}

}
