Browse Source

创意标签

yumeng 4 năm trước cách đây
mục cha
commit
21f79ec726

+ 22 - 15
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/BatchServiceImpl.java

@@ -1863,13 +1863,13 @@ public class BatchServiceImpl implements IBatchService {
                         if (!Check.isNull(details)) {
                             JSONArray returnArr = new JSONArray();
                             for (int i = 0; i < details.size(); i++) {
-                                JSONObject jsonObject = details.getJSONObject(i);
+                                JSONObject firstJson = details.getJSONObject(i);
 
-                                String level = jsonObject.getString("level");
-                                if ("1".equals(level)) {
-                                    JSONArray LevelArr = getSubLevel(jsonObject.getInteger("category_id"), details);
-                                    jsonObject.put("child", LevelArr);
-                                    returnArr.add(jsonObject);
+                                Integer parent_id = firstJson.getInteger("parent_id");
+                                if (0 == parent_id) {
+                                    JSONArray LevelArr = getSecond(firstJson.getString("category_id"), details);
+                                    firstJson.put("child", LevelArr);
+                                    returnArr.add(firstJson);
                                 }
                             }
                             return returnArr;
@@ -1884,19 +1884,13 @@ public class BatchServiceImpl implements IBatchService {
     }
 
 
-    private JSONArray getSubLevel(Integer categoryId, JSONArray details) {
+    private JSONArray getSecond(String categoryId, JSONArray details) {
 
         JSONArray secondArr = new JSONArray();
         for (int i = 0; i < details.size(); i++) {
             JSONObject secondJson = details.getJSONObject(i);
-            if ("2".equals(secondJson.getString("level")) && categoryId.equals(secondJson.getInteger("parent_id"))) {
-                JSONArray thirdArr = new JSONArray();
-                for (int j = 0; j < details.size(); j++) {
-                    JSONObject thirdJson = details.getJSONObject(j);
-                    if ("3".equals(thirdJson.getString("level")) && secondJson.getInteger("category_id").equals(thirdJson.getInteger("parent_id"))) {
-                        thirdArr.add(thirdJson);
-                    }
-                }
+            if (categoryId.equals(secondJson.getString("parent_id"))) {
+                JSONArray thirdArr = getThird(secondJson.getString("category_id"), details);
                 secondJson.put("child", thirdArr);
                 secondArr.add(secondJson);
             }
@@ -1904,6 +1898,19 @@ public class BatchServiceImpl implements IBatchService {
         return secondArr;
     }
 
+
+    private JSONArray getThird(String categoryId, JSONArray details) {
+        JSONArray thirdArr = new JSONArray();
+        for (int i = 0; i < details.size(); i++) {
+            JSONObject thirdJson = details.getJSONObject(i);
+            String parent_id = thirdJson.getString("parent_id");
+            if (categoryId.equals(parent_id)) {
+                thirdArr.add(thirdJson);
+            }
+
+        }
+        return thirdArr;
+    }
 }