package com.szpg.plc.message.response.read;

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

import com.szpg.db.dao.PgDeviceDao;
import com.szpg.db.dao.PgWsDao;
import com.szpg.db.dao.impl.PgDeviceDaoImpl;
import com.szpg.db.dao.impl.PgWsDaoImpl;
import com.szpg.plc.message.response.ReadMemoryCommandResponse;
import com.szpg.util.TimeFormat;

public class ReadWSValueCommandResponse extends ReadMemoryCommandResponse {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1427194192669696325L;
	
	private List<Float> wd; //温度监测值
	private List<Float> sd; //湿度监测值
	private List<Float> wdbjz; //温度报警阈值
	private List<Float> sdbjz; //湿度报警阈值
	
	public ReadWSValueCommandResponse() {
		wd = new ArrayList<Float>();
		sd = new ArrayList<Float>();
		wdbjz = new ArrayList<Float>();
		sdbjz = new ArrayList<Float>();
	}

	public List<Float> getWd() {
		return wd;
	}

	public void setWd(List<Float> wd) {
		this.wd = wd;
	}

	public List<Float> getSd() {
		return sd;
	}

	public void setSd(List<Float> sd) {
		this.sd = sd;
	}

	public List<Float> getWdbjz() {
		return wdbjz;
	}

	public void setWdbjz(List<Float> wdbjz) {
		this.wdbjz = wdbjz;
	}

	public List<Float> getSdbjz() {
		return sdbjz;
	}

	public void setSdbjz(List<Float> sdbjz) {
		this.sdbjz = sdbjz;
	}

	@Override
	public void afterAction() {
		// 1将温湿度监测值数据存入数据库
		PgWsDao wsDao = new PgWsDaoImpl();
		PgDeviceDao deviceDao = new PgDeviceDaoImpl();
		
		List<Integer> ids = deviceDao.findDeviceIdByDestAndType(this.getMessageProducerId(), "WS");
		
		for (int i = 0; i < wd.size(); i++) {
			if (i < ids.size()) {
				wsDao.addWsdzRecord(wd.get(i), sd.get(i), TimeFormat.formatTimestamp(this.getTime().getTime()), ids.get(i));
			}
		}
	}

}
