|
@@ -1,13 +1,14 @@
|
|
package com.persagy.meiku.services
|
|
package com.persagy.meiku.services
|
|
|
|
|
|
import com.persagy.database.SFilter
|
|
import com.persagy.database.SFilter
|
|
-import com.persagy.meiku.models.entities.MeiKuAnchor
|
|
|
|
|
|
+import com.persagy.database.extensions.keyMap
|
|
import com.persagy.meiku.models.entities.PipelineCategory
|
|
import com.persagy.meiku.models.entities.PipelineCategory
|
|
import com.persagy.mybatis.SMybatisDao
|
|
import com.persagy.mybatis.SMybatisDao
|
|
import com.persagy.service.SObjectService
|
|
import com.persagy.service.SObjectService
|
|
import com.persagy.service.models.enums.SResponseType
|
|
import com.persagy.service.models.enums.SResponseType
|
|
import com.persagy.service.models.responses.SQueryResponse
|
|
import com.persagy.service.models.responses.SQueryResponse
|
|
import java.util.*
|
|
import java.util.*
|
|
|
|
+import java.util.stream.Collectors
|
|
|
|
|
|
/**
|
|
/**
|
|
* 管线服务
|
|
* 管线服务
|
|
@@ -26,18 +27,29 @@ object PipelineCategoryService: SObjectService<PipelineCategory>(SMybatisDao(Pip
|
|
return try {
|
|
return try {
|
|
/** 返回对象 */
|
|
/** 返回对象 */
|
|
val sQueryResponse = SQueryResponse<PipelineCategory>()
|
|
val sQueryResponse = SQueryResponse<PipelineCategory>()
|
|
- /** 查询一级节点 */
|
|
|
|
- val pipelineCategoryList = select(SFilter.isNull("parentId")).exec()
|
|
|
|
- /** 遍历节点 */
|
|
|
|
- for (pipelineCategory in pipelineCategoryList){
|
|
|
|
- /** 查询子节点 */
|
|
|
|
- pipelineCategory.categoryList = select(SFilter.eq("parentId",pipelineCategory.id!!)).exec()
|
|
|
|
|
|
+ /** 查询所有类型 */
|
|
|
|
+ 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 = pipelineCategoryList
|
|
|
|
|
|
+ sQueryResponse.content = rsList
|
|
/** 类型长度 */
|
|
/** 类型长度 */
|
|
- sQueryResponse.total = pipelineCategoryList.size.toLong()
|
|
|
|
|
|
+ sQueryResponse.total = rsList.size.toLong()
|
|
/** 类型标志 */
|
|
/** 类型标志 */
|
|
sQueryResponse.result = SResponseType.success
|
|
sQueryResponse.result = SResponseType.success
|
|
/** 返回的对象 */
|
|
/** 返回的对象 */
|