Esempio n. 1
0
 /**
  * 字符串格式参数转换成HashMap
  *
  * @param str String 字符串参数
  * @return Map
  */
 public static Map splitParam(String str) {
   Map result = new HashMap();
   Document doc = XMLTools.stringToDocument(str);
   NodeList elements = doc.getElementsByTagName("param");
   for (int i = 0, j = elements.getLength(); i < j; i++) {
     Node param = elements.item(i);
     NodeList childs = param.getChildNodes();
     String paramName = null;
     String paramValue = null;
     for (int m = 0, n = childs.getLength(); m < n; m++) {
       Node child = childs.item(m);
       if (child.getNodeName().equalsIgnoreCase("name")) {
         paramName = child.getFirstChild().getNodeValue();
       } else {
         if (child.hasChildNodes()) {
           paramValue = child.getFirstChild().getNodeValue();
         } else {
           paramValue = "";
         }
       }
     }
     result.put(paramName, paramValue);
   }
   return result;
 }
Esempio n. 2
0
 /**
  * 将字符串格式的页面元素信息解析成Java对象列表
  *
  * @param s String 元素字段串
  * @return List 对象列表
  */
 public static List extractLabel(String s) {
   List result = new ArrayList();
   if (!s.equalsIgnoreCase("")) {
     Document doc = XMLTools.stringToDocument(s);
     NodeList elements = doc.getElementsByTagName("element");
     for (int i = 0, j = elements.getLength(); i < j; i++) {
       Node node = elements.item(i);
       StaticTextInfor ele = new StaticTextInfor(node);
       result.add(ele);
     }
   }
   return result;
 }
Esempio n. 3
0
 /**
  * 将字符串格式的页面元素信息解析成Java对象列表
  *
  * @param s String 元素字段串
  * @return Object 对象列表,第一个元素是参数对象列表,第二个对象是参数值
  */
 public static Object[] extractParam(String s) {
   Object[] results = new Object[2];
   List result = new ArrayList();
   Map paramValues = new HashMap();
   if (!s.equalsIgnoreCase("")) {
     Document doc = XMLTools.stringToDocument(s);
     NodeList elements = doc.getElementsByTagName("element");
     for (int i = 0, j = elements.getLength(); i < j; i++) {
       Node node = elements.item(i);
       ParamFieldInfor ele = new ParamFieldInfor(node);
       result.add(ele);
     }
     NodeList values = doc.getElementsByTagName("content");
     for (int i = 0, j = elements.getLength(); i < j; i++) {
       Node node = values.item(i);
       String value = node.getFirstChild().getNodeValue();
       String name = node.getAttributes().item(0).getNodeValue();
       paramValues.put(name, value);
     }
   }
   results[0] = result;
   results[1] = paramValues;
   return results;
 }
