fix: 修复hotel_id越界问题并更正项目名称
在构建数据库行时,添加了对hotel_id的边界检查,确保其值在PostgreSQL smallint类型允许的范围内(-32768 到 32767)。对于超出范围或非数字的值,现将其设置为0以防止数据库插入错误。同时,将package-lock.json中的项目名称从“bls-rcu-action-backend”更正为“bls-onoffline-backend”。
This commit is contained in:
6
bls-onoffline-backend/dist/index.js
vendored
6
bls-onoffline-backend/dist/index.js
vendored
@@ -660,11 +660,15 @@ const buildRowsFromPayload = (rawPayload) => {
|
|||||||
const mac = normalizeText(payload.MAC) || "";
|
const mac = normalizeText(payload.MAC) || "";
|
||||||
const deviceId = normalizeText(payload.HostNumber) || "";
|
const deviceId = normalizeText(payload.HostNumber) || "";
|
||||||
const roomId = normalizeText(payload.RoomNumber) || "";
|
const roomId = normalizeText(payload.RoomNumber) || "";
|
||||||
|
let hotelId = payload.HotelCode;
|
||||||
|
if (typeof hotelId !== "number" || Number.isNaN(hotelId) || hotelId < -32768 || hotelId > 32767) {
|
||||||
|
hotelId = 0;
|
||||||
|
}
|
||||||
const row = {
|
const row = {
|
||||||
guid: createGuid(),
|
guid: createGuid(),
|
||||||
ts_ms: tsMs,
|
ts_ms: tsMs,
|
||||||
write_ts_ms: Date.now(),
|
write_ts_ms: Date.now(),
|
||||||
hotel_id: payload.HotelCode,
|
hotel_id: hotelId,
|
||||||
mac,
|
mac,
|
||||||
device_id: deviceId,
|
device_id: deviceId,
|
||||||
room_id: roomId,
|
room_id: roomId,
|
||||||
|
|||||||
4
bls-onoffline-backend/package-lock.json
generated
4
bls-onoffline-backend/package-lock.json
generated
@@ -1,11 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "bls-rcu-action-backend",
|
"name": "bls-onoffline-backend",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "bls-rcu-action-backend",
|
"name": "bls-onoffline-backend",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
|
|||||||
@@ -57,11 +57,17 @@ export const buildRowsFromPayload = (rawPayload) => {
|
|||||||
const deviceId = normalizeText(payload.HostNumber) || '';
|
const deviceId = normalizeText(payload.HostNumber) || '';
|
||||||
const roomId = normalizeText(payload.RoomNumber) || '';
|
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 = {
|
const row = {
|
||||||
guid: createGuid(),
|
guid: createGuid(),
|
||||||
ts_ms: tsMs,
|
ts_ms: tsMs,
|
||||||
write_ts_ms: Date.now(),
|
write_ts_ms: Date.now(),
|
||||||
hotel_id: payload.HotelCode,
|
hotel_id: hotelId,
|
||||||
mac: mac,
|
mac: mac,
|
||||||
device_id: deviceId,
|
device_id: deviceId,
|
||||||
room_id: roomId,
|
room_id: roomId,
|
||||||
@@ -120,13 +126,13 @@ export const processKafkaMessage = async ({ message, dbManager, config }) => {
|
|||||||
rowsLength: rows?.length || 0,
|
rowsLength: rows?.length || 0,
|
||||||
sampleRow: sample
|
sampleRow: sample
|
||||||
? {
|
? {
|
||||||
guid: sample.guid,
|
guid: sample.guid,
|
||||||
ts_ms: sample.ts_ms,
|
ts_ms: sample.ts_ms,
|
||||||
mac: sample.mac,
|
mac: sample.mac,
|
||||||
device_id: sample.device_id,
|
device_id: sample.device_id,
|
||||||
room_id: sample.room_id,
|
room_id: sample.room_id,
|
||||||
current_status: sample.current_status
|
current_status: sample.current_status
|
||||||
}
|
}
|
||||||
: null
|
: null
|
||||||
};
|
};
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
Reference in New Issue
Block a user