23
23
import de .rwth .idsg .steve .repository .dto .Transaction ;
24
24
import de .rwth .idsg .steve .repository .dto .TransactionDetails ;
25
25
import de .rwth .idsg .steve .utils .DateTimeUtils ;
26
+ import de .rwth .idsg .steve .utils .TransactionStopServiceHelper ;
26
27
import de .rwth .idsg .steve .web .dto .TransactionQueryForm ;
27
28
import jooq .steve .db .enums .TransactionStopEventActor ;
28
29
import jooq .steve .db .tables .records .ConnectorMeterValueRecord ;
29
30
import jooq .steve .db .tables .records .TransactionStartRecord ;
31
+ import ocpp .cs ._2015 ._10 .UnitOfMeasure ;
30
32
import org .joda .time .DateTime ;
31
33
import org .jooq .Condition ;
32
34
import org .jooq .DSLContext ;
@@ -149,11 +151,16 @@ public TransactionDetails getDetails(int transactionPk) {
149
151
timestampCondition = CONNECTOR_METER_VALUE .VALUE_TIMESTAMP .between (startTimestamp , stopTimestamp );
150
152
}
151
153
154
+ // https://github.com/steve-community/steve/issues/1514
155
+ Condition unitCondition = CONNECTOR_METER_VALUE .UNIT .isNull ()
156
+ .or (CONNECTOR_METER_VALUE .UNIT .in ("" , UnitOfMeasure .WH .value (), UnitOfMeasure .K_WH .value ()));
157
+
152
158
// Case 1: Ideal and most accurate case. Station sends meter values with transaction id set.
153
159
//
154
160
SelectQuery <ConnectorMeterValueRecord > transactionQuery =
155
161
ctx .selectFrom (CONNECTOR_METER_VALUE )
156
162
.where (CONNECTOR_METER_VALUE .TRANSACTION_PK .eq (transactionPk ))
163
+ .and (unitCondition )
157
164
.getQuery ();
158
165
159
166
// Case 2: Fall back to filtering according to time windows
@@ -165,6 +172,7 @@ public TransactionDetails getDetails(int transactionPk) {
165
172
.where (CONNECTOR .CHARGE_BOX_ID .eq (chargeBoxId ))
166
173
.and (CONNECTOR .CONNECTOR_ID .eq (connectorId ))))
167
174
.and (timestampCondition )
175
+ .and (unitCondition )
168
176
.getQuery ();
169
177
170
178
// Actually, either case 1 applies or 2. If we retrieved values using 1, case 2 is should not be
@@ -199,7 +207,10 @@ public TransactionDetails getDetails(int transactionPk) {
199
207
.location (r .value6 ())
200
208
.unit (r .value7 ())
201
209
.phase (r .value8 ())
202
- .build ());
210
+ .build ())
211
+ .stream ()
212
+ .filter (TransactionStopServiceHelper ::isEnergyValue )
213
+ .toList ();
203
214
204
215
return new TransactionDetails (new TransactionMapper ().map (transaction ), values , nextTx );
205
216
}
0 commit comments