feat(csms): 充电桩添加 deviceName 字段,区别于 identifier 用于区分设备

This commit is contained in:
2026-03-16 13:43:46 +08:00
parent 0118dd2e15
commit 654a2a66d9
14 changed files with 2095 additions and 40 deletions

View File

@@ -0,0 +1 @@
ALTER TABLE "charge_point" ADD COLUMN "device_name" varchar(100);

File diff suppressed because it is too large Load Diff

View File

@@ -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
}
]
}

View File

@@ -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),
/**
* 计费模式

View File

@@ -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);

View File

@@ -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