diff --git a/BACKEND/app/models/line.ts b/BACKEND/app/models/line.ts index 50a66bc..a1ac256 100644 --- a/BACKEND/app/models/line.ts +++ b/BACKEND/app/models/line.ts @@ -51,4 +51,7 @@ export default class Line extends BaseModel { @column.dateTime({ autoCreate: true, autoUpdate: true }) declare updatedAt: DateTime + + @column() + declare history: string } diff --git a/BACKEND/app/services/line_connection.ts b/BACKEND/app/services/line_connection.ts index 00573a2..6fdc6e3 100644 --- a/BACKEND/app/services/line_connection.ts +++ b/BACKEND/app/services/line_connection.ts @@ -15,6 +15,7 @@ import APCController from './apc_connection.js' import path from 'node:path' import axios from 'axios' import redis from '@adonisjs/redis/services/main' +import Line from '#models/line' type Inventory = { pid: string @@ -196,7 +197,7 @@ export default class LineConnection { if (resolvedOrRejected) return resolvedOrRejected = true console.error(`❌ Error line ${lineNumber}:`, err.message) - this.config.output += err.message + this.config.output += '\r\n' + err.message + '\r\n' this.socketIO.emit('line_error', { stationId, lineId: id, @@ -707,7 +708,7 @@ export default class LineConnection { (Tóm tắt trạng thái tổng thể của hệ thống trong 2–4 ý) issue: - (Tóm tắt cực ngắn gọn các lỗi/dấu hiệu bất thường, mỗi vấn đề 1 dòng, bỏ qua các vấn đề không quan trọng như về port changed state to up/down hay Invalid input, Incomplete command) + (Tóm tắt cực ngắn gọn các lỗi/dấu hiệu bất thường, mỗi vấn đề 1 dòng, không bắt các vấn đề không quan trọng như về port changed state to up/down hay Invalid input, Incomplete command) Quy tắc: Không giải thích dài dòng. @@ -759,11 +760,19 @@ export default class LineConnection { } } + const line = await Line.find(lineId) + if (line) { + const listHistory = line.history ? JSON.parse(line.history) : [] + listHistory.unshift(newItem) + line.history = JSON.stringify(listHistory) + await line.save() + } + // Add vào ZSET await redis.zadd(key, now, newItem) - // Tự động xóa item > 72h - const expireTime = now - 72 * 60 * 60 * 1000 + // Tự động xóa item > 96h + const expireTime = now - 96 * 60 * 60 * 1000 await redis.zremrangebyscore(key, 0, expireTime) return true diff --git a/BACKEND/database/migrations/1764657444023_update_history_to_lines_table.ts b/BACKEND/database/migrations/1764657444023_update_history_to_lines_table.ts new file mode 100644 index 0000000..c9eca36 --- /dev/null +++ b/BACKEND/database/migrations/1764657444023_update_history_to_lines_table.ts @@ -0,0 +1,17 @@ +import { BaseSchema } from '@adonisjs/lucid/schema' + +export default class extends BaseSchema { + protected tableName = 'lines' + + async up() { + this.schema.alterTable(this.tableName, (table) => { + table.text('history').defaultTo('').nullable() + }) + } + + async down() { + this.schema.alterTable(this.tableName, (table) => { + table.dropColumn('history') + }) + } +} diff --git a/FRONTEND/src/components/BottomToolBar.tsx b/FRONTEND/src/components/BottomToolBar.tsx index 4b05a2b..583c4a7 100644 --- a/FRONTEND/src/components/BottomToolBar.tsx +++ b/FRONTEND/src/components/BottomToolBar.tsx @@ -623,12 +623,7 @@ const BottomToolBar = ({ className={classes.buttonControl} variant="outline" onClick={() => { - const lines = station.lines.filter( - (line) => - !line?.userOpenCLI || - line?.userOpenCLI === user?.userName - ); - lines.forEach((line) => { + selectedLines.forEach((line) => { socket?.emit("close_cli", { lineId: line?.id, stationId: line.stationId || line.station_id, @@ -745,7 +740,7 @@ const BottomToolBar = ({ }); }); } else { - lines.forEach((line) => { + selectedLines.forEach((line) => { socket?.emit("close_cli", { lineId: line?.id, stationId: line.stationId || line.station_id, diff --git a/FRONTEND/src/components/ButtonAction.tsx b/FRONTEND/src/components/ButtonAction.tsx index 4f1ef1d..c0cb05c 100644 --- a/FRONTEND/src/components/ButtonAction.tsx +++ b/FRONTEND/src/components/ButtonAction.tsx @@ -37,6 +37,27 @@ export const ButtonDPELP = ({ onClick(); selectedLines?.forEach((el) => { const body = [ + { + expect: "", + send: "", + delay: "1000", + repeat: "1", + note: "", + }, + { + expect: "", + send: " no", + delay: "1000", + repeat: "1", + note: "", + }, + { + expect: "", + send: "", + delay: "1000", + repeat: "2", + note: "", + }, { expect: "", send: " terminal length 0",