|
@@ -1,6 +1,7 @@
|
|
|
package com.persagy.labsl.services
|
|
|
|
|
|
import com.persagy.database.SFilter
|
|
|
+import com.persagy.labsl.Opts
|
|
|
import com.persagy.labsl.models.entities.GraphCategory
|
|
|
import com.persagy.labsl.models.request.GraphCategoryRequest
|
|
|
import com.persagy.mybatis.SMybatisDao
|
|
@@ -21,7 +22,7 @@ object GraphCategoryService : SObjectService<GraphCategory>(SMybatisDao(GraphCat
|
|
|
/** 自定义sql */
|
|
|
private val customMapper by lazy {
|
|
|
SSpringContextUtil.getBean(CustomService::class.java) as CustomService
|
|
|
- } // customMapper
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 系统图分类查询
|
|
@@ -30,59 +31,93 @@ object GraphCategoryService : SObjectService<GraphCategory>(SMybatisDao(GraphCat
|
|
|
* @return 查询结果
|
|
|
*/
|
|
|
fun graphCategoryQuery(request: GraphCategoryRequest): SQueryResponse<GraphCategory> {
|
|
|
- /** 项目id */
|
|
|
- val projectId = SPageContext.getHeader("projectId")
|
|
|
+ /** 返回结果 */
|
|
|
val sQueryResponse = SQueryResponse<GraphCategory>()
|
|
|
return try {
|
|
|
+ /** true 获取所有图类型,false 获取已有图类型 */
|
|
|
if (request.switch) {
|
|
|
+ /** 查询图类型的父节点 */
|
|
|
val graphCategoryList = select(SFilter.isNull("parentId")).exec()
|
|
|
+ /** 遍历父节点图类型 */
|
|
|
for (graphCategory in graphCategoryList) {
|
|
|
+ /** 递归获取子节点 */
|
|
|
val treeClimate = treeClimate(graphCategory.id!!, true)
|
|
|
+ /** 子节点列表不可以为空 */
|
|
|
if (treeClimate.size > 0) {
|
|
|
+ /** 赋值子节点列表 */
|
|
|
graphCategory.categoryList = treeClimate
|
|
|
}
|
|
|
}
|
|
|
+ /** 列表赋值 */
|
|
|
sQueryResponse.content = graphCategoryList
|
|
|
+ /** 列表长度 */
|
|
|
sQueryResponse.total = graphCategoryList.size.toLong()
|
|
|
+ /** 反馈标志 */
|
|
|
sQueryResponse.result = SResponseType.success
|
|
|
+ /** 返回的对象 */
|
|
|
sQueryResponse
|
|
|
} else {
|
|
|
- val calcAffectedList = customMapper.draftsCategory(projectId!!)
|
|
|
- val pubCategoryList = customMapper.pubCategory(projectId)
|
|
|
+ /** 草稿箱类型统计 */
|
|
|
+ val calcAffectedList = customMapper.draftsCategory(Opts.projectId!!)
|
|
|
+ /** 已发布类型统计 */
|
|
|
+ val pubCategoryList = customMapper.pubCategory(Opts.projectId!!)
|
|
|
+ /** 类型数组 */
|
|
|
val set = HashSet<String>()
|
|
|
+ /** 草稿箱或已发布不可以为空 */
|
|
|
if (!pubCategoryList.isNullOrEmpty() || !calcAffectedList.isNullOrEmpty()) {
|
|
|
+ /** 已发布类型不可以为空 */
|
|
|
if (!pubCategoryList.isNullOrEmpty()) {
|
|
|
+ /** 遍历已发布类型 */
|
|
|
for (pubCategory in pubCategoryList) {
|
|
|
set.add(pubCategory.categoryId!!)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /** 草稿箱已发布类型不可以为空 */
|
|
|
if (!calcAffectedList.isNullOrEmpty()) {
|
|
|
+ /** 遍历草稿箱类型 */
|
|
|
for (calcAffected in calcAffectedList) {
|
|
|
set.add(calcAffected.categoryId!!)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /** 查询主分类 */
|
|
|
val graphCategoryList = select(SFilter.isNull("parentId")).exec()
|
|
|
+ /** 遍历主分类 */
|
|
|
for (graphCategory in graphCategoryList) {
|
|
|
+ /** 递归查询子分类 */
|
|
|
val treeClimate = treeClimate(graphCategory.id!!, true)
|
|
|
+ /** 子分类数量大于0 */
|
|
|
if (treeClimate.size > 0) {
|
|
|
+ /** 子分类列表赋值 */
|
|
|
graphCategory.categoryList = treeClimate
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /** 遍历分类列表 */
|
|
|
for (id in set) {
|
|
|
+ /** 遍历分类列表 */
|
|
|
for (graphCategory in graphCategoryList) {
|
|
|
+ /** 相等的做标记 */
|
|
|
if (graphCategory.id == id) {
|
|
|
graphCategory.sign = true
|
|
|
}
|
|
|
+ /** 子分类不为空 */
|
|
|
if (!graphCategory.categoryList.isNullOrEmpty()) {
|
|
|
val categoryList = graphCategory.categoryList!!
|
|
|
+ /** 遍历分类 */
|
|
|
for (category in categoryList) {
|
|
|
+ /** 相等的做标记 */
|
|
|
if (category.id == id) {
|
|
|
category.sign = true
|
|
|
graphCategory.sign = true
|
|
|
}
|
|
|
+ /** 分类列表不为空 */
|
|
|
if (!category.categoryList.isNullOrEmpty()) {
|
|
|
val categoryList1 = category.categoryList!!
|
|
|
+ /** 遍历列表 */
|
|
|
for (category2 in categoryList1) {
|
|
|
+ /** id相等的做标记 */
|
|
|
if (category2.id == id) {
|
|
|
category2.sign = true
|
|
|
category.sign = true
|
|
@@ -94,47 +129,65 @@ object GraphCategoryService : SObjectService<GraphCategory>(SMybatisDao(GraphCat
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
val iterator = graphCategoryList.iterator()
|
|
|
+ /** 遍历分类 */
|
|
|
while (iterator.hasNext()) {
|
|
|
val next = iterator.next()
|
|
|
+ /** 标记为true */
|
|
|
if (next.sign) {
|
|
|
+ /** 列表不为空 */
|
|
|
if (!next.categoryList.isNullOrEmpty()) {
|
|
|
val iterator1 = next.categoryList!!.iterator()
|
|
|
+ /** 遍历子列表 */
|
|
|
while (iterator1.hasNext()) {
|
|
|
val next1 = iterator1.next()
|
|
|
+ /** 标记为 true */
|
|
|
if (next1.sign) {
|
|
|
if (!next1.categoryList.isNullOrEmpty()) {
|
|
|
val iterator2 = next1.categoryList!!.iterator()
|
|
|
+ /** 遍历子列表 */
|
|
|
while (iterator2.hasNext()) {
|
|
|
val next2 = iterator2.next()
|
|
|
+ /** 标记为 true 删除 */
|
|
|
if (!next2.sign) {
|
|
|
+ /** 删除 */
|
|
|
iterator2.remove()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
+ /** 删除 */
|
|
|
iterator1.remove()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
+ /** 删除 */
|
|
|
iterator.remove()
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /** 赋值分类列表 */
|
|
|
sQueryResponse.content = graphCategoryList
|
|
|
+ /** 列表长度 */
|
|
|
sQueryResponse.total = graphCategoryList.size.toLong()
|
|
|
} else {
|
|
|
+ /** 赋值分类列表 */
|
|
|
sQueryResponse.content = ArrayList()
|
|
|
}
|
|
|
+ /** 返回标记 */
|
|
|
sQueryResponse.result = SResponseType.success
|
|
|
+ /** 返回对象 */
|
|
|
sQueryResponse
|
|
|
}
|
|
|
} catch (e: Exception) {
|
|
|
e.printStackTrace()
|
|
|
sQueryResponse.result = SResponseType.failure
|
|
|
+ sQueryResponse.message = e.message!!
|
|
|
sQueryResponse
|
|
|
}
|
|
|
- } // Fun graphCategoryQuery()
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 气候区 递归查询
|
|
@@ -144,12 +197,18 @@ object GraphCategoryService : SObjectService<GraphCategory>(SMybatisDao(GraphCat
|
|
|
* @return 类型列表
|
|
|
*/
|
|
|
private fun treeClimate(parent: String, hasChildren: Boolean = true): ArrayList<GraphCategory> {
|
|
|
+ /** 父指针为空的分类 */
|
|
|
val content = select("parentId" to parent).exec()
|
|
|
+ /** 是否查询子列表 */
|
|
|
if (hasChildren) {
|
|
|
+ /** 遍历父指针 */
|
|
|
for (item in content) {
|
|
|
try {
|
|
|
+ /** 调用本方法 */
|
|
|
val children = treeClimate(item.id!!)
|
|
|
+ /** 子列表大于0 */
|
|
|
if (children.size > 0) {
|
|
|
+ /** 赋值 */
|
|
|
item.categoryList = children
|
|
|
}
|
|
|
} catch (e: Exception) {
|
|
@@ -158,6 +217,6 @@ object GraphCategoryService : SObjectService<GraphCategory>(SMybatisDao(GraphCat
|
|
|
}
|
|
|
}
|
|
|
return content
|
|
|
- } // Function treeClimate()
|
|
|
+ }
|
|
|
|
|
|
-} // Object GraphCategoryService
|
|
|
+}
|