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

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

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

public class ReadO2StatusCommandResponse extends ReadMemoryCommandResponse {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -7689160555457222001L;
	
	private List<Boolean> o2bj; // 氧气浓度报警状态
	private List<Boolean> o2ldbj; // 氧气是否联动报警

	public ReadO2StatusCommandResponse() {
		o2bj = new ArrayList<Boolean>();
		o2ldbj = new ArrayList<Boolean>();
	}

	public List<Boolean> getO2bj() {
		return o2bj;
	}

	public void setO2bj(List<Boolean> o2bj) {
		this.o2bj = o2bj;
	}

	public List<Boolean> getO2ldbj() {
		return o2ldbj;
	}

	public void setO2ldbj(List<Boolean> o2ldbj) {
		this.o2ldbj = o2ldbj;
	}

	@Override
	public void afterAction() {
		// 1将氧气报警状态数据存入数据库
		PgO2Dao o2alm = new PgO2DaoImpl();
		PgDeviceDao deviceDao = new PgDeviceDaoImpl();

		List<Integer> ids = deviceDao.findDeviceIdByDestAndType(this.getMessageProducerId(), "O2");

		for (int i = 0; i < o2bj.size(); i++) {
			if (i < ids.size()) {
				o2alm.addSbjzRecord(o2bj.get(i), TimeFormat.formatTimestamp(this.getTime().getTime()), ids.get(i));

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

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

				}
			}
		}
	}

}
