create checkIndexSN auto
This commit is contained in:
parent
2069222261
commit
7fc9ce5ae0
|
|
@ -164,7 +164,8 @@ export default class ErpsController {
|
||||||
|
|
||||||
if (arrayLine[i].search("Serial Number") !== -1) {
|
if (arrayLine[i].search("Serial Number") !== -1) {
|
||||||
let PCB_SN = arrayLine[i]
|
let PCB_SN = arrayLine[i]
|
||||||
?.split("Serial Number")[1].split(":")[1]
|
?.split("Serial Number")[1]
|
||||||
|
.split(":")[1]
|
||||||
?.replace("\r", "")
|
?.replace("\r", "")
|
||||||
.trim()
|
.trim()
|
||||||
.replace(/[!@#$%^&*()_+{}\[\]:;<>,.?~\\/]/g, "");
|
.replace(/[!@#$%^&*()_+{}\[\]:;<>,.?~\\/]/g, "");
|
||||||
|
|
@ -222,25 +223,23 @@ export default class ErpsController {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (
|
if (PBID?.length >= 8) {
|
||||||
PBID?.length >= 8
|
let fName = urls[index]
|
||||||
) {
|
?.split("/")
|
||||||
let fName = urls[index]
|
[urls[index]?.split("/")?.length - 1]?.trim();
|
||||||
?.split("/")
|
output.push({
|
||||||
[urls[index]?.split("/")?.length - 1]?.trim();
|
PID: "",
|
||||||
output.push({
|
VID: "",
|
||||||
PID: "",
|
SN: PBID?.search(" ") !== -1 ? PBID?.split(" ")[0] : PBID,
|
||||||
VID: "",
|
line: [i + 1],
|
||||||
SN: PBID?.search(" ") !== -1 ? PBID?.split(" ")[0] : PBID,
|
fileName: fName,
|
||||||
line: [i + 1],
|
warehouse:
|
||||||
fileName: fName,
|
fName.search("-US") !== -1 ||
|
||||||
warehouse:
|
fName.search(".US") !== -1 ||
|
||||||
fName.search("-US") !== -1 ||
|
fName.search("US-") !== -1
|
||||||
fName.search(".US") !== -1 ||
|
? "US"
|
||||||
fName.search("US-") !== -1
|
: "AU",
|
||||||
? "US"
|
});
|
||||||
: "AU",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -262,7 +261,9 @@ export default class ErpsController {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
// console.log(report);
|
// console.log(report);
|
||||||
return report.filter((i) => i.SN !== "" && /^[A-Z0-9-]{5,}$/.test(i.SN)===true);
|
return report.filter(
|
||||||
|
(i) => i.SN !== "" && /^[A-Z0-9-]{5,}$/.test(i.SN) === true
|
||||||
|
);
|
||||||
// }, 15000);
|
// }, 15000);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
response
|
response
|
||||||
|
|
@ -285,9 +286,11 @@ export default class ErpsController {
|
||||||
const { fileName, line, range } = request.all();
|
const { fileName, line, range } = request.all();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await axios.get("http://192.168.5.7:8080/" + fileName);
|
let fName =
|
||||||
|
fileName.search("AUTO") !== -1 ? "AUTOlog/" + fileName : fileName;
|
||||||
|
const res = await axios.get("http://192.168.5.7:8080/" + fName);
|
||||||
const arrayLine = res?.data?.split("\n");
|
const arrayLine = res?.data?.split("\n");
|
||||||
// console.log(arrayLine)
|
|
||||||
if (range >= line) {
|
if (range >= line) {
|
||||||
response.status(200).json({
|
response.status(200).json({
|
||||||
content: arrayLine?.slice(0, line + range)?.join("\n"),
|
content: arrayLine?.slice(0, line + range)?.join("\n"),
|
||||||
|
|
@ -305,9 +308,7 @@ export default class ErpsController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async store({request, response}: HttpContextContract) {
|
public async store({ request, response }: HttpContextContract) {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public async show({}: HttpContextContract) {}
|
public async show({}: HttpContextContract) {}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,168 @@
|
||||||
|
// const axios = require("axios");
|
||||||
|
// import fs from "fs";
|
||||||
|
|
||||||
|
export const checkIndexSN = async (content, beginLine, nameF) => {
|
||||||
|
try {
|
||||||
|
const arrayLine = content.slice(beginLine);
|
||||||
|
|
||||||
|
let output = [];
|
||||||
|
if (arrayLine !== undefined) {
|
||||||
|
for (let i = 0; i < arrayLine.length; i++) {
|
||||||
|
let SN = arrayLine[i]
|
||||||
|
?.split("SN:")[1]
|
||||||
|
?.trim()
|
||||||
|
.replace(/[!@#$%^&*()_+{}\[\]:;<>,.?~\\/]/g, "");
|
||||||
|
if (
|
||||||
|
arrayLine[i].search("PID:") !== -1 &&
|
||||||
|
arrayLine[i].search("SN:") !== -1 &&
|
||||||
|
arrayLine[i].search("%") === -1 &&
|
||||||
|
arrayLine[i]
|
||||||
|
?.split(",")[2]
|
||||||
|
?.split(":")[1]
|
||||||
|
?.replace("\r", "")
|
||||||
|
.trim() !== "" &&
|
||||||
|
SN !== "N/A"
|
||||||
|
) {
|
||||||
|
if (output.some((u) => u.SN === SN)) {
|
||||||
|
output.map((u, index) => {
|
||||||
|
if (u.SN === SN) {
|
||||||
|
output[index].PID =
|
||||||
|
arrayLine[i]?.split("VID:")[0] !== undefined
|
||||||
|
? arrayLine[i]
|
||||||
|
?.split("VID:")[0]
|
||||||
|
?.slice(arrayLine[i]?.split("VID:")[0]?.search("PID"))
|
||||||
|
?.split(":")[1]
|
||||||
|
?.split(",")[0]
|
||||||
|
?.trim()
|
||||||
|
: "";
|
||||||
|
(output[index].VID =
|
||||||
|
arrayLine[i]?.split("SN:")[0] !== undefined
|
||||||
|
? arrayLine[i]
|
||||||
|
?.split("SN:")[0]
|
||||||
|
?.split("VID:")[1]
|
||||||
|
?.split(",")[0]
|
||||||
|
?.trim()
|
||||||
|
: ""),
|
||||||
|
(output[index].line = output[index].line.concat([i + 1]));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
output.push({
|
||||||
|
PID:
|
||||||
|
arrayLine[i]?.split("VID:")[0] !== undefined
|
||||||
|
? arrayLine[i]
|
||||||
|
?.split("VID:")[0]
|
||||||
|
?.slice(arrayLine[i]?.split("VID:")[0]?.search("PID"))
|
||||||
|
?.split(":")[1]
|
||||||
|
?.split(",")[0]
|
||||||
|
?.trim()
|
||||||
|
: "",
|
||||||
|
VID:
|
||||||
|
arrayLine[i]?.split("SN:")[0] !== undefined
|
||||||
|
? arrayLine[i]
|
||||||
|
?.split("SN:")[0]
|
||||||
|
?.split("VID:")[1]
|
||||||
|
?.split(",")[0]
|
||||||
|
?.trim()
|
||||||
|
: "",
|
||||||
|
SN:
|
||||||
|
arrayLine[i].split("SN:")[1] !== undefined
|
||||||
|
? SN.search(" ") !== -1
|
||||||
|
? SN?.split(" ")[0]
|
||||||
|
: SN
|
||||||
|
: "",
|
||||||
|
line: [i + 1],
|
||||||
|
fileName: nameF,
|
||||||
|
warehouse:
|
||||||
|
(nameF.search("-US") !== -1 ||
|
||||||
|
nameF.search(".US") !== -1 ||
|
||||||
|
nameF.search("US-") !== -1) &&
|
||||||
|
nameF.search("AUS") === -1
|
||||||
|
? "US"
|
||||||
|
: "AU",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arrayLine[i].search("Serial Number") !== -1) {
|
||||||
|
let PCB_SN = arrayLine[i]
|
||||||
|
?.split("Serial Number")[1]
|
||||||
|
.split(":")[1]
|
||||||
|
?.replace("\r", "")
|
||||||
|
.trim()
|
||||||
|
.replace(/[!@#$%^&*()_+{}\[\]:;<>,.?~\\/]/g, "");
|
||||||
|
if (
|
||||||
|
//Neu SN da nam trong output
|
||||||
|
output.some((u) => u.SN === PCB_SN)
|
||||||
|
) {
|
||||||
|
output.map((u, index) => {
|
||||||
|
if (u.SN === PCB_SN) {
|
||||||
|
output[index].line = output[index].line.concat([i + 1]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// if (
|
||||||
|
// /^[A-Z0-9-]{5,}$/.test(
|
||||||
|
// PCB_SN
|
||||||
|
// )
|
||||||
|
// ) {
|
||||||
|
|
||||||
|
output.push({
|
||||||
|
PID: "",
|
||||||
|
VID: "",
|
||||||
|
SN: PCB_SN?.search(" ") !== -1 ? PCB_SN?.split(" ")[0] : PCB_SN,
|
||||||
|
line: [i + 1],
|
||||||
|
fileName: nameF,
|
||||||
|
warehouse:
|
||||||
|
(nameF.search("-US") !== -1 ||
|
||||||
|
nameF.search(".US") !== -1 ||
|
||||||
|
nameF.search("US-") !== -1) &&
|
||||||
|
nameF.search("AUS") === -1
|
||||||
|
? "US"
|
||||||
|
: "AU",
|
||||||
|
});
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arrayLine[i].search("Processor board ID") !== -1) {
|
||||||
|
let PBID = arrayLine[i]
|
||||||
|
?.split(" ")
|
||||||
|
[arrayLine[i]?.split(" ").length - 1]?.replace("\r", "")
|
||||||
|
.trim()
|
||||||
|
.replace(/[!@#$%^&*()_+{}\[\]:;<>,.?~\\/]/g, "");
|
||||||
|
if (
|
||||||
|
//Neu SN da nam trong output
|
||||||
|
output.some((u) => u.SN === PBID)
|
||||||
|
) {
|
||||||
|
output.map((u, index) => {
|
||||||
|
if (u.SN === PBID) {
|
||||||
|
output[index].line = output[index].line.concat([i + 1]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (PBID?.length >= 8) {
|
||||||
|
output.push({
|
||||||
|
PID: "",
|
||||||
|
VID: "",
|
||||||
|
SN: PBID?.search(" ") !== -1 ? PBID?.split(" ")[0] : PBID,
|
||||||
|
line: [i + 1],
|
||||||
|
fileName: nameF,
|
||||||
|
warehouse:
|
||||||
|
(nameF.search("-US") !== -1 ||
|
||||||
|
nameF.search(".US") !== -1 ||
|
||||||
|
nameF.search("US-") !== -1) &&
|
||||||
|
nameF.search("AUS") === -1
|
||||||
|
? "US"
|
||||||
|
: "AU",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(output);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Can't connect to log server", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -8,6 +8,7 @@ import KeyValue from "App/Models/KeyValue";
|
||||||
import Database from "@ioc:Adonis/Lucid/Database";
|
import Database from "@ioc:Adonis/Lucid/Database";
|
||||||
import { sendMessToZulip } from "./sendMessToZulip";
|
import { sendMessToZulip } from "./sendMessToZulip";
|
||||||
import { getListLineByItem } from "./getListLineByItem";
|
import { getListLineByItem } from "./getListLineByItem";
|
||||||
|
import { checkIndexSN } from './checkIndexSN';
|
||||||
|
|
||||||
export async function runtimeCheckLogs(folderPath) {
|
export async function runtimeCheckLogs(folderPath) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -127,8 +128,9 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
.toString()
|
.toString()
|
||||||
?.split("\n");
|
?.split("\n");
|
||||||
|
|
||||||
//get all values to check
|
//get index SN and send to ERP
|
||||||
|
|
||||||
|
checkIndexSN(contentFile, lastLine, fileName)
|
||||||
|
|
||||||
//get list item to check
|
//get list item to check
|
||||||
let listKeyValues = allValue.filter(
|
let listKeyValues = allValue.filter(
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,6 @@ export const uploadFileToZulip = async (filename) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error uploading file:", error.message);
|
console.log("Error uploading file:", error.message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue