Update note sn to erp

This commit is contained in:
nguyentrungthat 2026-03-09 10:05:30 +07:00
parent 5305e64453
commit faf37c7136
3 changed files with 40 additions and 10 deletions

View File

@ -24,7 +24,7 @@ import {
updateNoteToERP,
} from '../ultils/helper.js'
import Scenario from '#models/scenario'
import path, { join } from 'node:path'
import path from 'node:path'
import axios from 'axios'
import redis from '@adonisjs/redis/services/main'
import Line from '#models/line'
@ -33,7 +33,6 @@ import momentTZ from 'moment-timezone'
import { PhysicalPortTest } from './physical_test_service.js'
import Station from '#models/station'
import IosLicenseController from '#controllers/ios_license_controller'
import ConfigRam from '#models/config_ram'
type Inventory = {
pid: string
@ -618,9 +617,9 @@ export default class LineConnection {
// }
if (this.config.latestScenario)
this.config.latestScenario = { ...this.config.latestScenario, detectAI: detectLog }
if (result.sn) {
this.updateNote(result.sn, result)
}
// if (result.sn) {
// this.updateNote(result.sn, result)
// }
}
this.config.data = data
this.socketIO.emit('data_textfsm', {
@ -1088,6 +1087,13 @@ export default class LineConnection {
* Update note of SN to ERP after run DPELP
*/
async updateNote(sn: string, data: DataDPELP) {
const portPhysical = Array.from(this.physicalTest.ports.values())
const missing = portPhysical.filter((p) => !p.tested)
const missingPoE = missing.filter((p) => !p.name.includes('SFP'))
const missingSFP = missing.filter((p) => p.name.includes('SFP'))
const tested = portPhysical.filter((p) => p.tested)
const testedPoE = tested.filter((p) => !p.name.includes('SFP'))
const testedSFP = tested.filter((p) => p.name.includes('SFP'))
const licenses = Array.isArray(data.license)
? [...new Set(data.license)]
: data.license
@ -1095,7 +1101,16 @@ export default class LineConnection {
: []
const timeZone = process.env.TIME_ZONE || 'Australia/Sydney'
const dataFormat = momentTZ().tz(timeZone).format('YYYY/MM/DD, HH:mm')
const note = `-------[ATC]-[${dataFormat}]-------\nLicense: ${licenses.join(', ')}\nSummary: ${data?.summary || ''}\nIssues:\n${data.issues?.length ? `- ` + data.issues.join(`\n- `) : ''}\n\n`
const note = `-------[ATC]-[${dataFormat}]-------
*****[DPELP]*****
License: ${licenses.join(', ')}
Summary: ${data?.summary || ''}
Issues:
${data.issues?.length ? `- ` + data.issues.join(`\n- `) : ''}
*****[Physical]*****
Total Ports: ${portPhysical?.length}
Ports Tested (Link UP): ${tested.length} (${testedPoE?.length} PoE, ${testedSFP?.length} SFP)
Ports Missing/Down: ${missing.length}\n\n`
await updateNoteToERP(sn, note)
}
@ -1103,9 +1118,24 @@ export default class LineConnection {
* Update note of SN to ERP from user input
*/
async updateNoteFromUser(sn: string, note: string, licenses: string[]) {
const portPhysical = Array.from(this.physicalTest.ports.values())
const missing = portPhysical.filter((p) => !p.tested)
const missingPoE = missing.filter((p) => !p.name.includes('SFP'))
const missingSFP = missing.filter((p) => p.name.includes('SFP'))
const tested = portPhysical.filter((p) => p.tested)
const testedPoE = tested.filter((p) => !p.name.includes('SFP'))
const testedSFP = tested.filter((p) => p.name.includes('SFP'))
const timeZone = process.env.TIME_ZONE || 'Australia/Sydney'
const dataFormat = momentTZ().tz(timeZone).format('YYYY/MM/DD, HH:mm')
const data = `-------[ATC]-[${dataFormat}]-------\nLicense: ${licenses.join(', ')}\nIssues:\n${note}\n\n`
const data = `-------[ATC]-[${dataFormat}]-------
*****[DPELP]*****
License: ${licenses.join(', ')}
Issues:
${note}
*****[Physical]*****
Total Ports: ${portPhysical?.length}
Ports Tested (Link UP): ${tested.length} (${testedPoE?.length} PoE, ${testedSFP?.length} SFP)
Ports Missing/Down: ${missing.length}\n\n`
const issueList = note
.split('\n')
.map((line) => (line[0] === '-' ? line.substring(1).trim() : line.trim()))
@ -1816,6 +1846,7 @@ ${log}
</tr>
</table>`
this.updateNote(config?.inventory?.sn, this.dataDPELP as DataDPELP)
await sendMessageToMail(
`[ATC] - [${config.stationName} - Line: ${config.lineNumber}] - Summary of Testing Results`,
body

View File

@ -621,12 +621,11 @@ export class WebSocketIo {
const line = this.lineMap.get(lineId)
if (line && line.config.isReady) {
lineIds.push(lineId)
console.log(lineId, skipTestPorts)
if (skipTestPorts) {
line.config.listFeatureTested = [
...new Set([...line.config.listFeatureTested, 'PHYSICAL']),
]
} else {
} else if (line.config.status === 'connected') {
console.log('Reset list feature tested for line', lineId)
line.resetDPELP()
}

View File

@ -1400,7 +1400,7 @@ const ModalTerminal = ({
<Button
fw={400}
mr={"5px"}
disabled={isDisable || selectedLines.length === 0}
disabled={isDisable}
variant="outline"
color="green"
style={{ height: "30px", width: "100px" }}