From 1c40b6aa8207732bb34ce9d345b9c12fab064f41 Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Thu, 25 Sep 2025 12:28:45 -0500 Subject: [PATCH] feat(lstv2): added zechetti stuff in so we can print :D --- .../zechettis}/plcController.ts | 68 +++++++++---------- .../zechettis/zechettiConnect.ts | 8 ++- lstV2/server/services/ocp/ocpService.ts | 2 +- .../sqlServer/querys/ocp/mainMaterial.ts | 33 +++++++-- 4 files changed, 66 insertions(+), 45 deletions(-) rename lstV2/server/services/ocp/{utils => controller/specialProcesses/zechettis}/plcController.ts (66%) diff --git a/lstV2/server/services/ocp/utils/plcController.ts b/lstV2/server/services/ocp/controller/specialProcesses/zechettis/plcController.ts similarity index 66% rename from lstV2/server/services/ocp/utils/plcController.ts rename to lstV2/server/services/ocp/controller/specialProcesses/zechettis/plcController.ts index 97c3f1a..cf4e85e 100644 --- a/lstV2/server/services/ocp/utils/plcController.ts +++ b/lstV2/server/services/ocp/controller/specialProcesses/zechettis/plcController.ts @@ -1,11 +1,6 @@ import { ControllerManager } from "st-ethernet-ip"; -import { getMac } from "./getMachineId.js"; -import { format } from "date-fns-tz"; -import { tryCatch } from "../../../globalUtils/tryCatch.js"; - -import { getCurrentLabel } from "../../sqlServer/querys/ocp/getLabel.js"; -import { query } from "../../sqlServer/prodSqlServer.js"; -import { createLog } from "../../logger/logger.js"; +import { getMac } from "../../../utils/getMachineId.js"; +import { labelingProcess } from "../../labeling/labelProcess.js"; export const createPlcMonitor = (config: any) => { let cm: any; @@ -77,34 +72,39 @@ export const createPlcMonitor = (config: any) => { setTimeout(async () => { if (tag.value === 0) return; const macId = await getMac(tag.value); - console.log(macId); - const { data, error } = (await tryCatch( - query( - getCurrentLabel - .replace( - "[macId]", - macId[0]?.HumanReadableId - ) - .replace( - "[time]", - format(time, "yyyy-MM-dd HH:mm") - ), - "Current label data" - ) - )) as any; + // const { data, error } = (await tryCatch( + // query( + // getCurrentLabel + // .replace( + // "[macId]", + // macId[0]?.HumanReadableId + // ) + // .replace( + // "[time]", + // format(time, "yyyy-MM-dd HH:mm") + // ), + // "Current label data" + // ) + // )) as any; - createLog( - "info", - "zechettii", - "zechettii", - `${format(time, "yyyy-MM-dd HH:mm")} [${cfg.id}] ${ - tag.name - }: ${prevVal} -> ${ - tag.value - }, the running number is ${ - error ? null : data.data[0]?.LfdNr - }}` - ); + // createLog( + // "info", + // "zechettii", + // "zechettii", + // `${format(time, "yyyy-MM-dd HH:mm")} [${cfg.id}] ${ + // tag.name + // }: ${prevVal} -> ${ + // tag.value + // }, the running number is ${ + // error ? null : data.data[0]?.LfdNr + // }}` + // ); + const zechette = { + line: tag.value.toString(), + printer: cfg.printerId, // this is the id of the zechetti 2 to print we should move this to the db + printerName: cfg.id, + }; + labelingProcess({ zechette: zechette }); }, 1000); } }); diff --git a/lstV2/server/services/ocp/controller/specialProcesses/zechettis/zechettiConnect.ts b/lstV2/server/services/ocp/controller/specialProcesses/zechettis/zechettiConnect.ts index aa59cdc..8651e99 100644 --- a/lstV2/server/services/ocp/controller/specialProcesses/zechettis/zechettiConnect.ts +++ b/lstV2/server/services/ocp/controller/specialProcesses/zechettis/zechettiConnect.ts @@ -1,20 +1,22 @@ -import { createPlcMonitor } from "../../../utils/plcController.js"; +import { createPlcMonitor } from "./plcController.js"; export const zechettiConnect = () => { const config: any = { controllers: [ { - id: "Z1", + id: "Zecchetti_1", ip: "192.168.193.97", slot: 0, rpi: 250, + printerId: 22, // grabbed from 2.0 tags: ["N7[0]"], }, { - id: "Z2", + id: "Zecchetti_2", ip: "192.168.193.111", slot: 0, rpi: 100, + printerId: 23, tags: ["N8[0]"], }, ], diff --git a/lstV2/server/services/ocp/ocpService.ts b/lstV2/server/services/ocp/ocpService.ts index 0ac1c48..a250e52 100644 --- a/lstV2/server/services/ocp/ocpService.ts +++ b/lstV2/server/services/ocp/ocpService.ts @@ -25,7 +25,7 @@ import labelRatio from "./routes/labeling/getLabelRatio.js"; import resetRatio from "./routes/labeling/resetLabelRatio.js"; import materialTransferLot from "./routes/materials/lotTransfer.js"; import pendingTransfers from "./routes/materials/currentPending.js"; -import { createPlcMonitor } from "./utils/plcController.js"; +import { createPlcMonitor } from "./controller/specialProcesses/zechettis/plcController.js"; import { zechettiConnect } from "./controller/specialProcesses/zechettis/zechettiConnect.js"; const app = new OpenAPIHono(); diff --git a/lstV2/server/services/sqlServer/querys/ocp/mainMaterial.ts b/lstV2/server/services/sqlServer/querys/ocp/mainMaterial.ts index 13e5476..1679a89 100644 --- a/lstV2/server/services/sqlServer/querys/ocp/mainMaterial.ts +++ b/lstV2/server/services/sqlServer/querys/ocp/mainMaterial.ts @@ -55,13 +55,32 @@ MaterialHumanReadableId ,case when cp.Pieces >= 0.001 then (lot.TotalProducedLoadingUnits+1) * cp.Pieces else (a.Weight *((case when cp.Percentage is null then 80 else cp.Percentage end) / 100) * ((lot.TotalProducedLoadingUnits+1) * p.LoadingUnitPieces)) / 1000 end totalNeeded - ,case when IsMainMaterial = 1 then - case when (case when x.ProvidedAmount <> 0 - then x.ProvidedAmount else x.EffectiveConsumption end) > - (case when cp.Pieces >= 0.001 then (lot.TotalProducedQuantity+1) * cp.Pieces else - (a.Weight *((case when cp.Percentage is null then 80 else cp.Percentage end) / 100) * ((lot.TotalProducedLoadingUnits+1) * p.LoadingUnitPieces)) / 1000 end) - then 'mmGood' - else 'noMM' end else null end as noMMShortage + ,CASE + WHEN IsMainMaterial = 1 THEN + CASE + WHEN + (CASE + WHEN x.ProvidedAmount > 0 + THEN x.ProvidedAmount + ELSE x.EffectiveConsumption + END) + > + (CASE + WHEN cp.Pieces >= 0.001 + THEN (lot.TotalProducedQuantity + 1) * cp.Pieces + ELSE + (a.Weight * + (CASE + WHEN cp.Percentage IS NULL THEN 80 + ELSE cp.Percentage + END) / 100 + ) * (lot.TotalProducedQuantity + 1) / 1000 + END) + THEN 'mmGood' + ELSE 'noMM' + END + ELSE NULL + END AS noMMShortage -- pkg check auto ,case when pkg.QuantityPosition is null then null else