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; /** * */ public class OVERAGE_LOSS_DETAIL extends BaseBean{ public final static Map KEYS = new HashMap(); private Map BEAN_VALUES = null; static { KEYS.put("id", "String"); KEYS.put("order_id", "String"); KEYS.put("entity_id", "String"); KEYS.put("reason", "String"); KEYS.put("reason_key", "String"); KEYS.put("note", "String"); } public Map getColumnMap(){ return KEYS; } private String id; private Boolean isSetted_id = false;; private String order_id; private Boolean isSetted_order_id = false; private String entity_id; private Boolean isSetted_entity_id = false; private String reason; private Boolean isSetted_reason = false; private String reason_key; private Boolean isSetted_reason_key = false; private String note; private Boolean isSetted_note = false; private void initBeanValues(){ BEAN_VALUES = new HashMap(); BEAN_VALUES.put("id",id); BEAN_VALUES.put("order_id", null); BEAN_VALUES.put("entity_id", null); BEAN_VALUES.put("reason", null); BEAN_VALUES.put("reason_key", null); BEAN_VALUES.put("note", null); } public OVERAGE_LOSS_DETAIL() { initBeanValues(); } public OVERAGE_LOSS_DETAIL(String id) { super(); this.id = id; initBeanValues(); BEAN_VALUES.put("id",id); } /** * 获取ID */ public String getId() { return this.id; } /** * 设置ID */ public OVERAGE_LOSS_DETAIL 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 OVERAGE_LOSS_DETAIL set "); if (isSetted_order_id) { sBuffer.append("order_id=:order_id,"); } if (isSetted_entity_id) { sBuffer.append("entity_id=:entity_id,"); } if (isSetted_reason) { sBuffer.append("reason=:reason,"); } if (isSetted_reason_key) { sBuffer.append("reason_key=:reason_key,"); } if (isSetted_note) { sBuffer.append("note=:note,"); } String sql = sBuffer.toString(); return StringUtils.removeEnd(sql, ",") + " where id=:id"; } @Override public String getInsertSql() { StringBuffer sBuffer = new StringBuffer("insert into OVERAGE_LOSS_DETAIL("); StringBuffer fileds = new StringBuffer("id,"); StringBuffer values = new StringBuffer(":id,"); fileds.append("order_id,"); values.append(":order_id,"); fileds.append("entity_id,"); values.append(":entity_id,"); fileds.append("reason,"); values.append(":reason,"); fileds.append("reason_key,"); values.append(":reason_key,"); fileds.append("note,"); values.append(":note,"); sBuffer.append(StringUtils.removeEnd(fileds.toString(), ",") + ") values("+StringUtils.removeEnd(values.toString(), ",")+")"); return sBuffer.toString(); } /** * 获取工单ID
* 䣺2017-05-06 hh:06 */ public String getOrder_id() { return order_id; } /** * 设置工单ID
* 2017-05-06 hh:06 */ public OVERAGE_LOSS_DETAIL setOrder_id(String order_id) { this.order_id = order_id; this.isSetted_order_id = true; BEAN_VALUES.put("order_id",order_id); return this; } /** * 获取备件实体ID
* 䣺2017-05-06 hh:06 */ public String getEntity_id() { return entity_id; } /** * 设置备件实体ID
* 2017-05-06 hh:06 */ public OVERAGE_LOSS_DETAIL setEntity_id(String entity_id) { this.entity_id = entity_id; this.isSetted_entity_id = true; BEAN_VALUES.put("entity_id",entity_id); return this; } /** * 获取原因
* 䣺2017-05-06 hh:06 */ public String getReason() { return reason; } /** * 设置原因
* 2017-05-06 hh:06 */ public OVERAGE_LOSS_DETAIL setReason(String reason) { this.reason = reason; this.isSetted_reason = true; BEAN_VALUES.put("reason",reason); return this; } /** * 获取原因KEY
* 䣺2017-05-06 hh:06 */ public String getReason_key() { return reason_key; } /** * 设置原因KEY
* 2017-05-06 hh:06 */ public OVERAGE_LOSS_DETAIL setReason_key(String reason_key) { this.reason_key = reason_key; this.isSetted_reason_key = true; BEAN_VALUES.put("reason_key",reason_key); return this; } /** * 获取备注
* 䣺2017-05-06 hh:06 */ public String getNote() { return note; } /** * 设置备注
* 2017-05-06 hh:06 */ public OVERAGE_LOSS_DETAIL setNote(String note) { this.note = note; this.isSetted_note = true; BEAN_VALUES.put("note",note); 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 OVERAGE_LOSS_DETAIL getInstanceById() { if (StringUtils.isBlank(id)) { throw new RuntimeException("获取Bean时ID不能为空"); } return dao.queryForBean("select * from " + getTableName() + " where id=:id", BEAN_VALUES, this); } @Override public OVERAGE_LOSS_DETAIL queryForBean() { StringBuffer sBuffer = new StringBuffer("select * from OVERAGE_LOSS_DETAIL where "); if(isSetted_id){ sBuffer.append("id=:id and "); } if (isSetted_order_id) { sBuffer.append("order_id=:order_id and "); } if (isSetted_entity_id) { sBuffer.append("entity_id=:entity_id and "); } if (isSetted_reason) { sBuffer.append("reason=:reason and "); } if (isSetted_reason_key) { sBuffer.append("reason_key=:reason_key and "); } if (isSetted_note) { sBuffer.append("note=:note and "); } String sql = sBuffer.toString(); sql = StringUtils.removeEnd(sql, " and "); return dao.queryForBean(sql,this); } @Override public String getTableName() { return "OVERAGE_LOSS_DETAIL"; } public Map getBeanValues(){ return this.BEAN_VALUES; } @Override public OVERAGE_LOSS_DETAIL insert() { if (StringUtils.isBlank(id)) { this.setId(StringUtil.getUUID()); } dao.execute(getInsertSql(),BEAN_VALUES); return this; } @Override public OVERAGE_LOSS_DETAIL update() { if (StringUtils.isBlank(id)) { throw new RuntimeException("更新Bean时ID不能为空"); } dao.execute(getUpdateSql(),BEAN_VALUES); return this; } public OVERAGE_LOSS_DETAIL 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 OVERAGE_LOSS_DETAIL 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("ORDER_ID"); BEAN_VALUES.put("order_id",obj); this.setOrder_id(ConvertUtil.obj2Str(obj)); obj = rs.getObject("ENTITY_ID"); BEAN_VALUES.put("entity_id",obj); this.setEntity_id(ConvertUtil.obj2Str(obj)); obj = rs.getObject("REASON"); BEAN_VALUES.put("reason",obj); this.setReason(ConvertUtil.obj2Str(obj)); obj = rs.getObject("REASON_KEY"); BEAN_VALUES.put("reason_key",obj); this.setReason_key(ConvertUtil.obj2Str(obj)); obj = rs.getObject("NOTE"); BEAN_VALUES.put("note",obj); this.setNote(ConvertUtil.obj2Str(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 OVERAGE_LOSS_DETAIL newInstance(){ return new OVERAGE_LOSS_DETAIL(); } }