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

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

import com.szpg.db.dao.PgDeviceDao;
import com.szpg.db.dao.PgFjDao;
import com.szpg.db.dao.impl.PgDeviceDaoImpl;
import com.szpg.db.dao.impl.PgFjDaoImpl;
import com.szpg.db.data.PgFjStat;
import com.szpg.plc.message.response.ReadMemoryCommandResponse;

public class ReadFjStatCommandResponse extends ReadMemoryCommandResponse {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -6983756717484259517L;
	
	private List<PgFjStat> fjzt;

	public ReadFjStatCommandResponse() {
		fjzt = new ArrayList<PgFjStat>();
	}

	public List<PgFjStat> getFjzt() {
		return fjzt;
	}

	public void setFjzt(List<PgFjStat> fjzt) {
		this.fjzt = fjzt;
	}

	@Override
	public void afterAction() {
		// 1将风机运行状态数据存入数据库
		PgFjDao fjDao = new PgFjDaoImpl();
		PgDeviceDao deviceDao = new PgDeviceDaoImpl();

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

		for (int i = 0; i < fjzt.size(); i++) {
			if (i < ids.size()) {
				fjzt.get(i).setPgdeviceid(ids.get(i));
				fjzt.get(i).setTm(this.getTime().getTime());
				fjDao.addStatRecord(fjzt.get(i));
				
				// 有报警状态
				if (fjzt.get(i).getFlt() == true) {
					// TODO
					// 1存入报警管理表
					
					
				}
			}
		}
	}

}
