Update api erp, short log
This commit is contained in:
parent
e9c99814b2
commit
5135f7ba9a
|
|
@ -7,7 +7,7 @@ const remoteUrl = process.env.ERP_URL || 'https://stage.nswteam.net'
|
||||||
|
|
||||||
export default class HealCheckController {
|
export default class HealCheckController {
|
||||||
// GET /health-check
|
// GET /health-check
|
||||||
async check({}: HttpContext) {
|
async check({ }: HttpContext) {
|
||||||
try {
|
try {
|
||||||
const header = {
|
const header = {
|
||||||
Authorization: 'Bearer ' + process.env.ERP_TOKEN,
|
Authorization: 'Bearer ' + process.env.ERP_TOKEN,
|
||||||
|
|
@ -21,21 +21,21 @@ 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',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
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,18 +47,15 @@ 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',
|
id: dataSN?.id,
|
||||||
data: {
|
serialNumberA: dataSN?.serialNumberA,
|
||||||
id: dataSN?.id,
|
productModelId: dataSN?.productModelId,
|
||||||
serialNumberA: dataSN?.serialNumberA,
|
orgId: dataSN?.orgId,
|
||||||
productModelId: dataSN?.productModelId,
|
condition: dataSN?.condition,
|
||||||
orgId: dataSN?.orgId,
|
testNotes: dataSN?.testNotes,
|
||||||
condition: dataSN?.condition,
|
healthCheck: true,
|
||||||
testNotes: dataSN?.testNotes,
|
|
||||||
healthCheck: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: header,
|
headers: header,
|
||||||
|
|
|
||||||
|
|
@ -216,8 +216,8 @@ export function mapToLineFormat(input: InputData) {
|
||||||
const license =
|
const license =
|
||||||
dataLicense?.textfsm && Array.isArray(dataLicense.textfsm)
|
dataLicense?.textfsm && Array.isArray(dataLicense.textfsm)
|
||||||
? dataLicense.textfsm
|
? dataLicense.textfsm
|
||||||
?.filter((el: any) => el.LICENSE_TYPE === 'Permanent')
|
?.filter((el: any) => el.LICENSE_TYPE === 'Permanent')
|
||||||
.map((v: any) => v.FEATURE)
|
.map((v: any) => v.FEATURE)
|
||||||
: ''
|
: ''
|
||||||
|
|
||||||
// // Mode (DPEL / DPELP)
|
// // Mode (DPEL / DPELP)
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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 lý trong môi trường Web (React/Vue/Vanilla)
|
* Hàm in log ra máy in vật lý 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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue