feat(ocmeserver): the server was just migrated so it can be upgraded to lstv2

This commit is contained in:
2025-03-17 16:13:58 -05:00
parent 491de26a0b
commit e258aaead9
8 changed files with 282 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
// import {runQuery} from "../utils/sql/config/sqlConfig.js";
// /**
// * 1. Copy the Setup.xml to the desktop.
// * 2. run the createJson script.
// * 3. get the alplaprod lanes with this query select IdLagerAbteilung as id,Bezeichnung as name from [dbo].[V_LagerAbteilungen] where IdWarenLager not in (6,5) and aktiv = 1
// * 4. convert this to a json
// *
// * in the ocme data we want grab the section in each section called "clsParkingRow" this is inside the RowList. thenjust copy the array into the lanes.
// *
// */
// export const lanes = [];
// export const prodNames = [];
// const combinedInfo = [];
// const updatedLanesWithNames = lanes.map((l) => {
// //filter the prodnames out
// if (l.CustomerKey === "") {
// return;
// }
// const names = prodNames.filter((v) => v.id === l.CustomerKey);
// if (names) {
// //console.log({...l, laneName: names[0]?.name});
// combinedInfo.push({...l, laneName: names[0]?.name});
// }
// });
// // get the skey from ocme
// const matcheverything = async () => {
// const query = `select SKEY as ocme_laneLevelID, id_row, id_park from [Agv_AlplaDayton].[dbo].[Park] where id_park in (4,3)`;
// const ocmeData = await runQuery(query, "lanes");
// //console.log(ocmeData)
// const ocmeToSend = [];
// const correctOcmeData = ocmeData.map((o) => {
// // filter out the prod lanes
// const prodInfo = combinedInfo.filter((f) => f.Id === o.id_row && f.ParkId === o.id_park);
// if (prodInfo.length === 0) {
// return;
// }
// if (prodInfo) {
// ocmeToSend.push({...o, laneName: prodInfo[0].laneName, laneId: prodInfo[0].CustomerKey});
// }
// });
// function delay(ms) {
// return new Promise((resolve) => setTimeout(resolve, ms));
// }
// //console.log(ocmeToSend)
// for (let i = 0; i < ocmeToSend.length; i++) {
// let updateQuery = `
// MERGE INTO [Alpla_Lst].[dbo].[lanes] AS target
// USING (SELECT '${ocmeToSend[i].ocme_laneLevelID}' AS ocme_laneLevelID, ${ocmeToSend[i].laneId} AS alpla_laneID, '${ocmeToSend[i].laneName}' AS alpla_laneDescription, getdate() as upd_date) AS source
// ON target.ocme_laneLevelID LIKE source.ocme_laneLevelID
// WHEN MATCHED THEN
// UPDATE SET target.alpla_laneID = source.alpla_laneID,
// target.alpla_laneDescription = source.alpla_laneDescription,
// target.upd_date = source.upd_date
// WHEN NOT MATCHED BY TARGET THEN
// INSERT (ocme_laneLevelID, alpla_laneID, alpla_laneDescription, upd_date)
// VALUES (source.ocme_laneLevelID, source.alpla_laneID, source.alpla_laneDescription, source.upd_date);
// `;
// const queryRan = await runQuery(updateQuery, "running");
// console.log(
// `${ocmeToSend[i].ocme_laneLevelID} just updated in park ${ocmeToSend[i].id_park}, remaining to update ${
// ocmeToSend.length - i
// }`
// );
// await delay(150);
// }
// };
// matcheverything();

View File

