Example #1
0
 @Override
 public List<Map<String, String>> getExistedFile(String fileName) throws Exception {
   String path = ResourceUtil.getTablesDataSourceDirectoryPath();
   System.out.println(fileName);
   if (fileName != null && fileName.length() > 0) {
     this.getJsonString(fileName);
   }
   Set<File> set = FileUtil.getAllFiles(path);
   List<Map<String, String>> fileNames = new ArrayList<Map<String, String>>();
   for (File file : set) {
     if (file.getName().endsWith(".json")) {
       Map<String, String> map = new HashMap<String, String>();
       String fName = file.getName();
       map.put("id", fName);
       map.put("text", fName.substring(0, fName.lastIndexOf(".json")));
       String fileString = "";
       ObjectMapper mapper = new ObjectMapper();
       Map<String, String> attrMap;
       try {
         fileString = this.readFile(file.getAbsolutePath());
         Map<String, Object> filemap = mapper.readValue(fileString, Map.class);
         attrMap = (Map<String, String>) filemap.get("attribute");
       } catch (Exception e) {
         e.printStackTrace();
         continue;
       }
       map.put("attribute", mapper.writeValueAsString(attrMap));
       fileNames.add(map);
     }
   }
   return fileNames;
 }
Example #2
0
 @Override
 public void saveCommGrid(String param) throws Exception {
   String path = ResourceUtil.getTablesDataSourceDirectoryPath();
   JSONObject paramObj = new JSONObject(param);
   path = path + paramObj.getJSONObject("attribute").get("fileName") + ".json";
   FileUtil.writeFile(param.toString(), path, "UTF-8");
 }
Example #3
0
 @Override
 public String getJsonString(String jsonStringName) throws Exception {
   if (jsonStringName == null || jsonStringName.equals("")) {
     return null;
   }
   String path = ResourceUtil.getTablesDataSourceDirectoryPath();
   if (!jsonStringName.endsWith(".json")) {
     jsonStringName = jsonStringName + ".json";
   }
   path = path + jsonStringName;
   return this.readFile(path);
 }
Example #4
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;
  }