
package com.qst.dms.entity;

import java.io.Serializable;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

//用户登录日志记录
public class LogRec extends DataBase implements Serializable{
	/**
	 *  登录用户名
	 */
	private String user;
	/**
	 * 登录用户主机IP地址
	 */
	private String ip;
	/**
	 * 登录状态：登录、登出
	 */
	private int logType;
	/**
	 * 登录常量LOG_IN、登出常量常量LOG_OUT
	 */
    public static final int LOG_IN=1;
    public static final int LOG_OUT=0;
	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}


	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public int getLogType() {
		return logType;
	}

	public static LogRec get_LogRec(Object[] info)
	{
		int id = (int)info[0],type = (int)info[3],logtype = (int)info[6];
		Date time = Date.from( ((LocalDateTime)info[1]).atZone( ZoneId.systemDefault()).toInstant());
		String address = (String)info[2],username = (String)info[4],ip = (String)info[5];
		return new LogRec(id,time,address,type,username,ip,logtype);
	}
	public Object[] get_DB_param()
	{
		return new Object[]{
				this.getId(),
				new Timestamp(this.getTime().getTime()),
				this.getAddress(),this.getType(),this.getUser(),
				this.getIp(),this.getLogType()
		};
	}

	
	public void setLogType(int logType) {
		this.logType = logType;
	}

	public LogRec() {
	}

	public LogRec(int id, Date time, String address, int type,String user,String ip,int logType) {
		super(id,time,address,type);
		this.user=user;
		this.ip=ip;
		this.logType=logType;
	}
	
	public String toString() {
		return this.getId() + "," +this.getTime() + "," +this.getAddress() + "," + this.getType() + ","+user+","+ip+","+logType;
	}
}
