Authored by wangnan9279

fix bug

@@ -129,7 +129,7 @@ public class CustomizeTagBaseService { @@ -129,7 +129,7 @@ public class CustomizeTagBaseService {
129 private Map<String, List<CustomizeTag>> buildCustomizeTagMap() { 129 private Map<String, List<CustomizeTag>> buildCustomizeTagMap() {
130 try { 130 try {
131 Map<String, List<CustomizeTag>> customizeTagBOMap = new HashMap(); 131 Map<String, List<CustomizeTag>> customizeTagBOMap = new HashMap();
132 - List<CustomizeTag> customizeTagList = this.queryValidCustomizeTags(null); 132 + List<CustomizeTag> customizeTagList = this.queryValidCustomizeTags();
133 if (CollectionUtils.isEmpty(customizeTagList)) { 133 if (CollectionUtils.isEmpty(customizeTagList)) {
134 return new HashMap<>(); 134 return new HashMap<>();
135 } 135 }
@@ -154,14 +154,40 @@ public class CustomizeTagBaseService { @@ -154,14 +154,40 @@ public class CustomizeTagBaseService {
154 } 154 }
155 155
156 /** 156 /**
157 - * 查CustomizeTag索引,可以查指定的poolId的 157 + * 查CustomizeTag索引,需要满足默认条件
158 */ 158 */
159 - private List<CustomizeTag> queryValidCustomizeTags(Collection<?> poolIds) throws Exception { 159 + private List<CustomizeTag> queryValidCustomizeTags() throws Exception {
160 SearchParam searchParam = new SearchParam(); 160 SearchParam searchParam = new SearchParam();
161 BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); 161 BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
162 - if (CollectionUtils.isNotEmpty(poolIds)) {  
163 - boolQueryBuilder.must(QueryBuilders.termsQuery("poolId", poolIds)); 162 + boolQueryBuilder.must(QueryBuilders.termQuery("status", 1));
  163 + long currentTime = DateUtil.getCurrentTimeSecond();
  164 + boolQueryBuilder.must(QueryBuilders.rangeQuery("beginTime").lt(currentTime));
  165 + boolQueryBuilder.must(QueryBuilders.rangeQuery("endTime").gt(currentTime));
  166 + searchParam.setFiter(boolQueryBuilder);
  167 + searchParam.setSize(10000);
  168 + SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_CUSTOMIZE_TAG, searchParam);
  169 + if (searchResult == null || CollectionUtils.isEmpty(searchResult.getResultList())) {
  170 + return Collections.emptyList();
  171 + }
  172 + List<CustomizeTag> resultList = new ArrayList<>();
  173 + for (Map<String, Object> esMap : searchResult.getResultList()) {
  174 + if (!esMap.isEmpty()) {
  175 + resultList.add(parseCustomizeTagInfo(esMap));
164 } 176 }
  177 + }
  178 + return resultList;
  179 + }
  180 +
  181 + /**
  182 + * 查CustomizeTag索引,用poolid过滤和满足默认条件
  183 + */
  184 + private List<CustomizeTag> queryValidCustomizeTagsWithPoolId(Collection<?> poolIds) throws Exception {
  185 + if (CollectionUtils.isEmpty(poolIds)) {
  186 + return Collections.emptyList();
  187 + }
  188 + SearchParam searchParam = new SearchParam();
  189 + BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
  190 + boolQueryBuilder.must(QueryBuilders.termsQuery("poolId", poolIds));
165 boolQueryBuilder.must(QueryBuilders.termQuery("status", 1)); 191 boolQueryBuilder.must(QueryBuilders.termQuery("status", 1));
166 long currentTime = DateUtil.getCurrentTimeSecond(); 192 long currentTime = DateUtil.getCurrentTimeSecond();
167 boolQueryBuilder.must(QueryBuilders.rangeQuery("beginTime").lt(currentTime)); 193 boolQueryBuilder.must(QueryBuilders.rangeQuery("beginTime").lt(currentTime));
@@ -205,7 +231,7 @@ public class CustomizeTagBaseService { @@ -205,7 +231,7 @@ public class CustomizeTagBaseService {
205 */ 231 */
206 public List<Map<String, Object>> getTagListByIds(List<String> poolIdList, int maxReturnSize) { 232 public List<Map<String, Object>> getTagListByIds(List<String> poolIdList, int maxReturnSize) {
207 try { 233 try {
208 - List<CustomizeTag> customizeTagBOList = this.queryValidCustomizeTags(poolIdList); 234 + List<CustomizeTag> customizeTagBOList = this.queryValidCustomizeTagsWithPoolId(poolIdList);
209 if (CollectionUtils.isEmpty(customizeTagBOList)) { 235 if (CollectionUtils.isEmpty(customizeTagBOList)) {
210 return new ArrayList<>(); 236 return new ArrayList<>();
211 } 237 }