Popolamento giacenze riportate le movimentazioni di EC in BZ
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package it.integry.ems.retail.service;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import it.integry.ems.exception.PrimaryDatabaseNotPresentException;
|
||||
import it.integry.ems.expansion.RunnableThrowable;
|
||||
import it.integry.ems.javabeans.RequestDataDTO;
|
||||
import it.integry.ems.retail.dto.GiacenzaDTO;
|
||||
@@ -79,11 +80,27 @@ public class GiacenzaService {
|
||||
UtilityThread.executeParallel(calls);
|
||||
}
|
||||
|
||||
private List<String> getElencoDepositi(String codMdep) throws SQLException, IOException, PrimaryDatabaseNotPresentException {
|
||||
List<String> elencoDepositi = new ArrayList<>();
|
||||
elencoDepositi.add(codMdep);
|
||||
|
||||
String sql = Query.format(
|
||||
"SELECT cod_mdep\n" +
|
||||
"FROM stb_gest_setup_depo \n" +
|
||||
"WHERE gest_name = 'DATI_AZIENDA' and section = 'GIACENZA_DA_INV' and key_section = 'REPLACE_DEPO' and value = %s\n",
|
||||
codMdep);
|
||||
|
||||
elencoDepositi.addAll(UtilityDB.executeSimpleQueryOnlyFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql));
|
||||
return elencoDepositi;
|
||||
}
|
||||
|
||||
private void popolamentoDatiDeposito(String codMdep, String queryArt, Date startDate) throws Exception {
|
||||
|
||||
String codDtipRett = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), "DATI_AZIENDA", "GIACENZA_DA_INV", "TIPO_DOC_RETT");
|
||||
|
||||
cancellazioneKit(codMdep);
|
||||
List<String> elencoDepositi = getElencoDepositi(codMdep);
|
||||
|
||||
cancellazioneKit(elencoDepositi);
|
||||
logger.debug(String.format(GiacenzaService.class.getSimpleName() + " - Deposito %s - Cancellazione kit: Timing " + ((new Date().getTime() - startDate.getTime()) / 1000) + " secs", codMdep));
|
||||
|
||||
String dataParm = setupGest.getSetupDepo(multiDBTransactionManager.getPrimaryConnection(), "DATI_AZIENDA", "GIACENZA_DA_INV", "DATA_INIZ", codMdep);
|
||||
@@ -93,7 +110,7 @@ public class GiacenzaService {
|
||||
else
|
||||
throw new Exception(String.format("Data inizio popolamento non valorizzata per il depostio %s", codMdep));
|
||||
|
||||
nuoviInserimenti(codMdep, dataIniz, queryArt);
|
||||
nuoviInserimenti(codMdep, dataIniz, queryArt, elencoDepositi);
|
||||
logger.debug(String.format(GiacenzaService.class.getSimpleName() + " - Deposito %s - Popolamento da griglia: Timing " + ((new Date().getTime() - startDate.getTime()) / 1000) + " secs", codMdep));
|
||||
|
||||
String sql;
|
||||
@@ -106,25 +123,26 @@ public class GiacenzaService {
|
||||
List<String> articoliSalvati = UtilityDB.executeSimpleQueryOnlyFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
popolaQtaCarInventario(codMdep, dataIniz, queryArt, articoliSalvati, codDtipRett);
|
||||
logger.debug(String.format(GiacenzaService.class.getSimpleName() + " - Deposito %s - Popolamento da inventario: Timing " + ((new Date().getTime() - startDate.getTime()) / 1000) + " secs", codMdep));
|
||||
popolaQtaMovimenti(codMdep, queryArt, articoliSalvati);
|
||||
popolaQtaMovimenti(codMdep, queryArt, articoliSalvati, elencoDepositi);
|
||||
logger.debug(String.format(GiacenzaService.class.getSimpleName() + " - Deposito %s - Popolamento da movimenti: Timing " + ((new Date().getTime() - startDate.getTime()) / 1000) + " secs", codMdep));
|
||||
}
|
||||
|
||||
private void nuoviInserimenti(String codMdep, Date dataIniz, String queryArt) throws Exception {
|
||||
private void nuoviInserimenti(String codMdep, Date dataIniz, String queryArt, List<String> elencoDepositi) throws Exception {
|
||||
String sql = Query.format(
|
||||
"SELECT g.cod_mdep, a.cod_mart_mov as cod_mart, GETDATE() as data_ins, 'G' as tipo_car,\n" +
|
||||
"SELECT %s as cod_mdep, a.cod_mart_mov as cod_mart, GETDATE() as data_ins, 'G' as tipo_car,\n" +
|
||||
"case when min(g.data_validita) < %s THEN %s ELSE min(g.data_validita) END as data_reg \n" +
|
||||
"FROM dbo.getgrigliaacquisto(NULL, null, %s, NULL, NULL) g\n" +
|
||||
"FROM dbo.getgrigliaacquisto(NULL, null, NULL, NULL, NULL) g\n" +
|
||||
" INNER JOIN (" + queryArt + ") a ON g.cod_mart = a.cod_mart\n" +
|
||||
" INNER JOIN mtb_aart ON a.cod_mart_mov = mtb_aart.cod_mart\n" +
|
||||
"WHERE g.tipo_variazione <> 'D'\n" +
|
||||
" AND g.cod_mdep IN ([elencoDepositi]) "+
|
||||
" AND NOT EXISTS\n" +
|
||||
" (SELECT cod_mart\n" +
|
||||
" FROM carelli_giacenza_prog\n" +
|
||||
" WHERE carelli_giacenza_prog.cod_mart = a.cod_mart_mov\n" +
|
||||
" AND carelli_giacenza_prog.cod_mdep = g.cod_mdep)\n" +
|
||||
"GROUP BY g.cod_mdep, a.cod_mart_mov",
|
||||
dataIniz, dataIniz, codMdep);
|
||||
" AND carelli_giacenza_prog.cod_mdep = %s)\n" +
|
||||
"GROUP BY a.cod_mart_mov",
|
||||
codMdep, dataIniz, dataIniz, codMdep).replace("[elencoDepositi]", UtilityDB.listValueToString(elencoDepositi));
|
||||
|
||||
List<CarelliGiacenzaProg> carelliGiacenzaProgs = new ResultSetMapper().mapQuerySetToList(multiDBTransactionManager.getPrimaryConnection(), sql, CarelliGiacenzaProg.class, OperationType.INSERT);
|
||||
|
||||
@@ -134,12 +152,12 @@ public class GiacenzaService {
|
||||
}
|
||||
|
||||
|
||||
private void cancellazioneKit(String codMdep) throws Exception {
|
||||
String sql = Query.format(
|
||||
private void cancellazioneKit(List<String> elencodDepositi) throws Exception {
|
||||
String sql = String.format(
|
||||
"SELECT g.cod_mdep, g.cod_mart\n" +
|
||||
"FROM carelli_giacenza_prog g INNER JOIN mtb_aart ON g.cod_mart =mtb_aart.cod_mart \n" +
|
||||
"WHERE articolo_composto = 'S' AND g.cod_mdep = %s\n",
|
||||
codMdep);
|
||||
"WHERE articolo_composto = 'S' AND g.cod_mdep in (%s)\n",
|
||||
UtilityDB.listValueToString(elencodDepositi));
|
||||
|
||||
List<CarelliGiacenzaProg> carelliGiacenzaProgs = new ResultSetMapper().mapQuerySetToList(multiDBTransactionManager.getPrimaryConnection(), sql, CarelliGiacenzaProg.class, OperationType.DELETE);
|
||||
|
||||
@@ -150,12 +168,12 @@ public class GiacenzaService {
|
||||
}
|
||||
|
||||
|
||||
private void popolaQtaMovimenti(String codMdep, String queryArt, List<String> articoliSalvati) throws Exception {
|
||||
private void popolaQtaMovimenti(String codMdep, String queryArt, List<String> articoliSalvati, List<String> elencoDepositi) throws Exception {
|
||||
String sql;
|
||||
sql =
|
||||
(
|
||||
"WITH art AS (" + queryArt + "),\n" +
|
||||
" movimenti AS (SELECT mtb_movi.cod_mdep,\n" +
|
||||
" movimenti AS (SELECT '[COD_MDEP]' as cod_mdep,\n" +
|
||||
" mtb_movi.cod_mart,\n" +
|
||||
" mtb_movi.data_reg,\n" +
|
||||
" mtb_movi.qta_car AS qta_car,\n" +
|
||||
@@ -168,9 +186,9 @@ public class GiacenzaService {
|
||||
" dtb_doct.data_doc = mtb_movi.data_doc AND\n" +
|
||||
" dtb_doct.ser_doc = mtb_movi.ser_doc AND\n" +
|
||||
" dtb_doct.num_doc = mtb_movi.num_doc\n" +
|
||||
" WHERE mtb_movi.cod_mdep = '[COD_MDEP]'\n" +
|
||||
" WHERE mtb_movi.cod_mdep IN ([ELENCO_DEPOSITI])\n" +
|
||||
" UNION ALL\n" +
|
||||
" SELECT ntb_doct.cod_mdep,\n" +
|
||||
" SELECT '[COD_MDEP]' as cod_mdep,\n" +
|
||||
" ntb_docr.cod_mart,\n" +
|
||||
" ntb_doct.date_only_doc as data_reg,\n" +
|
||||
" 0,\n" +
|
||||
@@ -182,7 +200,7 @@ public class GiacenzaService {
|
||||
" ntb_doct.cod_cassa = ntb_docr.cod_cassa AND\n" +
|
||||
" ntb_doct.data_doc = ntb_docr.data_doc\n" +
|
||||
" LEFT OUTER JOIN dtb_tipi ON ntb_doct.cod_dtip_val = dtb_tipi.cod_dtip\n" +
|
||||
" WHERE ntb_doct.cod_mdep = '[COD_MDEP]'\n" +
|
||||
" WHERE ntb_doct.cod_mdep IN ([ELENCO_DEPOSITI])\n" +
|
||||
" AND ntb_doct.causale = 'V'\n" +
|
||||
" AND (ntb_doct.data_doc_val IS NULL OR dtb_tipi.segno_qta_scar = 0))\n" +
|
||||
"\n" +
|
||||
@@ -197,9 +215,10 @@ public class GiacenzaService {
|
||||
" LEFT OUTER JOIN carelli_giacenza_prog giac ON giac.cod_mdep = movimenti.cod_mdep AND giac.cod_mart = art.cod_mart_mov\n" +
|
||||
"WHERE movimenti.data_reg >= CAST(ISNULL(giac.data_reg, GETDATE()) AS DATE) AND \n" +
|
||||
" (giac.tipo_car is null OR giac.tipo_car <> 'R' OR (giac.tipo_car = 'R' AND movimenti.data_ins >= giac.data_reg)) \n" +
|
||||
"GROUP BY movimenti.cod_mdep,\n " +
|
||||
" art.cod_mart_mov,\n" +
|
||||
" giac.qta_iniz\n").replace("[COD_MDEP]", codMdep);
|
||||
"GROUP BY movimenti.cod_mdep, art.cod_mart_mov,\n" +
|
||||
" giac.qta_iniz\n")
|
||||
.replace("[COD_MDEP]", codMdep)
|
||||
.replace("[ELENCO_DEPOSITI]", UtilityDB.listValueToString(elencoDepositi) );
|
||||
|
||||
List<CarelliGiacenzaProg> carelliGiacenzaProgs = new ResultSetMapper().mapQuerySetToList(multiDBTransactionManager.getPrimaryConnection(), sql, CarelliGiacenzaProg.class);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user