@WithTimer
public QueueMetrics metrics(UUID orgId, UUID prjId, Set<String> statuses) {
return txResult(tx -> {
SelectConditionStep<Record4<Integer, Integer, Integer, String>> q = tx.select(
field("1", Integer.class).as("count_process"),
when(V_PROCESS_QUEUE.ORG_ID.eq(orgId), 1).otherwise(0).as("count_per_org"),
when(V_PROCESS_QUEUE.PROJECT_ID.eq(prjId), 1).otherwise(0).as("count_per_project"),
V_PROCESS_QUEUE.CURRENT_STATUS.as("status"))
.from(V_PROCESS_QUEUE)
.where(V_PROCESS_QUEUE.CURRENT_STATUS.in(statuses));
List<Record4<BigDecimal, BigDecimal, BigDecimal, String>> result = tx.select(
sum(q.field("count_process", Integer.class)),
sum(q.field("count_per_org", Integer.class)),
sum(q.field("count_per_project", Integer.class)),
q.field("status", String.class))
.from(q)
.groupBy(q.field("status", String.class))
.fetch();
Map<String, Integer> process = new HashMap<>();
Map<String, Integer> perOrg = new HashMap<>();
Map<String, Integer> perProject = new HashMap<>();
result.forEach(r -> {
String status = r.value4();
process.put(status, getInt(r.value1()));
perOrg.put(status, getInt(r.value2()));
perProject.put(status, getInt(r.value3()));
});
return new QueueMetrics(process, perOrg, perProject);
});
}