Commit 78d91a2e by 黄明步

修复查询法院调用量错误

parent a2ec6745
...@@ -33,6 +33,7 @@ import com.gxmailu.ocrCloudPlatform.service.CourtService; ...@@ -33,6 +33,7 @@ import com.gxmailu.ocrCloudPlatform.service.CourtService;
import com.gxmailu.ocrCloudPlatform.utils.IpUtils; import com.gxmailu.ocrCloudPlatform.utils.IpUtils;
import com.gxmailu.ocrCloudPlatform.vo.BrokenLineData; import com.gxmailu.ocrCloudPlatform.vo.BrokenLineData;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -145,8 +146,12 @@ public class ElasticSearchService { ...@@ -145,8 +146,12 @@ public class ElasticSearchService {
*/ */
public Object getCourtUseCount(Court court, DateTime start, DateTime end) { public Object getCourtUseCount(Court court, DateTime start, DateTime end) {
JSONObject object = new JSONObject(); JSONObject object = new JSONObject();
SearchResponse<Map> searchResponse; SearchResponse<Void> searchResponse;
try { try {
// 获取法院ip段
List<String> ipScopes = StrUtil.splitTrim(court.getIpScope(), "-");
List<String> ipRange = ipScopes.size() != 2 ? Arrays.asList("255.255.255.255", "255.255.255.255") : IpUtils.getIPRange(ipScopes.get(0), ipScopes.get(1), 3);
searchResponse = client.search(srBuilder -> srBuilder searchResponse = client.search(srBuilder -> srBuilder
.index(APP_ABILITY_RECORD_INDEX) .index(APP_ABILITY_RECORD_INDEX)
.query(queryBuilder -> queryBuilder.bool(boolQuery -> { .query(queryBuilder -> queryBuilder.bool(boolQuery -> {
...@@ -155,20 +160,15 @@ public class ElasticSearchService { ...@@ -155,20 +160,15 @@ public class ElasticSearchService {
.field("callTime") .field("callTime")
.gte(JsonData.of(start.toString())) .gte(JsonData.of(start.toString()))
.lte(JsonData.of(end.toString())))); .lte(JsonData.of(end.toString()))));
// 法院ip前缀查询 // 多个ip前缀过滤
if (ObjUtil.isNotNull(court) && StrUtil.isNotBlank(court.getIpScope())) { boolQuery.must(mustQuery -> mustQuery.bool(bq -> {
List<String> ipScopes = StrUtil.splitTrim(court.getIpScope(), "-"); ipRange.forEach(ip -> bq.should(q -> q.prefix(pq -> pq.field("ip.keyword").value(ip))));
try { return bq;
List<String> ipRange = ipScopes.size() != 2 ? new ArrayList<>() : IpUtils.getIPRange(ipScopes.get(0), ipScopes.get(1), 3); }));
ipRange.forEach(ip -> boolQuery.must(q -> q.prefix(pq -> pq.field("ip.keyword").value(ip))));
} catch (Exception e) {
log.error("IP段解析错误", e);
}
}
return boolQuery; return boolQuery;
})) }))
// 总命中数,与hits.size()不同的是trackTotalHits不会限制10000 // 总命中数,与hits.size()不同的是trackTotalHits不会限制10000
.trackTotalHits(tb -> tb.enabled(true)), Map.class); .trackTotalHits(tb -> tb.enabled(true)), Void.class);
TotalHits totalHits = searchResponse.hits().total(); TotalHits totalHits = searchResponse.hits().total();
object.set("count", ObjUtil.isNull(totalHits) ? 0 : totalHits.value()); object.set("count", ObjUtil.isNull(totalHits) ? 0 : totalHits.value());
} catch (Exception e) { } catch (Exception e) {
...@@ -194,7 +194,7 @@ public class ElasticSearchService { ...@@ -194,7 +194,7 @@ public class ElasticSearchService {
for (Court court : courtList) { for (Court court : courtList) {
List<String> ipScopes = StrUtil.splitTrim(court.getIpScope(), "-"); List<String> ipScopes = StrUtil.splitTrim(court.getIpScope(), "-");
try { try {
List<String> ipRange = ipScopes.size() != 2 ? new ArrayList<>() : IpUtils.getIPRange(ipScopes.get(0), ipScopes.get(1), 3); List<String> ipRange = ipScopes.size() != 2 ? Arrays.asList("255.255.255.255", "255.255.255.255") : IpUtils.getIPRange(ipScopes.get(0), ipScopes.get(1), 3);
ipRange.forEach(ip -> boolQuery.should(q -> q.prefix(pq -> pq.field("ip.keyword").value(ip)))); ipRange.forEach(ip -> boolQuery.should(q -> q.prefix(pq -> pq.field("ip.keyword").value(ip))));
} catch (Exception e) { } catch (Exception e) {
log.error("IP段解析错误", e); log.error("IP段解析错误", e);
...@@ -214,7 +214,7 @@ public class ElasticSearchService { ...@@ -214,7 +214,7 @@ public class ElasticSearchService {
for (Court court : courtList) { for (Court court : courtList) {
List<String> ipScopes = StrUtil.splitTrim(court.getIpScope(), "-"); List<String> ipScopes = StrUtil.splitTrim(court.getIpScope(), "-");
try { try {
List<String> ipRange = ipScopes.size() != 2 ? new ArrayList<>() : IpUtils.getIPRange(ipScopes.get(0), ipScopes.get(1), 3); List<String> ipRange = ipScopes.size() != 2 ? Arrays.asList("255.255.255.255", "255.255.255.255") : IpUtils.getIPRange(ipScopes.get(0), ipScopes.get(1), 3);
ipRange.forEach(ip -> { ipRange.forEach(ip -> {
if (bucket.key().stringValue().startsWith(ip)) { if (bucket.key().stringValue().startsWith(ip)) {
// 若此 IP 范围已存在,则取出并更新 sum // 若此 IP 范围已存在,则取出并更新 sum
...@@ -359,7 +359,7 @@ public class ElasticSearchService { ...@@ -359,7 +359,7 @@ public class ElasticSearchService {
if (StrUtil.isNotBlank(ipScope)) { if (StrUtil.isNotBlank(ipScope)) {
List<String> ipScopes = StrUtil.splitTrim(ipScope, "-"); List<String> ipScopes = StrUtil.splitTrim(ipScope, "-");
try { try {
List<String> ipRange = ipScopes.size() != 2 ? new ArrayList<>() : IpUtils.getIPRange(ipScopes.get(0), ipScopes.get(1), 3); List<String> ipRange = ipScopes.size() != 2 ? Arrays.asList("255.255.255.255", "255.255.255.255") : IpUtils.getIPRange(ipScopes.get(0), ipScopes.get(1), 3);
ipRange.forEach(ip -> bq.should(q -> q.prefix(pq -> pq.field("ip.keyword").value(ip)))); ipRange.forEach(ip -> bq.should(q -> q.prefix(pq -> pq.field("ip.keyword").value(ip))));
} catch (Exception e) { } catch (Exception e) {
log.error("IP段解析错误", e); log.error("IP段解析错误", e);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment