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 ReadCH4ValueCommandResponse extends ReadMemoryCommandResponse {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 6615138314462518854L;
	
	private List<Float> jwnd; //甲烷浓度值
	private List<Float> jwldbjz; //甲烷联动报警值
	
	public ReadCH4ValueCommandResponse() {
		jwnd = new ArrayList<Float>();
		jwldbjz = new ArrayList<Float>();
	}

	public List<Float> getJwnd() {
		return jwnd;
	}

	public void setJwnd(List<Float> jwnd) {
		this.jwnd = jwnd;
	}

	public List<Float> getJwldbjz() {
		return jwldbjz;
	}

	public void setJwldbjz(List<Float> jwldbjz) {
		this.jwldbjz = jwldbjz;
	}

	@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 < jwnd.size(); i++) {
			if (i < ids.size()) {
				ch4Dao.addPblzRecord(jwnd.get(i), TimeFormat.formatTimestamp(this.getTime().getTime()), ids.get(i));
			}
		}
	}

}
