Skip to content

Commit fff6038

Browse files
committed
refactor(基础模块): 优化es索引以及查询逻辑
1 parent b952f34 commit fff6038

39 files changed

Lines changed: 897 additions & 177 deletions

File tree

jetlinks-components/common-component/src/main/java/org/jetlinks/community/Interval.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,23 @@ public class Interval {
5252

5353
private String expression;
5454

55+
public Interval(String expr) {
56+
char[] chars = expr.toCharArray();
57+
int numIndex = 0;
58+
for (char c : expr.toCharArray()) {
59+
if (c == '-' || c == '.' || (c >= '0' && c <= '9')) {
60+
numIndex++;
61+
} else {
62+
BigDecimal val = new BigDecimal(chars, 0, numIndex);
63+
this.expression = expr.substring(numIndex);
64+
this.number = val;
65+
}
66+
}
67+
if (this.expression == null) {
68+
throw new IllegalArgumentException("can not parse interval expression:" + expr);
69+
}
70+
}
71+
5572
@Override
5673
public String toString() {
5774
return (number) + expression;
@@ -67,6 +84,11 @@ public static Interval ofDays(int days) {
6784
return of(days, Interval.days);
6885
}
6986

87+
@Generated
88+
public static Interval ofWeeks(int weeks) {
89+
return of(weeks, Interval.weeks);
90+
}
91+
7092
@Generated
7193
public static Interval ofHours(int hours) {
7294
return of(hours, Interval.hours);
@@ -88,20 +110,7 @@ public static Interval of(int month, String expression) {
88110
}
89111

90112
public static Interval of(String expr) {
91-
92-
char[] chars = expr.toCharArray();
93-
int numIndex = 0;
94-
for (char c : expr.toCharArray()) {
95-
if (c == '-' || c == '.' || (c >= '0' && c <= '9')) {
96-
numIndex++;
97-
} else {
98-
BigDecimal val = new BigDecimal(chars, 0, numIndex);
99-
return new Interval(val, expr.substring(numIndex));
100-
}
101-
102-
}
103-
104-
throw new IllegalArgumentException("can not parse interval expression:" + expr);
113+
return new Interval(expr);
105114
}
106115

107116
public String getDefaultFormat() {

jetlinks-components/common-component/src/main/java/org/jetlinks/community/lock/DefaultReactiveLock.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2025 JetLinks https://www.jetlinks.cn
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.jetlinks.community.lock;
217

318
import lombok.AllArgsConstructor;

jetlinks-components/common-component/src/main/java/org/jetlinks/community/lock/DefaultReactiveLockManager.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2025 JetLinks https://www.jetlinks.cn
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.jetlinks.community.lock;
217

318
import com.github.benmanes.caffeine.cache.Caffeine;

jetlinks-components/common-component/src/main/java/org/jetlinks/community/lock/ReactiveLock.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2025 JetLinks https://www.jetlinks.cn
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.jetlinks.community.lock;
217

318
import reactor.core.publisher.Flux;

jetlinks-components/common-component/src/main/java/org/jetlinks/community/lock/ReactiveLockHolder.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2025 JetLinks https://www.jetlinks.cn
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.jetlinks.community.lock;
217

318
/**

jetlinks-components/common-component/src/main/java/org/jetlinks/community/lock/ReactiveLockManager.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2025 JetLinks https://www.jetlinks.cn
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.jetlinks.community.lock;
217

318
/**

jetlinks-components/common-component/src/main/java/org/jetlinks/community/micrometer/MeterRegistryConfiguration.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2025 JetLinks https://www.jetlinks.cn
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.jetlinks.community.micrometer;
217

318
import org.springframework.beans.factory.ObjectProvider;

jetlinks-components/common-component/src/main/java/org/jetlinks/community/micrometer/NoopMeterRegistry.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2025 JetLinks https://www.jetlinks.cn
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.jetlinks.community.micrometer;
217

318
import io.micrometer.core.instrument.*;

jetlinks-components/configure-component/src/main/java/org/jetlinks/community/configure/redis/PublishOnReactiveRedisTemplate.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2025 JetLinks https://www.jetlinks.cn
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.jetlinks.community.configure.redis;
217

318
import org.springframework.data.redis.connection.ReactiveRedisConnection;

jetlinks-components/elasticsearch-component/elasticsearch-7x/src/main/java/org/jetlinks/community/elastic/search/ElasticSearch7xSupport.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,22 @@
1515
*/
1616
package org.jetlinks.community.elastic.search;
1717

18-
import co.elastic.clients.elasticsearch._types.aggregations.DateHistogramBucket;
19-
import co.elastic.clients.elasticsearch._types.aggregations.HistogramBucket;
20-
import co.elastic.clients.elasticsearch._types.aggregations.MultiBucketBase;
18+
import co.elastic.clients.elasticsearch._types.aggregations.*;
2119
import co.elastic.clients.elasticsearch._types.mapping.DynamicTemplate;
2220
import co.elastic.clients.elasticsearch._types.mapping.Property;
21+
import co.elastic.clients.elasticsearch._types.mapping.TypeMapping;
2322
import co.elastic.clients.elasticsearch.indices.*;
23+
import co.elastic.clients.elasticsearch.indices.get_index_template.IndexTemplate;
24+
import co.elastic.clients.elasticsearch.indices.get_index_template.IndexTemplateItem;
25+
import co.elastic.clients.elasticsearch.indices.get_index_template.IndexTemplateSummary;
2426
import co.elastic.clients.elasticsearch.indices.get_mapping.IndexMappingRecord;
2527
import co.elastic.clients.transport.Version;
26-
import org.jetlinks.community.elastic.search.enums.ElasticSearchTermTypes;
2728
import org.jetlinks.community.elastic.search.enums.ElasticSearch7xTermType;
29+
import org.jetlinks.community.elastic.search.enums.ElasticSearchTermTypes;
2830
import org.jetlinks.community.elastic.search.index.ElasticSearchIndexProperties;
31+
import org.jetlinks.reactor.ql.utils.CastUtils;
32+
33+
import java.util.Objects;
2934

3035
public class ElasticSearch7xSupport extends ElasticSearchSupport {
3136

@@ -59,6 +64,20 @@ public TemplateMapping getTemplateMapping(GetTemplateResponse response, String i
5964
return response.get(index);
6065
}
6166

67+
@Override
68+
public TypeMapping getIndexTemplateMapping(GetIndexTemplateResponse response, String index) {
69+
for (IndexTemplateItem indexTemplate : response.indexTemplates()) {
70+
if (Objects.equals(indexTemplate.name(), index)) {
71+
IndexTemplate template = indexTemplate.indexTemplate();
72+
IndexTemplateSummary summary = template.template();
73+
if (summary != null) {
74+
return summary.mappings();
75+
}
76+
}
77+
}
78+
return null;
79+
}
80+
6281
@Override
6382
public IndexState getIndexState(GetIndexResponse response, String index) {
6483
return response.get(index);
@@ -71,6 +90,15 @@ public IndexMappingRecord getIndexMapping(GetMappingResponse response, String in
7190

7291
@Override
7392
public Object getBucketKey(MultiBucketBase bucket) {
93+
if (bucket instanceof LongTermsBucket) {
94+
return CastUtils.castNumber(((LongTermsBucket) bucket).key()).longValue();
95+
}
96+
if (bucket instanceof DoubleTermsBucket) {
97+
return ((DoubleTermsBucket) bucket).key();
98+
}
99+
if (bucket instanceof StringTermsBucket) {
100+
return ((StringTermsBucket) bucket).key()._get();
101+
}
74102
if (bucket instanceof DateHistogramBucket _bucket) {
75103
return _bucket.key();
76104
}
@@ -79,4 +107,4 @@ public Object getBucketKey(MultiBucketBase bucket) {
79107
}
80108
return null;
81109
}
82-
}
110+
}

0 commit comments

Comments
 (0)