Beispiel #1
0
  @Override
  public Map<String, Object> findFuzzy(
      String column, String objectType, String condition, int page, int pageSize)
      throws ClassNotFoundException, JSONException {
    String[] columnArray = column.split(",");
    StringBuffer sbColumn = new StringBuffer();
    StringBuffer sbEntity = new StringBuffer();
    Map<String, String> aliasMap = new HashMap<String, String>();
    for (int i = 0; i < columnArray.length; i++) {
      if (columnArray[i].indexOf(".") != -1) {
        String columnHead = columnArray[i].substring(0, columnArray[i].lastIndexOf("."));
        String columnBody = columnArray[i].substring(columnArray[i].lastIndexOf(".") + 1);
        String columnAlias = "";
        // Field f = ReflectionUtils.findField(this.getType(objectType), columnHead);
        Field f = BeanFieldUtil.findField(this.getType(objectType), columnHead);

        if (null == f) {
          continue;
        }
        if (!aliasMap.containsKey(columnHead)) {
          columnAlias = "t_" + i;
          aliasMap.put(columnHead, "t_" + i);
          sbEntity.append(" left join " + "t_." + columnHead + " as " + "t_" + i);
        } else {
          columnAlias = aliasMap.get(columnHead);
        }
        sbColumn.append(
            columnAlias
                + "."
                + columnBody
                + " as "
                + columnArray[i].replace(".", "_alias_point_")
                + ",");
      } else {
        Field f = ReflectionUtils.findField(this.getType(objectType), columnArray[i]);
        if (null == f) {
          continue;
        }

        sbColumn.append("t_." + columnArray[i] + " as " + columnArray[i] + ",");
      }
    }
    String sbColumnString = sbColumn.toString();
    String hql =
        "select new map("
            + sbColumnString.substring(0, sbColumnString.lastIndexOf(","))
            + ") from "
            + objectType
            + " as t_ "
            + sbEntity.toString()
            + "";
    if (condition != null && !condition.equals("")) {
      String conditionString = "";
      JSONObject conditionObject = new JSONObject(condition);
      System.out.println(conditionObject.keys());
      Iterator<String> it = conditionObject.keys();

      while (it.hasNext()) { // 遍历
        String key = it.next();
        String value = conditionObject.getString(key);
        if (value != null && !value.equals("")) {
          conditionString += " AND t_." + key + " like '%" + value + "%'";
        }
      }
      /*String[] conditionArray = condition.split(";");
      for (int i = 0; i < conditionArray.length; i++) {
      	String[] cds = conditionArray[i].split("=");
      	if (cds.length > 1 && cds[1] != null && !cds[1].equals("")) {
      		conditionString += "t_."+cds[0] + " like '%" + cds[1] +"%'";
      	}
      }*/
      if (!conditionString.equals("")) {
        hql += " where " + conditionString.substring(4);
      }
    }
    System.out.println(hql);
    return this.commDao.findPageList(page, pageSize, hql);
    // return this.commDao.findFuzzy(hql, conditionString, page, pageSize);
  }
