Update api erp, short log

This commit is contained in:
joseph le 2026-05-20 14:05:53 +07:00
parent e9c99814b2
commit 5135f7ba9a
3 changed files with 63 additions and 64 deletions

View File

@ -21,10 +21,11 @@ export default class HealCheckController {
status: true, status: true,
message: 'Checking api update note SN success', message: 'Checking api update note SN success',
} }
const responseDataSN = await axios.post(
remoteUrl + '/api/transferGetData', const responseDataSN = await axios.get(
remoteUrl + '/api/stock-model-serial/get-list-for-test-log',
{ {
urlAPI: '/api/stock-model-serial/get-list-for-test-log', params: {
filter: { filter: {
where: { where: {
_q: 'FOC1425Z3RN', _q: 'FOC1425Z3RN',
@ -32,10 +33,9 @@ export default class HealCheckController {
}, },
orgId: ['5fadc798f070e4b64b53ac9c', '5fadc7b0f070e4b64b53ac9d'], orgId: ['5fadc798f070e4b64b53ac9c', '5fadc7b0f070e4b64b53ac9d'],
}, },
{
headers: header, headers: header,
} }
) );
if (!responseDataSN?.data?.data || responseDataSN?.data?.data?.length === 0) { if (!responseDataSN?.data?.data || responseDataSN?.data?.data?.length === 0) {
dataCheckNote = { dataCheckNote = {
name: 'update-note-sn', name: 'update-note-sn',
@ -47,10 +47,8 @@ export default class HealCheckController {
// console.log(payload) // console.log(payload)
const resSN = await axios.post( const resSN = await axios.post(
remoteUrl + '/api/transferPostData', remoteUrl + '/api/stock-model-serial/data-save-for-test-log',
{ {
urlAPI: '/api/stock-model-serial/data-save-for-test-log',
data: {
id: dataSN?.id, id: dataSN?.id,
serialNumberA: dataSN?.serialNumberA, serialNumberA: dataSN?.serialNumberA,
productModelId: dataSN?.productModelId, productModelId: dataSN?.productModelId,
@ -59,7 +57,6 @@ export default class HealCheckController {
testNotes: dataSN?.testNotes, testNotes: dataSN?.testNotes,
healthCheck: true, healthCheck: true,
}, },
},
{ {
headers: header, headers: header,
} }

View File

@ -681,21 +681,20 @@ export async function updateNoteToERP(sn: string, note: string) {
const header = { const header = {
Authorization: 'Bearer ' + process.env.ERP_TOKEN, Authorization: 'Bearer ' + process.env.ERP_TOKEN,
} }
const responseDataSN = await axios.post( const responseDataSN = await axios.get(
remoteUrl + '/api/transferGetData', remoteUrl + '/api/stock-model-serial/get-list-for-test-log',
{ {
urlAPI: '/api/stock-model-serial/get-list-for-test-log', params: {
filter: { filter: {
where: { where: {
_q: sn, _q: 'FOC1425Z3RN',
}, },
}, },
orgId: ['5fadc798f070e4b64b53ac9c', '5fadc7b0f070e4b64b53ac9d'], orgId: ['5fadc798f070e4b64b53ac9c', '5fadc7b0f070e4b64b53ac9d'],
}, },
{
headers: header, headers: header,
} }
) );
// console.log('updateNoteToERP', responseDataSN?.data?.data) // console.log('updateNoteToERP', responseDataSN?.data?.data)
if (!responseDataSN?.data?.data || responseDataSN?.data?.data?.length === 0) { if (!responseDataSN?.data?.data || responseDataSN?.data?.data?.length === 0) {
@ -718,11 +717,8 @@ export async function updateNoteToERP(sn: string, note: string) {
} }
// console.log(payload) // console.log(payload)
await axios.post( await axios.post(
remoteUrl + '/api/transferPostData', remoteUrl + '/api/stock-model-serial/data-save-for-test-log',
{ payload,
urlAPI: '/api/stock-model-serial/data-save-for-test-log',
data: payload,
},
{ {
headers: header, headers: header,
} }
@ -1445,20 +1441,19 @@ export async function getIncomingInfoBySN(sn: string) {
const header = { const header = {
Authorization: 'Bearer ' + process.env.ERP_TOKEN, Authorization: 'Bearer ' + process.env.ERP_TOKEN,
} }
const responseDataSN = await axios.post( const responseDataSN = await axios.get(
remoteUrl + '/api/transferGetData', remoteUrl + '/api/package-po/get-incoming-by-sn',
{ {
urlAPI: '/api/package-po/get-incoming-by-sn', params: {
filter: { filter: {
where: { where: {
serialNumber: sn, serialNumber: sn,
}, },
}, },
}, },
{
headers: header, headers: header,
} }
) );
if (!responseDataSN?.data?.data) { if (!responseDataSN?.data?.data) {
return return

View File

@ -249,35 +249,42 @@ export function convertFromKilobytesString(
* @returns {string} Chuỗi log đã đưc rút gọn theo đnh dạng yêu cầu * @returns {string} Chuỗi log đã đưc rút gọn theo đnh dạng yêu cầu
*/ */
export function createShortLog(rawLog: string): string { export function createShortLog(rawLog: string): string {
const shortLog = []; const shortLog: string[] = [];
// 1. Tách show inventory // 1. Tách TOÀN BỘ show inventory bằng vòng lặp Regex
const invRegex = // Sử dụng cờ /gi để quét toàn bộ file tìm các khối NAME + PID kế tiếp
/(NAME:\s*"[^"]*",\s*DESCR:\s*"[^"]*"\r?\nPID:\s*[^,]+,\s*VID:\s*[^,]+,\s*SN:\s*\S+)/i; const invRegex = /(NAME:\s*"[^"]*",\s*DESCR:\s*"[^"]*"\s*PID:\s*[^,]+,\s*VID:\s*[^,]*,\s*SN:[^\r\n]*)/gi;
const invMatch = rawLog.match(invRegex); const invMatches = rawLog.match(invRegex);
if (invMatch) { if (invMatches && invMatches.length > 0) {
shortLog.push(invMatch[1].trim()); // Gom tất cả các module tìm thấy và trim() sạch sẽ khoảng trắng dư thừa
const allModules = invMatches.map(module => module.trim()).join('\n\n');
shortLog.push(allModules);
} }
// 2. Tách show version (Đã fix vụ bỏ phần thừa ở giữa) // 2. Tách show version (Cập nhật để bắt được cả Cisco/cisco và các dòng ISR/Catalyst khác nhau)
const verRegex = // - Group 1: System image file
/(System image file is[^\r\n]+)[\s\S]*?(cisco\s+[a-zA-Z0-9\-]+\s+\([^)]+\)\s+processor[\s\S]*?Configuration register is 0x[0-9a-fA-F]+)/i; // - Nhảy qua đoạn rác (Cryptographic/License info rườm rà)
// - Group 2: Bắt đầu từ chữ Cisco (bất kể hoa thường) + Mã máy + "processor" cho đến hết Config register
const verRegex = /(System image file is[^\r\n]+)[\s\S]*?((?:[Cc]isco)\s+\S+.*processor[\s\S]*?Configuration register is 0x[0-9a-fA-F]+)/i;
const verMatch = rawLog.match(verRegex); const verMatch = rawLog.match(verRegex);
if (verMatch) { if (verMatch) {
shortLog.push(`${verMatch[1].trim()}\n${verMatch[2].trim()}`); // verMatch[1] là dòng System image
// verMatch[2] là đoạn từ "cisco ISR..." hoặc "Cisco CISCO..." đến hết
shortLog.push(`\n${verMatch[1].trim()}\n${verMatch[2].trim()}`);
} }
// 3. Tách show license // 3. Tách show license
const licRegex = // Hỗ trợ cả định dạng cũ (Index 1 Feature) và định dạng Suite mới trên IOS-XE
/(Index\s+1\s+Feature:[\s\S]*?)(?=\r?\n[a-zA-Z0-9\-\_]+[#>]|$)/i; const licRegex = /(Index\s+1\s+Feature:[\s\S]*?)(?=\r?\n[a-zA-Z0-9\-\_]+[#>]|$)/i;
const licMatch = rawLog.match(licRegex); const licMatch = rawLog.match(licRegex);
if (licMatch) { if (licMatch && licMatch[1]) {
shortLog.push("\n" + licMatch[1].trim()); shortLog.push(`\n${licMatch[1].trim()}`);
} }
return shortLog.join("\n"); return shortLog.join('\n');
} }
/** /**
* Hàm in log ra máy in vật trong môi trường Web (React/Vue/Vanilla) * Hàm in log ra máy in vật trong môi trường Web (React/Vue/Vanilla)
* @param shortLog - Chuỗi log đã đưc rút gọn * @param shortLog - Chuỗi log đã đưc rút gọn