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

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

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

public class ReadHSStatusCommandResponse extends ReadMemoryCommandResponse {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6630884988346141548L;
	
	private List<Boolean> hsbj; // 硫化氢浓度报警状态
	private List<Boolean> hsldbj; // 硫化氢是否联动报警

	public ReadHSStatusCommandResponse() {
		hsbj = new ArrayList<Boolean>();
		hsldbj = new ArrayList<Boolean>();
	}

	public List<Boolean> getHsbj() {
		return hsbj;
	}

	public void setHsbj(List<Boolean> hsbj) {
		this.hsbj = hsbj;
	}

	public List<Boolean> getHsldbj() {
		return hsldbj;
	}

	public void setHsldbj(List<Boolean> hsldbj) {
		this.hsldbj = hsldbj;
	}

	@Override
	public void afterAction() {
		// 1将硫化氢报警状态数据存入数据库
		PgHSDao hsalmDao = new PgHSDaoImpl();
		PgDeviceDao deviceDao = new PgDeviceDaoImpl();

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

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

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

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

				}
			}
		}
	}

}
