package org.springblade.modules.nh.factory.saj.scheduler;

import lombok.AllArgsConstructor;
import org.springblade.common.utils.CommonUtil;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.modules.nh.factory.common.EachRunner;
import org.springblade.modules.nh.factory.ginlong.GinlongApi;
import org.springblade.modules.nh.factory.ginlong.IRet;
import org.springblade.modules.nh.factory.ginlong.dto.stationmonth.GetStationMonthR;
import org.springblade.modules.nh.factory.ginlong.dto.stationmonth.GetStationMonthReq;
import org.springblade.modules.nh.factory.saj.SajApi;
import org.springblade.modules.nh.factory.saj.resp.SajPlantDetail;
import org.springblade.modules.nh.factory.saj.resp.SajRet;
import org.springblade.modules.nh.pojo.entity.MonitorEntryStatEntity;
import org.springblade.modules.nh.service.IMonitorEntryStatService;
import org.springblade.modules.nh.service.IMonitorEntryYearStatService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 实时获取电站当前的发电量和功率
 */
@Service
@AllArgsConstructor
public class SajStationDetailEachRunner extends EachRunner<String> {

	private final SajApi sajApi;
	private final IMonitorEntryStatService entryStatService;

	@Override
	public void handle(String stationId, Map<String, Object> ctx) throws IOException {
		handleData(stationId);
	}

	public void handleData(String stationId) throws IOException {
		SajRet<SajPlantDetail> resp =  sajApi.getPlantDetail(stationId);
		if(resp.getCode()==200){
			SajPlantDetail detail = resp.getData();
			MonitorEntryStatEntity entryStat = entryStatService.getByOutId(stationId);
			if(detail!=null && entryStat!=null){
				entryStat.setCapacity(detail.getSystemPower());
				entryStat.setState(1);
				entryStatService.updateById(entryStat);
			}

		}

	}

}
