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 ReadO2ValueCommandResponse extends ReadMemoryCommandResponse {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3740028978076262508L;
	
	private List<Float> o2nd; // 氧气浓度值
	private List<Float> o2ldbjz; // 氧气联动报警值

	public ReadO2ValueCommandResponse() {
		o2nd = new ArrayList<Float>();
		o2ldbjz = new ArrayList<Float>();
	}

	public List<Float> getO2nd() {
		return o2nd;
	}

	public void setO2nd(List<Float> o2nd) {
		this.o2nd = o2nd;
	}

	public List<Float> getO2ldbjz() {
		return o2ldbjz;
	}

	public void setO2ldbjz(List<Float> o2ldbjz) {
		this.o2ldbjz = o2ldbjz;
	}

	@Override
	public void afterAction() {
		// 1将氧气浓度数据存入数据库
		PgO2Dao o2Dao = new PgO2DaoImpl();
		PgDeviceDao deviceDao = new PgDeviceDaoImpl();

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

		for (int i = 0; i < o2nd.size(); i++) {
			if (i < ids.size()) {
				o2Dao.addPblzRecord(o2nd.get(i), TimeFormat.formatTimestamp(this.getTime().getTime()), ids.get(i));
			}
		}
	}

}
