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 ReadWSStatusCommandResponse extends ReadMemoryCommandResponse {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2256619329720969351L;
	
	private List<Boolean> wdbj; // 温度报警状态
	private List<Boolean> sdbj; // 湿度报警状态
	private List<Boolean> wdldbj; // 温度是否联动报警
	private List<Boolean> sdldbj; // 湿度是否联动报警

	public ReadWSStatusCommandResponse() {
		wdbj = new ArrayList<Boolean>();
		sdbj = new ArrayList<Boolean>();
		wdldbj = new ArrayList<Boolean>();
		sdldbj = new ArrayList<Boolean>();
	}

	public List<Boolean> getWdbj() {
		return wdbj;
	}

	public void setWdbj(List<Boolean> wdbj) {
		this.wdbj = wdbj;
	}

	public List<Boolean> getSdbj() {
		return sdbj;
	}

	public void setSdbj(List<Boolean> sdbj) {
		this.sdbj = sdbj;
	}

	public List<Boolean> getWdldbj() {
		return wdldbj;
	}

	public void setWdldbj(List<Boolean> wdldbj) {
		this.wdldbj = wdldbj;
	}

	public List<Boolean> getSdldbj() {
		return sdldbj;
	}

	public void setSdldbj(List<Boolean> sdldbj) {
		this.sdldbj = sdldbj;
	}

	@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 < wdbj.size(); i++) {
			if (i < ids.size()) {
				wsDao.addWsdbjRecord(wdbj.get(i), sdbj.get(i), TimeFormat.formatTimestamp(this.getTime().getTime()), ids.get(i));

				// 有报警状态
				if (wdbj.get(i) == true) {
					// TODO
					// 1存入报警管理表

					// 2发送查询报警值的命令

				}
				
				if (sdbj.get(i) == true) {
					// TODO
					// 1存入报警管理表

					// 2发送查询报警值的命令

				}
			}
		}
	}

}
