Update link ip and dns, update view AI

This commit is contained in:
andrew.ng 2026-05-21 16:18:03 +07:00
parent 46f72decd3
commit a356552d5b
3 changed files with 84 additions and 61 deletions

View File

@ -32,7 +32,7 @@ export default class AuthController {
const user = await User.query().where('user_name', userName).first()
if (!user) {
const remoteUrl = process.env.ERP_URL || 'https://stage.nswteam.net'
const remoteUrl = process.env.ERP_URL_AUTH || 'https://stage.nswteam.net'
const remoteResp = await axios.post(remoteUrl + '/api/login', {
userEmail: userName,
password: password,

View File

@ -924,7 +924,7 @@ export default class LineConnection {
},
],
}
const remoteUrl = process.env.ERP_URL || 'https://stage.nswteam.net'
const remoteUrl = process.env.ERP_URL_AUTH || 'https://stage.nswteam.net'
const remoteResp = await axios.post(
remoteUrl + '/api/transferPostData',
{
@ -937,7 +937,6 @@ export default class LineConnection {
},
}
)
console.log('AI detect log response:', remoteResp.data)
return remoteResp.data?.Status === 'OK' ? remoteResp.data?.data : ''
} catch (error: any) {
console.log('[ERROR] Detect log from AI', error)
@ -1059,7 +1058,7 @@ export default class LineConnection {
await sendMessageToMail(
`[ATC] - [${this.config.stationName} - Line: ${this.config.lineNumber}] - Raw log issue ${result?.errors?.some((e) => e.category === 'SPECIAL_KEYWORD') ? '+ Special keywords' : ''}`,
tableHTML +
`${`
`${`
<hr />
<p>Logs:</p>
<div style="white-space: break-spaces; background-color: #f5f5f5; color: black; padding: 8px; max-height: 500px; overflow-y: scroll; border: 1px #ccc solid;"><span style="color: black;">
@ -1100,9 +1099,9 @@ export default class LineConnection {
<td style="padding:6px; text-align:center;">${r.rule}</td>
<td style="padding:6px; text-align:center;">${r.message}</td>
<td style="padding:6px; font-family:monospace;">${escapeHtml(r.log.trim())
.split('*')
.filter((el) => el)
.join('<br/>*')}</td>
.split('*')
.filter((el) => el)
.join('<br/>*')}</td>
</tr>
`
)
@ -1479,7 +1478,7 @@ Ports Missing/Down: ${missing.length}\n\n`
await sendMessageToMail(
`[ATC] - [${this.config.stationName} - Line: ${this.config.lineNumber}] - Load IOS Report`,
body +
`${`
`${`
<hr />
<p>Logs:</p>
<div style="white-space: break-spaces; background-color: #f5f5f5; color: black; padding: 8px; max-height: 500px; overflow-y: scroll; border: 1px #ccc solid;"><span style="color: black;">
@ -1517,7 +1516,7 @@ Ports Missing/Down: ${missing.length}\n\n`
await sendMessageToMail(
`[ATC] - [${this.config.stationName} - Line: ${this.config.lineNumber}] - Load License Report`,
body +
`${`
`${`
<hr />
<p>Logs:</p>
<div style="white-space: break-spaces; background-color: #f5f5f5; color: black; padding: 8px; max-height: 500px; overflow-y: scroll; border: 1px #ccc solid;"><span style="color: black;">
@ -1767,7 +1766,7 @@ Ports Missing/Down: ${missing.length}\n\n`
},
],
}
const remoteUrl = process.env.ERP_URL || 'https://stage.nswteam.net'
const remoteUrl = process.env.ERP_URL_AUTH || 'https://stage.nswteam.net'
const remoteResp = await axios.post(
remoteUrl + '/api/transferPostData',
{
@ -1806,15 +1805,15 @@ Ports Missing/Down: ${missing.length}\n\n`
<hr />
<div style="white-space: break-spaces; background-color: #f5f5f5; color: black; padding: 8px; max-height: 500px; overflow-y: scroll; border: 1px #ccc solid;"><span style="color: black;">
${escapeHtml(output)
.replace('show ver', '')
.replace('sh ver', '')
.replace('show version', '')
.replace('sh version', '')
.replace(mem, `<span style="color: ${isWarningRAM ? 'red' : 'black'};">${mem}</span>`)
.replace(
flash,
`<span style="color: ${isWarningFlash ? 'red' : 'black'};">${flash}</span>`
)}</span></div>
.replace('show ver', '')
.replace('sh ver', '')
.replace('show version', '')
.replace('sh version', '')
.replace(mem, `<span style="color: ${isWarningRAM ? 'red' : 'black'};">${mem}</span>`)
.replace(
flash,
`<span style="color: ${isWarningFlash ? 'red' : 'black'};">${flash}</span>`
)}</span></div>
`
await sendMessageToMail(subject, body)
}
@ -1891,37 +1890,34 @@ Ports Missing/Down: ${missing.length}\n\n`
IOS: <b>${dataShowVersion?.SOFTWARE_IMAGE ?? ''}</b> <b>${dataShowVersion?.VERSION ?? ''}</b><br/>
MEM: <b>${dataShowVersion?.MEMORY ? convertFromKilobytesString(dataShowVersion?.MEMORY) : ''}</b><br/>
FLASH: <b>${dataShowVersion?.USB_FLASH ? convertFromKilobytesString(dataShowVersion?.USB_FLASH) : ''}</b><br/>
Licenses: <b>${
dataShowLic
? dataShowLic
?.filter((el) => el.LICENSE_TYPE?.toLowerCase()?.includes('permanent'))
?.map((v) => v.FEATURE)
?.join(', ')
: ''
}</b><br/>
Licenses: <b>${dataShowLic
? dataShowLic
?.filter((el) => el.LICENSE_TYPE?.toLowerCase()?.includes('permanent'))
?.map((v) => v.FEATURE)
?.join(', ')
: ''
}</b><br/>
Detect from AI: <b style="color: 'black';">${issue?.length ? `<br>- ` + issue.join(`<br>`) : 'No issues detected.'}</b><br/>
</td>
<td>
Total Ports: ${portPhysical?.length}<br/>
Ports Tested (Link UP): <b style="color: #008000;">${tested.length} (${testedPoE?.length} PoE, ${testedSFP?.length} SFP)</b><br/>
Ports Missing/Down: <b style="color: #ff0000;">${missing.length}</b><br/>
${
missingPoE?.length
? `
${missingPoE?.length
? `
<br/><b style="color: #ff0000;">Ports Missing PoE</b><br/>
<br/>
<div style="column-count: 6;">${missingPoE.map((p) => physicalTest.normalizePortName(p.name)).join('<br/>')}</div>
`
: ''
}
${
missingSFP?.length
? `
: ''
}
${missingSFP?.length
? `
<br/><b style="color: #ff0000;">Ports Missing SFP</b><br/>
<br/>
<div style="column-count: 6;">${missingSFP.map((p) => physicalTest.normalizePortName(p.name)).join('<br/>')}</div>`
: ''
}
: ''
}
${reasonSkipPhysical}
</td>
</tr>
@ -2059,25 +2055,27 @@ Ports Missing/Down: ${missing.length}\n\n`
// AI issue rows (one per real AI issue, fall back to file's hardcoded row when none)
const aiIssueRowsHtml =
issues.length > 0
? issues
? issues.length > 1
? issues
.slice(0, 1)
.map(
(issue) =>
`<table cellpadding="0" cellspacing="0" border="0" width="100%" style="background:#f5f3ff;border:1px solid #c4b5fd;border-radius:6px;margin-bottom:5px;border-collapse:separate;"><tr><td style="padding:7px 12px;font-size:12px;color:#5f6978;font-weight:500;"><span style="display:inline-block;background:#7c3aed;color:#fff;font-size:9px;font-weight:700;letter-spacing:.5px;padding:2px 6px;border-radius:4px;vertical-align:middle;">&#9733; AI</span><span style="margin-left:8px;vertical-align:middle;">${escapeHtml(issue)}</span></td><td align="right" style="padding:7px 12px;width:90px;"></td></tr></table>`
)
.join('')
: `<table cellpadding="0" cellspacing="0" border="0" width="100%" style="background:#f5f3ff;border:1px solid #c4b5fd;border-radius:6px;margin-bottom:5px;border-collapse:separate;"><tr><td style="padding:7px 12px;font-size:12px;color:#5f6978;font-weight:500;"><span style="display:inline-block;background:#7c3aed;color:#fff;font-size:9px;font-weight:700;letter-spacing:.5px;padding:2px 6px;border-radius:4px;vertical-align:middle;">&#9733; AI</span><span style="margin-left:8px;vertical-align:middle;">${escapeHtml(issues[0].split('\n')[0] || '')}</span></td><td align="right" style="padding:7px 12px;width:90px;"></td></tr></table>`
: ``
// License boxes (real licenses if available, else file's hardcoded boxes)
const licenseBoxesHtml =
dataShowLic && dataShowLic.length > 0
? dataShowLic
.filter((l) => l.LICENSE_TYPE && l.FEATURE)
.map(
(l: any) =>
`<div style="background:#f9fafb;border:1px solid #f0f1f3;border-radius:6px;padding:8px 12px;margin-bottom:6px;"><div style="font-weight:700;color:#3b82f6;font-size:13px;">${escapeHtml(String(l.FEATURE || ''))}</div><div style="font-size:10px;color:#9ca3af;">${escapeHtml(String(l.LICENSE_TYPE || ''))}${l.STATUS ? ' · ' + escapeHtml(String(l.STATUS)) : ''}</div></div>`
)
.join('')
.filter((l) => l.LICENSE_TYPE && l.FEATURE)
.map(
(l: any) =>
`<div style="background:#f9fafb;border:1px solid #f0f1f3;border-radius:6px;padding:8px 12px;margin-bottom:6px;"><div style="font-weight:700;color:#3b82f6;font-size:13px;">${escapeHtml(String(l.FEATURE || ''))}</div><div style="font-size:10px;color:#9ca3af;">${escapeHtml(String(l.LICENSE_TYPE || ''))}${l.STATUS ? ' · ' + escapeHtml(String(l.STATUS)) : ''}</div></div>`
)
.join('')
: ``
// Port stat values (real numbers if any port data, else file's defaults)
@ -2152,7 +2150,7 @@ Ports Missing/Down: ${missing.length}\n\n`
const image = imageList[idx]
const label = imageLabels[idx]
return image && image.url
? imageCellHtml(process.env.ERP_URL + image.url, label)
? imageCellHtml(process.env.ERP_URL_AUTH + image.url, label)
: photoCellHtml(label)
}
const photoGridRowsHtml = `
@ -2460,14 +2458,13 @@ Ports Missing/Down: ${missing.length}\n\n`
<td width="33%" valign="top" style="padding-right:8px;">
<div style="font-size:10px;font-weight:700;text-transform:uppercase;color:#9ca3af;letter-spacing:.5px;margin-bottom:8px;">Hardware Inventory</div>
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="font-size:11px;">
${
this.config?.inventory?.listInventory
?.map(
(item: any) => `
${this.config?.inventory?.listInventory
?.map(
(item: any) => `
<tr><td style="margin-top:4px;padding:4px 0;border-bottom:1px solid #f0f1f3;font-weight:600;color:#5f6978;">${item.pid}</td><td style="padding:2px 0;border-bottom:1px solid #f0f1f3;font-family:Consolas,monospace;color:#9ca3af;text-align:right;"><a href="#${item.sn}" style="text-decoration: underline;">${item.sn}</a></td></tr>`
)
.join('') || ''
}
)
.join('') || ''
}
</table>
</td>
<td width="33%" valign="top" style="padding:0 4px;">
@ -2483,7 +2480,6 @@ Ports Missing/Down: ${missing.length}\n\n`
</tr>
<tr>
<td width="50%" style="padding:0 3px 0 0;"><table cellpadding="0" cellspacing="0" border="0" width="100%" style="background:#f8fafc;border:1px solid #e2e8f0;border-radius:6px;border-collapse:separate;"><tr><td align="center" style="padding:6px;"><div style="font-weight:800;font-size:14px;color: ${missingSFP.length > 0 || missingPoE.length > 0 ? '#f59e0b' : '#10b981'};">${missingSFP.length > 0 || missingPoE.length > 0 ? 'WARN' : 'PASS'}</div><div style="font-size:9px;font-weight:600;color:#9ca3af;text-transform:uppercase;">PoE+ Test</div></td></tr></table></td>
<td width="50%" style="padding:0 0 0 3px;"><table cellpadding="0" cellspacing="0" border="0" width="100%" style="background:#f8fafc;border:1px solid #e2e8f0;border-radius:6px;border-collapse:separate;"><tr><td align="center" style="padding:6px;"><div style="font-weight:800;font-size:14px;color: ${missingSFP.length > 0 || missingPoE.length > 0 ? '#f59e0b' : '#10b981'};">${totalPoE + totalSFP === 0 ? 100 : Math.round(((totalPoE + totalSFP - (missingPoE.length + missingSFP.length)) / (totalPoE + totalSFP)) * 100)}%</div><div style="font-size:9px;font-weight:600;color:#9ca3af;text-transform:uppercase;">Throughput</div></td></tr></table></td>
</tr>
</table>
${missingDetailsHtml}

View File

@ -681,13 +681,29 @@ export async function updateNoteToERP(sn: string, note: string) {
const header = {
Authorization: 'Bearer ' + process.env.ERP_TOKEN,
}
// const responseDataSN = await axios.post(
// 'https://stage.nswteam.net/api/transferGetData',
// {
// urlAPI: '/api/stock-model-serial/get-list-for-test-log',
// filter: {
// where: {
// _q: 'FOC1425Z3RN',
// },
// orgId: ['5fadc798f070e4b64b53ac9c', '5fadc7b0f070e4b64b53ac9d'],
// },
// },
// {
// headers: header,
// }
// )
const responseDataSN = await axios.get(
remoteUrl + '/api/stock-model-serial/get-list-for-test-log',
{
params: {
filter: {
where: {
_q: 'FOC1425Z3RN',
_q: sn,
},
},
orgId: ['5fadc798f070e4b64b53ac9c', '5fadc7b0f070e4b64b53ac9d'],
@ -716,13 +732,9 @@ export async function updateNoteToERP(sn: string, note: string) {
testNotes: note + (dataSN?.testNotes || ''),
}
// console.log(payload)
await axios.post(
remoteUrl + '/api/stock-model-serial/data-save-for-test-log',
payload,
{
headers: header,
}
)
await axios.post(remoteUrl + '/api/stock-model-serial/data-save-for-test-log', payload, {
headers: header,
})
} catch (error) {
console.log('updateNoteToERP', error)
}
@ -1441,6 +1453,21 @@ export async function getIncomingInfoBySN(sn: string) {
const header = {
Authorization: 'Bearer ' + process.env.ERP_TOKEN,
}
// const responseDataSN = await axios.post(
// 'https://stage.nswteam.net/api/transferGetData',
// {
// urlAPI: '/api/package-po/get-incoming-by-sn',
// filter: {
// where: {
// serialNumber: sn,
// },
// },
// },
// {
// headers: header,
// }
// )
const responseDataSN = await axios.get(
remoteUrl + '/api/package-po/get-incoming-by-sn',
{