Ver código fonte

解决管线类型查询超时问题

yucheng 3 anos atrás
pai
commit
eca89a57d2

+ 33 - 20
meiku/src/main/kotlin/com/persagy/meiku/services/PipelineCategoryService.kt

@@ -27,29 +27,42 @@ object PipelineCategoryService: SObjectService<PipelineCategory>(SMybatisDao(Pip
         return try {
             /** 返回对象 */
             val sQueryResponse = SQueryResponse<PipelineCategory>()
-            /** 查询所有类型 */
-            val pipelineCategoryList = selectAll().exec();
-            val categoryMap = pipelineCategoryList!!.associateBy({it.id},{t -> t});
-            // 转换为树型
-            val rsList = ArrayList<PipelineCategory>()
-            for (data in pipelineCategoryList) {
-                val parentId = data.parentId;
-                // 如果找不到上级节点,直接添加到结果列表中
-                if (parentId == null || categoryMap[parentId] == null) {
-                    rsList.add(data)
-                    continue
-                }
-                // 能找到上级节点,则放入上级节点的子节点列表中
-                val parent = categoryMap[parentId];
-                if(parent!!.categoryList == null) {
-                    parent.categoryList = ArrayList<PipelineCategory>();
-                }
-                parent.categoryList!!.add(data)
+            // 不是此原因导致的查询慢,数据量有限,原查询1秒可以接受,暂不调整了,代码先留着
+//            /** 查询所有类型 */
+//            val pipelineCategoryList = selectAll().exec();
+//            val categoryMap = pipelineCategoryList!!.associateBy({it.id},{t -> t});
+//            // 转换为树型
+//            val rsList = ArrayList<PipelineCategory>()
+//            for (data in pipelineCategoryList) {
+//                val parentId = data.parentId;
+//                // 如果找不到上级节点,直接添加到结果列表中
+//                if (parentId == null || categoryMap[parentId] == null) {
+//                    rsList.add(data)
+//                    continue
+//                }
+//                // 能找到上级节点,则放入上级节点的子节点列表中
+//                val parent = categoryMap[parentId];
+//                if(parent!!.categoryList == null) {
+//                    parent.categoryList = ArrayList<PipelineCategory>();
+//                }
+//                parent.categoryList!!.add(data)
+//            }
+//            /** 类型列表 */
+//            sQueryResponse.content = rsList
+//            /** 类型长度 */
+//            sQueryResponse.total = rsList.size.toLong()
+            /** 查询一级节点 */
+            val pipelineCategoryList = select(SFilter.isNull("parentId")).exec()
+            /** 遍历节点 */
+            for (pipelineCategory in pipelineCategoryList){
+                /** 查询子节点 */
+                pipelineCategory.categoryList = select(SFilter.eq("parentId",pipelineCategory.id!!)).exec()
             }
+
             /** 类型列表 */
-            sQueryResponse.content = rsList
+            sQueryResponse.content = pipelineCategoryList
             /** 类型长度 */
-            sQueryResponse.total = rsList.size.toLong()
+            sQueryResponse.total = pipelineCategoryList.size.toLong()
             /** 类型标志 */
             sQueryResponse.result = SResponseType.success
             /** 返回的对象 */