Appearance
createDeploymentQuery
Flowable 7.1.0 摘要:创建部署查询对象,用于查询已创建的流程定义部署。
方法签名与说明
DeploymentQuery createDeploymentQuery()
创建部署查询构建器,用于查询和检索流程定义部署信息。
Returns:
- DeploymentQuery - 部署查询构建器
常见使用场景
1. 部署列表管理
在管理后台展示所有已部署的流程定义包。
2. 部署历史追踪
查看某个时间段内的部署记录,用于版本管理和审计。
3. 按名称查找部署
根据部署名称快速定位特定的部署。
Kotlin + Spring Boot 调用示例
示例1:查询所有部署
kotlin
import org.flowable.engine.RepositoryService
import org.springframework.stereotype.Service
@Service
class DeploymentQueryService(
private val repositoryService: RepositoryService
) {
/**
* 查询所有部署
* 企业场景:部署管理后台列表展示
*/
fun getAllDeployments(): List<Map<String, Any>> {
val deployments = repositoryService.createDeploymentQuery()
.orderByDeploymentTime()
.desc()
.list()
return deployments.map { deployment ->
mapOf(
"id" to deployment.id,
"name" to deployment.name,
"category" to deployment.category,
"key" to deployment.key,
"deploymentTime" to deployment.deploymentTime,
"tenantId" to deployment.tenantId
)
}
}
}示例2:按名称模糊查询
kotlin
import org.flowable.engine.RepositoryService
import org.springframework.stereotype.Service
@Service
class DeploymentSearchService(
private val repositoryService: RepositoryService
) {
/**
* 按名称搜索部署
* 企业场景:管理后台搜索功能
*/
fun searchDeployments(namePattern: String): List<Map<String, Any>> {
val deployments = repositoryService.createDeploymentQuery()
.deploymentNameLike("%$namePattern%")
.orderByDeploymentTime()
.desc()
.list()
return deployments.map { deployment ->
mapOf(
"id" to deployment.id,
"name" to deployment.name,
"deploymentTime" to deployment.deploymentTime
)
}
}
}示例3:分页查询部署
kotlin
import org.flowable.engine.RepositoryService
import org.springframework.stereotype.Service
@Service
class DeploymentPageService(
private val repositoryService: RepositoryService
) {
/**
* 分页查询部署
* 企业场景:大量部署时的分页展示
*/
fun getDeploymentsPage(page: Int, size: Int): Map<String, Any> {
val query = repositoryService.createDeploymentQuery()
val total = query.count()
val deployments = query
.orderByDeploymentTime()
.desc()
.listPage((page - 1) * size, size)
return mapOf(
"data" to deployments.map { mapOf(
"id" to it.id,
"name" to it.name,
"category" to it.category,
"deploymentTime" to it.deploymentTime
)},
"total" to total,
"page" to page,
"size" to size
)
}
}示例4:REST API
kotlin
import org.flowable.engine.RepositoryService
import org.springframework.web.bind.annotation.*
@RestController
@RequestMapping("/api/deployments")
class DeploymentQueryController(
private val repositoryService: RepositoryService
) {
@GetMapping
fun listDeployments(
@RequestParam(required = false) name: String?,
@RequestParam(defaultValue = "1") page: Int,
@RequestParam(defaultValue = "10") size: Int
): Map<String, Any> {
val query = repositoryService.createDeploymentQuery()
name?.let { query.deploymentNameLike("%$it%") }
val total = query.count()
val deployments = query
.orderByDeploymentTime()
.desc()
.listPage((page - 1) * size, size)
return mapOf(
"data" to deployments,
"total" to total,
"page" to page,
"size" to size
)
}
}注意事项
1. 性能优化
- 大数据量场景使用分页查询
- 添加适当的查询条件,避免全表扫描
2. 排序建议
- 推荐按部署时间排序,便于查看最新部署
3. 多租户场景
- 使用
deploymentTenantId()进行租户隔离
相关 API
RepositoryService.createDeploymentQuery()- 创建查询RepositoryService.createDeployment()- 创建部署RepositoryService.deleteDeployment()- 删除部署
本文档说明
- 基于 Flowable 7.1.0 版本编写
- 所有示例均可直接在 Spring Boot + Kotlin 项目中使用