Handle particular case in CleanTransactionsInProgressTask
MODIFY
src/scheduler/tasks/CloseTransactionsInProgressTask.ts
src/scheduler/tasks/CloseTransactionsInProgressTask.ts
@@ -5,10 +5,12 @@ import LockingHelper from '../../locking/LockingHelper';
import LockingManager from '../../locking/LockingManager';
import Logging from '../../utils/Logging';
import OCPPService from '../../server/ocpp/services/OCPPService';
+import OCPPUtils from '../../server/ocpp/utils/OCPPUtils';
import { ServerAction } from '../../types/Server';
import Tenant from '../../types/Tenant';
import TenantSchedulerTask from '../TenantSchedulerTask';
import TransactionStorage from '../../storage/mongodb/TransactionStorage';
+import User from '../../types/User';
import Utils from '../../utils/Utils';
const MODULE_NAME = 'CleanTransactionsInProgressTask';
@@ -22,6 +24,7 @@ export default class CloseTransactionsInProgressTask extends TenantSchedulerTask
inError: 0,
inSuccess: 0,
};
+ let authUser: { user: User, alternateUser: User };
const startTime = new Date().getTime();
// Instantiate the OCPPService
const ocppService = new OCPPService(Configuration.getChargingStationConfig());
@@ -35,14 +38,22 @@ export default class CloseTransactionsInProgressTask extends TenantSchedulerTask
if (await ocppService.softStopTransaction(tenant, transaction, transaction.chargeBox, transaction.siteArea)) {
result.inSuccess++;
} else {
- result.inError++;
- await Logging.logError({
- tenantID: tenant.id,
- action: ServerAction.TRANSACTION_SOFT_STOP,
- module: MODULE_NAME, method: 'processTenant',
- message: `Cannot soft stop Transaction ID '${transaction.id}'`,
- detailedMessages: { transaction }
- });
+ if (transaction.chargeBox) {
+ // Transaction is stopped by central system?
+ authUser = await ocppService.checkAuthorizeStopTransactionAndGetUsers(
+ tenant, transaction.chargeBox, transaction, transaction.tagID, true);
+ }
+ // Update Transaction with Stop Transaction and Stop MeterValues
+ OCPPUtils.updateTransactionWithStopTransaction(transaction, transaction.chargeBox ? transaction.chargeBox : null, {
+ transactionId: transaction.id,
+ chargeBoxID: transaction.chargeBoxID,
+ idTag: transaction.tagID,
+ timestamp: Utils.convertToDate(transaction.lastConsumption ? transaction.lastConsumption.timestamp : transaction.timestamp).toISOString(),
+ meterStop: transaction.lastConsumption ? transaction.lastConsumption.value : transaction.meterStart
+ }, authUser?.user, authUser?.alternateUser, transaction.tagID, true);
+ // Save the transaction
+ await TransactionStorage.saveTransaction(tenant, transaction);
+ result.inSuccess++;
}
} catch (error) {
result.inError++;

MODIFY
src/server/ocpp/services/OCPPService.ts
src/server/ocpp/services/OCPPService.ts
@@ -559,26 +559,7 @@ export default class OCPPService {
return (result.idTagInfo?.status === OCPPAuthorizationStatus.ACCEPTED);
}
- private checkAndUpdateTransactionWithSignedDataInStopTransaction(transaction: Transaction, stopTransaction: OCPPStopTransactionRequestExtended) {
- // Handle Signed Data in Stop Transaction
- if (!Utils.isEmptyArray(stopTransaction.transactionData)) {
- for (const meterValue of stopTransaction.transactionData as OCPPMeterValue[]) {
- for (const sampledValue of meterValue.sampledValue) {
- if (sampledValue.format === OCPPValueFormat.SIGNED_DATA) {
- // Set Signed data in Start of Transaction
- if (sampledValue.context === OCPPReadingContext.TRANSACTION_BEGIN) {
- transaction.signedData = sampledValue.value;
- }
- if (sampledValue.context === OCPPReadingContext.TRANSACTION_END) {
- transaction.currentSignedData = sampledValue.value;
- }
- }
- }
- }
- }
- }
-
- private async checkAuthorizeStopTransactionAndGetUsers(tenant: Tenant, chargingStation: ChargingStation, transaction: Transaction,
+ public async checkAuthorizeStopTransactionAndGetUsers(tenant: Tenant, chargingStation: ChargingStation, transaction: Transaction,
tagId: string, isStoppedByCentralSystem: boolean): Promise<{ user: User; alternateUser: User; }> {
let user: User;
let alternateUser: User;
@@ -607,6 +588,25 @@ export default class OCPPService {
return { user, alternateUser };
}
+ private checkAndUpdateTransactionWithSignedDataInStopTransaction(transaction: Transaction, stopTransaction: OCPPStopTransactionRequestExtended) {
+ // Handle Signed Data in Stop Transaction
+ if (!Utils.isEmptyArray(stopTransaction.transactionData)) {
+ for (const meterValue of stopTransaction.transactionData as OCPPMeterValue[]) {
+ for (const sampledValue of meterValue.sampledValue) {
+ if (sampledValue.format === OCPPValueFormat.SIGNED_DATA) {
+ // Set Signed data in Start of Transaction
+ if (sampledValue.context === OCPPReadingContext.TRANSACTION_BEGIN) {
+ transaction.signedData = sampledValue.value;
+ }
+ if (sampledValue.context === OCPPReadingContext.TRANSACTION_END) {
+ transaction.currentSignedData = sampledValue.value;
+ }
+ }
+ }
+ }
+ }
+ }
+
private async triggerSmartChargingStopTransaction(tenant: Tenant, chargingStation: ChargingStation, transaction: Transaction) {
if (Utils.isTenantComponentActive(tenant, TenantComponents.SMART_CHARGING)) {
// Delete TxProfile if any

Handle particular case in CleanTransactionsInProgressTask