Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
@@ -102,6 +102,10 @@ public abstract class BaseMigration implements MigrationModelInterface {
|
||||
alterObject(SqlObjectTypeEnum.FUNCTION, objectName, createFunctionSql);
|
||||
}
|
||||
|
||||
protected void dropFunction(String objectName) throws SQLException, IOException {
|
||||
dropObject(SqlObjectTypeEnum.FUNCTION, objectName);
|
||||
}
|
||||
|
||||
protected void createOrUpdateView(String objectName, String createViewSql) throws SQLException, IOException {
|
||||
alterObject(SqlObjectTypeEnum.VIEW, objectName, createViewSql);
|
||||
}
|
||||
@@ -120,6 +124,11 @@ public abstract class BaseMigration implements MigrationModelInterface {
|
||||
sql);
|
||||
}
|
||||
|
||||
private void dropObject(SqlObjectTypeEnum sqlObject, String objectName) throws SQLException, IOException {
|
||||
executeStatement("IF EXISTS (SELECT * FROM SYSOBJECTS WHERE id = object_id('" + objectName + "'))\r\n" +
|
||||
"\tDROP " + sqlObject.toString() + " " + objectName);
|
||||
}
|
||||
|
||||
|
||||
protected boolean existsColumn(String tableName, String columnName) throws SQLException, IOException {
|
||||
String schema = null;
|
||||
|
||||
@@ -11,6 +11,51 @@ public class Migration_20240620132505 extends BaseMigration implements Migration
|
||||
return;
|
||||
|
||||
|
||||
createOrUpdateView("olvw_caratteristiche_lotto", "CREATE view [dbo].[olvw_caratteristiche_lotto] as \n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"SELECT\n" +
|
||||
" * \n" +
|
||||
"FROM\n" +
|
||||
" (\n" +
|
||||
" SELECT\n" +
|
||||
" mtb_partita_mag_carat.cod_mart,\n" +
|
||||
" mtb_partita_mag_carat.partita_mag,\n" +
|
||||
" mtb_partita_mag_carat.carat,\n" +
|
||||
" mtb_partita_mag_carat.val_carat\n" +
|
||||
" from\n" +
|
||||
" mtb_partita_mag_carat\n" +
|
||||
" )\n" +
|
||||
" as caratteristiche PIVOT ( min(val_carat) FOR carat IN \n" +
|
||||
" (\n" +
|
||||
" [Anno],\n" +
|
||||
" [Numero Certificato],\n" +
|
||||
" [Data Certificato],\n" +
|
||||
" [Temperatura estrazione],\n" +
|
||||
" [% Resa],\n" +
|
||||
" [Orario Accettazione],\n" +
|
||||
" [Conto Terzi],\n" +
|
||||
" [Varieta]\n" +
|
||||
" )\n" +
|
||||
") AS PivotTable\n" +
|
||||
"/*\n" +
|
||||
"--Ho dovuto disattivare tutti i controlli perchè bloccavano le moliture\n" +
|
||||
"SELECT distinct\n" +
|
||||
" mtb_partita_mag_carat.cod_mart,\n" +
|
||||
" mtb_partita_mag_carat.partita_mag,\n" +
|
||||
" '' as Anno,\n" +
|
||||
" '' as [Numero Certificato],\n" +
|
||||
" '' as [Data Certificato],\n" +
|
||||
" '' as [Temperatura estrazione],\n" +
|
||||
" '' as [ % Resa],\n" +
|
||||
" '' as [Orario Accettazione],\n" +
|
||||
" '' as [Conto Terzi],\n" +
|
||||
" '' as [Varieta]\n" +
|
||||
" \n" +
|
||||
" from\n" +
|
||||
" mtb_partita_mag_carat\n" +
|
||||
" */");
|
||||
|
||||
createOrUpdateFunction("f_lol_getOperazione", "CREATE FUNCTION [dbo].[f_lol_getOperazione] ( @codDtip varchar(5), @nazione varchar(3), @codMartIniz varchar(15), @partitaMagIniz varchar(20), @codMartFine varchar(15), @partitaMagFine varchar(20), @omaggio bit, @tipoMiscela varchar(1) )\n" +
|
||||
"RETURNS varchar(max)\n" +
|
||||
"AS\n" +
|
||||
|
||||
@@ -10,6 +10,74 @@ public class Migration_20240620142950 extends BaseMigration implements Migration
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
createOrUpdateFunction("getCompatibiltaCaratteristiche", "CREATE FUNCTION [dbo].[getCompatibiltaCaratteristiche] \n" +
|
||||
"(\n" +
|
||||
" @codMart1 varchar(15), @partitaMag1 varchar(20), @codMart2 varchar(15), @partitaMag2 varchar(20), @checkVarieta varchar(1)\n" +
|
||||
")\n" +
|
||||
"RETURNS TABLE as\n" +
|
||||
"return \n" +
|
||||
"( \n" +
|
||||
" with art_carat as (\n" +
|
||||
" SELECT IsNull(art1.carat, art2.carat) as carat,\n" +
|
||||
" art1.val_carat as val_carat1,\n" +
|
||||
" art2.val_carat as val_carat2,\n" +
|
||||
" case when IsNull(art1.val_carat, '') = IsNull(art2.val_carat, '') THEN 1 ELSE 0 END as compatibilita\n" +
|
||||
" from (\n" +
|
||||
" select carat, \n" +
|
||||
" case when carat in ('Biologico', 'Conto terzi', 'Estratto a freddo', 'In conversione', 'Non etichettato', 'Prima spremitura a freddo') and val_carat IS null THEN 'N' ELSE val_carat END as val_carat \n" +
|
||||
" from mtb_aart_carat where cod_mart = @codMart1 \n" +
|
||||
" UNION \n" +
|
||||
" SELECT carat, \n" +
|
||||
" case when carat in ('Biologico', 'Conto terzi', 'Estratto a freddo', 'In conversione', 'Non etichettato', 'Prima spremitura a freddo') and val_carat IS null THEN 'N' ELSE val_carat END as val_carat \n" +
|
||||
" FROM mtb_partita_mag_carat WHERE cod_mart = @codMart1 AND partita_mag = @partitaMag1 and\n" +
|
||||
" ((@checkVarieta = 'S') OR (@checkVarieta = 'N' AND carat <> 'Varieta'))\n" +
|
||||
" ) art1 full outer join\n" +
|
||||
" (\n" +
|
||||
" select carat, \n" +
|
||||
" case when carat in ('Biologico', 'Conto terzi', 'Estratto a freddo', 'In conversione', 'Non etichettato', 'Prima spremitura a freddo') and val_carat IS null THEN 'N' ELSE val_carat END as val_carat \n" +
|
||||
" from mtb_aart_carat where cod_mart = @codMart2\n" +
|
||||
" UNION \n" +
|
||||
" SELECT carat, \n" +
|
||||
" case when carat in ('Biologico', 'Conto terzi', 'Estratto a freddo', 'In conversione', 'Non etichettato', 'Prima spremitura a freddo') and val_carat IS null THEN 'N' ELSE val_carat END as val_carat \n" +
|
||||
" FROM mtb_partita_mag_carat WHERE cod_mart = @codMart2 AND partita_mag = @partitaMag2 and \n" +
|
||||
" ((@checkVarieta = 'S') OR (@checkVarieta = 'N' AND carat <> 'Varieta'))\n" +
|
||||
" ) art2 on\n" +
|
||||
" art1.carat = art2.carat \n" +
|
||||
" )\n" +
|
||||
" ,\n" +
|
||||
" risultato_tb as (\n" +
|
||||
" select art_carat.carat,\n" +
|
||||
" art_carat.val_carat1,\n" +
|
||||
" art_carat.val_carat2,\n" +
|
||||
" case when art_carat.compatibilita = 0 AND id_carat is null THEN 0 ELSE 1 END as compatibilita,\n" +
|
||||
" case when art_carat.compatibilita = 1 THEN ISNull(art_carat.val_carat1, art_carat.val_carat2) ELSE mtb_aart_carat_mix.risultato END as risultato\n" +
|
||||
" from art_carat \n" +
|
||||
" left outer join mtb_aart_carat_mix\n" +
|
||||
" on art_carat.carat = mtb_aart_carat_mix.carat AND\n" +
|
||||
" IsNull(art_carat.val_carat1, '') = IsNull(mtb_aart_carat_mix.val_carat1, '') AND\n" +
|
||||
" IsnUll(art_carat.val_carat2, '') = IsNull(mtb_aart_carat_mix.val_carat2, '')\n" +
|
||||
" ) ,\n" +
|
||||
" tab as ( \n" +
|
||||
"\n" +
|
||||
" SELECT *, 0 AS ERROR, null as error_message FROM risultato_tb WHERE not existS(SELECT carat from risultato_tb where compatibilita = 0 )\n" +
|
||||
" UNION ALL \n" +
|
||||
"\n" +
|
||||
" SELECT null, null, null, null, null, 1 AS ERROR,\n" +
|
||||
" \n" +
|
||||
" 'Articoli con carattaretistiche non compatibili. [' +\n" +
|
||||
" (SELECT STUFF((\n" +
|
||||
" SELECT ', ' + carat FROM risultato_tb WHERE existS(SELECT carat from risultato_tb where compatibilita = 0) AND compatibilita = 0\n" +
|
||||
" FOR XML PATH('')\n" +
|
||||
" ), 1, 1, '' )) + ']'\n" +
|
||||
" /*** ATTENZIONE Ho dovuto disattivare il messaggio perchè bloccava le operazioni di molitura nache su oli compatibili*/\n" +
|
||||
" --'' \n" +
|
||||
" as error_message WHERE existS(SELECT carat from risultato_tb where compatibilita = 0)\n" +
|
||||
" \n" +
|
||||
" )\n" +
|
||||
" \n" +
|
||||
" select * from tab\n" +
|
||||
" )");
|
||||
|
||||
|
||||
createOrUpdateFunction("lol_chkPostureSian", "CREATE FUNCTION [dbo].[lol_chkPostureSian] \n" +
|
||||
"(\n" +
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20240621105122 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
|
||||
dropFunction("getListinoVenditaRange");
|
||||
|
||||
|
||||
createOrUpdateFunction("getListinoVenditaPedane", "CREATE FUNCTION [dbo].[getListinoVenditaPedane](@datavalidita DATETIME, @codvlis VARCHAR(5), @codmart VARCHAR(15), @pedane INT)\n" +
|
||||
" RETURNS TABLE AS\n" +
|
||||
" RETURN\n" +
|
||||
" WITH trasp AS (SELECT mtb_lisv_data_spese.cod_vlis,\n" +
|
||||
" mtb_lisv_data_spese.versione,\n" +
|
||||
" mtb_lisv_data_spese.cod_spes,\n" +
|
||||
" mtb_lisv_data_spese.perc_ricarico,\n" +
|
||||
" mtb_lisv_data_spese.val_ricarico,\n" +
|
||||
" mtb_lisv_data_spese.perc_sconto,\n" +
|
||||
" mtb_lisv_data_spese.da,\n" +
|
||||
" mtb_lisv_data_spese.a\n" +
|
||||
" FROM (SELECT cod_vlis,\n" +
|
||||
" MAX(CASE\n" +
|
||||
" WHEN vtb_list_data.versione IS NULL THEN NULL\n" +
|
||||
" ELSE CONVERT(VARCHAR(10), vtb_list_data.data_iniz, 111) + ' ' +\n" +
|
||||
" REPLICATE('0', 5 - LEN(vtb_list_data.versione)) +\n" +
|
||||
" CONVERT(VARCHAR(5), vtb_list_data.versione) END) AS max_lisv\n" +
|
||||
" FROM vtb_list_data\n" +
|
||||
" WHERE vtb_list_data.data_iniz <= ISNULL(@datavalidita, CAST(GETDATE() AS DATE))\n" +
|
||||
" GROUP BY cod_vlis) t\n" +
|
||||
" INNER JOIN vtb_list_data ON t.cod_vlis = vtb_list_data.cod_vlis AND\n" +
|
||||
" CONVERT(INT, RIGHT(t.max_lisv, 5)) = vtb_list_data.versione\n" +
|
||||
" INNER JOIN mtb_lisv_data_spese\n" +
|
||||
" ON vtb_list_data.cod_vlis = mtb_lisv_data_spese.cod_vlis AND\n" +
|
||||
" vtb_list_data.versione = mtb_lisv_data_spese.versione)\n" +
|
||||
"\n" +
|
||||
" SELECT list.*,\n" +
|
||||
" trasp.cod_spes,\n" +
|
||||
" trasp.perc_ricarico,\n" +
|
||||
" trasp.val_ricarico,\n" +
|
||||
" trasp.perc_sconto,\n" +
|
||||
" trasp.da,\n" +
|
||||
" trasp.a,\n" +
|
||||
" (list.prz_vend +\n" +
|
||||
" IIF(list.flag_add_trasp = 1,\n" +
|
||||
" ((ISNULL(val_ricarico, 0)) * list.add_val_spese) /\n" +
|
||||
" IIF(ISNULL(list.colli_pedana, 1) = 0, 1, list.colli_pedana), 0)) +\n" +
|
||||
" ((ISNULL(perc_ricarico, 0) * list.add_ric_spese * list.prz_vend) / 100) *\n" +
|
||||
" (1 - (ISNULL(perc_sconto, 0) * list.add_sco_spese) / 100) prz_vend_trasp\n" +
|
||||
" FROM getlistinovendita(@datavalidita, @codvlis, @codmart) list\n" +
|
||||
" LEFT OUTER JOIN trasp ON list.cod_vlis = trasp.cod_vlis AND\n" +
|
||||
" (@pedane IS NULL OR @pedane BETWEEN da AND a OR\n" +
|
||||
" (@pedane IS NOT NULL AND da = 0 AND a = 0))");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20240621111156 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
|
||||
createOrUpdateView("dbo.cvw_gg_dilazione_media", "CREATE VIEW [dbo].[cvw_gg_dilazione_media] AS\n" +
|
||||
"SELECT\n" +
|
||||
" ctb_scad.tipo_anag,\n" +
|
||||
" ctb_scad.cod_anag,\n" +
|
||||
" ctb_scad.anno_part,\n" +
|
||||
" ctb_scad.data_doc,\n" +
|
||||
" ctb_scad.num_doc,\n" +
|
||||
" ctb_scad.ser_doc,\n" +
|
||||
" ctb_scad.id_riga,\n" +
|
||||
" sum(\n" +
|
||||
" (ctb_part.tipo_partita * ctb_scad.imp_dare) + ((ctb_part.tipo_partita - 1) * ctb_scad.imp_avere) / ctb_part.cambio_divi_cont\n" +
|
||||
" ) AS imp_scad,\n" +
|
||||
" Sum(\n" +
|
||||
" (\n" +
|
||||
" CASE\n" +
|
||||
" WHEN ctb_scad.data_pag <= '2000/01/01' THEN (ctb_part.tipo_partita * ctb_scad.imp_dare) + ((ctb_part.tipo_partita - 1) * ctb_scad.imp_avere) / ctb_part.cambio_divi_cont\n" +
|
||||
" ELSE 0\n" +
|
||||
" END\n" +
|
||||
" )\n" +
|
||||
" ) AS imp_pagato,\n" +
|
||||
" Sum(\n" +
|
||||
" (\n" +
|
||||
" CASE\n" +
|
||||
" WHEN ctb_scad.data_pag > '2000/01/01' THEN (ctb_part.tipo_partita * ctb_scad.imp_dare) + ((ctb_part.tipo_partita - 1) * ctb_scad.imp_avere) / ctb_part.cambio_divi_cont\n" +
|
||||
" ELSE (\n" +
|
||||
" CASE\n" +
|
||||
" WHEN ctb_scad.data_pag IS NULL THEN (ctb_part.tipo_partita * ctb_scad.imp_dare) + ((ctb_part.tipo_partita - 1) * ctb_scad.imp_avere) / ctb_part.cambio_divi_cont\n" +
|
||||
" ELSE 0\n" +
|
||||
" END\n" +
|
||||
" )\n" +
|
||||
" END\n" +
|
||||
" )\n" +
|
||||
" ) AS imp_scoperto,\n" +
|
||||
" Round(\n" +
|
||||
" CASE\n" +
|
||||
" WHEN sum(\n" +
|
||||
" (ctb_part.tipo_partita * ctb_scad.imp_dare) + ((ctb_part.tipo_partita - 1) * ctb_scad.imp_avere) / ctb_part.cambio_divi_cont\n" +
|
||||
" ) <> 0 THEN sum(\n" +
|
||||
" dateDiff(DAY, ctb_part.data_doc, ctb_scad.data_scad) * (\n" +
|
||||
" (ctb_part.tipo_partita * ctb_scad.imp_dare) + ((ctb_part.tipo_partita - 1) * ctb_scad.imp_avere) / ctb_part.cambio_divi_cont\n" +
|
||||
" )\n" +
|
||||
" ) / sum(\n" +
|
||||
" (ctb_part.tipo_partita * ctb_scad.imp_dare) + ((ctb_part.tipo_partita - 1) * ctb_scad.imp_avere) / ctb_part.cambio_divi_cont\n" +
|
||||
" )\n" +
|
||||
" ELSE 0\n" +
|
||||
" END,\n" +
|
||||
" 0\n" +
|
||||
" ) AS gg_cred_conc,\n" +
|
||||
" Round(\n" +
|
||||
" CASE\n" +
|
||||
" WHEN sum(\n" +
|
||||
" (ctb_part.tipo_partita * ctb_scad.imp_dare) + ((ctb_part.tipo_partita - 1) * ctb_scad.imp_avere) / ctb_part.cambio_divi_cont\n" +
|
||||
" ) <> 0 THEN sum(\n" +
|
||||
" dateDiff(\n" +
|
||||
" DAY,\n" +
|
||||
" ctb_part.data_doc,\n" +
|
||||
" isnull(ctb_scad.data_pag, '2000/01/01')\n" +
|
||||
" ) * (\n" +
|
||||
" (ctb_part.tipo_partita * ctb_scad.imp_dare) + ((ctb_part.tipo_partita - 1) * ctb_scad.imp_avere) / ctb_part.cambio_divi_cont\n" +
|
||||
" )\n" +
|
||||
" ) / sum(\n" +
|
||||
" (ctb_part.tipo_partita * ctb_scad.imp_dare) + ((ctb_part.tipo_partita - 1) * ctb_scad.imp_avere) / ctb_part.cambio_divi_cont\n" +
|
||||
" )\n" +
|
||||
" ELSE 0\n" +
|
||||
" END,\n" +
|
||||
" 0\n" +
|
||||
" ) AS gg_medi_cred, \n" +
|
||||
" convert (numeric(20,5),0) as gg_medi_eff_ad_oggi\n" +
|
||||
"FROM\n" +
|
||||
" ctb_part,\n" +
|
||||
" ctb_scad\n" +
|
||||
"WHERE\n" +
|
||||
" (ctb_part.tipo_anag = ctb_scad.tipo_anag)\n" +
|
||||
" AND (ctb_part.cod_anag = ctb_scad.cod_anag)\n" +
|
||||
" AND (ctb_part.anno_part = ctb_scad.anno_part)\n" +
|
||||
" AND (ctb_part.ser_doc = ctb_scad.ser_doc)\n" +
|
||||
" AND (ctb_part.num_doc = ctb_scad.num_doc)\n" +
|
||||
" AND (ctb_part.data_doc = ctb_scad.data_doc)\n" +
|
||||
" AND (\n" +
|
||||
" (\n" +
|
||||
" ctb_part.tipo_partita = 1\n" +
|
||||
" AND ctb_scad.imp_dare <> 0\n" +
|
||||
" )\n" +
|
||||
" OR (\n" +
|
||||
" ctb_part.tipo_partita = 0\n" +
|
||||
" AND ctb_scad.imp_avere <> 0\n" +
|
||||
" )\n" +
|
||||
" )\n" +
|
||||
"GROUP BY\n" +
|
||||
" ctb_scad.tipo_anag,\n" +
|
||||
" ctb_scad.cod_anag,\n" +
|
||||
" ctb_scad.anno_part,\n" +
|
||||
" ctb_scad.data_doc,\n" +
|
||||
" ctb_scad.num_doc,\n" +
|
||||
" ctb_scad.ser_doc,\n" +
|
||||
" ctb_scad.id_riga");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20240621142815 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
|
||||
executeStatement(
|
||||
"exec dropPrimaryKey 'mtb_depo_intercode'",
|
||||
"alter table mtb_depo_intercode drop column id_intercode",
|
||||
"alter table mtb_depo_intercode add id bigint identity not null",
|
||||
"alter table mtb_depo_intercode add constraint pk_mtb_depo_intecode primary key(id)" );
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20240621163035 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
|
||||
createSetup("IMPORT_DOCUMENTI ACQUISTO", "CASSETTO_FISCALE", "ATTIVO", "S", "Inserire S/N per attivare/disattivare il tipo di importazione", false, null, false, false, false, false, false, null, false, null);
|
||||
createSetup("IMPORT_DOCUMENTI ACQUISTO", "CASSETTO_FISCALE", "EMAIL_FOR_LOG", null, "Inserire il file l'indirizzo email per inviare il log dell'importazione", false, null, false, false, false, false, false, null, false, null);
|
||||
createSetup("IMPORT_DOCUMENTI ACQUISTO", "CASSETTO_FISCALE", "FILE_FILTER", null, "Inserire il criterio di filtro dei file o il nome del file specifio (seguire la sintassi di java)", false, null, false, false, false, false, false, null, false, null);
|
||||
createSetup("IMPORT_DOCUMENTI ACQUISTO", "CASSETTO_FISCALE", "GG_CANC_FILE", null, "Giorni per la cancellazione dei file dalla cartella di appoggio", false, null, false, false, false, false, false, null, false, null);
|
||||
createSetup("IMPORT_DOCUMENTI ACQUISTO", "CASSETTO_FISCALE", "IMPORT_REST", "S", "Inserire S/N per attivare/disattivare il salvataggio con i servizi REST", false, null, false, false, false, false, false, null, false, null);
|
||||
createSetup("IMPORT_DOCUMENTI ACQUISTO", "CASSETTO_FISCALE", "LISTENING", "N", "Se LISTENIG = 'N' la procedura di importazione non si potrà mai mettere in ascolto sulla directory perchè nella procedura vengono prese in considerazione più file.", false, null, false, false, false, false, false, null, false, null);
|
||||
createSetup("IMPORT_DOCUMENTI ACQUISTO", "CASSETTO_FISCALE", "PATH_FILE", null, "Directory contente i file da importare.", false, null, false, false, false, false, false, null, false, null);
|
||||
createSetup("IMPORT_DOCUMENTI ACQUISTO", "CASSETTO_FISCALE", "PATH_FILE_IMPORTED", null, "Directory dove vengono spostati i file dopo l'importazione.", false, null, false, false, false, false, false, null, false, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -4,14 +4,17 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import it.integry.ems_model.annotation.*;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.base.EquatableEntityInterface;
|
||||
import org.kie.api.definition.type.PropertyReactive;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
@PropertyReactive
|
||||
@Table(DtbOrds.ENTITY)
|
||||
@JsonTypeName(DtbOrds.ENTITY)
|
||||
public class DtbOrds extends EntityBase {
|
||||
public class DtbOrds extends EntityBase implements EquatableEntityInterface<DtbOrds> {
|
||||
|
||||
public static final String ENTITY = "dtb_ords";
|
||||
|
||||
@@ -245,4 +248,32 @@ public class DtbOrds extends EntityBase {
|
||||
this.qtaProd = qtaProd;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equalsKey(DtbOrds other) {
|
||||
if (this == other) return true;
|
||||
|
||||
return Objects.equals(getDataOrd(), other.getDataOrd()) &&
|
||||
Objects.equals(getGestione(), other.getGestione()) &&
|
||||
Objects.equals(getIdRiga(), other.getIdRiga()) &&
|
||||
Objects.equals(getNumOrd(), other.getNumOrd());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equalsContent(DtbOrds other) {
|
||||
if (this == other) return true;
|
||||
return Objects.equals(getDataOrd(), other.getDataOrd()) &&
|
||||
Objects.equals(getGestione(), other.getGestione()) &&
|
||||
Objects.equals(getIdRiga(), other.getIdRiga()) &&
|
||||
Objects.equals(getNumOrd(), other.getNumOrd()) &&
|
||||
Objects.equals(getCodAliq(), other.getCodAliq()) &&
|
||||
Objects.equals(getCodSpes(), other.getCodSpes()) &&
|
||||
Objects.equals(getDescrizione(), other.getDescrizione()) &&
|
||||
Objects.equals(getImporto(), other.getImporto()) &&
|
||||
Objects.equals(getNumFase(), other.getNumFase()) &&
|
||||
Objects.equals(getQta(), other.getQta()) &&
|
||||
Objects.equals(getUntMis(), other.getUntMis()) &&
|
||||
Objects.equals(getValUnt(), other.getValUnt());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,12 +1,9 @@
|
||||
package it.integry.ems_model.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import it.integry.ems_model.annotation.PK;
|
||||
import it.integry.ems_model.annotation.SqlField;
|
||||
import it.integry.ems_model.annotation.Table;
|
||||
import it.integry.ems_model.annotation.*;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import org.kie.api.definition.type.PropertyReactive;
|
||||
import it.integry.ems_model.annotation.FK;
|
||||
|
||||
@PropertyReactive
|
||||
@Table(MtbDepoIntercode.ENTITY)
|
||||
@@ -17,17 +14,17 @@ public class MtbDepoIntercode extends EntityBase {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@PK
|
||||
@ImportFromParent
|
||||
@SqlField(value = "cod_mdep", maxLength = 5, nullable = false)
|
||||
private String codMdep;
|
||||
|
||||
@PK
|
||||
@SqlField(value = "cod_forn", maxLength = 5, nullable = false)
|
||||
private String codForn;
|
||||
|
||||
@PK
|
||||
@SqlField(value = "id_intercode", nullable = false)
|
||||
private Integer idIntercode;
|
||||
@Identity
|
||||
@SqlField(value = "id", nullable = false)
|
||||
private Long id;
|
||||
|
||||
@SqlField(value = "intercode", maxLength = 40, nullable = false)
|
||||
private String intercode;
|
||||
@@ -49,55 +46,62 @@ public class MtbDepoIntercode extends EntityBase {
|
||||
return codMdep;
|
||||
}
|
||||
|
||||
public void setCodMdep(String codMdep) {
|
||||
public MtbDepoIntercode setCodMdep(String codMdep) {
|
||||
this.codMdep = codMdep;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodForn() {
|
||||
return codForn;
|
||||
}
|
||||
|
||||
public void setCodForn(String codForn) {
|
||||
public MtbDepoIntercode setCodForn(String codForn) {
|
||||
this.codForn = codForn;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getIdIntercode() {
|
||||
return idIntercode;
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setIdIntercode(Integer idIntercode) {
|
||||
this.idIntercode = idIntercode;
|
||||
public MtbDepoIntercode setId(Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getIntercode() {
|
||||
return intercode;
|
||||
}
|
||||
|
||||
public void setIntercode(String intercode) {
|
||||
public MtbDepoIntercode setIntercode(String intercode) {
|
||||
this.intercode = intercode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodVdes() {
|
||||
return codVdes;
|
||||
}
|
||||
|
||||
public void setCodVdes(String codVdes) {
|
||||
public MtbDepoIntercode setCodVdes(String codVdes) {
|
||||
this.codVdes = codVdes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
public MtbDepoIntercode setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getEmailOrdine() {
|
||||
return emailOrdine;
|
||||
}
|
||||
|
||||
public void setEmailOrdine(String emailOrdine) {
|
||||
public MtbDepoIntercode setEmailOrdine(String emailOrdine) {
|
||||
this.emailOrdine = emailOrdine;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package it.integry.ems.system.exchange.controller;
|
||||
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.response.ServiceRestResponse;
|
||||
import it.integry.ems.system.exchange.service.ExchangeOrderImportService;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@RestController
|
||||
@Scope("request")
|
||||
@RequestMapping("exchange/ordini/")
|
||||
public class ExchangeOrdiniImportController {
|
||||
|
||||
|
||||
private final Logger logger = LogManager.getLogger();
|
||||
|
||||
@Autowired
|
||||
private ExchangeOrderImportService exchangeOrderImportService;
|
||||
|
||||
|
||||
|
||||
@RequestMapping(value = "importLavorazione", method = RequestMethod.GET)
|
||||
public @ResponseBody
|
||||
ServiceRestResponse importLavorazione(HttpServletRequest request,
|
||||
@RequestParam(CommonConstants.PROFILE_DB) String configuration) throws Exception {
|
||||
|
||||
exchangeOrderImportService.importOrdiniLavorazione();
|
||||
return ServiceRestResponse.createPositiveResponse();
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,10 @@
|
||||
package it.integry.ems.system.exchange.service;
|
||||
|
||||
import it.integry.ems.dto.EntityHierarchy;
|
||||
import it.integry.ems.service.EntityProcessor;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.base.EntityPropertyHolder;
|
||||
import it.integry.ems_model.base.EquatableEntityInterface;
|
||||
import it.integry.ems_model.entity.MtbColr;
|
||||
import it.integry.ems_model.entity.MtbColt;
|
||||
import it.integry.ems_model.types.OperationType;
|
||||
import it.integry.ems_model.utility.Query;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import it.integry.ems_model.utility.UtilityLocalDate;
|
||||
import it.integry.ems_model.utility.UtilityQuery;
|
||||
@@ -18,13 +13,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Service
|
||||
@Scope("request")
|
||||
public class ExchangeColliImportService {
|
||||
@@ -41,38 +36,43 @@ public class ExchangeColliImportService {
|
||||
@Autowired
|
||||
private ExchangeImportSchemaManagerService exchangeImportSchemaManagerService;
|
||||
|
||||
@Autowired
|
||||
private ExchangeImportDataManagerService exchangeImportDataManagerService;
|
||||
|
||||
public void importColliLavorazione() throws Exception {
|
||||
|
||||
try (MultiDBTransactionManager exchangeDb = new MultiDBTransactionManager(ROSSOGARGANO_EXCHANGE_PROFILEDB)) {
|
||||
|
||||
exchangeImportSchemaManagerService.syncSchema(exchangeDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.ColliLavorazione);
|
||||
|
||||
// final List<MtbColt> internalMtbColts = retrieveInternalColliLavorazione(
|
||||
// UtilityLocalDate.getNow().minusMonths(1),
|
||||
// UtilityLocalDate.getNow());
|
||||
|
||||
final List<MtbColt> exchangeImportedMtbColts = retrieveExchangeColliLavorazione(
|
||||
final List<MtbColt> exchangeImportedMtbColts = importColliLavorazione(
|
||||
exchangeDb.getPrimaryConnection(),
|
||||
UtilityLocalDate.getNow().minusDays(1),
|
||||
UtilityLocalDate.getNow().minusMonths(1),
|
||||
UtilityLocalDate.getNow(),
|
||||
true);
|
||||
|
||||
List<MtbColt> exchangeUpdatedMtbColts = retrieveExchangeColliLavorazione(
|
||||
List<MtbColt> exchangeUpdatedMtbColts = importColliLavorazione(
|
||||
exchangeDb.getPrimaryConnection(),
|
||||
UtilityLocalDate.getNow().minusDays(1),
|
||||
UtilityLocalDate.getNow().minusMonths(1),
|
||||
UtilityLocalDate.getNow(),
|
||||
false);
|
||||
|
||||
|
||||
List<EquatableEntityInterface> importedMtbColts = exchangeImportedMtbColts.stream().map(x -> (EquatableEntityInterface) x).collect(Collectors.toList());
|
||||
List<EquatableEntityInterface> updatedMtbColts = exchangeUpdatedMtbColts.stream().map(x -> (EquatableEntityInterface) x).collect(Collectors.toList());
|
||||
List<EquatableEntityInterface> importedMtbColts = exchangeImportedMtbColts.stream()
|
||||
.map(x -> (EquatableEntityInterface) x)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<EquatableEntityInterface> allMtbColts = runSync(MtbColt.class, importedMtbColts, updatedMtbColts);
|
||||
List<EquatableEntityInterface> updatedMtbColts = exchangeUpdatedMtbColts.stream()
|
||||
.map(x -> (EquatableEntityInterface) x)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<EquatableEntityInterface> allMtbColts = exchangeImportDataManagerService
|
||||
.runSync(MtbColt.class, importedMtbColts, updatedMtbColts);
|
||||
|
||||
int importedCounter = 0;
|
||||
for (EquatableEntityInterface mtbColtToSave : allMtbColts) {
|
||||
|
||||
LogManager.getLogger().debug("Importati " + ++importedCounter + " di " + allMtbColts.size());
|
||||
LogManager.getLogger().debug("Importati {} di {}", ++importedCounter, allMtbColts.size());
|
||||
try {
|
||||
entityProcessor.processEntity(mtbColtToSave, multiDBTransactionManager);
|
||||
|
||||
@@ -83,78 +83,27 @@ public class ExchangeColliImportService {
|
||||
multiDBTransactionManager.rollbackAll();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//UtilityEntity.throwEntitiesException(mtbColtToAdd);
|
||||
|
||||
//Aggiornare prev gradualmente, quando viene processata deve controllare se esiste in prev e cancellarla
|
||||
// e successivamente inserirla di nuovo (aggiornata)
|
||||
//updateImportedTable(exchangeDb.getPrimaryConnection(), allMtbColts);
|
||||
|
||||
String a = "";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private List<MtbColt> retrieveInternalColliLavorazione(LocalDate minDate, LocalDate maxDate) throws Exception {
|
||||
final List<MtbColt> mtbColtRawData =
|
||||
UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(),
|
||||
Query.format("SELECT * FROM mtb_colt " +
|
||||
"WHERE data_collo BETWEEN %s and %s", minDate, maxDate),
|
||||
MtbColt.class);
|
||||
private List<MtbColt> importColliLavorazione(Connection connection,
|
||||
LocalDate minDate, LocalDate maxDate, boolean retrieveAlreadyImported) throws Exception {
|
||||
|
||||
final List<MtbColr> mtbColrRawData =
|
||||
UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(),
|
||||
Query.format("SELECT * FROM mtb_colr " +
|
||||
"WHERE data_collo BETWEEN %s and %s", minDate, maxDate), MtbColr.class);
|
||||
final List<MtbColt> mtbColtLav = exchangeImportDataManagerService.retrieveDataFromExchange(connection, MtbColt.class,
|
||||
"mtb_colt_lav", "data_collo", minDate, maxDate, retrieveAlreadyImported);
|
||||
|
||||
if (mtbColtRawData == null || mtbColtRawData.isEmpty())
|
||||
return new ArrayList<>();
|
||||
final List<MtbColr> mtbColrLav = exchangeImportDataManagerService.retrieveDataFromExchange(connection, MtbColr.class,
|
||||
"mtb_colr_lav", "data_collo", minDate, maxDate, retrieveAlreadyImported);
|
||||
|
||||
if (mtbColrRawData == null || mtbColrRawData.isEmpty())
|
||||
return mtbColtRawData;
|
||||
|
||||
mtbColtRawData
|
||||
.forEach(x -> {
|
||||
x.setMtbColr(mtbColrRawData.stream()
|
||||
.filter(y -> y.getDataCollo().equals(x.getDataCollo()) &&
|
||||
y.getGestione().equalsIgnoreCase(x.getGestione()) &&
|
||||
y.getNumCollo().equals(x.getNumCollo()) &&
|
||||
y.getSerCollo().equalsIgnoreCase(x.getSerCollo()))
|
||||
.collect(Collectors.toList()));
|
||||
});
|
||||
|
||||
return mtbColtRawData;
|
||||
}
|
||||
|
||||
private List<MtbColt> retrieveExchangeColliLavorazione(Connection connection, LocalDate minDate, LocalDate maxDate, boolean retrieveAlreadyImported) throws Exception {
|
||||
|
||||
final List<MtbColt> mtbColtRawData =
|
||||
UtilityDB.executeSimpleQueryDTO(connection,
|
||||
Query.format("SELECT * FROM mtb_colt_lav" + (retrieveAlreadyImported ? "_prev" : "") + " " +
|
||||
"WHERE data_collo BETWEEN %s and %s", minDate, maxDate),
|
||||
MtbColt.class);
|
||||
|
||||
if (mtbColtRawData == null || mtbColtRawData.isEmpty())
|
||||
return new ArrayList<>();
|
||||
|
||||
final List<MtbColr> mtbColrRawData =
|
||||
UtilityDB.executeSimpleQueryDTO(connection,
|
||||
Query.format("SELECT * FROM mtb_colr_lav" + (retrieveAlreadyImported ? "_prev" : "") + " " +
|
||||
"WHERE data_collo BETWEEN %s and %s", minDate, maxDate), MtbColr.class);
|
||||
|
||||
if (mtbColrRawData == null || mtbColrRawData.isEmpty())
|
||||
return mtbColtRawData;
|
||||
|
||||
mtbColtRawData
|
||||
mtbColtLav
|
||||
.forEach(x -> {
|
||||
|
||||
x.setDataDoc(null)
|
||||
.setSerDoc(null)
|
||||
.setCodDtip(null);
|
||||
|
||||
x.setMtbColr(mtbColrRawData.stream()
|
||||
x.setMtbColr(mtbColrLav.stream()
|
||||
.filter(y -> y.getDataCollo().equals(x.getDataCollo()) &&
|
||||
y.getGestione().equalsIgnoreCase(x.getGestione()) &&
|
||||
y.getNumCollo().equals(x.getNumCollo()) &&
|
||||
@@ -162,147 +111,10 @@ public class ExchangeColliImportService {
|
||||
.collect(Collectors.toList()));
|
||||
});
|
||||
|
||||
return mtbColtRawData;
|
||||
return mtbColtLav;
|
||||
}
|
||||
|
||||
|
||||
private List<EquatableEntityInterface> runSync(Class<? extends EquatableEntityInterface> clazz, List<EquatableEntityInterface> importedItems, List<EquatableEntityInterface> newItems) throws IllegalAccessException {
|
||||
//To be added
|
||||
List<EquatableEntityInterface> mtbColtToAdd = calcItemsToAdd(clazz, importedItems, newItems);
|
||||
|
||||
//To be deleted
|
||||
List<EquatableEntityInterface> mtbColtToDelete = calcItemsToDelete(clazz, importedItems, newItems);
|
||||
|
||||
//To be updated
|
||||
List<EquatableEntityInterface> mtbColtToUpdate = calcItemsToUpdate(clazz, importedItems, newItems);
|
||||
|
||||
List<EquatableEntityInterface> allMtbColts = new ArrayList<>();
|
||||
allMtbColts.addAll(mtbColtToAdd);
|
||||
allMtbColts.addAll(mtbColtToDelete);
|
||||
allMtbColts.addAll(mtbColtToUpdate);
|
||||
|
||||
return allMtbColts;
|
||||
}
|
||||
|
||||
private List<EquatableEntityInterface> calcItemsToAdd(Class<? extends EquatableEntityInterface> clazz, List<EquatableEntityInterface> importedMtbColts, List<EquatableEntityInterface> updatedMtbColts) throws IllegalAccessException {
|
||||
final List<EquatableEntityInterface> itemsToAdd = updatedMtbColts.stream()
|
||||
.filter(x -> importedMtbColts.stream().noneMatch(y -> y.equalsKey(x)))
|
||||
.peek(x -> x.setOperation(OperationType.INSERT))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
final List<EntityHierarchy> entityChildren = EntityPropertyHolder.getEntityChildrenStatic(clazz, EntityHierarchy::isEquatable);
|
||||
for (EntityHierarchy entityChild : entityChildren) {
|
||||
Field parentField = entityChild.getParentField();
|
||||
|
||||
for (EquatableEntityInterface item : itemsToAdd) {
|
||||
Object child = parentField.get(item);
|
||||
|
||||
if (child instanceof List) {
|
||||
List<EntityBase> childList = (List<EntityBase>) child;
|
||||
childList.stream()
|
||||
.forEach(y -> y.setOperation(OperationType.INSERT));
|
||||
} else {
|
||||
EntityBase childItem = (EntityBase) child;
|
||||
childItem.setOperation(OperationType.INSERT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return itemsToAdd;
|
||||
}
|
||||
|
||||
private List<EquatableEntityInterface> calcItemsToDelete(Class<? extends EquatableEntityInterface> clazz, List<EquatableEntityInterface> importedMtbColts, List<EquatableEntityInterface> updatedMtbColts) throws IllegalAccessException {
|
||||
final List<EquatableEntityInterface> itemsToDelete = importedMtbColts.stream()
|
||||
.filter(x -> updatedMtbColts.stream().noneMatch(y -> y.equalsKey(x)))
|
||||
.peek(x -> x.setOperation(OperationType.INSERT))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
final List<EntityHierarchy> entityChildren = EntityPropertyHolder.getEntityChildrenStatic(clazz, EntityHierarchy::isEquatable);
|
||||
for (EntityHierarchy entityChild : entityChildren) {
|
||||
Field parentField = entityChild.getParentField();
|
||||
|
||||
for (EquatableEntityInterface item : itemsToDelete) {
|
||||
Object child = parentField.get(item);
|
||||
|
||||
if (child instanceof List) {
|
||||
List<EntityBase> childList = (List<EntityBase>) child;
|
||||
childList.stream()
|
||||
.forEach(y -> y.setOperation(OperationType.DELETE));
|
||||
} else {
|
||||
EntityBase childItem = (EntityBase) child;
|
||||
childItem.setOperation(OperationType.DELETE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return itemsToDelete;
|
||||
}
|
||||
|
||||
private List<EquatableEntityInterface> calcItemsToUpdate(Class<? extends EquatableEntityInterface> clazz, List<EquatableEntityInterface> importedMtbColts, List<EquatableEntityInterface> updatedMtbColts) throws IllegalAccessException {
|
||||
List<EquatableEntityInterface> itemsToUpdate = updatedMtbColts.stream()
|
||||
.filter(x -> importedMtbColts.stream().anyMatch(y -> y.equalsKey(x)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
final List<EntityHierarchy> entityChildren = EntityPropertyHolder.getEntityChildrenStatic(clazz, EntityHierarchy::isEquatable);
|
||||
|
||||
for (EquatableEntityInterface itemToUpdate : itemsToUpdate) {
|
||||
for (EntityHierarchy entityChild : entityChildren) {
|
||||
Field parentField = entityChild.getParentField();
|
||||
|
||||
if (Collection.class.isAssignableFrom(parentField.getType())) { //Is a list
|
||||
|
||||
List<EquatableEntityInterface> importedChilds = importedMtbColts.stream()
|
||||
.filter(y -> y.equalsKey(itemToUpdate))
|
||||
.flatMap(y -> {
|
||||
try {
|
||||
return ((List<EquatableEntityInterface>) parentField.get(y)).stream();
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<EquatableEntityInterface> newChilds = (List<EquatableEntityInterface>) parentField.get(itemToUpdate);
|
||||
|
||||
List<EquatableEntityInterface> result =
|
||||
runSync((Class<EquatableEntityInterface>) entityChild.getClazz(), importedChilds, newChilds);
|
||||
|
||||
parentField.set(itemToUpdate, result);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
itemToUpdate.setOperation(OperationType.UPDATE);
|
||||
}
|
||||
return itemsToUpdate.stream()
|
||||
.filter(x -> {
|
||||
boolean anyChildToUpdate = false;
|
||||
|
||||
for (EntityHierarchy entityChild : entityChildren) {
|
||||
Field parentField = entityChild.getParentField();
|
||||
|
||||
if (Collection.class.isAssignableFrom(parentField.getType())) { //Is a list
|
||||
try {
|
||||
List<EquatableEntityInterface> childs = (List<EquatableEntityInterface>) parentField.get(x);
|
||||
|
||||
if(!childs.isEmpty()) {
|
||||
anyChildToUpdate = true;
|
||||
break;
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return anyChildToUpdate || importedMtbColts.stream().anyMatch(y -> y.equalsKey(x) && !y.equalsContent(x));
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
private void singleUpdateImported(Connection connection, MtbColt importedMtbColt) throws Exception {
|
||||
@@ -333,65 +145,4 @@ public class ExchangeColliImportService {
|
||||
}
|
||||
|
||||
|
||||
private void updateImportedTable(Connection connection, List<MtbColt> importedMtbColt) throws SQLException {
|
||||
List<MtbColt> withoutErrors = importedMtbColt.stream()
|
||||
.filter(x -> Objects.isNull(x.getException()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<MtbColt> withErrors = importedMtbColt.stream()
|
||||
.filter(x -> x.getException() != null)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
List<HashMap<String, Object>> withErrorsColliKeys = withErrors.stream()
|
||||
.map(x -> new HashMap<String, Object>() {{
|
||||
put("data_collo", x.getDataCollo());
|
||||
put("ser_collo", x.getSerCollo());
|
||||
put("num_collo", x.getNumCollo());
|
||||
put("gestione", x.getGestione());
|
||||
}})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
String whereCondKeys = UtilityQuery.concatFieldListInWhereCond(withErrorsColliKeys);
|
||||
|
||||
UtilityDB.executeStatement(connection,
|
||||
"DELETE FROM mtb_colr_lav_prev " +
|
||||
(!whereCondKeys.isEmpty() ? "WHERE NOT(" + whereCondKeys + ")" : ""),
|
||||
|
||||
"DELETE FROM mtb_colt_lav_prev " +
|
||||
(!whereCondKeys.isEmpty() ? "WHERE NOT(" + whereCondKeys + ")" : ""));
|
||||
|
||||
|
||||
// List<HashMap<String, Object>> insertedColliKeys = withoutErrors.stream()
|
||||
// .map(x -> new HashMap<String, Object>() {{
|
||||
// put("data_collo", x.getDataCollo());
|
||||
// put("ser_collo", x.getSerCollo());
|
||||
// put("num_collo", x.getNumCollo());
|
||||
// put("gestione", x.getGestione());
|
||||
// }})
|
||||
// .collect(Collectors.toList());
|
||||
|
||||
|
||||
// AtomicInteger counter = new AtomicInteger();
|
||||
//
|
||||
// final Collection<List<HashMap<String, Object>>> values = insertedColliKeys.stream()
|
||||
// .collect(groupingBy(x -> counter.getAndIncrement() / 500))
|
||||
// .values();
|
||||
//
|
||||
//
|
||||
// for (List<HashMap<String, Object>> items : values) {
|
||||
// whereCondKeys = UtilityQuery.concatFieldListInWhereCond(items);
|
||||
|
||||
UtilityDB.executeStatement(connection,
|
||||
"INSERT INTO mtb_colt_lav_prev " +
|
||||
"SELECT * FROM mtb_colt_lav " +
|
||||
(!whereCondKeys.isEmpty() ? " WHERE NOT(" + whereCondKeys + ")" : ""),
|
||||
|
||||
"INSERT INTO mtb_colr_lav_prev " +
|
||||
"SELECT * FROM mtb_colr_lav " +
|
||||
(!whereCondKeys.isEmpty() ? " WHERE NOT(" + whereCondKeys + ")" : ""));
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
package it.integry.ems.system.exchange.service;
|
||||
|
||||
import it.integry.ems.dto.EntityHierarchy;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.base.EntityPropertyHolder;
|
||||
import it.integry.ems_model.base.EquatableEntityInterface;
|
||||
import it.integry.ems_model.types.OperationType;
|
||||
import it.integry.ems_model.utility.Query;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.Connection;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
@Service
|
||||
public class ExchangeImportDataManagerService {
|
||||
|
||||
|
||||
public <T extends EquatableEntityInterface> List<T> retrieveDataFromExchange(Connection connection,
|
||||
Class<T> clazz,
|
||||
String tableName, String dateSqlFieldName,
|
||||
LocalDate minDate, LocalDate maxDate, boolean retrieveAlreadyImported) throws Exception {
|
||||
|
||||
final List<T> importedRawData =
|
||||
UtilityDB.executeSimpleQueryDTO(connection,
|
||||
Query.format("SELECT * FROM " + tableName + (retrieveAlreadyImported ? "_prev" : "") + " " +
|
||||
"WHERE " + dateSqlFieldName + " BETWEEN {} and {}", minDate, maxDate),
|
||||
clazz);
|
||||
|
||||
if (importedRawData == null || importedRawData.isEmpty())
|
||||
return new ArrayList<>();
|
||||
|
||||
|
||||
return importedRawData;
|
||||
}
|
||||
|
||||
|
||||
public List<EquatableEntityInterface> runSync(Class<? extends EquatableEntityInterface> clazz, List<EquatableEntityInterface> importedItems, List<EquatableEntityInterface> newItems) throws IllegalAccessException {
|
||||
//To be added
|
||||
List<EquatableEntityInterface> mtbColtToAdd = calcItemsToAdd(clazz, importedItems, newItems);
|
||||
|
||||
//To be deleted
|
||||
List<EquatableEntityInterface> mtbColtToDelete = calcItemsToDelete(clazz, importedItems, newItems);
|
||||
|
||||
//To be updated
|
||||
List<EquatableEntityInterface> mtbColtToUpdate = calcItemsToUpdate(clazz, importedItems, newItems);
|
||||
|
||||
List<EquatableEntityInterface> allMtbColts = new ArrayList<>();
|
||||
allMtbColts.addAll(mtbColtToAdd);
|
||||
allMtbColts.addAll(mtbColtToDelete);
|
||||
allMtbColts.addAll(mtbColtToUpdate);
|
||||
|
||||
return allMtbColts;
|
||||
}
|
||||
|
||||
private List<EquatableEntityInterface> calcItemsToAdd(Class<? extends EquatableEntityInterface> clazz, List<EquatableEntityInterface> importedMtbColts, List<EquatableEntityInterface> updatedMtbColts) throws IllegalAccessException {
|
||||
final List<EquatableEntityInterface> itemsToAdd = updatedMtbColts.stream()
|
||||
.filter(x -> importedMtbColts.stream().noneMatch(y -> y.equalsKey(x)))
|
||||
.peek(x -> x.setOperation(OperationType.INSERT))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
final List<EntityHierarchy> entityChildren = EntityPropertyHolder.getEntityChildrenStatic(clazz, EntityHierarchy::isEquatable);
|
||||
for (EntityHierarchy entityChild : entityChildren) {
|
||||
Field parentField = entityChild.getParentField();
|
||||
|
||||
for (EquatableEntityInterface item : itemsToAdd) {
|
||||
Object child = parentField.get(item);
|
||||
|
||||
if (child instanceof List) {
|
||||
List<EntityBase> childList = (List<EntityBase>) child;
|
||||
childList
|
||||
.forEach(y -> y.setOperation(OperationType.INSERT));
|
||||
} else {
|
||||
EntityBase childItem = (EntityBase) child;
|
||||
childItem.setOperation(OperationType.INSERT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return itemsToAdd;
|
||||
}
|
||||
|
||||
private List<EquatableEntityInterface> calcItemsToDelete(Class<? extends EquatableEntityInterface> clazz, List<EquatableEntityInterface> importedMtbColts, List<EquatableEntityInterface> updatedMtbColts) throws IllegalAccessException {
|
||||
final List<EquatableEntityInterface> itemsToDelete = importedMtbColts.stream()
|
||||
.filter(x -> updatedMtbColts.stream().noneMatch(y -> y.equalsKey(x)))
|
||||
.peek(x -> x.setOperation(OperationType.INSERT))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
final List<EntityHierarchy> entityChildren = EntityPropertyHolder.getEntityChildrenStatic(clazz, EntityHierarchy::isEquatable);
|
||||
for (EntityHierarchy entityChild : entityChildren) {
|
||||
Field parentField = entityChild.getParentField();
|
||||
|
||||
for (EquatableEntityInterface item : itemsToDelete) {
|
||||
Object child = parentField.get(item);
|
||||
|
||||
if (child instanceof List) {
|
||||
List<EntityBase> childList = (List<EntityBase>) child;
|
||||
childList.stream()
|
||||
.forEach(y -> y.setOperation(OperationType.DELETE));
|
||||
} else {
|
||||
EntityBase childItem = (EntityBase) child;
|
||||
childItem.setOperation(OperationType.DELETE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return itemsToDelete;
|
||||
}
|
||||
|
||||
private List<EquatableEntityInterface> calcItemsToUpdate(Class<? extends EquatableEntityInterface> clazz, List<EquatableEntityInterface> importedMtbColts, List<EquatableEntityInterface> updatedMtbColts) throws IllegalAccessException {
|
||||
List<EquatableEntityInterface> itemsToUpdate = updatedMtbColts.stream()
|
||||
.filter(x -> importedMtbColts.stream().anyMatch(y -> y.equalsKey(x)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
final List<EntityHierarchy> entityChildren = EntityPropertyHolder.getEntityChildrenStatic(clazz, EntityHierarchy::isEquatable);
|
||||
|
||||
for (EquatableEntityInterface itemToUpdate : itemsToUpdate) {
|
||||
for (EntityHierarchy entityChild : entityChildren) {
|
||||
Field parentField = entityChild.getParentField();
|
||||
|
||||
if (Collection.class.isAssignableFrom(parentField.getType())) { //Is a list
|
||||
|
||||
List<EquatableEntityInterface> importedChilds = importedMtbColts.stream()
|
||||
.filter(y -> y.equalsKey(itemToUpdate))
|
||||
.flatMap(y -> {
|
||||
try {
|
||||
return ((List<EquatableEntityInterface>) parentField.get(y)).stream();
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<EquatableEntityInterface> newChilds = (List<EquatableEntityInterface>) parentField.get(itemToUpdate);
|
||||
|
||||
List<EquatableEntityInterface> result =
|
||||
runSync((Class<EquatableEntityInterface>) entityChild.getClazz(), importedChilds, newChilds);
|
||||
|
||||
parentField.set(itemToUpdate, result);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
itemToUpdate.setOperation(OperationType.UPDATE);
|
||||
}
|
||||
return itemsToUpdate.stream()
|
||||
.filter(x -> {
|
||||
boolean anyChildToUpdate = false;
|
||||
|
||||
for (EntityHierarchy entityChild : entityChildren) {
|
||||
Field parentField = entityChild.getParentField();
|
||||
|
||||
if (Collection.class.isAssignableFrom(parentField.getType())) { //Is a list
|
||||
try {
|
||||
List<EquatableEntityInterface> childs = (List<EquatableEntityInterface>) parentField.get(x);
|
||||
|
||||
if(!childs.isEmpty()) {
|
||||
anyChildToUpdate = true;
|
||||
break;
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return anyChildToUpdate || importedMtbColts.stream().anyMatch(y -> y.equalsKey(x) && !y.equalsContent(x));
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public class ExchangeImportSchemaManagerService {
|
||||
|
||||
public enum SchemaType {
|
||||
ColliLavorazione,
|
||||
Ordini
|
||||
OrdiniLavorazione
|
||||
}
|
||||
|
||||
|
||||
@@ -27,14 +27,25 @@ public class ExchangeImportSchemaManagerService {
|
||||
SQLServerDBSchemaManager sqlServerDBSchemaManager = new SQLServerDBSchemaManager(connection);
|
||||
|
||||
List<DatabaseTableView> objectsToSync = new ArrayList<>();
|
||||
DatabaseView tmpView = null;
|
||||
|
||||
switch (schemaType) {
|
||||
case ColliLavorazione:
|
||||
DatabaseView tmpView = sqlServerDBSchemaManager.getView("mtb_colt_lav");
|
||||
tmpView = sqlServerDBSchemaManager.getView("mtb_colt_lav");
|
||||
if (tmpView != null) objectsToSync.add(tmpView);
|
||||
tmpView = sqlServerDBSchemaManager.getView("mtb_colr_lav");
|
||||
if (tmpView != null) objectsToSync.add(tmpView);
|
||||
break;
|
||||
|
||||
case OrdiniLavorazione:
|
||||
tmpView = sqlServerDBSchemaManager.getView("dtb_ordt_lav");
|
||||
if (tmpView != null) objectsToSync.add(tmpView);
|
||||
tmpView = sqlServerDBSchemaManager.getView("dtb_ordr_lav");
|
||||
if (tmpView != null) objectsToSync.add(tmpView);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Exception("Si prega di definire gli oggetti del database da sincronizzare per " + schemaType);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,17 +1,138 @@
|
||||
package it.integry.ems.system.exchange.service;
|
||||
|
||||
import it.integry.ems.service.EntityProcessor;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems_model.base.EquatableEntityInterface;
|
||||
import it.integry.ems_model.entity.DtbOrdr;
|
||||
import it.integry.ems_model.entity.DtbOrdt;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import it.integry.ems_model.utility.UtilityLocalDate;
|
||||
import it.integry.ems_model.utility.UtilityQuery;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Scope("request")
|
||||
public class ExchangeOrderImportService {
|
||||
|
||||
//TODO: To be remove, only for fast development
|
||||
private final String ROSSOGARGANO_EXCHANGE_PROFILEDB = "ROSSO_GARGANO_EXCHANGE";
|
||||
|
||||
@Autowired
|
||||
private EntityProcessor entityProcessor;
|
||||
|
||||
@Autowired
|
||||
private MultiDBTransactionManager multiDBTransactionManager;
|
||||
|
||||
@Autowired
|
||||
private ExchangeImportSchemaManagerService exchangeImportSchemaManagerService;
|
||||
|
||||
@Autowired
|
||||
private ExchangeImportDataManagerService exchangeImportDataManagerService;
|
||||
|
||||
public void importOrdiniLavorazione() throws Exception {
|
||||
|
||||
try (MultiDBTransactionManager exchangeDb = new MultiDBTransactionManager(ROSSOGARGANO_EXCHANGE_PROFILEDB)) {
|
||||
|
||||
exchangeImportSchemaManagerService.syncSchema(exchangeDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.OrdiniLavorazione);
|
||||
|
||||
final List<DtbOrdt> exchangeImportedMtbColts = importOrdiniLavorazione(
|
||||
exchangeDb.getPrimaryConnection(),
|
||||
UtilityLocalDate.getNow().minusMonths(1),
|
||||
UtilityLocalDate.getNow(),
|
||||
true);
|
||||
|
||||
final List<DtbOrdt> exchangeUpdatedMtbColts = importOrdiniLavorazione(
|
||||
exchangeDb.getPrimaryConnection(),
|
||||
UtilityLocalDate.getNow().minusMonths(1),
|
||||
UtilityLocalDate.getNow(),
|
||||
false);
|
||||
|
||||
|
||||
List<EquatableEntityInterface> importedMtbColts = exchangeImportedMtbColts.stream()
|
||||
.map(x -> (EquatableEntityInterface) x)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<EquatableEntityInterface> updatedMtbColts = exchangeUpdatedMtbColts.stream()
|
||||
.map(x -> (EquatableEntityInterface) x)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<EquatableEntityInterface> allOrders = exchangeImportDataManagerService
|
||||
.runSync(DtbOrdt.class, importedMtbColts, updatedMtbColts);
|
||||
|
||||
int importedCounter = 0;
|
||||
for (EquatableEntityInterface dtbOrdtToSave : allOrders) {
|
||||
|
||||
LogManager.getLogger().debug("Importati {} di {}", ++importedCounter, allOrders.size());
|
||||
try {
|
||||
entityProcessor.processEntity(dtbOrdtToSave, multiDBTransactionManager);
|
||||
|
||||
singleUpdateImported(exchangeDb.getPrimaryConnection(), (DtbOrdt) dtbOrdtToSave);
|
||||
multiDBTransactionManager.commitAll();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
multiDBTransactionManager.rollbackAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<DtbOrdt> importOrdiniLavorazione(Connection connection,
|
||||
LocalDate minDate, LocalDate maxDate, boolean retrieveAlreadyImported) throws Exception {
|
||||
|
||||
final List<DtbOrdt> dtbOrdtLav = exchangeImportDataManagerService.retrieveDataFromExchange(connection, DtbOrdt.class,
|
||||
"dtb_ordt_lav", "data_ord", minDate, maxDate, retrieveAlreadyImported);
|
||||
|
||||
final List<DtbOrdr> dtbOrdrLav = exchangeImportDataManagerService.retrieveDataFromExchange(connection, DtbOrdr.class,
|
||||
"dtb_ordr_lav", "data_ord", minDate, maxDate, retrieveAlreadyImported);
|
||||
|
||||
|
||||
dtbOrdtLav
|
||||
.forEach(x -> {
|
||||
|
||||
x.setDtbOrdr(dtbOrdrLav.stream()
|
||||
.filter(y -> y.getDataOrd().equals(x.getDataOrd()) &&
|
||||
y.getGestione().equalsIgnoreCase(x.getGestione()) &&
|
||||
y.getNumOrd().equals(x.getNumOrd()))
|
||||
.collect(Collectors.toList()));
|
||||
});
|
||||
|
||||
return dtbOrdtLav;
|
||||
}
|
||||
|
||||
|
||||
private void singleUpdateImported(Connection connection, DtbOrdt importedDtbOrdt) throws Exception {
|
||||
final HashMap<String, Object> importedMtbColtKey = new HashMap<String, Object>() {{
|
||||
put("data_ord", importedDtbOrdt.getDataOrd());
|
||||
put("num_ord", importedDtbOrdt.getNumOrd());
|
||||
put("gestione", importedDtbOrdt.getGestione());
|
||||
}};
|
||||
|
||||
String whereCondKey = UtilityQuery.concatFieldsInWhereCond(importedMtbColtKey);
|
||||
|
||||
UtilityDB.executeStatement(connection,
|
||||
"DELETE FROM dtb_ordr_lav_prev " +
|
||||
"WHERE (" + whereCondKey + ")",
|
||||
|
||||
"DELETE FROM dtb_ordt_lav_prev " +
|
||||
"WHERE (" + whereCondKey + ")",
|
||||
|
||||
"INSERT INTO dtb_ordr_lav_prev " +
|
||||
"SELECT * FROM dtb_ordr_lav " +
|
||||
"WHERE (" + whereCondKey + ")",
|
||||
|
||||
"INSERT INTO dtb_ordt_lav_prev " +
|
||||
"SELECT * FROM dtb_ordt_lav " +
|
||||
"WHERE (" + whereCondKey + ")");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user