package cn.ksource.beans; import java.sql.ResultSet; import java.sql.SQLException; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.apache.commons.lang.StringUtils; import cn.ksource.core.dao.BaseBean; import cn.ksource.core.util.ConvertUtil; import cn.ksource.core.util.StringUtil; /** * 员工登录IP */ public class GG_USER_LOGINIP extends BaseBean{ public final static Map KEYS = new HashMap(); private Map BEAN_VALUES = null; static { KEYS.put("id", "String"); KEYS.put("userid", "String"); KEYS.put("lastip", "String"); KEYS.put("lasttime", "Long"); KEYS.put("thisip", "String"); KEYS.put("thistime", "Long"); } public Map getColumnMap(){ return KEYS; } private String id; private Boolean isSetted_id = false;; private String userid; private Boolean isSetted_userid = false; private String lastip; private Boolean isSetted_lastip = false; private Long lasttime; private Boolean isSetted_lasttime = false; private String thisip; private Boolean isSetted_thisip = false; private Long thistime; private Boolean isSetted_thistime = false; private void initBeanValues(){ BEAN_VALUES = new HashMap(); BEAN_VALUES.put("id",id); BEAN_VALUES.put("userid", null); BEAN_VALUES.put("lastip", null); BEAN_VALUES.put("lasttime", null); BEAN_VALUES.put("thisip", null); BEAN_VALUES.put("thistime", null); } public GG_USER_LOGINIP() { initBeanValues(); } public GG_USER_LOGINIP(String id) { super(); this.id = id; initBeanValues(); BEAN_VALUES.put("id",id); } /** * 获取ID */ public String getId() { return this.id; } /** * 设置ID */ public GG_USER_LOGINIP setId(String id) { this.id = id; this.isSetted_id = true; BEAN_VALUES.put("id",id); return this; } @Override public String getUpdateSql() { StringBuffer sBuffer = new StringBuffer("update GG_USER_LOGINIP set "); if (isSetted_userid) { sBuffer.append("userid=:userid,"); } if (isSetted_lastip) { sBuffer.append("lastip=:lastip,"); } if (isSetted_lasttime) { sBuffer.append("lasttime=:lasttime,"); } if (isSetted_thisip) { sBuffer.append("thisip=:thisip,"); } if (isSetted_thistime) { sBuffer.append("thistime=:thistime,"); } String sql = sBuffer.toString(); return StringUtils.removeEnd(sql, ",") + " where id=:id"; } @Override public String getInsertSql() { StringBuffer sBuffer = new StringBuffer("insert into GG_USER_LOGINIP("); StringBuffer fileds = new StringBuffer("id,"); StringBuffer values = new StringBuffer(":id,"); fileds.append("userid,"); values.append(":userid,"); fileds.append("lastip,"); values.append(":lastip,"); fileds.append("lasttime,"); values.append(":lasttime,"); fileds.append("thisip,"); values.append(":thisip,"); fileds.append("thistime,"); values.append(":thistime,"); sBuffer.append(StringUtils.removeEnd(fileds.toString(), ",") + ") values("+StringUtils.removeEnd(values.toString(), ",")+")"); return sBuffer.toString(); } /** * 获取户用ID
* 䣺2014-02-26 hh:06 */ public String getUserid() { return userid; } /** * 设置户用ID
* 2014-02-26 hh:06 */ public GG_USER_LOGINIP setUserid(String userid) { this.userid = userid; this.isSetted_userid = true; BEAN_VALUES.put("userid",userid); return this; } /** * 获取最后一次登陆IP
* 䣺2014-02-26 hh:06 */ public String getLastip() { return lastip; } /** * 设置最后一次登陆IP
* 2014-02-26 hh:06 */ public GG_USER_LOGINIP setLastip(String lastip) { this.lastip = lastip; this.isSetted_lastip = true; BEAN_VALUES.put("lastip",lastip); return this; } /** * 获取最后一次登陆时间
* 䣺2014-02-26 hh:06 */ public Long getLasttime() { return lasttime; } /** * 设置最后一次登陆时间
* 2014-02-26 hh:06 */ public GG_USER_LOGINIP setLasttime(Long lasttime) { this.lasttime = lasttime; this.isSetted_lasttime = true; BEAN_VALUES.put("lasttime",lasttime); return this; } /** * 获取本次登陆IP
* 䣺2014-02-26 hh:06 */ public String getThisip() { return thisip; } /** * 设置本次登陆IP
* 2014-02-26 hh:06 */ public GG_USER_LOGINIP setThisip(String thisip) { this.thisip = thisip; this.isSetted_thisip = true; BEAN_VALUES.put("thisip",thisip); return this; } /** * 获取本次登陆时间
* 䣺2014-02-26 hh:06 */ public Long getThistime() { return thistime; } /** * 设置本次登陆时间
* 2014-02-26 hh:06 */ public GG_USER_LOGINIP setThistime(Long thistime) { this.thistime = thistime; this.isSetted_thistime = true; BEAN_VALUES.put("thistime",thistime); return this; } /** * 使用ID删除Bean
*/ public void deleteById() { if (StringUtils.isBlank(id)) { throw new RuntimeException("删除bean时ID不能为空"); } dao.execute("delete from " + getTableName() + " where id = :id", BEAN_VALUES); } @Override public GG_USER_LOGINIP getInstanceById() { if (StringUtils.isBlank(id)) { throw new RuntimeException("获取Bean时ID不能为空"); } return dao.queryForBean("select * from " + getTableName() + " where id=:id", BEAN_VALUES, this); } @Override public GG_USER_LOGINIP queryForBean() { StringBuffer sBuffer = new StringBuffer("select * from GG_USER_LOGINIP where "); if(isSetted_id){ sBuffer.append("id=:id and "); } if (isSetted_userid) { sBuffer.append("userid=:userid and "); } if (isSetted_lastip) { sBuffer.append("lastip=:lastip and "); } if (isSetted_lasttime) { sBuffer.append("lasttime=:lasttime and "); } if (isSetted_thisip) { sBuffer.append("thisip=:thisip and "); } if (isSetted_thistime) { sBuffer.append("thistime=:thistime and "); } String sql = sBuffer.toString(); sql = StringUtils.removeEnd(sql, " and "); return dao.queryForBean(sql,this); } @Override public String getTableName() { return "GG_USER_LOGINIP"; } public Map getBeanValues(){ return this.BEAN_VALUES; } @Override public GG_USER_LOGINIP insert() { if (StringUtils.isBlank(id)) { this.setId(StringUtil.getUUID()); } dao.execute(getInsertSql(),BEAN_VALUES); return this; } @Override public GG_USER_LOGINIP update() { if (StringUtils.isBlank(id)) { throw new RuntimeException("更新Bean时ID不能为空"); } dao.execute(getUpdateSql(),BEAN_VALUES); return this; } public GG_USER_LOGINIP insertOrUpdate(){ if (StringUtils.isNotBlank(id)) { return update(); } else { return insert(); } } /** * 通过ID获取该条信息的Map结构 */ public Map getBeanMapById() { if (StringUtils.isBlank(id)) { throw new RuntimeException("ID不能为空!"); } return dao.queryForMap("select * from GG_USER_LOGINIP where id=:id",BEAN_VALUES); } public Object mapRow(ResultSet rs, int rownum) throws SQLException { Object id = rs.getObject("ID"); this.setId(ConvertUtil.obj2Str(id)); BEAN_VALUES.put("id",id); Object obj = null; obj = rs.getObject("USERID"); BEAN_VALUES.put("userid",obj); this.setUserid(ConvertUtil.obj2Str(obj)); obj = rs.getObject("LASTIP"); BEAN_VALUES.put("lastip",obj); this.setLastip(ConvertUtil.obj2Str(obj)); obj = rs.getObject("LASTTIME"); BEAN_VALUES.put("lasttime",obj); this.setLasttime(ConvertUtil.obj2Long(obj)); obj = rs.getObject("THISIP"); BEAN_VALUES.put("thisip",obj); this.setThisip(ConvertUtil.obj2Str(obj)); obj = rs.getObject("THISTIME"); BEAN_VALUES.put("thistime",obj); this.setThistime(ConvertUtil.obj2Long(obj)); return this; } public String toString() { StringBuffer sb = new StringBuffer("["); for (Iterator iterator = KEYS.keySet().iterator(); iterator.hasNext();) { String key = (String) iterator.next(); sb.append(key+"=" + BEAN_VALUES.get(key)+","); } sb.append("]"); return sb.toString(); } public GG_USER_LOGINIP newInstance(){ return new GG_USER_LOGINIP(); } }