@@ -0,0 +1,55 @@
// import fs from "fs";
// import {XMLParser} from "fast-xml-parser";
// //const xmlData = fs.readFileSync('C:\\Users\\adm_matthes01\\Desktop\\Setup.xml', 'utf8');
// // Read the XML file as a string
// const xmlData = fs.readFileSync("C:\\Users\\adm_matthes01\\Desktop\\Setup.xml", "utf8");
// // Create a parser instance with options
// const parser = new XMLParser({
// ignoreAttributes: false, // Keep attributes in JSON
// attributeNamePrefix: "@_", // Prefix for attributes
// allowBooleanAttributes: true,
// trimValues: true,
// parseTagValue: true,
// parseAttributeValue: true,
// });
// // Parse the XML into a JSON object
// const jsonObj = parser.parse(xmlData);
// // Convert JSON object to a formatted string
// const jsonString = JSON.stringify(jsonObj.clsAGVManagerProject.ParkingList, null, 2);
// // Write the JSON to a file
// fs.writeFileSync("large.json", jsonString, "utf8");
// console.log("JSON saved to large.json");
// fs.readFile("large.json", "utf8", (err, data) => {
// if (err) {
// console.error(err);
// return;
// }
// const json = JSON.parse(data);
// //console.log(JSON.stringify(json[0].RowList, null, 2));
// const rowUpates = [];
// const updates = json.clsParking.map((i) => {
// // i.RowList.clsParkingRow.map(r =>{
// // rowUpates.push({id: r.Id, CustomerKey: r.CustomerKey})
// // })
// //console.log({id: i.Id,name: i. Name, lanes: i.RowList.clsParkingRow })
// rowUpates.push({id: i.Id, name: i.Name, lanes: i.RowList.clsParkingRow});
// });
// //console.log(Object.keys(json.clsAGVManagerProject.PalletCardConfigList. ParkingList.clsParking));
// //console.log(rowUpates)
// for (var i = 0; i <= 1; i++) {
// const laneID = {ID_ROW: rowUpates[i].lanes};
// if (laneID) {
// console.log(laneID.Id);
// }
// }
// });

View File

@@ -0,0 +1,18 @@
// import express from 'express'
// import cors from "cors";
// import getLanes from './route/getLanes.js'
// import getLaneData from './route/getLaneData.js'
// const port = 3250
// const app = express()
// app.use(express.json());
// app.use(cors({origin: true, credentials: true}));
// app.use('/api/v1', getLanes)
// app.use('/api/v1', getLaneData)
// app.listen(port, ()=>{
// console.log(`Listing on port: ${port}`)
// })

View File

@@ -0,0 +1,38 @@
// import {Router} from 'express'
// import { runQuery } from '../utils/sql/config/sqlConfig.js'
// import { ocmeInventory } from '../utils/sql/querys/getOCMEInventory.js'
// const router = Router()
// router.post('/getLaneData', async (req,res)=>{
// let filterdOCMELane
// // the body will need to have 1 lane in it. lane: 'B050'
// const data = req.body
// // add the lane in so we dont crash
// if(req.body.lane){
// filterdOCMELane = ocmeInventory.replaceAll('[lane]', data.lane)
// // get lanes
// const laneData = await runQuery(filterdOCMELane, 'Getting current ocme lanes linked')
// res.status(200).json({success: true,message: `All current lanes from the ocme system.`, totalpallets: laneData.length,data: laneData})
// return
// }
// // if the plant sends the id over lets change the entire where statement.
// if(req.body.laneID){
// console.log(`Getting the lane data by id`)
// filterdOCMELane = ocmeInventory.replaceAll(`alpla_laneDescription = '[lane]'`, `alpla_laneID = ${data.laneID}`)
// // get lanes
// const laneData = await runQuery(filterdOCMELane, 'Getting current ocme lanes linked')
// res.status(200).json({success: true,message: `All current lanes from the ocme system.`, totalpallets: laneData.length,data: laneData})
// return
// }
// // if everything is missing we send false
// res.status(200).json({success: false,message: `Missing either lane name or lane id.`})
// })
// export default router

View File

