Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ import io.swagger.v3.oas.annotations.media.Schema
@Schema(title = "节点列表查询信息")
data class NodeFetchReq(
@get:Schema(title = "查询标签列表")
val tags: List<NodeTagFetchReq>?
val tags: List<NodeTagFetchReq>?,
@get:Schema(title = "大IP查询 (空格、中英文逗号/分号、换行、| 分隔)时,支持解析出 IP 列表")
val ipListSearch: String? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ class NodeDao {
sortType: String?,
collation: String?,
tagValueIds: Set<Long>?,
operatorStatus: NodeOperatorStatus? = null
operatorStatus: NodeOperatorStatus? = null,
nodeIpList: Set<String>? = null
): List<TNodeRecord> {
return with(TNode.T_NODE) {
val dsl = dslContext.select(*TNode.T_NODE.fields()).from(this)
Expand All @@ -128,7 +129,8 @@ class NodeDao {
sortType = sortType,
collation = collation,
tagValueIds = tagValueIds,
operatorStatus = operatorStatus
operatorStatus = operatorStatus,
nodeIpList = nodeIpList
)
query.limit(limit).offset(offset)
.fetchInto(this)
Expand All @@ -153,7 +155,8 @@ class NodeDao {
collation: String?,
tagValueIds: Set<Long>?,
nodeIds: List<Long>? = null,
operatorStatus: NodeOperatorStatus? = null
operatorStatus: NodeOperatorStatus? = null,
nodeIpList: Set<String>? = null
) {
if (!keywords.isNullOrEmpty()) {
query.and(NODE_IP.like("%$keywords%").or(DISPLAY_NAME.like("%$keywords%")))
Expand All @@ -168,6 +171,8 @@ class NodeDao {
nodeIps.size == 1 -> query.and(NODE_IP.like("%${nodeIps[0]}%"))
nodeIps.size > 1 -> query.and(NODE_IP.`in`(nodeIps))
}
} else if (!nodeIpList.isNullOrEmpty()) {
query.and(NODE_IP.`in`(nodeIpList))
}
if (!displayName.isNullOrEmpty()) {
query.and(DISPLAY_NAME.like("%$displayName%"))
Expand Down Expand Up @@ -259,7 +264,8 @@ class NodeDao {
collation: String?,
tagValueIds: Set<Long>?,
nodeIds: List<Long>? = null,
operatorStatus: NodeOperatorStatus? = null
operatorStatus: NodeOperatorStatus? = null,
nodeIpList: Set<String>? = null
): Int {
with(TNode.T_NODE) {
val dsl = dslContext.selectCount().from(TNode.T_NODE)
Expand All @@ -285,7 +291,8 @@ class NodeDao {
collation = collation,
tagValueIds = tagValueIds,
nodeIds = nodeIds,
operatorStatus = operatorStatus
operatorStatus = operatorStatus,
nodeIpList = nodeIpList
)
return query.fetchOne(0, Int::class.java)!!
}
Expand Down Expand Up @@ -482,7 +489,7 @@ class NodeDao {
userId: String,
agentVersion: String?
): Long
/** Node ID **/
/** Node ID **/
{
var nodeId = 0L
with(TNode.T_NODE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,16 @@ class NodeService @Autowired constructor(
null
} else {
val t = mutableSetOf<Long>()
data?.tags?.forEach { tag ->
data.tags?.forEach { tag ->
t.addAll(tag.tagValues ?: return@forEach)
}
t
}
val nodeIpList = if (data?.ipListSearch.isNullOrBlank()) {
null
} else {
parseIpList(data.ipListSearch)?.toSet()
}
val nodeRecordList =
if (-1 != page) {
val sqlLimit = PageUtil.convertPageSizeToSQLMAXLimit(page ?: 1, pageSize ?: 20, 200)
Expand Down Expand Up @@ -265,15 +270,16 @@ class NodeService @Autowired constructor(
sortType = sortType,
collation = collation,
tagValueIds = tagValues,
operatorStatus = operatorStatus
operatorStatus = operatorStatus,
nodeIpList = nodeIpList
)
} else {
nodeDao.listNodes(
dslContext = dslContext, projectId = projectId, nodeType = if (createMode == true) {
NodeType.CREATE
} else {
nodeType
}
NodeType.CREATE
} else {
nodeType
}
)
}
if (nodeRecordList.isEmpty()) {
Expand Down Expand Up @@ -324,7 +330,8 @@ class NodeService @Autowired constructor(
collation = collation,
tagValueIds = tagValues,
nodeIds = authorizedNodeIds,
operatorStatus = operatorStatus
operatorStatus = operatorStatus,
nodeIpList = nodeIpList
).toLong()
}
if (-1 != page) {
Expand Down Expand Up @@ -364,6 +371,44 @@ class NodeService @Autowired constructor(
)
}

private fun parseIpList(input: String?): List<String>? {
if (input.isNullOrBlank()) {
return null
}

val result = LinkedHashSet<String>()
val current = StringBuilder()

fun flushCurrent() {
val ip = current.toString().trim()
if (ip.isNotEmpty()) {
result.add(ip)
}
current.clear()
}

for (ch in input) {
if (isIpSeparator(ch)) {
flushCurrent()
} else {
current.append(ch)
}
}

flushCurrent()

return result.toList()
}

private fun isIpSeparator(ch: Char): Boolean {
return ch.isWhitespace() ||
ch == ',' ||
ch == ',' ||
ch == ';' ||
ch == ';' ||
ch == '|'
}

fun fetchNodesCount(projectId: String): Map<NodeType, Int> {
return nodeDao.fetchProjectNodeCount(dslContext, projectId)
}
Expand Down Expand Up @@ -1068,7 +1113,7 @@ class NodeService @Autowired constructor(
.addExtendData("targetProjectId", targetProjectId)
logger.info(
"transfer node success|userId=$userId|sourceProjectId=$sourceProjectId|" +
"targetProjectId=$targetProjectId|nodeHashId=$nodeHashId"
"targetProjectId=$targetProjectId|nodeHashId=$nodeHashId"
)
return true
}
Expand Down
Loading