feat(rfid): work on the readers and there functions

This commit is contained in:
2025-03-27 21:08:05 -05:00
parent f9f68ce969
commit b5de6445b3
9 changed files with 275 additions and 134 deletions

View File

@@ -8,6 +8,12 @@ import type { TagData } from "../tagData.js";
import { tagStuff } from "../tags/crudTag.js";
export const station3Tags = async (tagData: TagData[]) => {
createLog(
"info",
"rfid",
"rfid",
`${tagData[0].reader} has a ${tagData[0].tag} will post it :)`
);
// make sure we only have one tag or dont update
if (tagData.length != 1) {
createLog(

View File

@@ -8,28 +8,14 @@ import { labelingProcess } from "../../../ocp/controller/labeling/labelProcess.j
import type { TagData } from "../tagData.js";
import { tagStuff } from "../tags/crudTag.js";
import { sendEmail } from "../../../notifications/controller/sendMail.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { db } from "../../../../../database/dbclient.js";
import { rfidTags } from "../../../../../database/schema/rfidTags.js";
import { eq } from "drizzle-orm";
export const wrapperStuff = async (tagData: TagData[]) => {
if (tagData[0]?.lastareaIn === "NeedsChecked") {
createLog(
"error",
"rfid",
"rfid",
`The tags on this pallet need to be checked as it was flagged as more than 1 tag number. please validate and looks at both sides.`
);
export const wrapperStuff = async (tagData: any) => {
console.log("WrapperTag", tagData[0].tag);
// just making sure we clear out the running number if one really came over.
for (let i = 0; i < tagData.length; i++) {
const tag = { ...tagData[i], runningNr: 0 };
tagStuff([tag]);
}
monitorChecks();
return {
success: false,
message:
"The tags on this pallet need to be checked as it was flagged as more than 1 tag number. please validate and looks at both sides.",
};
}
if (tagData.length != 1) {
createLog(
"error",
@@ -38,39 +24,55 @@ export const wrapperStuff = async (tagData: TagData[]) => {
`There are ${tagData.length} tags and this ${tagData[0].reader} only allows 1 tag to create a label.`
);
const tag = { ...tagData[0], runningNr: 0 };
tagStuff([tag]);
//tagStuff([tag]);
monitorChecks();
} else {
if (!tagData) {
createLog("error", "rfid", "rfid", `No tagData was grabbed.`);
monitorChecks();
}
const tagdata = await tagStuff(tagData);
/**
* we want to make sure this pallet came from a line as its last spot if not we need to have a manual check.
*/
const lines = tagdata[0]?.lastareaIn.includes("line3");
const { data: tagdata, error: tagError } = await tryCatch(
db.select().from(rfidTags).where(eq(rfidTags.tag, tagData[0].tag))
);
if (tagError) {
return {
success: false,
message: `There was an error getting the tag data for ${tagData[0].tag}.`,
};
}
const checkTag: any = tagdata;
if (checkTag[0]?.lastareaIn === "NeedsChecked") {
createLog(
"error",
"rfid",
"rfid",
`The tags on this pallet need to be checked as it was flagged as more than 1 tag number. please validate and looks at both sides.`
);
for (let i = 0; i < tagData.length; i++) {
const tag = { ...tagData[i], runningNr: 0 };
tagStuff([tag]);
}
monitorChecks();
return {
success: false,
message:
"The tags on this pallet need to be checked as it was flagged as more than 1 tag number. please validate and looks at both sides.",
};
}
const lines = checkTag[0]?.lastareaIn.includes("line3");
if (!lines) {
createLog(
"error",
"rfid",
"rfid",
`${tagdata[0].tag}, Did not come from a line please check the pallet and manually print the label.`
`${tagData[0].tag}, Did not come from a line please check the pallet and manually print the label.`
);
monitorChecks();
return {
success: false,
message: `${tagdata[0].tag}, Did not come from a line please check the pallet and manually print the label.`,
message: `${tagData[0].tag}, Did not come from a line please check the pallet and manually print the label.`,
};
// when we manually run again we want to make sure we read from the 3rd antenna this way we do not get the wrong info.
// more testing will need to be done on this.
}
// check if a running number exists
if (lines[0].runningNumber) {
createLog(
"info",
@@ -83,12 +85,10 @@ export const wrapperStuff = async (tagData: TagData[]) => {
"info",
"rfid",
"rfid",
`A new label will be created and linked to this ${tagdata[0].tag} tag`
`A new label will be created and linked to this ${tagData[0].tag} tag`
);
// get the actaul line number from the last area in
const lineNum = parseInt(
tagdata[0]?.lastareaIn.repalceAll("line3", "")
checkTag[0]?.lastareaIn.repalceAll("line3", "")
);
createLog(
"info",
@@ -96,17 +96,16 @@ export const wrapperStuff = async (tagData: TagData[]) => {
"rfid",
`Line to be checked for printing: ${lineNum}`
);
const genlabel = await labelingProcess({
line: lineNum.toString(),
});
if (genlabel?.success) {
// update the tag and add the label into it
const createPrintData = {
...tagData[0],
runnungNr: parseInt(genlabel.data?.SSCC.slice(10, -1)),
};
tagStuff([createPrintData]);
}
}
}