/** * 保存数据 * * @param conn * @param jbo * @return */ public boolean save(Connection conn, JboIFace jbo) throws JxException { if (conn == null || jbo == null) { LOG.warn("保存数据失败,conn is null or jbo is null."); return false; } Map<String, Object> data = jbo.getData(); if (data == null) { LOG.info("没有要保存的数据"); return false; } int res; if (jbo.isToBeAdd() && jbo.isToBeDel()) { return true; } String tableName = jbo.getJboSet().getEntityname(); if (jbo.isToBeDel() && !jbo.isToBeAdd()) { if (delete(conn, jbo) > 0) { removeCache(tableName); return true; } else { return false; } } if (!jbo.isModify() && !jbo.isToBeAdd()) { return true; } String keyName = jbo.getUidName(); if (StrUtil.isNull(keyName)) { throw new JxException("表" + tableName + "没有指定关键字,请与管理员联系。"); } Object keyValue = data.get(keyName); JboSetIFace js = jbo.getJboSet(); DataQuery dq = DBFactory.getDataQuery(js.getDbtype(), js.getDataSourceName()); // 设定记录信息 java.sql.Timestamp ts = DateUtil.sqlDateTime(); JxUserInfo user = JxSession.getJxUserInfo(); if (user != null && jbo != null) { jbo.setString("MODIFIER_ID", user.getUserid()); jbo.setString("MODIFIER", user.getDisplayname()); jbo.setObject("MODIFY_TIME", ts); jbo.setObject("MODIFY_DATE", ts); jbo.setString("CHANGEBY", user.getUserid()); jbo.setObject("CHANGEDATE", ts); } if (dq.exist(conn, tableName, keyName, keyValue)) { // 更改记录,修改人、修改时间要设置为现在 res = update(conn, jbo); } else { res = insert(conn, jbo); } if (res > 0) { removeCache(tableName); return true; } else { LOG.info("没有保存到数据," + tableName + "." + keyName + "=" + keyValue); return false; } }
@Override public List<JboIFace> query() throws JxException { App app = JxSession.getMainApp(); if (app.getAppNameType().equalsIgnoreCase("PUBDEPARTMENT.LIST")) { DataQueryInfo queryInfo = getQueryInfo(); App userApp = JxSession.getApp("pubdepartment.user"); if (null != userApp) { JboIFace userJbo = userApp.getJbo(); if (null != userJbo) { JboSetIFace userRoleJboSet = userJbo.getRelationJboSet("PUB_ROLE_USERUSER_IDP"); if (null != userRoleJboSet) { List<JboIFace> userRoleList = userRoleJboSet.getJbolist(); if (!userRoleList.isEmpty()) { StringBuffer sb = new StringBuffer(); sb.append("ROLE_ID NOT IN ("); int size = userRoleList.size(); for (int i = 0; i < size; i++) { JboIFace tempJbo = userRoleList.get(i); sb.append("'").append(tempJbo.getString("ROLE_ID")).append("'"); if (i < size - 1) { sb.append(","); } } sb.append(")"); queryInfo.setWhereCause(sb.toString()); } } } } } getQueryInfo().setPageNum(0); getQueryInfo().setPageSize(40); return super.query(); }