浏览代码

修改量表接口,给返回的数据排序

hujing 6 年之前
父节点
当前提交
7f1cffafbe

+ 61 - 11
graph/src/main/java/org/diagbot/graph/jdbc/Neo4jAPI.java

@@ -1657,9 +1657,9 @@ public class Neo4jAPI {
         Map<String, Object> threeLevelItems = new LinkedHashMap<>();
         //<<=44,0>
 
-        Map<String, Object> result = null;
+        TreeMap<String, Object> result = null;
         Map<String, Object> title = new LinkedHashMap<>();
-        List<Object> results = new ArrayList<>();
+        List<TreeMap<String, Object>> results = new ArrayList<>();
         List<Object> titles;
 
         threeLevelItems.put("type", "");
@@ -1669,7 +1669,7 @@ public class Neo4jAPI {
                     "r2.score,n2.type,r2.p order by toInt(r2.p),n2.type";
 
             String query2 = "match (m:Scale)-[r1]->(n1)-[r2]->(n2)-[r3]->(n3) WHERE m.name=~'.*" + scaleName + ".*' return n1.name,r1.score,n2.name," +
-                    "r2.score,n3.name,r3.score,r3.p,n3.type order by toInt(r2.p),n2.type";
+                    "r2.score,r2.p,n3.name,r3.score,r3.p,n3.type order by toInt(r2.p),n2.type";
             writeLog(query1);
             Rset1 = session.run(query1);
             Rset2 = session.run(query2);
@@ -1680,27 +1680,30 @@ public class Neo4jAPI {
             String score1 = "";
             String index = "";
             String score2 = "";
+            String priority1 = "";
+            String priority2 = "";
 
             while (Rset1.hasNext()) {
                 rec = Rset1.next();
                 item = rec.get("n1.name").toString().replace("\"", "");
                 optionOrIndex = rec.get("n2.name").toString().replace("\"", "");
                 score1 = rec.get("r2.score").toString().replace("\"", "");
+                priority1 = rec.get("r2.p").toString().replace("\"", "");
 
 
                 if (!"NULL".equals(score1)) {
-                    if ("计算方法".equals(item)) {
+                    if (item.contains("计算方法")) {
                         String[] score = score1.split("~|-");
                         String min = score[0];
                         String max = score[1];
-                        result = new LinkedHashMap<>();
+                        result = new TreeMap<>();
                         result.put("min", min);
                         result.put("max", max);
                         result.put("text", optionOrIndex);
+                        result.put("priority",priority1);
                         results.add(result);
                     }
 
-                    threeLevelItems.put("result", results);
                 } else {
                     titles = new ArrayList<>();
                     title.put("name", item);
@@ -1716,14 +1719,27 @@ public class Neo4jAPI {
                     titles.add(title);
                     title = new LinkedHashMap<>();
                     title.put("name", "推荐选项");
-                    title.put("column", "");
+                    title.put("column", "state");
                     titles.add(title);
                     threeLevelItems.put("title", titles);
                 }
             }
 
+            Collections.sort(results, new Comparator<TreeMap<String, Object>>() {
+                @Override
+                public int compare(TreeMap<String, Object> o1, TreeMap<String, Object> o2) {
+                    Integer priorityo1 = Integer.valueOf(o1.get("priority").toString());
+                    Integer priorityo2 = Integer.valueOf(o2.get("priority").toString());
+                    return priorityo1.compareTo(priorityo2);
+                }
+            });
+            for (TreeMap<String, Object> resMap:results) {
+                resMap.remove("priority");
+            }
+            threeLevelItems.put("result", results);
+
             Map<String, List<Map<String, String>>> nameDetails = new HashMap<>();
-            List<Object> finalResult = new ArrayList<>();
+            List<TreeMap<String, Object>> finalResult = new ArrayList<>();
             while (Rset2.hasNext()) {
                 rec = Rset2.next();
                 item = rec.get("n1.name").toString().replace("\"", "");
@@ -1733,11 +1749,17 @@ public class Neo4jAPI {
                 index = rec.get("n3.name").toString().replace("\"", "");
                 //score
                 score2 = rec.get("r3.score").toString().replace("\"", "");
+                priority1 = rec.get("r2.p").toString().replace("\"", "");
+                priority2 = rec.get("r3.p").toString().replace("\"", "");
+
+                optionOrIndex = optionOrIndex + "_" + priority1;
 
                 Map<String, String> detailInfo = new LinkedHashMap<>();
                 detailInfo.put("detailName", index);
                 detailInfo.put("score", score2);
                 detailInfo.put("state","0");
+                detailInfo.put("priority",priority2);
+
                 if (nameDetails.containsKey(optionOrIndex)){
                     nameDetails.get(optionOrIndex).add(detailInfo);
                 }else{
@@ -1745,15 +1767,43 @@ public class Neo4jAPI {
                     nameDetails.get(optionOrIndex).add(detailInfo);
                 }
             }
+
             for (Map.Entry<String, List<Map<String, String>>> nameDetailEntry: nameDetails.entrySet()){
                 String key = nameDetailEntry.getKey();
                 List<Map<String, String>> value = nameDetailEntry.getValue();
-                Map<String, Object> detailsResult = new LinkedHashMap<>();
-                detailsResult.put("name", key);
+                TreeMap<String, Object> detailsResult = new TreeMap<>();
+
+                Collections.sort(value, new Comparator<Map<String, String>>() {
+                    @Override
+                    public int compare(Map<String, String> o1, Map<String, String> o2) {
+                        Integer priorityo1 = Integer.valueOf(o1.get("priority"));
+                        Integer priorityo2 = Integer.valueOf(o2.get("priority"));
+                        return priorityo1.compareTo(priorityo2);
+                    }
+                });
+
+                for (Map<String, String> map:value){
+                    map.remove("priority");
+                }
+
+                detailsResult.put("name", key.split("_")[0]);
                 detailsResult.put("details", value);
-                detailsResult.put("type","1:radio,2:checkbox.....");
+                detailsResult.put("type",0);
+                detailsResult.put("priority",key.split("_")[1]);
                 finalResult.add(detailsResult);
             }
+            Collections.sort(finalResult, new Comparator<TreeMap<String,Object>>() {
+
+                @Override
+                public int compare(TreeMap<String, Object> o1, TreeMap<String, Object> o2) {
+                    Integer priorityo1 = Integer.valueOf(o1.get("priority").toString());
+                    Integer priorityo2 = Integer.valueOf(o2.get("priority").toString());
+                    return priorityo1.compareTo(priorityo2);
+                }
+            });
+            for (TreeMap<String, Object> map:finalResult) {
+                map.remove("priority");
+            }
             threeLevelItems.put("detials", finalResult);
         } catch (Exception ex) {
             ex.printStackTrace();

+ 1 - 1
push-web/src/main/java/org/diagbot/push/controller/GraphController.java

@@ -73,7 +73,7 @@ public class GraphController extends BaseController {
     @RequestMapping(value = "/scale", method = RequestMethod.POST)
     @ResponseBody
     public Map<String, Object> scale(HttpServletRequest request, @RequestBody SearchData searchData) throws Exception {
-        Neo4jAPI neo4jAPI = new Neo4jAPI(DriverManager.newDrive("localhost","neo4j","root"));
+        Neo4jAPI neo4jAPI = new Neo4jAPI(DriverManager.newDrive("192.168.2.233","neo4j","root"));
         String scaleName = searchData.getScaleName();
         Map<String, Object> scale = neo4jAPI.getScale(scaleName);
         return scale;