@Override public ExternalChargePointSelect getStationFromConnector(int connectorPK) { Result<Record4<String, String, String, Integer>> record = ctx.select(CHARGE_BOX.CHARGE_BOX_ID, CHARGE_BOX.ENDPOINT_ADDRESS, CHARGE_BOX.OCPP_PROTOCOL, CONNECTOR.CONNECTOR_ID) .from(CHARGE_BOX) .join(CONNECTOR) .on(CHARGE_BOX.CHARGE_BOX_ID.eq(CONNECTOR.CHARGE_BOX_ID)) .where(CONNECTOR.CONNECTOR_PK.eq(connectorPK)) .fetch(); List<ExternalChargePointSelect> bb = record.map(r -> { OcppProtocol protocol = OcppProtocol.fromCompositeValue(r.value3()); ChargePointSelect s = new ChargePointSelect(protocol.getTransport(), r.value1(), r.value2()); return ExternalChargePointSelect.builder() .version(protocol.getVersion()) .select(s) .connectorId(r.value4()) .connectorPk(connectorPK) .build(); }); if (bb == null || bb.isEmpty()) { throw new SteveException("EVSE not found"); } else if (bb.size() == 1) { return bb.get(0); } else { throw new SteveException("EVSE not found"); } }
public Collection<BalanceModel> getTopBalance(boolean user, boolean bank, int fromRank, int toRank, boolean showHidden) { SelectJoinStep<Record4<String, String, String, Long>> from = db.getDSL() .select(TABLE_BALANCE.ACCOUNT_ID, TABLE_BALANCE.CURRENCY, TABLE_BALANCE.CONTEXT, TABLE_BALANCE.BALANCE) .from(TABLE_BALANCE.join(TABLE_ACCOUNT).on(TABLE_BALANCE.ACCOUNT_ID.eq(TABLE_ACCOUNT.ID))); Condition userCond = TABLE_ACCOUNT.IS_UUID.eq(true); Condition bankCond = TABLE_ACCOUNT.IS_UUID.eq(false); SelectConditionStep<Record4<String, String, String, Long>> where; if (!user && !bank) { throw new IllegalArgumentException(); } if (user) { where = from.where(userCond); } else if (bank) { where = from.where(bankCond); } else { where = from.where(DSL.condition(true)); } if (!showHidden) { where = where.and(TABLE_ACCOUNT.HIDDEN.eq(false)); } return where.orderBy(TABLE_BALANCE.BALANCE.desc()).limit(fromRank - 1, toRank - fromRank + 1).fetchInto(BalanceModel.class); }
@Override public List<ProcessSummary> getProcessSummary() { final Map<String, ProcessSummary> processSummary = new TreeMap<>(); final Field<Boolean> running = DSL.field(PROCESS_INSTANCE.RUNNING_PROCESS_SERVER_ID.isNotNull()).as("running"); final Field<Boolean> delayed = DSL.field(PROCESS_INSTANCE.RUN_AFTER.greaterThan(new Date())).as("foo"); final Field<Integer> count = PROCESS_INSTANCE.PROCESS_NAME.count().as("count"); create() .select(PROCESS_INSTANCE.PROCESS_NAME, running, delayed, count) .from(PROCESS_INSTANCE) .where(PROCESS_INSTANCE.END_TIME.isNull()) .groupBy(PROCESS_INSTANCE.PROCESS_NAME, running, delayed) .fetchInto(new RecordHandler<Record4<String, Boolean, Boolean, Integer>>() { @Override public void next(Record4<String, Boolean, Boolean, Integer> record) { String name = record.getValue(PROCESS_INSTANCE.PROCESS_NAME); int c = record.getValue(count); boolean r = record.getValue(running); Boolean d = record.getValue(delayed); ProcessSummary summary = processSummary.get(name); if (summary == null) { summary = new ProcessSummary(); summary.setProcessName(name); processSummary.put(name, summary); } if (r) { summary.setRunning(summary.getRunning() + c); } else if (d == null || !d) { summary.setReady(summary.getReady() + c); } else { summary.setDelay(summary.getDelay() + c); } } }); return new ArrayList<>(processSummary.values()); }