Add history tracking to Line model and update CLI actions
Introduces a 'history' column to the Line model and database, storing line history as a JSON string. Updates line_connection service to persist history and extends Redis cleanup to 96 hours. Refactors BottomToolBar and ButtonAction components to use selectedLines for CLI actions and adjusts command sequences.
This commit is contained in:
parent
ffad475c2b
commit
997e9b2a1b
|
|
@ -51,4 +51,7 @@ export default class Line extends BaseModel {
|
|||
|
||||
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
||||
declare updatedAt: DateTime
|
||||
|
||||
@column()
|
||||
declare history: string
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in New Issue