From a6cc17ccb12b0d99ffdb1d371c5daf3bbb91f7ba Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Sat, 1 Nov 2025 06:54:28 -0500 Subject: [PATCH] fix(historicalinv): removed the second running one that caused duplicates --- app/src/internal/system/utlis/addListeners.ts | 10 ++ .../services/eom/utils/historicalInv.ts | 4 +- .../logistics/controller/eom/historicalInv.ts | 150 +++++++++--------- .../services/logistics/logisticsService.ts | 111 ++++++------- 4 files changed, 143 insertions(+), 132 deletions(-) diff --git a/app/src/internal/system/utlis/addListeners.ts b/app/src/internal/system/utlis/addListeners.ts index c4b9745..1a28ab6 100644 --- a/app/src/internal/system/utlis/addListeners.ts +++ b/app/src/internal/system/utlis/addListeners.ts @@ -48,4 +48,14 @@ export const addListeners = async () => { } catch (e) { log.info({}, "label listener exists"); } + + try { + log.info({}, "Bad data removing bad history data"); + await client.query(` + DELETE FROM public."invHistoricalData" + WHERE upd_user = 'LST' + `); + } catch (e) { + log.info({}, "Error deleting bad inv data"); + } }; diff --git a/lstV2/server/services/eom/utils/historicalInv.ts b/lstV2/server/services/eom/utils/historicalInv.ts index bb9ea76..e5bbc31 100644 --- a/lstV2/server/services/eom/utils/historicalInv.ts +++ b/lstV2/server/services/eom/utils/historicalInv.ts @@ -96,7 +96,7 @@ export const historicalInvIMmport = async () => { } if (dataImport) { - createLog("info", "eom", "eom", `All data was imported succefully.`); + createLog("info", "eom", "eom", `All data was imported successfully.`); return; } } else { @@ -104,5 +104,5 @@ export const historicalInvIMmport = async () => { } // do the check to delete old data - deleteHistory(); + //deleteHistory(); }; diff --git a/lstV2/server/services/logistics/controller/eom/historicalInv.ts b/lstV2/server/services/logistics/controller/eom/historicalInv.ts index 223927f..70c977a 100644 --- a/lstV2/server/services/logistics/controller/eom/historicalInv.ts +++ b/lstV2/server/services/logistics/controller/eom/historicalInv.ts @@ -1,93 +1,93 @@ +import { format } from "date-fns-tz"; +import { sql } from "drizzle-orm"; import { db } from "../../../../../database/dbclient.js"; +import { invHistoricalData } from "../../../../../database/schema/historicalINV.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 { totalInvNoRn } from "../../../sqlServer/querys/dataMart/totalINV.js"; -import { invHistoricalData } from "../../../../../database/schema/historicalINV.js"; -import { format } from "date-fns-tz"; -import { settings } from "../../../../../database/schema/settings.js"; -import { sql } from "drizzle-orm"; import { createLogisticsJob } from "../../utils/logisticsIntervals.js"; -export const runHistoricalData = async () => { - /** - * Runs a query at shift change on first shift each day this will be the closest date to the true historical data for blocked, consignment - */ +// export const runHistoricalData = async () => { +// /** +// * Runs a query at shift change on first shift each day this will be the closest date to the true historical data for blocked, consignment +// */ - const { data: set, error: setError } = await tryCatch( - db.select().from(settings) - ); +// const { data: set, error: setError } = await tryCatch( +// db.select().from(settings) +// ); - if (setError) { - createLog( - "error", - "lst", - "eom", - "There was an error getting eom historical inv data." - ); - return; - } +// if (setError) { +// createLog( +// "error", +// "lst", +// "eom", +// "There was an error getting eom historical inv data." +// ); +// return; +// } - const timeZone = set.filter((n: any) => n.name === "timezone"); +// const timeZone = set.filter((n: any) => n.name === "timezone"); - createLogisticsJob("histInv", `0 6 * * *`, timeZone[0].value, async () => { - // remove the lotnumber from the query - const updatedQuery = totalInvNoRn.replaceAll( - ",IdProdPlanung", - "--,IdProdPlanung" - ); +// createLogisticsJob("histInv", `0 6 * * *`, timeZone[0].value, async () => { +// // remove the lotnumber from the query +// const updatedQuery = totalInvNoRn.replaceAll( +// ",IdProdPlanung", +// "--,IdProdPlanung" +// ); - const { data: inv, error: invError } = await tryCatch( - query(updatedQuery, "EOM historical inv") - ); +// const { data: inv, error: invError } = await tryCatch( +// query(updatedQuery, "EOM historical inv") +// ); - if (invError) { - createLog( - "error", - "lst", - "eom", - "There was an error getting eom historical inv data." - ); - return; - } +// if (invError) { +// createLog( +// "error", +// "lst", +// "eom", +// "There was an error getting eom historical inv data." +// ); +// return; +// } - /** - * add the inv into the hist table - */ +// /** +// * add the inv into the hist table +// */ - const setting: any = set; +// const setting: any = set; - for (let i = 0; i < inv?.data.length; i++) { - const current = inv?.data[i]; - const { data, error } = await tryCatch( - db.insert(invHistoricalData).values({ - histDate: format(new Date(), "MM-dd-yyyy"), - plantToken: setting.filter( - (n: any) => n.name === "plantToken" - )[0].value, - article: current.av, - articleDescription: current.Alias, - total_QTY: current.Total_PalletQTY, - avaliable_QTY: current.Avaliable_PalletQTY, - coa_QTY: current.COA_QTY, - held_QTY: current.Held_QTY, - consignment: current.Consigment, - //location: integer("location"), - upd_user: "LST", - upd_date: sql`NOW()`, - }) - ); +// for (let i = 0; i < inv?.data.length; i++) { +// const current = inv?.data[i]; +// const { data, error } = await tryCatch( +// db.insert(invHistoricalData).values({ +// histDate: format(new Date(), "MM-dd-yyyy"), +// plantToken: setting.filter( +// (n: any) => n.name === "plantToken" +// )[0].value, +// article: current.av, +// articleDescription: current.Alias, +// total_QTY: current.Total_PalletQTY, +// avaliable_QTY: current.Avaliable_PalletQTY, +// coa_QTY: current.COA_QTY, +// held_QTY: current.Held_QTY, +// consignment: current.Consigment, +// //location: integer("location"), +// upd_user: "LST", +// upd_date: sql`NOW()`, +// }) +// ); - createLog("info", "lst", "eom", ` historical data was just added.`); +// createLog("info", "lst", "eom", ` historical data was just added.`); - if (error) { - createLog( - "error", - "lst", - "eom", - `Error addeding historical data, ${error}` - ); - } - } - }); -}; +// if (error) { +// createLog( +// "error", +// "lst", +// "eom", +// `Error addeding historical data, ${error}` +// ); +// } +// } +// }); +// }; diff --git a/lstV2/server/services/logistics/logisticsService.ts b/lstV2/server/services/logistics/logisticsService.ts index 0393d2f..22cbe80 100644 --- a/lstV2/server/services/logistics/logisticsService.ts +++ b/lstV2/server/services/logistics/logisticsService.ts @@ -1,72 +1,70 @@ import { OpenAPIHono } from "@hono/zod-openapi"; - +import { migrateAdjustments } from "./controller/siloAdjustments/migrateAdjustments.js"; +import { getLanesToCycleCount } from "./controller/warehouse/cycleCountChecks/cyclecountCheck.js"; +import attachSilo from "./route/attachSilo.js"; import comsumeMaterial from "./route/consumeMaterial.js"; +import detachSilo from "./route/detachSilo.js"; +import postBulkOrders from "./route/dm/bulkOrdersIn.js"; +import postForecast from "./route/dm/forecastIn.js"; +import standardForcasttemplate from "./route/dm/getStandardForecastTemplate.js"; +import standardTemplate from "./route/dm/getStandardTemplate.js"; +import getActiveLanes from "./route/getActiveLanes.js"; +import intervalChecks from "./route/getActiveLogistics.js"; +import getCycleCountCheck from "./route/getCycleCountChecks.js"; +import getcyclecount from "./route/getCycleCountLanes.js"; +import outbound from "./route/getOutbound.js"; +import getPPOO from "./route/getPPOO.js"; +import getConnectionType from "./route/getSiloConnectionData.js"; +import getSSCC from "./route/getSSCCNumber.js"; +import removeAsNonReable from "./route/removeAsNonReusable.js"; import returnMat from "./route/returnMaterial.js"; import createSiloAdjustment from "./route/siloAdjustments/createSiloAdjustment.js"; -import postComment from "./route/siloAdjustments/postComment.js"; -import getStockSilo from "./route/siloAdjustments/getStockData.js"; -import { migrateAdjustments } from "./controller/siloAdjustments/migrateAdjustments.js"; import getSiloAdjustments from "./route/siloAdjustments/getSiloAdjustments.js"; -import { getLanesToCycleCount } from "./controller/warehouse/cycleCountChecks/cyclecountCheck.js"; -import getCycleCountCheck from "./route/getCycleCountChecks.js"; -import getPPOO from "./route/getPPOO.js"; -import getcyclecount from "./route/getCycleCountLanes.js"; -import postBulkOrders from "./route/dm/bulkOrdersIn.js"; -import standardTemplate from "./route/dm/getStandardTemplate.js"; -import standardForcasttemplate from "./route/dm/getStandardForecastTemplate.js"; -import postForecast from "./route/dm/forecastIn.js"; -import outbound from "./route/getOutbound.js"; -import { runHistoricalData } from "./controller/eom/historicalInv.js"; -import intervalChecks from "./route/getActiveLogistics.js"; -import getActiveLanes from "./route/getActiveLanes.js"; -import removeAsNonReable from "./route/removeAsNonReusable.js"; -import getSSCC from "./route/getSSCCNumber.js"; -import getConnectionType from "./route/getSiloConnectionData.js"; -import detachSilo from "./route/detachSilo.js"; -import attachSilo from "./route/attachSilo.js"; +import getStockSilo from "./route/siloAdjustments/getStockData.js"; +import postComment from "./route/siloAdjustments/postComment.js"; const app = new OpenAPIHono(); const routes = [ - comsumeMaterial, - returnMat, + comsumeMaterial, + returnMat, - // silo - createSiloAdjustment, - postComment, - getStockSilo, - getSiloAdjustments, - getConnectionType, - detachSilo, - attachSilo, - //lanes - getCycleCountCheck, - //warehouse - getPPOO, - getcyclecount, - getActiveLanes, - //DM - postBulkOrders, - standardTemplate, - postForecast, - standardForcasttemplate, - // outbound deliveries - outbound, - intervalChecks, + // silo + createSiloAdjustment, + postComment, + getStockSilo, + getSiloAdjustments, + getConnectionType, + detachSilo, + attachSilo, + //lanes + getCycleCountCheck, + //warehouse + getPPOO, + getcyclecount, + getActiveLanes, + //DM + postBulkOrders, + standardTemplate, + postForecast, + standardForcasttemplate, + // outbound deliveries + outbound, + intervalChecks, - // logisitcs - removeAsNonReable, - getSSCC, + // logisitcs + removeAsNonReable, + getSSCC, ] as const; // app.route("/server", modules); const appRoutes = routes.forEach((route) => { - app.route("/logistics", route); + app.route("/logistics", route); }); setTimeout(() => { - migrateAdjustments(); - runHistoricalData(); + migrateAdjustments(); + //runHistoricalData(); }, 120 * 1000); // starts 2 min after a server restart or crash. /** @@ -74,10 +72,13 @@ setTimeout(() => { */ setTimeout(() => { - getLanesToCycleCount(); + getLanesToCycleCount(); }, 5 * 1000); -setInterval(async () => { - getLanesToCycleCount(); -}, 15 * 60 * 1000); +setInterval( + async () => { + getLanesToCycleCount(); + }, + 15 * 60 * 1000, +); export default app;