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

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

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

public class ReadCOStatusCommandResponse extends ReadMemoryCommandResponse {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6730342916591454611L;
	
	private List<Boolean> cobj; // 一氧化碳浓度报警状态
	private List<Boolean> coldbj; // 一氧化碳是否联动报警

	public ReadCOStatusCommandResponse() {
		cobj = new ArrayList<Boolean>();
		coldbj = new ArrayList<Boolean>();
	}

	public List<Boolean> getCobj() {
		return cobj;
	}

	public void setCobj(List<Boolean> cobj) {
		this.cobj = cobj;
	}

	public List<Boolean> getColdbj() {
		return coldbj;
	}

	public void setColdbj(List<Boolean> coldbj) {
		this.coldbj = coldbj;
	}

	@Override
	public void afterAction() {
		// 1将一氧化碳报警状态数据存入数据库
		PgCODao coalm = new PgCODaoImpl();
		PgDeviceDao deviceDao = new PgDeviceDaoImpl();

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

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

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

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

				}
			}
		}
	}

}
