package com.gyee.frame.service;

import com.gyee.frame.common.spring.Constant;
import com.gyee.frame.mapper.auto.WindTurbineTestingPointaiyjMapper;
import com.gyee.frame.model.auto.WindPowerStationTestingPoint;
import com.gyee.frame.model.custom.DataVo;
import com.gyee.frame.model.custom.PointData;
import com.gyee.frame.model.custom.ValueObjVo;
import com.gyee.frame.util.DateUtils;
import com.gyee.frame.util.IRealTimeDataBaseUtil;
import com.gyee.frame.util.RealTimeDataBaseFactory;
import com.gyee.frame.util.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


@Service
public class WinddirectionService {
	@Resource
	private WindTurbineTestingPointaiyjMapper windTurbineTestingPointaiyjMapper;

	IRealTimeDataBaseUtil realApiUtil = RealTimeDataBaseFactory.createRealTimeDataBase();
	@Resource
	private WindPowerstationTestingPoint2Service windPowerstationTestingPoint2Service;

	public List<DataVo>  winddirectionAjax(String wpId,Date recorddate) throws Exception {
		List<DataVo> vos = new ArrayList<DataVo>();

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

			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			SimpleDateFormat sdfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			SimpleDateFormat sfs = new SimpleDateFormat("HH时");
			Date endDate = sdfs.parse(sdf.format(DateUtils.addDays(recorddate, 1)) + " 00:00:00");
			Date beginDate = sdfs.parse(sdf.format(recorddate) + " 00:00:00");

			WindPowerStationTestingPoint fspoint = windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wpId, Constant.FCCFTFS70);
			WindPowerStationTestingPoint fxpoint = windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wpId, Constant.FCCFTFX70);

			List<PointData> fxls = realApiUtil.getHistoryDatasSnap(fxpoint, beginDate.getTime() / 1000, endDate.getTime() / 1000, 24l, 3600L);
			List<PointData> fsls = realApiUtil.getHistoryDatasSnap(fspoint, beginDate.getTime() / 1000, endDate.getTime() / 1000, 24l, 3600L);


			if (!fsls.isEmpty()) {
				for (int i = 0; i < fsls.size(); i++) {
					DataVo vo = new DataVo();

					Date date = new Date(fsls.get(i).getPointTime() * 1000);
					vo.setTimestr(sfs.format(date));
					ValueObjVo voobj = new ValueObjVo();
					voobj.setValue(StringUtils.round(fsls.get(i).getPointValueInDouble(), 2));
					voobj.setSymbol("arrow");
					voobj.setSymbolSize(20);
					voobj.setSymbolRotate(StringUtils.round(fxls.get(i).getPointValueInDouble(), 2));

					vo.setValueObjVo(voobj);
					vos.add(vo);
				}
			}
		}
		return vos;
	}



}