Esempio n. 4
0
  public String doExecute() {
    String cond = condition;
    String searCond = this.searchCond;
    if (!type.equalsIgnoreCase(ADVANCED_SEARCH) && !type.equalsIgnoreCase(ADVANCED_PAGINATION)) {
      if (searCond != null && !searCond.equals("")) {
        if (cond.equals("")) {
          cond = searCond;
        } else {
          cond += ";" + searCond;
        }
      }
    }

    Map paramsMap = new HashMap();
    DBHelper.parseParamsSimpleForSql(cond, paramsMap);

    if (userid == null) userid = (String) paramsMap.get("userid");

    // System.out.println("######################################################");
    // System.out.println("userId:" + userid);
    String userNumLimCondition = "";

    if (masterTableName != null
        && masterTableName.length() > 0
        && masterCompoName != null
        && masterCompoName.length() > 0) {
      if (masterTableName.equals(MetaManager.getCompoMeta(masterCompoName).getMasterTable())) {
        String realFieldName = request.getParameter("realFieldName");
        List realFieldNameList = java.util.Arrays.asList(realFieldName.split(","));

        TableMeta tableMeta = MetaManager.getTableMeta(masterTableName);
        if (masterSelectField != null && masterSelectField.length() > 0) {
          String[] sTemp = masterSelectField.split(",");
          for (int i = 0; i < sTemp.length; i++) {
            Field field = tableMeta.getField(sTemp[i]);
            if (field == null
                || !realFieldNameList.contains(
                    field.getRefField())) { // 主表选择字段对应的外部实体字段与外部实体的实际选择字段比较
              continue;
            }
            if (!field.isSave()) { // 非保存字段,查询此外部实体对应的其他保存字段的数值权限
              List fields = ((Foreign) tableMeta.getForeign(field.getRefName())).getFields();
              for (int j = 0; j < fields.size(); j++) {
                Field tField = (Field) fields.get(i);
                String fieldName = tField.getName();
                if (sTemp[i].equals(fieldName) || !tField.isSave()) continue;

                String refFieldName = tField.getRefField();

                String iCond = getListUserLimCondition(refFieldName, fieldName);
                if (iCond != null && iCond.length() > 0) {
                  if (userNumLimCondition.length() > 0) {
                    userNumLimCondition += " and " + iCond;
                  } else {
                    userNumLimCondition = iCond;
                  }
                }
              }
            } else { // 保存字段,添加数值权限
              String iCond = getListUserLimCondition(field.getRefField(), sTemp[i]);
              if (iCond != null && iCond.length() > 0) {
                if (userNumLimCondition.length() > 0) {
                  userNumLimCondition += " and " + iCond;
                } else {
                  userNumLimCondition = iCond;
                }
              }
            }
          }
        }
      }
    }

    String quotUserNumLim =
        RightUtil.getUserNumLimCondition(
            ServletActionContext.getRequest(), userid, "fquote", componame, null, null);
    // System.out.println("svCoCode:" + SessionUtils.getAttribute(request, "svCoCode"));
    // System.out.println("quotUserNumLim:" + quotUserNumLim);
    if (userNumLimCondition != null && userNumLimCondition.length() > 0) {
      if (quotUserNumLim != null && quotUserNumLim.length() > 0) {
        userNumLimCondition += " and ";
        userNumLimCondition += quotUserNumLim;
      }
    } else {
      if (quotUserNumLim != null && quotUserNumLim.length() > 0) {
        userNumLimCondition = quotUserNumLim;
      }
    }

    if (type.equalsIgnoreCase(ADVANCED_SEARCH)
        || type.equalsIgnoreCase(ADVANCED_PAGINATION)) { // 搜索类型为高级搜索时,将搜索条件附加上;
      if (userNumLimCondition != null && userNumLimCondition.length() > 0)
        userNumLimCondition += " and ";
      searCond = searCond.replaceAll(";", " and "); // 将;替换为and
      userNumLimCondition += searCond;
    }
    provider.setUserNumLimCondition(userNumLimCondition);

    // System.out.println("userNumLimCondition:" + userNumLimCondition);

    int pageIndex = Pub.calcPageIndex(currentpage, direction, pagesize, totalcount);
    if (pageIndex <= 0) pageIndex = 1;
    int rowmin = (pageIndex - 1) * pagesize + 1;
    int rowmax = pageIndex * pagesize;

    Datum datum = null;
    if (isFromSql && (sqlid == null || sqlid.length() == 0)) { // sqlid为空直接查询表
      DBSupport support = (DBSupport) ApplusContext.getBean("dbSupport");
      List newParams = new ArrayList();

      String matchCond = (String) paramsMap.get("matchCond"); // 仅添加搜索框的条件
      paramsMap = new HashMap();

      if (matchCond != null) {
        List saveFieldNames = MetaManager.getTableMeta(tablename).getSaveFieldNames();
        for (int i = 0; i < saveFieldNames.size(); i++)
          paramsMap.put(saveFieldNames.get(i), matchCond);
      }

      String sql = support.wrapSqlByTableName(tablename, paramsMap, newParams);

      if (matchCond != null) {
        sql = sql.replaceAll("[=]", "like");
        sql = sql.replaceAll("and", "or");
      }

      StringBuffer orderStr = new StringBuffer(""); // 排序和年度
      TableMeta tableMeta = MetaManager.getTableMeta(tablename);
      List keyFieldNames = tableMeta.getKeyFieldNames();
      if (keyFieldNames != null) {
        orderStr.append(" order by ");
        for (int i = 0; i < keyFieldNames.size(); i++) {
          orderStr.append(keyFieldNames.get(i) + ",");
          if ("ND".equalsIgnoreCase((String) keyFieldNames.get(i))) {
            sql =
                support.wrapSqlByCondtion(sql, "ND=" + SessionUtils.getAttribute(request, "svNd"));
          }
        }
      }

      if (orderStr.toString().endsWith(",")) {
        sql += orderStr.substring(0, orderStr.length() - 1);
      }

      if (totalcount < 0)
        totalcount = provider.getTotalCount(support.wrapSqlForCount(sql), newParams);
      if (totalcount <= 0) { // 没有数据
        return SUCCESS;
      }

      // System.out.println("sql:" + sql);
      paramsMap.put("rownum", rowmax + "");
      paramsMap.put("rn", rowmin + "");
      newParams.add(rowmax + "");
      newParams.add(rowmin + "");
      if (userNumLimCondition != null && userNumLimCondition.length() > 0) {
        sql = support.wrapSqlByCondtion(sql, userNumLimCondition);
      }
      sql = support.wrapPaginationSql(sql);
      datum =
          provider.getPaginationData(
              pageIndex, totalcount, pagesize, tablename, sql, newParams, false);
    } else {
      if (totalcount < 0) { // 取总条数
        totalcount = provider.getTotalCount(sqlid, paramsMap);
      }
      if (totalcount <= 0) { // 没有数据
        return SUCCESS;
      }

      paramsMap.put("rownum", rowmax + "");
      paramsMap.put("rn", rowmin + "");

      // 取分页数据
      datum =
          provider.getPaginationData(
              pageIndex, totalcount, pagesize, tablename, sqlid, paramsMap, false);
    }

    int totalPage = totalcount % pagesize == 0 ? totalcount / pagesize : totalcount / pagesize + 1;
    StringBuffer sb = new StringBuffer();
    sb.append("<?xml version=\"1.0\" encoding=\"GBK\"?>\n");
    List data = datum.getData();
    if (data != null) {
      sb.append(
          "<delta totalCount=\""
              + totalcount
              + "\" totalPage=\""
              + totalPage
              + "\" currentPage=\""
              + pageIndex
              + "\" pageSize=\""
              + pagesize
              + "\">\n");
      for (int i = 0; i < data.size(); i++) {
        sb.append("<entity name=\"null\">\n");
        Map map = (Map) data.get(i);
        Set entrySet = map.entrySet();
        Iterator itera = entrySet.iterator();
        while (itera.hasNext()) {
          Entry entry = (Entry) itera.next();
          sb.append("<field name=\"");
          sb.append(entry.getKey());
          sb.append("\" value=\"");
          sb.append(
              entry.getValue() == null
                  ? ""
                  : XMLTools.getValidStringForXML(entry.getValue().toString()));
          sb.append("\"/>\n");
        }
        sb.append("</entity>\n");
      }
      sb.append("</delta>\n");
    }

    // System.out.println("######################################################");

    resultstring = sb.toString();
    return SUCCESS;
  }