package com.szpg.db.data;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Date;

import com.szpg.util.TimeFormat;
import z.json.JSONException;
import z.json.JSONObject;

/**
 * 照明运行状态数据表
 * 
 * @author admin
 *
 */
public class PgZmStat implements java.io.Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 2636696758486735818L;
	
	private Integer id;
	private Date logtime;
	private Date uptime;
	private Integer pgdeviceid;
	private Boolean run; //运行状态标志位
	private Boolean flt; //故障报警
	private Boolean en; //手自动使能标志位
	private Boolean rout; //启停超时标志位

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Date getLogtime() {
		return logtime;
	}

	public void setLogtime(Date logtime) {
		this.logtime = logtime;
	}

	public Date getUptime() {
		return uptime;
	}

	public void setUptime(Date uptime) {
		this.uptime = uptime;
	}
	
	public Integer getPgdeviceid() {
		return pgdeviceid;
	}

	public void setPgdeviceid(Integer pgdeviceid) {
		this.pgdeviceid = pgdeviceid;
	}
	
	public Boolean getRun() {
		return run;
	}

	public void setRun(Boolean run) {
		this.run = run;
	}

	public Boolean getFlt() {
		return flt;
	}

	public void setFlt(Boolean flt) {
		this.flt = flt;
	}

	public Boolean getEn() {
		return en;
	}

	public void setEn(Boolean en) {
		this.en = en;
	}

	public Boolean getRout() {
		return rout;
	}

	public void setRout(Boolean rout) {
		this.rout = rout;
	}

	public void setTm(Date tm) {
		this.logtime = tm;
		this.uptime = tm;
	}
	
	public String getTmStr() {
		if (null != this.logtime) {
			return TimeFormat.formatTimestamp(logtime);
		} else {
			return "";
		}
	}
	
	public String getTmStrGB() {
		if (null != this.logtime) {
			return TimeFormat.format(logtime, "yyyyMMddHHmmss");
		} else {
			return "";
		}
	}

	@Override
	public String toString() {
		return "PgZmStat[run=" + run + ", flt=" + flt + ", logtime=" + TimeFormat.formatTimestamp(logtime) + "]";
	}

	public JSONObject toJson() {
		JSONObject json = new JSONObject();
		try {
			json.put("time", this.getTmStr());
			json.put("run", null != this.getRun() && this.getRun() == true ? URLEncoder.encode("照明启动", "UTF-8") : URLEncoder.encode("照明关闭", "UTF-8"));
			json.put("runStat", null != this.getRun() && this.getRun() == true ? "1" : "0");
		} catch (JSONException e) {
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}

		return json;
	}
}
