From e7658dd3bd4ddbcddeca22f90f23fb54ebf74b9c Mon Sep 17 00:00:00 2001 From: XuJiacheng Date: Thu, 26 Feb 2026 11:17:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dhotel=5Fid=E8=B6=8A?= =?UTF-8?q?=E7=95=8C=E9=97=AE=E9=A2=98=E5=B9=B6=E6=9B=B4=E6=AD=A3=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在构建数据库行时,添加了对hotel_id的边界检查,确保其值在PostgreSQL smallint类型允许的范围内(-32768 到 32767)。对于超出范围或非数字的值,现将其设置为0以防止数据库插入错误。同时,将package-lock.json中的项目名称从“bls-rcu-action-backend”更正为“bls-onoffline-backend”。 --- bls-onoffline-backend/dist/index.js | 6 ++++- bls-onoffline-backend/package-lock.json | 4 ++-- bls-onoffline-backend/src/processor/index.js | 24 ++++++++++++-------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/bls-onoffline-backend/dist/index.js b/bls-onoffline-backend/dist/index.js index 87f589f..0911b58 100644 --- a/bls-onoffline-backend/dist/index.js +++ b/bls-onoffline-backend/dist/index.js @@ -660,11 +660,15 @@ const buildRowsFromPayload = (rawPayload) => { const mac = normalizeText(payload.MAC) || ""; const deviceId = normalizeText(payload.HostNumber) || ""; const roomId = normalizeText(payload.RoomNumber) || ""; + let hotelId = payload.HotelCode; + if (typeof hotelId !== "number" || Number.isNaN(hotelId) || hotelId < -32768 || hotelId > 32767) { + hotelId = 0; + } const row = { guid: createGuid(), ts_ms: tsMs, write_ts_ms: Date.now(), - hotel_id: payload.HotelCode, + hotel_id: hotelId, mac, device_id: deviceId, room_id: roomId, diff --git a/bls-onoffline-backend/package-lock.json b/bls-onoffline-backend/package-lock.json index 704306b..5288e54 100644 --- a/bls-onoffline-backend/package-lock.json +++ b/bls-onoffline-backend/package-lock.json @@ -1,11 +1,11 @@ { - "name": "bls-rcu-action-backend", + "name": "bls-onoffline-backend", "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "bls-rcu-action-backend", + "name": "bls-onoffline-backend", "version": "1.0.0", "dependencies": { "dotenv": "^16.4.5", diff --git a/bls-onoffline-backend/src/processor/index.js b/bls-onoffline-backend/src/processor/index.js index 1fb6f69..d8d4840 100644 --- a/bls-onoffline-backend/src/processor/index.js +++ b/bls-onoffline-backend/src/processor/index.js @@ -57,11 +57,17 @@ export const buildRowsFromPayload = (rawPayload) => { const deviceId = normalizeText(payload.HostNumber) || ''; const roomId = normalizeText(payload.RoomNumber) || ''; + // Handle hotel_id boundary for PostgreSQL smallint (-32768 to 32767) + let hotelId = payload.HotelCode; + if (typeof hotelId !== 'number' || Number.isNaN(hotelId) || hotelId < -32768 || hotelId > 32767) { + hotelId = 0; + } + const row = { guid: createGuid(), ts_ms: tsMs, write_ts_ms: Date.now(), - hotel_id: payload.HotelCode, + hotel_id: hotelId, mac: mac, device_id: deviceId, room_id: roomId, @@ -90,7 +96,7 @@ export const parseMessageToRows = (message) => { // logger.info('Payload parsed', { payload }); const validationResult = kafkaPayloadSchema.safeParse(payload); - + if (!validationResult.success) { const error = new Error(`Schema Validation Failed: ${JSON.stringify(validationResult.error.errors)}`); error.type = 'VALIDATION_ERROR'; @@ -120,13 +126,13 @@ export const processKafkaMessage = async ({ message, dbManager, config }) => { rowsLength: rows?.length || 0, sampleRow: sample ? { - guid: sample.guid, - ts_ms: sample.ts_ms, - mac: sample.mac, - device_id: sample.device_id, - room_id: sample.room_id, - current_status: sample.current_status - } + guid: sample.guid, + ts_ms: sample.ts_ms, + mac: sample.mac, + device_id: sample.device_id, + room_id: sample.room_id, + current_status: sample.current_status + } : null }; throw error;