feat(ocp): prodlink check added
This commit is contained in:
68
server/services/ocp/controller/lots/prolinkCheck.ts
Normal file
68
server/services/ocp/controller/lots/prolinkCheck.ts
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
import { db } from "../../../../../database/dbclient.js";
|
||||||
|
import { settings } from "../../../../../database/schema/settings.js";
|
||||||
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
|
import { createLog } from "../../../logger/logger.js";
|
||||||
|
import { query } from "../../../sqlServer/prodSqlServer.js";
|
||||||
|
import { prolinkQuery } from "../../../sqlServer/querys/ocp/prolinkCheck.js";
|
||||||
|
|
||||||
|
// check the if the lot matches
|
||||||
|
export const prolinkCheck = async (lot: any) => {
|
||||||
|
const { data, error: settingError } = await tryCatch(
|
||||||
|
db.select().from(settings)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (settingError) {
|
||||||
|
createLog(
|
||||||
|
"error",
|
||||||
|
"ocp",
|
||||||
|
"ocp",
|
||||||
|
`There was an error getting the settings.`
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const settingData: any = data;
|
||||||
|
const plantToken = settingData.filter(
|
||||||
|
(s: any) => s.name === "plantToken"
|
||||||
|
)[0].value;
|
||||||
|
const prolinkCheck = settingData.filter(
|
||||||
|
(s: any) => s.name === "prolinkCheck"
|
||||||
|
)[0].value;
|
||||||
|
|
||||||
|
// if we want to ignore prolink check it will be disabled and then just return a pass as true
|
||||||
|
if (prolinkCheck === "0") {
|
||||||
|
createLog(
|
||||||
|
"info",
|
||||||
|
"ocp",
|
||||||
|
"ocp",
|
||||||
|
`Prolink Check is disabled skipping check.`
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// run the query
|
||||||
|
try {
|
||||||
|
const prolink = await query(prolinkQuery, "Prolink Checks");
|
||||||
|
|
||||||
|
//console.log(lot);
|
||||||
|
// filter out the lot
|
||||||
|
const filterdLot = prolink.filter(
|
||||||
|
(p: any) => p.AlplaLabelOnline === lot
|
||||||
|
);
|
||||||
|
|
||||||
|
//console.log(filterdLot);
|
||||||
|
if (filterdLot[0].LotCheck === "Good") {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
createLog(
|
||||||
|
"error",
|
||||||
|
"ocp",
|
||||||
|
"ocp",
|
||||||
|
`Error from running the Prolink Check query: ${err}`
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -8,6 +8,7 @@ import { settings } from "../../../database/schema/settings.js";
|
|||||||
import updateprinters from "./routes/printers/updatePrinters.js";
|
import updateprinters from "./routes/printers/updatePrinters.js";
|
||||||
import { updatePrinters } from "./controller/printers/updatePrinters.js";
|
import { updatePrinters } from "./controller/printers/updatePrinters.js";
|
||||||
import getLots from "./routes/lots/getLots.js";
|
import getLots from "./routes/lots/getLots.js";
|
||||||
|
import getLabels from "./routes/labeling/getLabels.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
@@ -18,6 +19,8 @@ const routes = [
|
|||||||
updateprinters,
|
updateprinters,
|
||||||
// lots
|
// lots
|
||||||
getLots,
|
getLots,
|
||||||
|
// labeling
|
||||||
|
getLabels,
|
||||||
] as const;
|
] as const;
|
||||||
const setting = await db.select().from(settings);
|
const setting = await db.select().from(settings);
|
||||||
|
|
||||||
@@ -33,6 +36,8 @@ app.all("/ocp/*", (c) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// run the printer update on restart just to keep everything good
|
// run the printer update on restart just to keep everything good
|
||||||
updatePrinters();
|
setTimeout(() => {
|
||||||
|
updatePrinters();
|
||||||
|
}, 3 * 1000);
|
||||||
|
|
||||||
export default app;
|
export default app;
|
||||||
|
|||||||
25
server/services/sqlServer/querys/ocp/prolinkCheck.ts
Normal file
25
server/services/sqlServer/querys/ocp/prolinkCheck.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
export const prolinkQuery = `
|
||||||
|
select * from (
|
||||||
|
select *
|
||||||
|
From(select
|
||||||
|
V_Maschinen_ProdPlanungen.MaschinenStandort as Machine,
|
||||||
|
V_Maschinen_ProdPlanungen.IdProdPlanung as AlplaLabelOnline,
|
||||||
|
prolink.lot Prolink,
|
||||||
|
case when AlplaPROD_test1.dbo.V_Maschinen_ProdPlanungen.IdProdPlanung <> prolink.lot
|
||||||
|
Then 'IncorrectLot'
|
||||||
|
Else 'Good' end as LotCheck
|
||||||
|
from AlplaPROD_test1.dbo.V_Maschinen_ProdPlanungen (nolock)
|
||||||
|
left join
|
||||||
|
(
|
||||||
|
SELECT *
|
||||||
|
FROM (SELECT IdMaschine,
|
||||||
|
Produktionslos as lot,
|
||||||
|
Startzeit as StartTime,
|
||||||
|
Upd_Date,
|
||||||
|
ROW_NUMBER() OVER (PARTITION BY IdMaschine ORDER BY Upd_Date DESC) RN_Prolink
|
||||||
|
FROM AlplaPROD_test1.dbo.T_HistoryProduktionsdaten (nolock)
|
||||||
|
WHERE Upd_Date BETWEEN DATEADD(DD, - 10, getdate()) AND DATEADD(DD, 1, getdate())) a
|
||||||
|
WHERE RN_Prolink = 1
|
||||||
|
) as prolink on AlplaPROD_test1.dbo.V_Maschinen_ProdPlanungen.IdMaschine=prolink.IdMaschine) a
|
||||||
|
) a
|
||||||
|
`;
|
||||||
Reference in New Issue
Block a user