diff --git a/EgwProxy.SqlDb.Test/SqlFromDebug/PAMA/GetMachineProdData.sql b/EgwProxy.SqlDb.Test/SqlFromDebug/PAMA/GetMachineProdData.sql index 5217969a..dc114fb0 100644 --- a/EgwProxy.SqlDb.Test/SqlFromDebug/PAMA/GetMachineProdData.sql +++ b/EgwProxy.SqlDb.Test/SqlFromDebug/PAMA/GetMachineProdData.sql @@ -1,4 +1,4 @@ -ALTER PROCEDURE [dbo].GetMachineProdData +ALTER PROCEDURE [dbo].[stp_GetMachineProdData] AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from @@ -24,9 +24,10 @@ BEGIN IF(@NewIdx > @LastIdx) BEGIN /* -------------------------------------------------- - * Invierň solo VARIAZIONI dei valori + * Invierò solo VARIAZIONI dei valori * - CurrentProdOrder (iniziato/concluso) - * - Quantitŕ Produzione + * - QuantitĂ  Produzione + * - dati FluxLog x ordini/quantitĂ /tempi di produzione * * andando ad incrociare ogni record col precedente... * -------------------------------------------------- */ @@ -86,7 +87,66 @@ BEGIN FROM cteActDec WHERE OrdAction <> 'NONE' - + -- ora processo ANCHE come fluxLog i record dei degli ordini (cod ordine, tempi...) + ;WITH cteCurrOrd AS + ( + SELECT ID + ,ProdOrder + ,Targa as IdxMacchina + ,[DateTime] AS DtEvento + ,ProdOrderState + ,ProdQty + ,ElapsedTime + FROM syn_M2ERP_PRODORDERS + WHERE ID > @LastIdx AND ID <= @NewIdx + ) + , ctePrevOrd AS + ( + SELECT ID + ,ProdOrder + ,Targa as IdxMacchina + ,[DateTime] AS DtEvento + ,ProdOrderState + ,ProdQty + ,ElapsedTime + FROM syn_M2ERP_PRODORDERS + WHERE ID >= @LastIdx AND ID < @NewIdx + ) + , cteActDec AS + ( + SELECT curr.DtEvento as DtEve + ,curr.IdxMacchina + ,CASE + WHEN curr.ProdOrderState = 1 THEN 'StartOrd' + --WHEN curr.ProdOrderState = 2 THEN 'PauseOrd' + WHEN curr.ProdOrderState = 3 THEN 'EndOrd' + --WHEN curr.ProdOrderState = 6 THEN 'InsOrd' + ELSE 'NONE' + END AS OrdAction + ,CAST(CASE + WHEN LEFT(curr.ProdOrder, 4) = 'PODL' THEN REPLACE(curr.ProdOrder,'PODL','') + ELSE '0' END AS NVARCHAR(50)) AS IdxPodl + ,CAST(CASE + WHEN LEFT(curr.ProdOrder, 3) = 'ODL' THEN REPLACE(curr.ProdOrder,'ODL','') + ELSE '0' END AS NVARCHAR(50)) AS IdxOdl + ,CAST(curr.ProdOrder AS NVARCHAR(50)) as CodComm + ,curr.ProdQty as PzCount + ,CAST(curr.ElapsedTime AS NVARCHAR(50)) AS ElapsedTime + FROM cteCurrOrd curr + INNER JOIN ctePrevOrd prev + ON curr.ID = prev.ID+1 + WHERE (curr.ProdOrder <> prev.ProdOrder) + OR (curr.ProdOrderState <> prev.ProdOrderState) + OR (curr.ProdQty <> prev.ProdQty) + ) + -- lego i valori col precedente x calcolare se siano variati x insert valori + --INSERT INTO MachineFluxLog(DtEvento, IdxMacchina, CodFlux, Valore, Cnt) + SELECT DtEve as DtEvento, IdxMacchina, CodFlux, Valore,0 as Cnt + FROM cteActDec + UNPIVOT (Valore FOR CodFlux IN (CodComm, ElapsedTime, IdxOdl, IdxPOdl)) AS Unpvt + WHERE OrdAction <> 'NONE' + AND Valore <> '0' + -- aggiorno valore indice processato MERGE SyncState AS tgt USING (SELECT @NewIdx as LastIdx, 'ToMachineProdData' AS TableName) as src (LastIdx, TableName) @@ -104,6 +164,3 @@ BEGIN COMMIT tran END -GO - - diff --git a/EgwProxy.SqlDb.Test/SqlFromDebug/PAMA/ImportAll.sql b/EgwProxy.SqlDb.Test/SqlFromDebug/PAMA/ImportAll.sql index 884d9f84..dc44ae24 100644 Binary files a/EgwProxy.SqlDb.Test/SqlFromDebug/PAMA/ImportAll.sql and b/EgwProxy.SqlDb.Test/SqlFromDebug/PAMA/ImportAll.sql differ diff --git a/EgwProxy.SqlDb.Test/SqlFromDebug/PAMA/Test.sql b/EgwProxy.SqlDb.Test/SqlFromDebug/PAMA/Test.sql index 0023323d..a0fae839 100644 --- a/EgwProxy.SqlDb.Test/SqlFromDebug/PAMA/Test.sql +++ b/EgwProxy.SqlDb.Test/SqlFromDebug/PAMA/Test.sql @@ -4,6 +4,11 @@ select * from SyncState select * from MesPODL_last select * from MesPODL_req +select * from MachineFluxLog +select * from MachineProdData +select * from MachineSignalLog + + -- test scrittura PODL: OK! exec dbo.SyncPodlToMachine @@ -18,9 +23,12 @@ set lastidx=0 where TableName='ToMachineFluxLog' */ +select top 2 * from MachineFluxLog order by 1 desc +select top 2 * from MachineProdData order by 1 desc +select top 10 * from MachineSignalLog order by 1 desc +select * from SyncState exec dbo.GetMachineFluxLog -select * from SyncState select * from MachineFluxLog select * from syn_ERP2M @@ -29,11 +37,12 @@ select * from syn_M2ERP_PRODORDERS select top 10 * from syn_M2ERP_PRODORDERS -where ProdOrder ='ODL0003743' +where ProdOrder LIKE 'PODL000%' select top 10 * from syn_M2ERP_PRODORDERS where ProdOrder LIKE '%ODL%' +order by 1 desc EXEC GetMachineProdData SELECT * FROM SyncState @@ -85,3 +94,5 @@ select * from M2ERP_MACHINE_STATE where ActiveProdOrder = 'ODL0003743' select * from M2ERP_PRODORDERS select * from M2ERP_PRODORDERS where ProdOrder = 'ODL0003743' + +