Update note from user

This commit is contained in:
nguyentrungthat 2026-01-20 10:51:51 +07:00
parent ae7050a719
commit e1f8e42112
4 changed files with 89 additions and 9 deletions

View File

@ -1042,6 +1042,28 @@ export default class LineConnection {
await updateNoteToERP(sn, note) await updateNoteToERP(sn, note)
} }
/**
* Update note of SN to ERP from user input
*/
async updateNoteFromUser(sn: string, note: string, licenses: string[]) {
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 issueList = note
.split('\n')
.map((line) => (line[0] === '-' ? line.substring(1).trim() : line.trim()))
const detectAI = this.config?.latestScenario?.detectAI
? { ...this.config.latestScenario.detectAI, issue: issueList }
: { issue: issueList, summary: '', status: [] }
if (this.config.latestScenario) {
this.config.latestScenario = { ...this.config.latestScenario, detectAI }
}
await updateNoteToERP(sn, data)
}
/** /**
* Starting physical test (PoE ports testing) * Starting physical test (PoE ports testing)
*/ */

View File

@ -639,11 +639,17 @@ export async function updateNoteToERP(sn: string, note: string) {
} }
) )
// console.log('updateNoteToERP', responseDataSN?.data?.data)
if (!responseDataSN?.data?.data || responseDataSN?.data?.data?.length === 0) { if (!responseDataSN?.data?.data || responseDataSN?.data?.data?.length === 0) {
console.log('updateNoteToERP', responseDataSN?.data)
return return
} }
const dataSN = responseDataSN?.data?.data[0] || {} const dataSN =
responseDataSN?.data?.data.length === 1
? responseDataSN?.data?.data[0]
: responseDataSN?.data?.data.length > 1
? responseDataSN?.data?.data.find((el: any) => el.serialNumberA === sn)
: {}
if (!dataSN?.id) return
const payload = { const payload = {
id: dataSN?.id, id: dataSN?.id,
@ -664,7 +670,7 @@ export async function updateNoteToERP(sn: string, note: string) {
} }
) )
} catch (error) { } catch (error) {
console.log(error) console.log('updateNoteToERP', error)
} }
} }

View File

@ -812,6 +812,24 @@ export class WebSocketIo {
{} {}
) )
}) })
socket.on('update_note', async (data) => {
console.log('Update note', data)
const { stationId, lineId, note, licenses, sn } = data
// Check station is active
const activeStation = await checkStationActive(stationId)
if (!activeStation) return
await this.handleLineOperation(
io,
stationId,
[lineId],
async (lineCon) => {
lineCon.updateNoteFromUser(sn, note, licenses)
},
{}
)
})
}) })
socketServer.listen(SOCKET_IO_PORT, () => { socketServer.listen(SOCKET_IO_PORT, () => {
@ -830,7 +848,8 @@ export class WebSocketIo {
station: Station, station: Station,
output = '', output = '',
inventory: string = '', inventory: string = '',
latestScenario?: any latestScenario?: any,
data?: any
) { ) {
try { try {
for (const line of lines) { for (const line of lines) {
@ -851,7 +870,7 @@ export class WebSocketIo {
openCLI: false, openCLI: false,
userEmailOpenCLI: '', userEmailOpenCLI: '',
userOpenCLI: '', userOpenCLI: '',
data: [], data: data,
ports: [], ports: [],
inventory: inventory, inventory: inventory,
runningPhysical: false, runningPhysical: false,
@ -941,7 +960,8 @@ export class WebSocketIo {
stationData, stationData,
line?.config?.output || '', line?.config?.output || '',
line?.config?.inventory || '', line?.config?.inventory || '',
line?.config?.latestScenario || undefined line?.config?.latestScenario || undefined,
line?.config?.data || []
) )
this.lineConnecting = this.lineConnecting.filter((el) => el !== lineId) this.lineConnecting = this.lineConnecting.filter((el) => el !== lineId)

View File

@ -824,11 +824,43 @@ const ModalTerminal = ({
</Text> </Text>
</Flex> </Flex>
<Box> <Box>
<Text size="md" mr={"sm"} fw={"bold"}> <Flex justify={"space-between"} align={"center"}>
Warning from test report: AI <Text size="md" mr={"sm"} fw={"bold"}>
</Text> Warning from test report: AI
</Text>
<Button
disabled={isDisable}
size="xs"
mb={"4px"}
variant="light"
onClick={() => {
setIsDisable(true);
setTimeout(() => {
setIsDisable(false);
}, 3000);
socket?.emit("update_note", {
lineId: line?.id,
stationId: stationItem?.id,
note: valueIssue,
sn: line?.inventory?.sn || "",
licenses: findDataShowLicense()
? findDataShowLicense()
?.filter(
(el: TextTSMLicense) =>
el.LICENSE_TYPE === "Permanent"
)
?.map((v: TextTSMLicense) => v.FEATURE)
: [],
});
}}
>
Update note
</Button>
</Flex>
<Box> <Box>
<Textarea <Textarea
disabled={isDisable}
rows={5} rows={5}
size="sm" size="sm"
placeholder="Report from AI" placeholder="Report from AI"