fix(historicalinv): removed the second running one that caused duplicates
This commit is contained in:
@@ -48,4 +48,14 @@ export const addListeners = async () => {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.info({}, "label listener exists");
|
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");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ export const historicalInvIMmport = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dataImport) {
|
if (dataImport) {
|
||||||
createLog("info", "eom", "eom", `All data was imported succefully.`);
|
createLog("info", "eom", "eom", `All data was imported successfully.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -104,5 +104,5 @@ export const historicalInvIMmport = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// do the check to delete old data
|
// do the check to delete old data
|
||||||
deleteHistory();
|
//deleteHistory();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,93 +1,93 @@
|
|||||||
|
import { format } from "date-fns-tz";
|
||||||
|
import { sql } from "drizzle-orm";
|
||||||
import { db } from "../../../../../database/dbclient.js";
|
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 { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
import { createLog } from "../../../logger/logger.js";
|
import { createLog } from "../../../logger/logger.js";
|
||||||
import { query } from "../../../sqlServer/prodSqlServer.js";
|
import { query } from "../../../sqlServer/prodSqlServer.js";
|
||||||
import { totalInvNoRn } from "../../../sqlServer/querys/dataMart/totalINV.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";
|
import { createLogisticsJob } from "../../utils/logisticsIntervals.js";
|
||||||
|
|
||||||
export const runHistoricalData = async () => {
|
// 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
|
// * 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(
|
// const { data: set, error: setError } = await tryCatch(
|
||||||
db.select().from(settings)
|
// db.select().from(settings)
|
||||||
);
|
// );
|
||||||
|
|
||||||
if (setError) {
|
// if (setError) {
|
||||||
createLog(
|
// createLog(
|
||||||
"error",
|
// "error",
|
||||||
"lst",
|
// "lst",
|
||||||
"eom",
|
// "eom",
|
||||||
"There was an error getting eom historical inv data."
|
// "There was an error getting eom historical inv data."
|
||||||
);
|
// );
|
||||||
return;
|
// 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 () => {
|
// createLogisticsJob("histInv", `0 6 * * *`, timeZone[0].value, async () => {
|
||||||
// remove the lotnumber from the query
|
// // remove the lotnumber from the query
|
||||||
const updatedQuery = totalInvNoRn.replaceAll(
|
// const updatedQuery = totalInvNoRn.replaceAll(
|
||||||
",IdProdPlanung",
|
// ",IdProdPlanung",
|
||||||
"--,IdProdPlanung"
|
// "--,IdProdPlanung"
|
||||||
);
|
// );
|
||||||
|
|
||||||
const { data: inv, error: invError } = await tryCatch(
|
// const { data: inv, error: invError } = await tryCatch(
|
||||||
query(updatedQuery, "EOM historical inv")
|
// query(updatedQuery, "EOM historical inv")
|
||||||
);
|
// );
|
||||||
|
|
||||||
if (invError) {
|
// if (invError) {
|
||||||
createLog(
|
// createLog(
|
||||||
"error",
|
// "error",
|
||||||
"lst",
|
// "lst",
|
||||||
"eom",
|
// "eom",
|
||||||
"There was an error getting eom historical inv data."
|
// "There was an error getting eom historical inv data."
|
||||||
);
|
// );
|
||||||
return;
|
// 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++) {
|
// for (let i = 0; i < inv?.data.length; i++) {
|
||||||
const current = inv?.data[i];
|
// const current = inv?.data[i];
|
||||||
const { data, error } = await tryCatch(
|
// const { data, error } = await tryCatch(
|
||||||
db.insert(invHistoricalData).values({
|
// db.insert(invHistoricalData).values({
|
||||||
histDate: format(new Date(), "MM-dd-yyyy"),
|
// histDate: format(new Date(), "MM-dd-yyyy"),
|
||||||
plantToken: setting.filter(
|
// plantToken: setting.filter(
|
||||||
(n: any) => n.name === "plantToken"
|
// (n: any) => n.name === "plantToken"
|
||||||
)[0].value,
|
// )[0].value,
|
||||||
article: current.av,
|
// article: current.av,
|
||||||
articleDescription: current.Alias,
|
// articleDescription: current.Alias,
|
||||||
total_QTY: current.Total_PalletQTY,
|
// total_QTY: current.Total_PalletQTY,
|
||||||
avaliable_QTY: current.Avaliable_PalletQTY,
|
// avaliable_QTY: current.Avaliable_PalletQTY,
|
||||||
coa_QTY: current.COA_QTY,
|
// coa_QTY: current.COA_QTY,
|
||||||
held_QTY: current.Held_QTY,
|
// held_QTY: current.Held_QTY,
|
||||||
consignment: current.Consigment,
|
// consignment: current.Consigment,
|
||||||
//location: integer("location"),
|
// //location: integer("location"),
|
||||||
upd_user: "LST",
|
// upd_user: "LST",
|
||||||
upd_date: sql`NOW()`,
|
// upd_date: sql`NOW()`,
|
||||||
})
|
// })
|
||||||
);
|
// );
|
||||||
|
|
||||||
createLog("info", "lst", "eom", ` historical data was just added.`);
|
// createLog("info", "lst", "eom", ` historical data was just added.`);
|
||||||
|
|
||||||
if (error) {
|
// if (error) {
|
||||||
createLog(
|
// createLog(
|
||||||
"error",
|
// "error",
|
||||||
"lst",
|
// "lst",
|
||||||
"eom",
|
// "eom",
|
||||||
`Error addeding historical data, ${error}`
|
// `Error addeding historical data, ${error}`
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
};
|
// };
|
||||||
|
|||||||
@@ -1,72 +1,70 @@
|
|||||||
import { OpenAPIHono } from "@hono/zod-openapi";
|
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 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 returnMat from "./route/returnMaterial.js";
|
||||||
import createSiloAdjustment from "./route/siloAdjustments/createSiloAdjustment.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 getSiloAdjustments from "./route/siloAdjustments/getSiloAdjustments.js";
|
||||||
import { getLanesToCycleCount } from "./controller/warehouse/cycleCountChecks/cyclecountCheck.js";
|
import getStockSilo from "./route/siloAdjustments/getStockData.js";
|
||||||
import getCycleCountCheck from "./route/getCycleCountChecks.js";
|
import postComment from "./route/siloAdjustments/postComment.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";
|
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
comsumeMaterial,
|
comsumeMaterial,
|
||||||
returnMat,
|
returnMat,
|
||||||
|
|
||||||
// silo
|
// silo
|
||||||
createSiloAdjustment,
|
createSiloAdjustment,
|
||||||
postComment,
|
postComment,
|
||||||
getStockSilo,
|
getStockSilo,
|
||||||
getSiloAdjustments,
|
getSiloAdjustments,
|
||||||
getConnectionType,
|
getConnectionType,
|
||||||
detachSilo,
|
detachSilo,
|
||||||
attachSilo,
|
attachSilo,
|
||||||
//lanes
|
//lanes
|
||||||
getCycleCountCheck,
|
getCycleCountCheck,
|
||||||
//warehouse
|
//warehouse
|
||||||
getPPOO,
|
getPPOO,
|
||||||
getcyclecount,
|
getcyclecount,
|
||||||
getActiveLanes,
|
getActiveLanes,
|
||||||
//DM
|
//DM
|
||||||
postBulkOrders,
|
postBulkOrders,
|
||||||
standardTemplate,
|
standardTemplate,
|
||||||
postForecast,
|
postForecast,
|
||||||
standardForcasttemplate,
|
standardForcasttemplate,
|
||||||
// outbound deliveries
|
// outbound deliveries
|
||||||
outbound,
|
outbound,
|
||||||
intervalChecks,
|
intervalChecks,
|
||||||
|
|
||||||
// logisitcs
|
// logisitcs
|
||||||
removeAsNonReable,
|
removeAsNonReable,
|
||||||
getSSCC,
|
getSSCC,
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
// app.route("/server", modules);
|
// app.route("/server", modules);
|
||||||
const appRoutes = routes.forEach((route) => {
|
const appRoutes = routes.forEach((route) => {
|
||||||
app.route("/logistics", route);
|
app.route("/logistics", route);
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
migrateAdjustments();
|
migrateAdjustments();
|
||||||
runHistoricalData();
|
//runHistoricalData();
|
||||||
}, 120 * 1000); // starts 2 min after a server restart or crash.
|
}, 120 * 1000); // starts 2 min after a server restart or crash.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,10 +72,13 @@ setTimeout(() => {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
getLanesToCycleCount();
|
getLanesToCycleCount();
|
||||||
}, 5 * 1000);
|
}, 5 * 1000);
|
||||||
setInterval(async () => {
|
setInterval(
|
||||||
getLanesToCycleCount();
|
async () => {
|
||||||
}, 15 * 60 * 1000);
|
getLanesToCycleCount();
|
||||||
|
},
|
||||||
|
15 * 60 * 1000,
|
||||||
|
);
|
||||||
|
|
||||||
export default app;
|
export default app;
|
||||||
|
|||||||
Reference in New Issue
Block a user