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 ReadCOValueCommandResponse extends ReadMemoryCommandResponse {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1701662136000200479L;
	
	private List<Float> cond; //一氧化碳浓度值
	private List<Float> coldbjz; //一氧化碳联动报警值
	
	public ReadCOValueCommandResponse() {
		cond = new ArrayList<Float>();
		coldbjz = new ArrayList<Float>();
	}

	public List<Float> getCond() {
		return cond;
	}

	public void setCond(List<Float> cond) {
		this.cond = cond;
	}

	public List<Float> getColdbjz() {
		return coldbjz;
	}

	public void setColdbjz(List<Float> coldbjz) {
		this.coldbjz = coldbjz;
	}

	@Override
	public void afterAction() {
		// 1将一氧化碳浓度数据存入数据库
		PgCODao coDao = new PgCODaoImpl();
		PgDeviceDao deviceDao = new PgDeviceDaoImpl();
		
		List<Integer> ids = deviceDao.findDeviceIdByDestAndType(this.getMessageProducerId(), "CO");
		
		for (int i = 0; i < cond.size(); i++) {
			if (i < ids.size()) {
				coDao.addPblzRecord(cond.get(i), TimeFormat.formatTimestamp(this.getTime().getTime()), ids.get(i));
			}
		}
	}

}
