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

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

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

public class ReadFjRtCommandResponse extends ReadMemoryCommandResponse {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8310205838594006103L;
	
	private List<Integer> fjscs; // 风机运行时长——秒数
	private List<Integer> fjsch; // 风机运行时长——小时数

	public ReadFjRtCommandResponse() {
		fjscs = new ArrayList<Integer>();
		fjsch = new ArrayList<Integer>();
	}

	public List<Integer> getFjscs() {
		return fjscs;
	}

	public void setFjscs(List<Integer> fjscs) {
		this.fjscs = fjscs;
	}

	public List<Integer> getFjsch() {
		return fjsch;
	}

	public void setFjsch(List<Integer> fjsch) {
		this.fjsch = fjsch;
	}

	@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 < fjscs.size(); i++) {
			if (i < ids.size()) {
				fjDao.addRtRecord(fjscs.get(i), fjsch.get(i), TimeFormat.formatTimestamp(this.getTime().getTime()), ids.get(i));
			}
		}
	}

}
