Migration per esportazione SIAN
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,191 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20240620142950 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
|
||||
createOrUpdateFunction("lol_chkPostureSian", "CREATE FUNCTION [dbo].[lol_chkPostureSian] \n" +
|
||||
"(\n" +
|
||||
" @idDepo int, @dataFile datetime, @progFile int, @codCcua varchar(16)\n" +
|
||||
")\n" +
|
||||
"RETURNS TABLE as\n" +
|
||||
"return \n" +
|
||||
"( \n" +
|
||||
"/*\n" +
|
||||
"DECLARE @idDepo int, @dataFile datetime, @progFile int, @codCcua varchar(16)\n" +
|
||||
"\n" +
|
||||
"SELECT @idDepo = id_depo, @dataFile = data_file, @progFile = prog_file, @codCcua = cod_cua\n" +
|
||||
"FROM oltb_operregi_file WHERE data_file = '2022/10/06' and prog_file = 1;\n" +
|
||||
"*/\n" +
|
||||
"with movimenti as ( \n" +
|
||||
"/*giacenza*/\n" +
|
||||
"select oltb_operregi_file.id_depo as id_depo, \n" +
|
||||
"g.posizione, \n" +
|
||||
"qta_esistente as qta_mov,\n" +
|
||||
"0 as num_operaz,\n" +
|
||||
"DateAdd(day, -1, oltb_operregi_file.da_dataOp ) as data_operaz,\n" +
|
||||
"g.cod_mart\n" +
|
||||
"from oltb_operregi_file inner join mtb_depo on oltb_operregi_file.id_depo = mtb_depo.id_Depo_sian\n" +
|
||||
"cross apply dbo.lol_getGiacenzaPostura(mtb_depo.cod_mdep, null, DateAdd(day, -1, oltb_operregi_file.da_dataOp )) g \n" +
|
||||
"inner join olvw_caratteristiche on g.cod_mart = olvw_caratteristiche.cod_mart\n" +
|
||||
"where data_file = @dataFile and\n" +
|
||||
"ID_depo = @idDepo AND\n" +
|
||||
"prog_file = @progFile AND\n" +
|
||||
"(IsNumeric(olvw_caratteristiche.categoria) = 1 and Cast(olvw_caratteristiche.categoria as int ) between 1 and 12)\n" +
|
||||
"union all \n" +
|
||||
"select ID_depo, \n" +
|
||||
"id_silos_stock,\n" +
|
||||
"case when dtb_tipi.gestione = 'A' AND dtb_tipi.segno_qta_car - dtb_tipi.segno_qta_scar > 0 THEN qta_car_olioSfuso \n" +
|
||||
" when dtb_tipi.gestione = 'V' AND dtb_tipi.segno_qta_car - dtb_tipi.segno_qta_scar > 0 THEN qta_car_olioSfuso \n" +
|
||||
" WHEN dtb_tipi.gestione = 'L' AND qta_scar_olioSfuso = 0 THEN qta_car_olioSfuso \n" +
|
||||
" when dtb_tipi.gestione = 'L' and qta_car_olioSfuso <> 0 and qta_scar_olioConf <> 0 then qta_car_olioSfuso\n" +
|
||||
" ELSE -qta_scar_olioSfuso END as qta_mov,\n" +
|
||||
"num_operaz,\n" +
|
||||
"data_operaz,\n" +
|
||||
"IsNull(cod_mart_fine, cod_mart ) as cod_mart\n" +
|
||||
"from oltb_operregi inner join dtb_tipi on oltb_operregi.cod_dtip = dtb_tipi.cod_dtip\n" +
|
||||
"where data_file = @dataFile and\n" +
|
||||
"ID_depo = @idDepo AND\n" +
|
||||
"prog_file = @progFile and\n" +
|
||||
"id_silos_stock is not null \n" +
|
||||
"union all\n" +
|
||||
"select ID_depo, \n" +
|
||||
"IsNull(id_silos_dest,id_silos_stock),\n" +
|
||||
"qta_car_olioSfuso,\n" +
|
||||
"num_operaz,\n" +
|
||||
"data_operaz,\n" +
|
||||
"cod_mart_fine\n" +
|
||||
"from oltb_operregi \n" +
|
||||
"inner join dtb_tipi on oltb_operregi.cod_dtip = dtb_tipi.cod_dtip\n" +
|
||||
"where data_file = @dataFile and\n" +
|
||||
"id_depo = @idDepo AND\n" +
|
||||
"prog_file = @progFile and\n" +
|
||||
"( id_silos_dest is not null OR ( id_silos_stock is not null AND ( SELECT top 1 flag_postura_a FROM oltb_operazioni o WHERE o.cod_dtip = oltb_operregi.cod_dtip AND flag_operazioni_frantoio = 0 )= 0)) \n" +
|
||||
")\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
", posture as (\n" +
|
||||
"select movimenti.id_depo,\n" +
|
||||
"movimenti.posizione,\n" +
|
||||
"movimenti.qta_mov,\n" +
|
||||
"movimenti.data_operaz, \n" +
|
||||
"movimenti.num_operaz, \n" +
|
||||
"sum(movimenti.qta_mov) over (partition by movimenti.id_depo, movimenti.posizione\n" +
|
||||
"order by movimenti.data_operaz,\n" +
|
||||
"movimenti.num_operaz,\n" +
|
||||
"movimenti.qta_mov \n" +
|
||||
"rows between UNBOUNDED PRECEDING AND CURRENT ROW ) as qta_mov_prog,\n" +
|
||||
"mtb_depo_posizioni.capacita,\n" +
|
||||
"movimenti.cod_mart,\n" +
|
||||
"case when movimenti.qta_mov > 0 THEN cod_mart ELSE null end as cod_mart_car,\n" +
|
||||
"sum(case when movimenti.qta_mov <= 0 then 0 else 1 end) over (\n" +
|
||||
"order by movimenti.id_depo,\n" +
|
||||
"movimenti.posizione,\n" +
|
||||
"movimenti.data_operaz,\n" +
|
||||
"movimenti.num_operaz,\n" +
|
||||
"movimenti.qta_mov) as value_partition\n" +
|
||||
"from movimenti inner join mtb_depo on movimenti.id_depo = mtb_depo.id_depo_sian\n" +
|
||||
" inner join mtb_depo_posizioni on mtb_depo.cod_mdep = mtb_depo_posizioni.cod_mdep \n" +
|
||||
"and movimenti.posizione = mtb_depo_posizioni.posizione\n" +
|
||||
")\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
", tmp as (\n" +
|
||||
"select id_depo, posizione, qta_mov, data_operaz, num_operaz, qta_mov_prog, capacita, cod_mart,\n" +
|
||||
"max(cod_mart_car) over (partition by value_partition) as cod_mart_before\n" +
|
||||
"from posture )\n" +
|
||||
", check_posture as (\n" +
|
||||
"select id_depo, posizione, qta_mov, data_operaz, num_operaz, qta_mov_prog, capacita, cod_mart, lag(cod_mart_before, 1, null) over (\n" +
|
||||
"partition by tmp.id_depo,\n" +
|
||||
"tmp.posizione\n" +
|
||||
"order by tmp.id_depo,\n" +
|
||||
"tmp.posizione,\n" +
|
||||
"tmp.data_operaz,\n" +
|
||||
"tmp.num_operaz,\n" +
|
||||
"tmp.qta_mov ) as cod_mart_before from tmp \n" +
|
||||
")\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"SELECT\n" +
|
||||
"@dataFile as data_file,\n" +
|
||||
"@progFile as prog_file,\n" +
|
||||
"@codCcua as cod_cua,\n" +
|
||||
"id_depo,num_operaz, \n" +
|
||||
"data_operaz, \n" +
|
||||
"'La postura ' + posizione + ' contiene un olio non compatibile ' as error_text\n" +
|
||||
"from check_posture\n" +
|
||||
"inner join olvw_caratteristiche on check_posture.cod_mart = olvw_caratteristiche.cod_mart\n" +
|
||||
"outer apply ( \n" +
|
||||
" select\n" +
|
||||
" top 1 mtb_aart_carat.cod_mart as miscela\n" +
|
||||
" from\n" +
|
||||
" dbo.getCompatibiltaCaratteristiche(check_posture.cod_mart, null, check_posture.cod_mart_before, null, 'S') comp \n" +
|
||||
" inner join\n" +
|
||||
" mtb_aart_carat \n" +
|
||||
" on comp.carat = mtb_aart_carat.carat \n" +
|
||||
" inner join\n" +
|
||||
" mtb_aart \n" +
|
||||
" on mtb_aart_carat.cod_mart = mtb_aart.cod_mart \n" +
|
||||
" inner join\n" +
|
||||
" olvw_caratteristiche c \n" +
|
||||
" on mtb_aart_carat.cod_mart = c.cod_mart \n" +
|
||||
" where\n" +
|
||||
" mtb_aart.flag_stato = 'A' \n" +
|
||||
" and c.confezionato = 'N' \n" +
|
||||
" and check_posture.cod_mart <> check_posture.cod_mart_before \n" +
|
||||
" and check_posture.cod_mart is not null \n" +
|
||||
" group by\n" +
|
||||
" mtb_aart_carat.cod_mart \n" +
|
||||
" having\n" +
|
||||
" sum(\n" +
|
||||
" case\n" +
|
||||
" when\n" +
|
||||
" mtb_aart_carat.carat IS null \n" +
|
||||
" or IsNull(risultato, '') <> IsNull(val_carat, '') \n" +
|
||||
" then\n" +
|
||||
" 0 \n" +
|
||||
" else\n" +
|
||||
" 1 \n" +
|
||||
" end) = SUM(compatibilita) ) t \n" +
|
||||
"\n" +
|
||||
"WHERE cod_mart_before is not null\n" +
|
||||
"and qta_mov <> qta_mov_prog and qta_mov > 0 \n" +
|
||||
"and check_posture.cod_mart_before <> check_posture.cod_mart\n" +
|
||||
"and check_posture.cod_mart <> IsNull(miscela, '')\n" +
|
||||
"and olvw_caratteristiche.Confezionato = 'N'\n" +
|
||||
"union all\n" +
|
||||
"select @dataFile as data_file,\n" +
|
||||
"@progFile as prog_file,\n" +
|
||||
"@codCcua as cod_cua,\n" +
|
||||
"id_depo,num_operaz, \n" +
|
||||
"data_operaz, \n" +
|
||||
"'La postura ' + posizione + ' supera la sua capacita ' as error_text\n" +
|
||||
"from check_posture \n" +
|
||||
"where qta_mov_prog > capacita and num_operaz <> 0 \n" +
|
||||
"union all\n" +
|
||||
"select @dataFile as data_file,\n" +
|
||||
"@progFile as prog_file,\n" +
|
||||
"@codCcua as cod_cua,\n" +
|
||||
"id_depo, \n" +
|
||||
"num_operaz, \n" +
|
||||
"data_operaz, \n" +
|
||||
"'La postura ' + posizione + ' va a negativo ' as error_text\n" +
|
||||
"from check_posture \n" +
|
||||
"where qta_mov_prog < 0 and num_operaz <> 0 \n" +
|
||||
"\n" +
|
||||
")");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user