From 654a2a66d9adc1013e169ef7834242d34bee0120 Mon Sep 17 00:00:00 2001 From: Timothy Yin Date: Mon, 16 Mar 2026 13:43:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(csms):=20=E5=85=85=E7=94=B5=E6=A1=A9?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20deviceName=20=E5=AD=97=E6=AE=B5=EF=BC=8C?= =?UTF-8?q?=E5=8C=BA=E5=88=AB=E4=BA=8E=20identifier=20=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E5=8C=BA=E5=88=86=E8=AE=BE=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/csms/drizzle/0004_nervous_frog_thor.sql | 1 + apps/csms/drizzle/meta/0004_snapshot.json | 1942 +++++++++++++++++ apps/csms/drizzle/meta/_journal.json | 7 + apps/csms/src/db/ocpp-schema.ts | 5 + apps/csms/src/routes/charge-points.ts | 5 + apps/csms/src/routes/transactions.ts | 4 + .../app/dashboard/charge-points/[id]/page.tsx | 21 +- apps/web/app/dashboard/charge-points/page.tsx | 53 +- apps/web/app/dashboard/charge/page.tsx | 18 +- apps/web/app/dashboard/page.tsx | 28 +- .../app/dashboard/topology/topology-flow.tsx | 26 +- .../app/dashboard/transactions/[id]/page.tsx | 11 +- apps/web/app/dashboard/transactions/page.tsx | 9 +- apps/web/lib/api.ts | 5 + 14 files changed, 2095 insertions(+), 40 deletions(-) create mode 100644 apps/csms/drizzle/0004_nervous_frog_thor.sql create mode 100644 apps/csms/drizzle/meta/0004_snapshot.json diff --git a/apps/csms/drizzle/0004_nervous_frog_thor.sql b/apps/csms/drizzle/0004_nervous_frog_thor.sql new file mode 100644 index 0000000..23b04d2 --- /dev/null +++ b/apps/csms/drizzle/0004_nervous_frog_thor.sql @@ -0,0 +1 @@ +ALTER TABLE "charge_point" ADD COLUMN "device_name" varchar(100); \ No newline at end of file diff --git a/apps/csms/drizzle/meta/0004_snapshot.json b/apps/csms/drizzle/meta/0004_snapshot.json new file mode 100644 index 0000000..a37f43b --- /dev/null +++ b/apps/csms/drizzle/meta/0004_snapshot.json @@ -0,0 +1,1942 @@ +{ + "id": "4a8a83e5-a252-452c-97b5-930068891ea2", + "prevId": "7507bde1-447c-4b9b-8219-678a5e7414b0", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.account": { + "name": "account", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "access_token_expires_at": { + "name": "access_token_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "refresh_token_expires_at": { + "name": "refresh_token_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "account_userId_idx": { + "name": "account_userId_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "account_user_id_user_id_fk": { + "name": "account_user_id_user_id_fk", + "tableFrom": "account", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.passkey": { + "name": "passkey", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "public_key": { + "name": "public_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "credential_id": { + "name": "credential_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "counter": { + "name": "counter", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "device_type": { + "name": "device_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "backed_up": { + "name": "backed_up", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "transports": { + "name": "transports", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "aaguid": { + "name": "aaguid", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "passkey_userId_idx": { + "name": "passkey_userId_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "passkey_credentialID_idx": { + "name": "passkey_credentialID_idx", + "columns": [ + { + "expression": "credential_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "passkey_user_id_user_id_fk": { + "name": "passkey_user_id_user_id_fk", + "tableFrom": "passkey", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.session": { + "name": "session", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "impersonated_by": { + "name": "impersonated_by", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "session_userId_idx": { + "name": "session_userId_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "session_user_id_user_id_fk": { + "name": "session_user_id_user_id_fk", + "tableFrom": "session", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "session_token_unique": { + "name": "session_token_unique", + "nullsNotDistinct": false, + "columns": [ + "token" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user": { + "name": "user", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email_verified": { + "name": "email_verified", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "banned": { + "name": "banned", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "ban_reason": { + "name": "ban_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ban_expires": { + "name": "ban_expires", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "display_username": { + "name": "display_username", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_email_unique": { + "name": "user_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + }, + "user_username_unique": { + "name": "user_username_unique", + "nullsNotDistinct": false, + "columns": [ + "username" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.verification": { + "name": "verification", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "verification_identifier_idx": { + "name": "verification_identifier_idx", + "columns": [ + { + "expression": "identifier", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.charge_point": { + "name": "charge_point", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "charge_point_identifier": { + "name": "charge_point_identifier", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "charge_point_serial_number": { + "name": "charge_point_serial_number", + "type": "varchar(25)", + "primaryKey": false, + "notNull": false + }, + "charge_point_model": { + "name": "charge_point_model", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "charge_point_vendor": { + "name": "charge_point_vendor", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "firmware_version": { + "name": "firmware_version", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "iccid": { + "name": "iccid", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "imsi": { + "name": "imsi", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "meter_serial_number": { + "name": "meter_serial_number", + "type": "varchar(25)", + "primaryKey": false, + "notNull": false + }, + "meter_type": { + "name": "meter_type", + "type": "varchar(25)", + "primaryKey": false, + "notNull": false + }, + "registration_status": { + "name": "registration_status", + "type": "varchar", + "primaryKey": false, + "notNull": true, + "default": "'Pending'" + }, + "heartbeat_interval": { + "name": "heartbeat_interval", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 60 + }, + "last_heartbeat_at": { + "name": "last_heartbeat_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_boot_notification_at": { + "name": "last_boot_notification_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "device_name": { + "name": "device_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "fee_per_kwh": { + "name": "fee_per_kwh", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "pricing_mode": { + "name": "pricing_mode", + "type": "varchar", + "primaryKey": false, + "notNull": true, + "default": "'fixed'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "charge_point_charge_point_identifier_unique": { + "name": "charge_point_charge_point_identifier_unique", + "nullsNotDistinct": false, + "columns": [ + "charge_point_identifier" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.charging_profile": { + "name": "charging_profile", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true + }, + "charge_point_id": { + "name": "charge_point_id", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "connector_id": { + "name": "connector_id", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "connector_number": { + "name": "connector_number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "transaction_id": { + "name": "transaction_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "stack_level": { + "name": "stack_level", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "charging_profile_purpose": { + "name": "charging_profile_purpose", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "charging_profile_kind": { + "name": "charging_profile_kind", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "recurrency_kind": { + "name": "recurrency_kind", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "valid_from": { + "name": "valid_from", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "valid_to": { + "name": "valid_to", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "charging_schedule": { + "name": "charging_schedule", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_charging_profile_charge_point_id": { + "name": "idx_charging_profile_charge_point_id", + "columns": [ + { + "expression": "charge_point_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_charging_profile_connector_id": { + "name": "idx_charging_profile_connector_id", + "columns": [ + { + "expression": "connector_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_charging_profile_purpose_stack": { + "name": "idx_charging_profile_purpose_stack", + "columns": [ + { + "expression": "connector_number", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "charging_profile_purpose", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "stack_level", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "charging_profile_charge_point_id_charge_point_id_fk": { + "name": "charging_profile_charge_point_id_charge_point_id_fk", + "tableFrom": "charging_profile", + "tableTo": "charge_point", + "columnsFrom": [ + "charge_point_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "charging_profile_connector_id_connector_id_fk": { + "name": "charging_profile_connector_id_connector_id_fk", + "tableFrom": "charging_profile", + "tableTo": "connector", + "columnsFrom": [ + "connector_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "charging_profile_transaction_id_transaction_id_fk": { + "name": "charging_profile_transaction_id_transaction_id_fk", + "tableFrom": "charging_profile", + "tableTo": "transaction", + "columnsFrom": [ + "transaction_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.connector": { + "name": "connector", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "charge_point_id": { + "name": "charge_point_id", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "connector_id": { + "name": "connector_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar", + "primaryKey": false, + "notNull": true, + "default": "'Unavailable'" + }, + "error_code": { + "name": "error_code", + "type": "varchar", + "primaryKey": false, + "notNull": true, + "default": "'NoError'" + }, + "info": { + "name": "info", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "vendor_error_code": { + "name": "vendor_error_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "last_status_at": { + "name": "last_status_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_connector_charge_point_id": { + "name": "idx_connector_charge_point_id", + "columns": [ + { + "expression": "charge_point_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_connector_charge_point_connector": { + "name": "idx_connector_charge_point_connector", + "columns": [ + { + "expression": "charge_point_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "connector_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "connector_charge_point_id_charge_point_id_fk": { + "name": "connector_charge_point_id_charge_point_id_fk", + "tableFrom": "connector", + "tableTo": "charge_point", + "columnsFrom": [ + "charge_point_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.connector_status_history": { + "name": "connector_status_history", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "connector_id": { + "name": "connector_id", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "connector_number": { + "name": "connector_number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "error_code": { + "name": "error_code", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "info": { + "name": "info", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "vendor_error_code": { + "name": "vendor_error_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "status_timestamp": { + "name": "status_timestamp", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "received_at": { + "name": "received_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_status_history_connector_id": { + "name": "idx_status_history_connector_id", + "columns": [ + { + "expression": "connector_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_status_history_timestamp": { + "name": "idx_status_history_timestamp", + "columns": [ + { + "expression": "status_timestamp", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_status_history_received_at": { + "name": "idx_status_history_received_at", + "columns": [ + { + "expression": "received_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "connector_status_history_connector_id_connector_id_fk": { + "name": "connector_status_history_connector_id_connector_id_fk", + "tableFrom": "connector_status_history", + "tableTo": "connector", + "columnsFrom": [ + "connector_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.id_tag": { + "name": "id_tag", + "schema": "", + "columns": { + "id_tag": { + "name": "id_tag", + "type": "varchar(20)", + "primaryKey": true, + "notNull": true + }, + "parent_id_tag": { + "name": "parent_id_tag", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar", + "primaryKey": false, + "notNull": true, + "default": "'Accepted'" + }, + "expiry_date": { + "name": "expiry_date", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "balance": { + "name": "balance", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "card_layout": { + "name": "card_layout", + "type": "varchar", + "primaryKey": false, + "notNull": false, + "default": "'around'" + }, + "card_skin": { + "name": "card_skin", + "type": "varchar", + "primaryKey": false, + "notNull": false, + "default": "'circles'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "id_tag_user_id_user_id_fk": { + "name": "id_tag_user_id_user_id_fk", + "tableFrom": "id_tag", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.local_auth_list": { + "name": "local_auth_list", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "charge_point_id": { + "name": "charge_point_id", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "list_version": { + "name": "list_version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id_tag": { + "name": "id_tag", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "parent_id_tag": { + "name": "parent_id_tag", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "id_tag_status": { + "name": "id_tag_status", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "expiry_date": { + "name": "expiry_date", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_local_auth_list_charge_point_id_tag": { + "name": "idx_local_auth_list_charge_point_id_tag", + "columns": [ + { + "expression": "charge_point_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id_tag", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "local_auth_list_charge_point_id_charge_point_id_fk": { + "name": "local_auth_list_charge_point_id_charge_point_id_fk", + "tableFrom": "local_auth_list", + "tableTo": "charge_point", + "columnsFrom": [ + "charge_point_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.meter_value": { + "name": "meter_value", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "transaction_id": { + "name": "transaction_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "connector_id": { + "name": "connector_id", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "charge_point_id": { + "name": "charge_point_id", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "connector_number": { + "name": "connector_number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "timestamp": { + "name": "timestamp", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "sampled_values": { + "name": "sampled_values", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "received_at": { + "name": "received_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_meter_value_transaction_id": { + "name": "idx_meter_value_transaction_id", + "columns": [ + { + "expression": "transaction_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_meter_value_connector_id": { + "name": "idx_meter_value_connector_id", + "columns": [ + { + "expression": "connector_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_meter_value_timestamp": { + "name": "idx_meter_value_timestamp", + "columns": [ + { + "expression": "timestamp", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "meter_value_transaction_id_transaction_id_fk": { + "name": "meter_value_transaction_id_transaction_id_fk", + "tableFrom": "meter_value", + "tableTo": "transaction", + "columnsFrom": [ + "transaction_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "meter_value_connector_id_connector_id_fk": { + "name": "meter_value_connector_id_connector_id_fk", + "tableFrom": "meter_value", + "tableTo": "connector", + "columnsFrom": [ + "connector_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "meter_value_charge_point_id_charge_point_id_fk": { + "name": "meter_value_charge_point_id_charge_point_id_fk", + "tableFrom": "meter_value", + "tableTo": "charge_point", + "columnsFrom": [ + "charge_point_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.reservation": { + "name": "reservation", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true + }, + "charge_point_id": { + "name": "charge_point_id", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "connector_id": { + "name": "connector_id", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "connector_number": { + "name": "connector_number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "expiry_date": { + "name": "expiry_date", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "id_tag": { + "name": "id_tag", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "parent_id_tag": { + "name": "parent_id_tag", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar", + "primaryKey": false, + "notNull": true, + "default": "'Active'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_reservation_charge_point_id": { + "name": "idx_reservation_charge_point_id", + "columns": [ + { + "expression": "charge_point_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_reservation_status": { + "name": "idx_reservation_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_reservation_expiry_date": { + "name": "idx_reservation_expiry_date", + "columns": [ + { + "expression": "expiry_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "reservation_charge_point_id_charge_point_id_fk": { + "name": "reservation_charge_point_id_charge_point_id_fk", + "tableFrom": "reservation", + "tableTo": "charge_point", + "columnsFrom": [ + "charge_point_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reservation_connector_id_connector_id_fk": { + "name": "reservation_connector_id_connector_id_fk", + "tableFrom": "reservation", + "tableTo": "connector", + "columnsFrom": [ + "connector_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.transaction": { + "name": "transaction", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "charge_point_id": { + "name": "charge_point_id", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "connector_id": { + "name": "connector_id", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "connector_number": { + "name": "connector_number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "id_tag": { + "name": "id_tag", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "id_tag_status": { + "name": "id_tag_status", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "start_timestamp": { + "name": "start_timestamp", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "start_meter_value": { + "name": "start_meter_value", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "stop_id_tag": { + "name": "stop_id_tag", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "stop_timestamp": { + "name": "stop_timestamp", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "stop_meter_value": { + "name": "stop_meter_value", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "stop_reason": { + "name": "stop_reason", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "charge_amount": { + "name": "charge_amount", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "electricity_fee": { + "name": "electricity_fee", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "service_fee": { + "name": "service_fee", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "reservation_id": { + "name": "reservation_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_transaction_charge_point_id": { + "name": "idx_transaction_charge_point_id", + "columns": [ + { + "expression": "charge_point_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_transaction_connector_id": { + "name": "idx_transaction_connector_id", + "columns": [ + { + "expression": "connector_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_transaction_id_tag": { + "name": "idx_transaction_id_tag", + "columns": [ + { + "expression": "id_tag", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_transaction_start_timestamp": { + "name": "idx_transaction_start_timestamp", + "columns": [ + { + "expression": "start_timestamp", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "transaction_charge_point_id_charge_point_id_fk": { + "name": "transaction_charge_point_id_charge_point_id_fk", + "tableFrom": "transaction", + "tableTo": "charge_point", + "columnsFrom": [ + "charge_point_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "transaction_connector_id_connector_id_fk": { + "name": "transaction_connector_id_connector_id_fk", + "tableFrom": "transaction", + "tableTo": "connector", + "columnsFrom": [ + "connector_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tariff": { + "name": "tariff", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "slots": { + "name": "slots", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "peak_electricity_price": { + "name": "peak_electricity_price", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "peak_service_fee": { + "name": "peak_service_fee", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "valley_electricity_price": { + "name": "valley_electricity_price", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "valley_service_fee": { + "name": "valley_service_fee", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "flat_electricity_price": { + "name": "flat_electricity_price", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "flat_service_fee": { + "name": "flat_service_fee", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/apps/csms/drizzle/meta/_journal.json b/apps/csms/drizzle/meta/_journal.json index c1fc072..95e9202 100644 --- a/apps/csms/drizzle/meta/_journal.json +++ b/apps/csms/drizzle/meta/_journal.json @@ -29,6 +29,13 @@ "when": 1773307380017, "tag": "0003_milky_supreme_intelligence", "breakpoints": true + }, + { + "idx": 4, + "version": "7", + "when": 1773639782622, + "tag": "0004_nervous_frog_thor", + "breakpoints": true } ] } \ No newline at end of file diff --git a/apps/csms/src/db/ocpp-schema.ts b/apps/csms/src/db/ocpp-schema.ts index 40aa984..5a141e8 100644 --- a/apps/csms/src/db/ocpp-schema.ts +++ b/apps/csms/src/db/ocpp-schema.ts @@ -71,6 +71,11 @@ export const chargePoint = pgTable('charge_point', { * 交易结束时按实际用电量从储值卡扣费:fee = ceil(energyWh * feePerKwh / 1000) * 默认为 0,即不计费。仅在 pricingMode = 'fixed' 时生效。 */ + /** + * 设备名称(系统内部维护,不会被设备上报信息覆盖) + * 供运营人员标记,例如"1号楼A区01号桩" + */ + deviceName: varchar('device_name', { length: 100 }), feePerKwh: integer('fee_per_kwh').notNull().default(0), /** * 计费模式 diff --git a/apps/csms/src/routes/charge-points.ts b/apps/csms/src/routes/charge-points.ts index bed989a..dff6060 100644 --- a/apps/csms/src/routes/charge-points.ts +++ b/apps/csms/src/routes/charge-points.ts @@ -71,6 +71,7 @@ app.post("/", async (c) => { registrationStatus?: "Accepted" | "Pending" | "Rejected"; feePerKwh?: number; pricingMode?: "fixed" | "tou"; + deviceName?: string; }>(); if (!body.chargePointIdentifier?.trim()) { @@ -93,6 +94,7 @@ app.post("/", async (c) => { registrationStatus: body.registrationStatus ?? "Pending", feePerKwh: body.feePerKwh ?? 0, pricingMode: body.pricingMode ?? "fixed", + deviceName: body.deviceName?.trim() || null, }) .returning() .catch((err: Error) => { @@ -142,6 +144,7 @@ app.patch("/:id", async (c) => { registrationStatus?: string; chargePointVendor?: string; chargePointModel?: string; + deviceName?: string | null; }>(); const set: { @@ -150,6 +153,7 @@ app.patch("/:id", async (c) => { registrationStatus?: "Accepted" | "Pending" | "Rejected"; chargePointVendor?: string; chargePointModel?: string; + deviceName?: string | null; updatedAt: Date; } = { updatedAt: dayjs().toDate() }; @@ -167,6 +171,7 @@ app.patch("/:id", async (c) => { } if (body.chargePointVendor !== undefined) set.chargePointVendor = body.chargePointVendor.trim() || "Unknown"; if (body.chargePointModel !== undefined) set.chargePointModel = body.chargePointModel.trim() || "Unknown"; + if ("deviceName" in body) set.deviceName = body.deviceName?.trim() || null; if (body.pricingMode !== undefined) { if (!['fixed', 'tou'].includes(body.pricingMode)) { return c.json({ error: "pricingMode must be 'fixed' or 'tou'" }, 400); diff --git a/apps/csms/src/routes/transactions.ts b/apps/csms/src/routes/transactions.ts index 1b1fee1..a7b1bc5 100644 --- a/apps/csms/src/routes/transactions.ts +++ b/apps/csms/src/routes/transactions.ts @@ -144,6 +144,7 @@ app.get("/", async (c) => { .select({ transaction, chargePointIdentifier: chargePoint.chargePointIdentifier, + chargePointDeviceName: chargePoint.deviceName, feePerKwh: chargePoint.feePerKwh, pricingMode: chargePoint.pricingMode, connectorNumber: connector.connectorId, @@ -217,6 +218,7 @@ app.get("/", async (c) => { return { ...r.transaction, chargePointIdentifier: r.chargePointIdentifier, + chargePointDeviceName: r.chargePointDeviceName, connectorNumber: r.connectorNumber, idTagUserId: r.idTagUserId, idTagUserName: r.idTagUserName, @@ -243,6 +245,7 @@ app.get("/:id", async (c) => { .select({ transaction, chargePointIdentifier: chargePoint.chargePointIdentifier, + chargePointDeviceName: chargePoint.deviceName, connectorNumber: connector.connectorId, feePerKwh: chargePoint.feePerKwh, pricingMode: chargePoint.pricingMode, @@ -294,6 +297,7 @@ app.get("/:id", async (c) => { return c.json({ ...row.transaction, chargePointIdentifier: row.chargePointIdentifier, + chargePointDeviceName: row.chargePointDeviceName, connectorNumber: row.connectorNumber, energyWh: row.transaction.stopMeterValue != null diff --git a/apps/web/app/dashboard/charge-points/[id]/page.tsx b/apps/web/app/dashboard/charge-points/[id]/page.tsx index a5314dc..8386701 100644 --- a/apps/web/app/dashboard/charge-points/[id]/page.tsx +++ b/apps/web/app/dashboard/charge-points/[id]/page.tsx @@ -77,6 +77,7 @@ function relativeTime(iso: string): string { // ── Edit form type ───────────────────────────────────────────────────────── type EditForm = { + deviceName: string; chargePointVendor: string; chargePointModel: string; registrationStatus: "Accepted" | "Pending" | "Rejected"; @@ -96,6 +97,7 @@ export default function ChargePointDetailPage({ params }: { params: Promise<{ id const [editOpen, setEditOpen] = useState(false); const [editBusy, setEditBusy] = useState(false); const [editForm, setEditForm] = useState({ + deviceName: "", chargePointVendor: "", chargePointModel: "", registrationStatus: "Pending", @@ -122,6 +124,7 @@ export default function ChargePointDetailPage({ params }: { params: Promise<{ id const openEdit = () => { if (!cp) return; setEditForm({ + deviceName: cp.deviceName ?? "", chargePointVendor: cp.chargePointVendor ?? "", chargePointModel: cp.chargePointModel ?? "", registrationStatus: cp.registrationStatus as EditForm["registrationStatus"], @@ -142,6 +145,7 @@ export default function ChargePointDetailPage({ params }: { params: Promise<{ id registrationStatus: editForm.registrationStatus, pricingMode: editForm.pricingMode, feePerKwh: editForm.pricingMode === "fixed" ? fee : 0, + deviceName: editForm.deviceName.trim() || null, }); await cpQuery.refetch(); setEditOpen(false); @@ -202,9 +206,12 @@ export default function ChargePointDetailPage({ params }: { params: Promise<{ id
-

- {cp.chargePointIdentifier} +

+ {cp.deviceName ?? {cp.chargePointIdentifier}}

+ {isAdmin && cp.deviceName && ( + {cp.chargePointIdentifier} + )} 编辑充电桩 + + + + setEditForm((f) => ({ ...f, deviceName: e.target.value })) + } + /> +
diff --git a/apps/web/app/dashboard/charge-points/page.tsx b/apps/web/app/dashboard/charge-points/page.tsx index d99ec36..bd019dc 100644 --- a/apps/web/app/dashboard/charge-points/page.tsx +++ b/apps/web/app/dashboard/charge-points/page.tsx @@ -97,6 +97,7 @@ const registrationColorMap: Record = { type FormData = { chargePointIdentifier: string; + deviceName: string; chargePointVendor: string; chargePointModel: string; registrationStatus: "Accepted" | "Pending" | "Rejected"; @@ -106,6 +107,7 @@ type FormData = { const EMPTY_FORM: FormData = { chargePointIdentifier: "", + deviceName: "", chargePointVendor: "", chargePointModel: "", registrationStatus: "Pending", @@ -141,6 +143,7 @@ export default function ChargePointsPage() { setFormTarget(cp); setFormData({ chargePointIdentifier: cp.chargePointIdentifier, + deviceName: cp.deviceName ?? "", chargePointVendor: cp.chargePointVendor ?? "", chargePointModel: cp.chargePointModel ?? "", registrationStatus: cp.registrationStatus as FormData["registrationStatus"], @@ -163,6 +166,7 @@ export default function ChargePointsPage() { registrationStatus: formData.registrationStatus, pricingMode: formData.pricingMode, feePerKwh: formData.pricingMode === "fixed" ? fee : 0, + deviceName: formData.deviceName.trim() || null, }); } else { // Create @@ -173,6 +177,7 @@ export default function ChargePointsPage() { registrationStatus: formData.registrationStatus, pricingMode: formData.pricingMode, feePerKwh: formData.pricingMode === "fixed" ? fee : 0, + deviceName: formData.deviceName.trim() || undefined, }); } await refetchList(); @@ -258,8 +263,18 @@ export default function ChargePointsPage() { } /> + + + + setFormData((f) => ({ ...f, deviceName: e.target.value })) + } + /> +
- + - + - {qrTarget?.chargePointIdentifier} — 充电二维码 + + {qrTarget?.deviceName ?? qrTarget?.chargePointIdentifier} — 充电二维码 +

@@ -431,7 +448,7 @@ export default function ChargePointsPage() { - 标识符 + 设备名称 {isAdmin && 品牌 / 型号} {isAdmin && 注册状态} 计费模式 @@ -469,12 +486,19 @@ export default function ChargePointsPage() { : "bg-gray-300" }`} /> - - {cp.chargePointIdentifier} - +

+ + {cp.deviceName ?? cp.chargePointIdentifier} + + {isAdmin && cp.deviceName && ( + + {cp.chargePointIdentifier} + + )} +
@@ -594,9 +618,14 @@ export default function ChargePointsPage() {

将删除充电桩{" "} - - {cp.chargePointIdentifier} + + {cp.deviceName ?? cp.chargePointIdentifier} + {cp.deviceName && ( + + ({cp.chargePointIdentifier}) + + )} 及其所有连接器和充电记录,此操作不可恢复。

diff --git a/apps/web/app/dashboard/charge/page.tsx b/apps/web/app/dashboard/charge/page.tsx index 8399439..b191cff 100644 --- a/apps/web/app/dashboard/charge/page.tsx +++ b/apps/web/app/dashboard/charge/page.tsx @@ -222,6 +222,7 @@ function QrScanner({ onResult, onClose }: ScannerProps) { function ChargePageContent() { const searchParams = useSearchParams(); const { data: sessionData } = useSession(); + const isAdmin = sessionData?.user?.role === "admin"; const [step, setStep] = useState(1); const [selectedCpId, setSelectedCpId] = useState(null); @@ -234,6 +235,7 @@ function ChargePageContent() { const [startSnapshot, setStartSnapshot] = useState<{ cpId: string; chargePointIdentifier: string; + deviceName: string | null; connectorId: number; idTag: string; } | null>(null); @@ -348,6 +350,7 @@ function ChargePageContent() { setStartSnapshot({ cpId: selectedCp.id, chargePointIdentifier: selectedCp.chargePointIdentifier, + deviceName: selectedCp.deviceName, connectorId: selectedConnectorId, idTag: selectedIdTag, }); @@ -424,7 +427,7 @@ function ChargePageContent() {
充电桩 - {startSnapshot?.chargePointIdentifier ?? selectedCp?.chargePointIdentifier} + {startSnapshot?.deviceName ?? startSnapshot?.chargePointIdentifier ?? selectedCp?.deviceName ?? selectedCp?.chargePointIdentifier}
@@ -617,12 +620,17 @@ function ChargePageContent() { : "cursor-pointer border-border bg-surface hover:border-accent/60 hover:bg-accent/5 active:scale-[0.98]", ].join(" ")} > - {/* Top row: identifier + status */} + {/* Top row: name + status */}
- {cp.chargePointIdentifier} + {cp.deviceName ?? cp.chargePointIdentifier} + {isAdmin && cp.deviceName && ( + + {cp.chargePointIdentifier} + + )} {(cp.chargePointVendor || cp.chargePointModel) && ( {[cp.chargePointVendor, cp.chargePointModel] @@ -686,7 +694,7 @@ function ChargePageContent() { 充电桩 - {selectedCp.chargePointIdentifier} + {selectedCp.deviceName ?? selectedCp.chargePointIdentifier}
)} @@ -773,7 +781,7 @@ function ChargePageContent() { 充电桩 - {selectedCp.chargePointIdentifier} + {selectedCp.deviceName ?? selectedCp.chargePointIdentifier}
)} diff --git a/apps/web/app/dashboard/page.tsx b/apps/web/app/dashboard/page.tsx index 42f7418..d0d8933 100644 --- a/apps/web/app/dashboard/page.tsx +++ b/apps/web/app/dashboard/page.tsx @@ -285,7 +285,7 @@ function TrendChart() { // ── RecentTransactions ──────────────────────────────────────────────────── -function RecentTransactions({ txns }: { txns: Transaction[] }) { +function RecentTransactions({ txns, isAdmin = false }: { txns: Transaction[]; isAdmin?: boolean }) { if (txns.length === 0) { return
暂无充电记录
; } @@ -312,10 +312,15 @@ function RecentTransactions({ txns }: { txns: Transaction[] }) {

- {tx.chargePointIdentifier ?? "—"} + {tx.chargePointDeviceName ?? tx.chargePointIdentifier ?? "—"} {tx.connectorNumber != null && ( #{tx.connectorNumber} )} + {isAdmin && tx.chargePointDeviceName && tx.chargePointIdentifier && ( + + ({tx.chargePointIdentifier}) + + )}

{tx.idTag} @@ -347,7 +352,7 @@ function RecentTransactions({ txns }: { txns: Transaction[] }) { // ── ChargePointStatus ───────────────────────────────────────────────────── -function ChargePointStatus({ cps }: { cps: ChargePoint[] }) { +function ChargePointStatus({ cps, isAdmin }: { cps: ChargePoint[]; isAdmin: boolean }) { if (cps.length === 0) { return

暂无充电桩
; } @@ -369,11 +374,16 @@ function ChargePointStatus({ cps }: { cps: ChargePoint[] }) { />

- {cp.chargePointIdentifier} -

-

- {cp.chargePointModel ?? cp.chargePointVendor ?? "未知型号"} + {cp.deviceName ?? cp.chargePointIdentifier}

+ {isAdmin && cp.deviceName && ( +

{cp.chargePointIdentifier}

+ )} + {!(isAdmin && cp.deviceName) && ( +

+ {cp.chargePointModel ?? cp.chargePointVendor ?? "未知型号"} +

+ )}
{online ? ( @@ -563,12 +573,12 @@ export default function DashboardPage() {
- +
- +
diff --git a/apps/web/app/dashboard/topology/topology-flow.tsx b/apps/web/app/dashboard/topology/topology-flow.tsx index 2c4f98c..53b31ce 100644 --- a/apps/web/app/dashboard/topology/topology-flow.tsx +++ b/apps/web/app/dashboard/topology/topology-flow.tsx @@ -17,6 +17,7 @@ import { } from "@xyflow/react"; import "@xyflow/react/dist/style.css"; import { api, type ChargePoint, type ConnectorSummary } from "@/lib/api"; +import { useSession } from "@/lib/auth-client"; import dayjs from "@/lib/dayjs"; import { Clock, EvCharger, Plug, Zap } from "lucide-react"; @@ -101,10 +102,10 @@ function CsmsHubNode({ data }: NodeProps) { // ── Charge Point Node ───────────────────────────────────────────────────── -type ChargePointNodeData = { cp: ChargePoint; status: ConnectionStatus }; +type ChargePointNodeData = { cp: ChargePoint; status: ConnectionStatus; isAdmin: boolean }; function ChargePointNode({ data }: NodeProps) { - const { cp, status } = data as ChargePointNodeData; + const { cp, status, isAdmin } = data as ChargePointNodeData; const cfg = STATUS_CONFIG[status]; const hbText = cp.lastHeartbeatAt ? dayjs(cp.lastHeartbeatAt).fromNow() : "从未"; @@ -123,9 +124,14 @@ function ChargePointNode({ data }: NodeProps) {
- - {cp.chargePointIdentifier} - +
+ + {cp.deviceName ?? cp.chargePointIdentifier} + + {isAdmin && cp.deviceName && ( + {cp.chargePointIdentifier} + )} +
buildGraph(chargePoints, connectedIds), - [chargePoints, connectedIds], + () => buildGraph(chargePoints, connectedIds, isAdmin), + [chargePoints, connectedIds, isAdmin], ); if (isLoading) { diff --git a/apps/web/app/dashboard/transactions/[id]/page.tsx b/apps/web/app/dashboard/transactions/[id]/page.tsx index 5ebde04..cfaa8b7 100644 --- a/apps/web/app/dashboard/transactions/[id]/page.tsx +++ b/apps/web/app/dashboard/transactions/[id]/page.tsx @@ -362,9 +362,14 @@ export default function TransactionDetailPage({ params }: { params: Promise<{ id
{tx.idTag}
-
桩编号
-
- {tx.chargePointIdentifier ?? "—"} +
充电桩
+
+
+ {tx.chargePointDeviceName ?? tx.chargePointIdentifier ?? "—"} + {isAdmin && tx.chargePointDeviceName && tx.chargePointIdentifier && ( + {tx.chargePointIdentifier} + )} +
diff --git a/apps/web/app/dashboard/transactions/page.tsx b/apps/web/app/dashboard/transactions/page.tsx index 8f41217..0b19e39 100644 --- a/apps/web/app/dashboard/transactions/page.tsx +++ b/apps/web/app/dashboard/transactions/page.tsx @@ -188,7 +188,14 @@ function TransactionsPageContent() { {tx.id} - {tx.chargePointIdentifier ?? "—"} + +
+ {tx.chargePointDeviceName ?? tx.chargePointIdentifier ?? "—"} + {isAdmin && tx.chargePointDeviceName && tx.chargePointIdentifier && ( + {tx.chargePointIdentifier} + )} +
+
{tx.connectorNumber ?? "—"} {tx.idTag} diff --git a/apps/web/lib/api.ts b/apps/web/lib/api.ts index a273ada..e7e8001 100644 --- a/apps/web/lib/api.ts +++ b/apps/web/lib/api.ts @@ -75,6 +75,7 @@ export type ConnectionsStatus = { export type ChargePoint = { id: string; chargePointIdentifier: string; + deviceName: string | null; chargePointVendor: string | null; chargePointModel: string | null; registrationStatus: string; @@ -90,6 +91,7 @@ export type ChargePoint = { export type ChargePointDetail = { id: string; chargePointIdentifier: string; + deviceName: string | null; chargePointVendor: string | null; chargePointModel: string | null; chargePointSerialNumber: string | null; @@ -114,6 +116,7 @@ export type ChargePointDetail = { export type Transaction = { id: number; chargePointIdentifier: string | null; + chargePointDeviceName: string | null; connectorNumber: number | null; idTag: string; idTagStatus: string | null; @@ -216,6 +219,7 @@ export const api = { registrationStatus?: "Accepted" | "Pending" | "Rejected"; feePerKwh?: number; pricingMode?: "fixed" | "tou"; + deviceName?: string; }) => apiFetch("/api/charge-points", { method: "POST", @@ -229,6 +233,7 @@ export const api = { registrationStatus?: "Accepted" | "Pending" | "Rejected"; chargePointVendor?: string; chargePointModel?: string; + deviceName?: string | null; }, ) => apiFetch(`/api/charge-points/${id}`, {