提交 f52fe928 编写于 作者: xuhui961310148's avatar xuhui961310148

update:临时解决高检信访报表数据量大,查询一年等报表数据查询报错问题。

上级 33df7395
......@@ -11,6 +11,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Repository;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
......@@ -42,6 +43,11 @@ public class ExecResultRepository {
@Value("${ibiz.saveAsyncResultData:false}")
private boolean saveAsync;
@Value("${ibiz.splitRule:false}")
private boolean splitRule;
@Value("${ibiz.splitRuleSize:10}")
private int splitRuleSize;
public ExecResultRepository(MappingManager mappingManager) {
createTable(mappingManager.getSession());
......@@ -212,6 +218,24 @@ public class ExecResultRepository {
public List<ExecResult> sum(Collection<String> ruleids, Integer retValue, List<String> dims, Timestamp start, Timestamp end) {
LocalDate st = ExecResult.time2LocalDate(start);
LocalDate ed = ExecResult.time2LocalDate(end);
if (splitRule){
log.info("sum规则切分查询");
List<String> list = new ArrayList<>(ruleids);
List<List<String>> lists = this.splitList(list, splitRuleSize);
if (lists.size() > 0){
List<ExecResult> execResults = new ArrayList<>();
for (List<String> ruleidList : lists) {
ResultSet result = session.execute(select().column("ruleid").column("retvalue").column("dimfield").sum("metricfield").as("metricfield").
from(TABLE).
where(in("ruleid", ruleidList)).
and(eq("retvalue", retValue)).
and(in("dimfield", dims)).
and(gte("timefield", st)).and(lte("timefield", ed)).groupBy("ruleid", "retvalue", "dimfield").limit(5000).setReadTimeoutMillis(200000));
execResults.addAll(mapper.map(result).all());
}
return execResults;
}
}
final ResultSet result = session.execute(select().column("ruleid").column("retvalue").column("dimfield").sum("metricfield").as("metricfield").
from(TABLE).
where(in("ruleid", ruleids)).
......@@ -234,6 +258,24 @@ public class ExecResultRepository {
public List<ExecResult> sum(Collection<String> ruleids, Integer retValue, List<String> dims, Timestamp start, Timestamp end, String ext_1field) {
LocalDate st = ExecResult.time2LocalDate(start);
LocalDate ed = ExecResult.time2LocalDate(end);
if (splitRule){
log.info("sum-ext_1field规则切分查询");
List<String> list = new ArrayList<>(ruleids);
List<List<String>> lists = this.splitList(list, splitRuleSize);
if (lists.size() > 0){
List<ExecResult> execResults = new ArrayList<>();
for (List<String> ruleidList : lists) {
ResultSet result = session.execute(select().column("ruleid").column("retvalue").column("dimfield").sum("metricfield").as("metricfield").
from(TABLE).
where(in("ruleid", ruleidList)).
and(eq("retvalue", retValue)).
and(in("dimfield", dims)).
and(gte("timefield", st)).and(lte("timefield", ed)).and(eq("ext_1field", ext_1field)).groupBy("ruleid", "retvalue", "dimfield").allowFiltering().limit(5000).setReadTimeoutMillis(200000));
execResults.addAll(mapper.map(result).all());
}
return execResults;
}
}
final ResultSet result = session.execute(select().column("ruleid").column("retvalue").column("dimfield").sum("metricfield").as("metricfield").
from(TABLE).
where(in("ruleid", ruleids)).
......@@ -246,6 +288,24 @@ public class ExecResultRepository {
public List<ExecResult> avg(Collection<String> ruleids, Integer retValue, List<String> dims, Timestamp start, Timestamp end) {
LocalDate st = ExecResult.time2LocalDate(start);
LocalDate ed = ExecResult.time2LocalDate(end);
if (splitRule){
log.info("avg规则切分查询");
List<String> list = new ArrayList<>(ruleids);
List<List<String>> lists = this.splitList(list, splitRuleSize);
if (lists.size() > 0){
List<ExecResult> execResults = new ArrayList<>();
for (List<String> ruleidList : lists) {
ResultSet result = session.execute(select().column("ruleid").column("retvalue").column("dimfield").avg("metricfield").as("metricfield").
from(TABLE).
where(in("ruleid", ruleidList)).
and(eq("retvalue", retValue)).
and(in("dimfield", dims)).
and(gte("timefield", st)).and(lte("timefield", ed)).groupBy("ruleid", "retvalue", "dimfield").limit(5000).setReadTimeoutMillis(200000));
execResults.addAll(mapper.map(result).all());
}
return execResults;
}
}
final ResultSet result = session.execute(select().column("ruleid").column("retvalue").column("dimfield").avg("metricfield").as("metricfield").
from(TABLE).
where(in("ruleid", ruleids)).
......@@ -268,6 +328,24 @@ public class ExecResultRepository {
public List<ExecResult> avg(Collection<String> ruleids, Integer retValue, List<String> dims, Timestamp start, Timestamp end, String ext_1field) {
LocalDate st = ExecResult.time2LocalDate(start);
LocalDate ed = ExecResult.time2LocalDate(end);
if (splitRule){
log.info("avg--ext_1field规则切分查询");
List<String> list = new ArrayList<>(ruleids);
List<List<String>> lists = this.splitList(list, splitRuleSize);
if (lists.size() > 0){
List<ExecResult> execResults = new ArrayList<>();
for (List<String> ruleidList : lists) {
ResultSet result = session.execute(select().column("ruleid").column("retvalue").column("dimfield").avg("metricfield").as("metricfield").
from(TABLE).
where(in("ruleid", ruleidList)).
and(eq("retvalue", retValue)).
and(in("dimfield", dims)).
and(gte("timefield", st)).and(lte("timefield", ed)).and(eq("ext_1field",ext_1field)).groupBy("ruleid", "retvalue", "dimfield").allowFiltering().limit(5000).setReadTimeoutMillis(200000));
execResults.addAll(mapper.map(result).all());
}
return execResults;
}
}
final ResultSet result = session.execute(select().column("ruleid").column("retvalue").column("dimfield").avg("metricfield").as("metricfield").
from(TABLE).
where(in("ruleid", ruleids)).
......@@ -388,6 +466,23 @@ public class ExecResultRepository {
public List<ExecResult> sumPerformancePiece(List<String> ruleids, Integer retValue, List<String> dims, Timestamp start, Timestamp end) {
LocalDate st = ExecResult.time2LocalDate(start);
LocalDate ed = ExecResult.time2LocalDate(end);
if (splitRule){
log.info("sumPerformancePiece规则切分查询");
List<List<String>> lists = this.splitList(ruleids, splitRuleSize);
if (lists.size() > 0){
List<ExecResult> execResults = new ArrayList<>();
for (List<String> ruleidList : lists) {
ResultSet result = session.execute(select().column("dimfield").column("keyvaluefield").
from(TABLE).
where(in("ruleid", ruleidList)).
and(eq("retvalue", retValue)).
and(in("dimfield", dims)).
and(gte("timefield", st)).and(lte("timefield", ed)).limit(5000).setReadTimeoutMillis(200000));
execResults.addAll(mapper.map(result).all());
}
return execResults;
}
}
final ResultSet result = session.execute(select().column("dimfield").column("keyvaluefield").
from(TABLE).
where(in("ruleid", ruleids)).
......@@ -459,4 +554,28 @@ public class ExecResultRepository {
session.execute(delete().all().from(TABLE).where(in("ruleid",ruleids)).and(eq("retvalue",1)));
}
public static <T> List<List<T>> splitList(List<T> list, int count){
List<List<T>> lists = new ArrayList<List<T>>(); // 结果集
int listSize = list.size(); // 原集合长度
int listCount = listSize / count; // 可直接拆分集合数量
// 按量拆分
for (int i = 0; i < listCount ; i++) {
List<T> sub2=new ArrayList<>();
for(int j = i*count;j<(i + 1) * count;j++)
sub2.add(list.get(j));
lists.add(sub2);
}
// 如果按量拆分后还有剩余, 收尾
int remainder = listSize % count;
if(remainder > 0) {
List<T> sub2=new ArrayList<>();
for(int j=listSize - remainder;j<listSize;j++)
sub2.add(list.get(j));
lists.add(sub2);
}
return lists;
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册