@@ -0,0 +1,15 @@
// import {Router} from 'express'
// import { runQuery } from '../utils/sql/config/sqlConfig.js'
// import { getLanes } from '../utils/sql/querys/getLanes.js'
// const router = Router()
// router.get('/getLanes', async (req,res)=>{
// // get lanes
// const lanes = await runQuery(getLanes, 'Getting current ocme lanes linked')
// const laneDescriptions = lanes.map(item => item.alpla_laneDescription);
// res.status(200).json({success: true,message: `All current lanes from the ocme system.`, totalLanes: lanes.length,data: laneDescriptions})
// })
// export default router

View File

@@ -0,0 +1,24 @@
export const ocmeInventory = `
SELECT [ocme_laneLevelID]
,[alpla_laneID]
,[alpla_laneDescription]
,bob.SKU as Article
,bob.description
,bob.sscc
,bob.runningNumber
FROM [Alpla_Lst].[dbo].[lanes] (nolock) a
left JOIN
(Select p.SKEY,
x.y.value('(value)[1]', 'varchar(max)') AS sscc,
b.y.value('(value)[1]', 'varchar(max)') AS runningNumber,
k.l.value('(value)[1]', 'varchar(max)') AS SKU,
d.l.value('(value)[1]', 'varchar(max)') AS description
from Agv_AlplaDayton.dbo.Park p (nolock)
outer apply p.pallet_card.nodes('/*:ArrayOfClsPalletCard/*:clsPalletCard/*:PalletCardConfig/*:palletCardFieldList/*:clsPalletCardField[Name="SSCC"]') as x(y)
outer apply p.pallet_card.nodes('/*:ArrayOfClsPalletCard/*:clsPalletCard/*:PalletCardConfig/*:palletCardFieldList/*:clsPalletCardField[Name="RUNNING_NUMBER"]') as b(y)
outer apply p.pallet_card.nodes('/*:ArrayOfClsPalletCard/*:clsPalletCard/*:PalletCardConfig/*:palletCardFieldList/*:clsPalletCardField[Name= "SKU" ]') as k(l)
outer apply p.pallet_card.nodes('/*:ArrayOfClsPalletCard/*:clsPalletCard/*:PalletCardConfig/*:palletCardFieldList/*:clsPalletCardField[Name= "DESCRIPTION" ]') as d(l)) as bob
on a.ocme_laneLevelID = bob.SKEY
where alpla_laneDescription = '[lane]' and runningNumber > 1
`;

View File

@@ -0,0 +1,6 @@
export const getLanes = `
select DISTINCT alpla_laneDescription
from Alpla_Lst.dbo.lanes (nolock)
where alpla_laneDescription is not null
order by alpla_laneDescription desc
`;

View File

@@ -0,0 +1,48 @@
import sql from "mssql";
// hardcoding everything to make sure it all works as intended
const server = "usday1vms010";
const dbUser = "ocme";
const dbPassword = "Democrat-Humongous";
export const sqlConfig_ocme = {
server: server,
database: `Alpla_lst`,
user: dbUser,
password: dbPassword,
options: {
encrypt: true,
trustServerCertificate: true,
},
requestTimeout: 90000, // in milliseconds
// ocmePool: {
// max: 20, // Maximum number of connections in the pool
// min: 0, // Minimum number of connections in the pool
// idleTimeoutMillis: 10000, // How long a connection is allowed to be idle before being released
// reapIntervalMillis: 1000, // how often to check for idle resourses to destory
// acquireTimeoutMillis: 100000, // How long until a complete timeout happens
// },
};
export async function runQuery(queryToRun: string, name: string) {
let connection;
try {
// Establish a direct connection to the different server
connection = await sql.connect(sqlConfig_ocme);
// Execute the query
const result = await connection.request().query(queryToRun);
console.log(`${name} query ran successfully on different server`);
return result.recordset;
} catch (err) {
console.log(`Error running ${name} query on different server: ${err}`);
return [];
} finally {
// Close the direct connection
if (connection) {
await connection.close();
}
}
}