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

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

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

public class ReadCH4StatusCommandResponse extends ReadMemoryCommandResponse {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4647640298404084468L;
	
	private List<Boolean> jwbj; // 甲烷浓度报警状态
	private List<Boolean> jwldbj; // 甲烷是否联动报警

	public ReadCH4StatusCommandResponse() {
		jwbj = new ArrayList<Boolean>();
		jwldbj = new ArrayList<Boolean>();
	}

	public List<Boolean> getJwbj() {
		return jwbj;
	}

	public void setJwbj(List<Boolean> jwbj) {
		this.jwbj = jwbj;
	}

	public List<Boolean> getJwldbj() {
		return jwldbj;
	}

	public void setJwldbj(List<Boolean> jwldbj) {
		this.jwldbj = jwldbj;
	}

	@Override
	public void afterAction() {
		// 1将甲烷浓度数据存入数据库
		PgCh4Dao ch4Dao = new PgCh4DaoImpl();
		PgDeviceDao deviceDao = new PgDeviceDaoImpl();

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

		for (int i = 0; i < jwbj.size(); i++) {
			if (i < ids.size()) {
				ch4Dao.addSbjzRecord(jwbj.get(i), TimeFormat.formatTimestamp(this.getTime().getTime()), ids.get(i));
				
				// 有报警状态
				if (jwbj.get(i) == true) {
					// TODO
					// 1存入报警管理表
					
					
					// 2发送查询报警值的命令
					
				}
			}
		}
	}

}
