Skip to content

Commit

Permalink
fix: IP选择器对搜索后进行全选时,错误将全部数据给全选了 TencentBlueKing#2076
Browse files Browse the repository at this point in the history
  • Loading branch information
jsonwan committed May 24, 2023
1 parent be278ce commit b7e31cf
Show file tree
Hide file tree
Showing 8 changed files with 266 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ public Response<PageData<HostIdWithMeta>> listHostIdByBizTopologyNodes(String us
req.getNodeList(),
req.getSearchContent(),
req.getAlive(),
req.getIpKeyList(),
req.getIpv6KeyList(),
req.getHostNameKeyList(),
req.getOsNameKeyList(),
pagePair.getLeft(),
pagePair.getRight()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ Long countHostInfoByMultiKeys(Collection<Long> bizIds,

/**
* 批量更新主机状态
* @param status 主机状态
*
* @param status 主机状态
* @param hostIdList 主机id列表
* @return 成功更新的条数
*/
Expand Down Expand Up @@ -233,8 +234,10 @@ Long countHostInfoByMultiKeys(Collection<Long> bizIds,
* @return 删除的主机数量
*/
int deleteBizHostInfoByBizId(long bizId);

/**
* 根据业务id统计主机状态数量
*
* @param bizIds 业务id
* @return 状态数量
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.jooq.BatchBindStep;
import org.jooq.Condition;
import org.jooq.DSLContext;
import org.jooq.Field;
import org.jooq.Query;
import org.jooq.Record;
import org.jooq.Record1;
Expand Down Expand Up @@ -381,11 +382,20 @@ public List<ApplicationHostDTO> listHostInfoByHostNames(Collection<String> hostN
}

@Override
public Long countHostInfoBySearchContents(Collection<Long> bizIds, Collection<Long> moduleIds,
Collection<Long> cloudAreaIds, List<String> searchContents,
public Long countHostInfoBySearchContents(Collection<Long> bizIds,
Collection<Long> moduleIds,
Collection<Long> cloudAreaIds,
List<String> searchContents,
Integer agentStatus) {
List<Long> hostIdList = getHostIdListBySearchContents(bizIds, moduleIds, cloudAreaIds, searchContents,
agentStatus, null, null);
List<Long> hostIdList = getHostIdListBySearchContents(
bizIds,
moduleIds,
cloudAreaIds,
searchContents,
agentStatus,
null,
null
);
return (long) (hostIdList.size());
}

Expand Down Expand Up @@ -550,6 +560,18 @@ private List<Condition> buildSearchContentsConditions(Collection<Long> bizIds,
return conditions;
}

private <T> void addFieldMultiLikeCondition(List<Condition> conditions, Field<T> field, Collection<String> keys) {
if (CollectionUtils.isNotEmpty(keys)) {
List<String> keyList = new ArrayList<>(keys);
String firstContent = keyList.get(0);
Condition condition = field.like("%" + firstContent + "%");
for (int i = 1; i < keyList.size(); i++) {
condition = condition.or(field.like("%" + keyList.get(i) + "%"));
}
conditions.add(condition);
}
}

private List<Condition> buildMultiKeysConditions(Collection<Long> bizIds,
Collection<Long> moduleIds,
Collection<Long> cloudAreaIds,
Expand All @@ -563,18 +585,10 @@ private List<Condition> buildMultiKeysConditions(Collection<Long> bizIds,
if (cloudAreaIds != null) {
conditions.add(tHost.CLOUD_AREA_ID.in(cloudAreaIds));
}
if (ipKeys != null) {
conditions.add(tHost.IP.in(ipKeys));
}
if (ipv6Keys != null) {
conditions.add(tHost.IP_V6.in(ipv6Keys));
}
if (hostNameKeys != null) {
conditions.add(tHost.IP_DESC.in(hostNameKeys));
}
if (osNameKeys != null) {
conditions.add(tHost.OS.in(osNameKeys));
}
addFieldMultiLikeCondition(conditions, tHost.IP, ipKeys);
addFieldMultiLikeCondition(conditions, tHost.IP_V6, ipv6Keys);
addFieldMultiLikeCondition(conditions, tHost.IP_DESC, hostNameKeys);
addFieldMultiLikeCondition(conditions, tHost.OS, osNameKeys);
return conditions;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-JOB蓝鲸智云作业平台 is licensed under the MIT License.
*
* License for BK-JOB蓝鲸智云作业平台:
* --------------------------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

package com.tencent.bk.job.manage.model.query;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.Collection;
import java.util.List;

/**
* 主机查询
*/
@Getter
@Setter
@ToString
@Builder
public class HostQuery {
/**
* 主机所在的业务ID
*/
private Collection<Long> bizIds;
/**
* 主机所在的业务模块ID
*/
private Collection<Long> moduleIds;
/**
* 主机云区域ID
*/
private Collection<Long> cloudAreaIds;
/**
* 模糊搜索key,匹配字段:IP、IP_V6、IP_DESC、OS
*/
private List<String> searchContents;
/**
* 主机Agent状态
*/
private Integer agentAlive;
/**
* 主机IP模糊搜索key列表,任意一个key匹配即命中
*/
private List<String> ipKeyList;
/**
* 主机IPv6模糊搜索key列表,任意一个key匹配即命中
*/
private List<String> ipv6KeyList;
/**
* 主机名称模糊搜索key列表,任意一个key匹配即命中
*/
private List<String> hostNameKeyList;
/**
* 主机系统名称模糊搜索key列表,任意一个key匹配即命中
*/
private List<String> osNameKeyList;
/**
* 起始位置
*/
private Long start;
/**
* 记录数量
*/
private Long limit;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.tencent.bk.job.common.model.PageData;
import com.tencent.bk.job.common.model.dto.ApplicationHostDTO;
import com.tencent.bk.job.manage.model.query.HostQuery;

import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -128,50 +129,18 @@ List<ApplicationHostDTO> getHostsByBizAndHostNames(Collection<Long> bizIds,
/**
* 根据条件查询主机ID
*
* @param bizIds 业务ID集合
* @param moduleIds 模块ID集合
* @param cloudAreaIds 云区域ID集合
* @param searchContents 搜索关键字列表
* @param agentAlive agent是否正常
* @param start 数据起始位置
* @param limit 查询数据条数
* @param hostQuery 主机查询条件
* @return 主机列表
*/
PageData<Long> pageListHostId(Collection<Long> bizIds,
Collection<Long> moduleIds,
Collection<Long> cloudAreaIds,
List<String> searchContents,
Integer agentAlive,
Long start,
Long limit);
PageData<Long> pageListHostId(HostQuery hostQuery);

/**
* 根据条件查询主机
*
* @param bizIds 业务ID集合
* @param moduleIds 模块ID集合
* @param cloudAreaIds 云区域ID集合
* @param searchContents 搜索关键字列表
* @param agentAlive agent是否正常
* @param ipKeyList IP关键字列表
* @param ipv6KeyList IPv6关键字列表
* @param hostNameKeyList 主机名关键字列表
* @param osNameKeyList 系统名关键字列表
* @param start 数据起始位置
* @param limit 查询数据条数
* @param hostQuery 主机查询条件
* @return 主机列表
*/
PageData<ApplicationHostDTO> pageListHost(Collection<Long> bizIds,
Collection<Long> moduleIds,
Collection<Long> cloudAreaIds,
List<String> searchContents,
Integer agentAlive,
List<String> ipKeyList,
List<String> ipv6KeyList,
List<String> hostNameKeyList,
List<String> osNameKeyList,
Long start,
Long limit);
PageData<ApplicationHostDTO> pageListHost(HostQuery hostQuery);

/**
* 根据 moduleId 集合查询主机信息
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ List<ApplicationHostDTO> getScopeHostsByHostNames(AppResourceScope appResourceSc
* @param appTopoNodeList 拓扑节点列表
* @param searchContent 模糊搜索关键字(同时对主机IP/主机名/操作系统/云区域名称进行模糊搜索)
* @param agentAlive 筛选条件:agentAlive:0为异常,1为正常
* @param ipKeyList IP关键字列表
* @param ipv6KeyList IPv6关键字列表
* @param hostNameKeyList 主机名称关键字列表
* @param osNameKeyList 操作系统名称关键字列表
* @param start 数据起始位置
* @param pageSize 拉取数量
* @return hostId列表
Expand All @@ -102,6 +106,10 @@ PageData<Long> listHostIdByBizTopologyNodes(AppResourceScope appResourceScope,
List<BizTopoNode> appTopoNodeList,
String searchContent,
Integer agentAlive,
List<String> ipKeyList,
List<String> ipv6KeyList,
List<String> hostNameKeyList,
List<String> osNameKeyList,
Long start,
Long pageSize);

Expand Down
Loading

0 comments on commit b7e31cf

Please sign in to comment.