Beispiel #2
0
  @Override
  public List<Map<String, String>> getColumnsProperty(HttpServletRequest request) throws Exception {
    // 返回数组
    List<Map<String, String>> returnList = new ArrayList<Map<String, String>>();

    // 判断传递的是类名称还是json字符串名称
    String objectType = request.getParameter("objectType");
    String fileName = request.getParameter("fileName");

    if (objectType != null && objectType != "") { // 类名
      returnList = this.commDao.getColumnsProperty(this.commDao.getType(objectType));
    } else if (fileName != null) { // json字符串
      String path = ResourceUtil.getTablesDataSourceDirectoryPath();
      String fileString = this.readFile(path + fileName);
      ObjectMapper mapper = new ObjectMapper();
      Map<String, Map<String, String>> temMap = new LinkedHashMap<String, Map<String, String>>();
      Map<String, Map<String, String>> _temMap = new LinkedHashMap<String, Map<String, String>>();
      Map<String, Map<String, String>> treeMap =
          new java.util.TreeMap<String, Map<String, String>>();

      Map<String, Object> map = mapper.readValue(fileString, Map.class);
      System.out.println(map);
      Map<String, String> attrMap = (Map<String, String>) map.get("attribute");
      // 通过json字符串中的attribute属性获取保存的类名,取得基础类
      List<String> sortFieldList = new ArrayList<String>();

      if (attrMap != null && attrMap.get("objectType") != null) {
        returnList =
            this.commDao.getColumnsProperty(this.commDao.getType(attrMap.get("objectType")));
        // 将
        for (Map<String, String> column : returnList) {
          // temMap.put(column.get("fieldName"), column);
          sortFieldList.add(column.get("fieldName"));
        }
      }

      // json字符串中保存的grid
      List gridList = (ArrayList) map.get("grid");
      // 搜素字段
      List searchList = (ArrayList) map.get("search");
      // 表单字段
      List formList = (ArrayList) map.get("form");
      // Map attrMap =  map.get("attribute");

      // 将表单字段排序
      // 归并将form和grid合并name字段

      List<String> sortGridList = new ArrayList<String>();
      Set<String> linkSet = new LinkedHashSet<String>();
      for (int i = 0; i < gridList.size(); i++) {
        Map<String, Object> gridField = (Map<String, Object>) gridList.get(i);
        String name = gridField.get("name").toString();
        if (name.contains(".")) {
          name = name.substring(0, name.indexOf("."));
        }
        linkSet.add(name);
      }
      sortGridList.addAll(linkSet);

      List<String> sortFormList = new ArrayList<String>();
      for (int i = 0; i < formList.size(); i++) {
        Map<String, Object> fromField = (Map<String, Object>) formList.get(i);
        sortFormList.add(fromField.get("name").toString());
      }

      List<String> sortGridAndForm = SortUtil.mergeArray(sortGridList, sortFormList);
      List<String> sortList = SortUtil.mergeArray(sortFieldList, sortGridAndForm);

      for (int i = 0; i < sortList.size(); i++) {
        temMap.put(sortList.get(i), null);
      }

      if (attrMap != null && attrMap.get("objectType") != null) {
        returnList =
            this.commDao.getColumnsProperty(this.commDao.getType(attrMap.get("objectType")));
        // 将
        for (Map<String, String> column : returnList) {
          temMap.put(column.get("fieldName"), column);
          // sortFieldList.add(column.get("fieldName"));
        }
      }

      if (!gridList.isEmpty()) {
        for (int i = 0; i < gridList.size(); i++) {
          Map<String, Object> gridField = (Map<String, Object>) gridList.get(i);

          Field f =
              BeanFieldUtil.findField(
                  this.commDao.getType(attrMap.get("objectType")),
                  gridField.get("name").toString());

          if (f != null) {}

          Map<String, String> columnMap = temMap.get(gridField.get("name"));
          if (null == columnMap) {
            columnMap = new HashMap<String, String>();
          }
          Set<String> keys = gridField.keySet();
          for (String keyString : keys) {
            String value = gridField.get(keyString).toString();
            columnMap.put("inlist", "true");
            // 将保存的jsonString转成页面的字段
            if (keyString.equals("name")) {
              columnMap.put("fieldName", value);
            } else if (keyString.equals("display")) {
              columnMap.put("showName", value);
            } else if (keyString.equals("width")) {
              columnMap.put("listwidth", value);
            } else if (keyString.equals("hide")) {
              if (value == "true") {
                columnMap.put("render", "hide");
              }
            } else {
              columnMap.put(keyString, value);
            }
          }
          temMap.put((String) gridField.get("name"), columnMap);
          _temMap.put((String) gridField.get("name"), columnMap);
        }
        ;
      }
      if (!searchList.isEmpty()) {
        for (int i = 0; i < searchList.size(); i++) {
          Map<String, Object> gridField = (Map<String, Object>) searchList.get(i);
          Map<String, String> columnMap = temMap.get(gridField.get("name"));
          if (null == columnMap) {
            columnMap = new HashMap<String, String>();
          }
          Set<String> keys = gridField.keySet();
          for (String keyString : keys) {
            String value = gridField.get(keyString).toString();
            columnMap.put("insearch", "true");
            if (keyString.equals("name")) {
              columnMap.put("fieldName", value);
            } else if (keyString.equals("display")) {
              columnMap.put("showName", value);
            } else {
              columnMap.put(keyString, value);
            }
          }
          temMap.put((String) gridField.get("name"), columnMap);
          _temMap.put((String) gridField.get("name"), columnMap);
        }
        ;
      }
      if (!formList.isEmpty()) {
        for (int i = 0; i < formList.size(); i++) {
          Map<String, Object> gridField = (Map<String, Object>) formList.get(i);
          Map<String, String> columnMap = temMap.get(gridField.get("name"));
          if (null == columnMap) {
            columnMap = new HashMap<String, String>();
          }
          Set<String> keys = gridField.keySet();
          for (String keyString : keys) {
            String value = gridField.get(keyString).toString();
            columnMap.put("inform", "true");

            if (keyString.equals("name")) {
              columnMap.put("fieldName", value);
            } else if (keyString.equals("display")) {
              columnMap.put("showName", value);
            } else {
              columnMap.put(keyString, value);
            }
          }
          temMap.put((String) gridField.get("name"), columnMap);
          _temMap.put((String) gridField.get("name"), columnMap);
        }
        ;
      }
      returnList.clear();
      for (String k : temMap.keySet()) {
        returnList.add(temMap.get(k));
      }
      returnList.add(attrMap);
    }
    return returnList;
  }