varie steup
This commit is contained in:
@@ -24,7 +24,7 @@ public class Migration_20251124143153 extends BaseMigration implements Migration
|
||||
|
||||
if (!isCustomerDb(IntegryCustomerDB.Carelli_Winact)) return;
|
||||
|
||||
executeStatement("insert into stb_gest_setup_det" +
|
||||
executeStatement("insert into stb_gest_setup_det \n" +
|
||||
"select gest_name, section, key_section, tipo_setup, f.cod_jfas, f.valUe\n" +
|
||||
"from stb_gest_setup\n" +
|
||||
"cross apply (\n" +
|
||||
|
||||
@@ -393,6 +393,17 @@ public class SteUPController {
|
||||
return ServiceRestResponse.createPositiveResponse();
|
||||
}
|
||||
|
||||
@PostMapping(value = "analisiRottureDiStock")
|
||||
public @ResponseBody
|
||||
ServiceRestResponse analisiRottureDiStock(HttpServletRequest request,
|
||||
@RequestParam(CommonConstants.PROFILE_DB) String profileDB,
|
||||
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate dataIspezione,
|
||||
@RequestParam (required = false) String codMdep) throws Exception {
|
||||
|
||||
steUPService.analisiRottureDiStock(dataIspezione, codMdep);
|
||||
return ServiceRestResponse.createPositiveResponse();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "recuperoIspezioni", method = RequestMethod.POST)
|
||||
public @ResponseBody
|
||||
ServiceRestResponse recuperoIspezioni(HttpServletRequest request,
|
||||
|
||||
@@ -665,9 +665,6 @@ public class SteUPService {
|
||||
String content = new String(contentB64);
|
||||
barcodes = UtilityString.splitStringToMultipleLine(content, CommonConstants.A_CAPO);
|
||||
saveFile = false;
|
||||
} else if (UtilityDebug.isDebugExecution()) {
|
||||
barcodes = UtilityDB.executeSimpleQueryOnlyFirstColumn(multiDBTransactionManager.getPrimaryConnection(),
|
||||
"select cod_mart from stb_activity where parent_activity_id = 'C0000843821'");
|
||||
} else {
|
||||
throw new Exception("File " + fileNameElencoArt + " non trovato.");
|
||||
}
|
||||
@@ -887,12 +884,12 @@ public class SteUPService {
|
||||
break;
|
||||
}
|
||||
|
||||
if (repartiFreschi.contains(codJfas) || (chkRotturaStock && barcode != null & !barcode.isEmpty() )) {
|
||||
if (repartiFreschi.contains(codJfas) || (chkRotturaStock && barcode != null & !barcode.isEmpty())) {
|
||||
sql =
|
||||
"WITH assortimento AS ( " +
|
||||
queryAssortimento +
|
||||
") " +
|
||||
"SELECT griglia.cod_mart, \n" +
|
||||
"SELECT griglia.cod_mart, \n" +
|
||||
"descrizione, \n" +
|
||||
"barcode, \n" +
|
||||
"cod_msgr\n " +
|
||||
@@ -908,8 +905,8 @@ public class SteUPService {
|
||||
" UNION \n" +
|
||||
" SELECT cod_mart \n" +
|
||||
" FROM dbo.steup_getInevasi([COD_MDEP], [COD_JFAS], [DATA_CREAZIONE]))\n " +
|
||||
(chkRotturaStock && barcode != null & !barcode.isEmpty()?
|
||||
"AND EXISTS(SELECT cod_mart from carelli.dbo.mvw_barcode WHERE cod_barre in (" + UtilityDB.listValueToString(barcode) + ") and art.cod_mart = mvw_barcode.cod_mart)\n" : "" ) +
|
||||
(chkRotturaStock && barcode != null & !barcode.isEmpty() ?
|
||||
"AND EXISTS(SELECT cod_mart from carelli.dbo.mvw_barcode WHERE cod_barre in (" + UtilityDB.listValueToString(barcode) + ") and art.cod_mart = mvw_barcode.cod_mart)\n" : "") +
|
||||
"order by descrizione";
|
||||
|
||||
sql = sql
|
||||
@@ -1473,4 +1470,235 @@ public class SteUPService {
|
||||
entityProcessor.processEntityList(entityList, true);
|
||||
}
|
||||
}
|
||||
|
||||
public void analisiRottureDiStock(LocalDate dataIspezione, String codMdep) throws Exception {
|
||||
Map<String, String> setup = setupGest.getSetupSection(multiDBTransactionManager.getPrimaryConnection(), "PVM", "RILEVAZIONI_STEUP");
|
||||
|
||||
String tipoAttivitaRotturaStock = setup.get("TIPO_ATTIVITA_ROTTURA_STOCK");
|
||||
List<String> repartiFreschi = Arrays.asList(StringUtils.split(UtilityString.isNull(setup.get("REPARTI_FRESCHI"), ""), "|"));
|
||||
List<String> tipiEsclusi = Arrays.asList(StringUtils.split(UtilityString.isNull(setup.get("EXCLUDE_COD_MTIP"), ""), "|"));
|
||||
List<String> fornitori = Arrays.asList(StringUtils.split(UtilityString.isNull(setup.get("ELENCO_FORN_INEVASI"), ""), "|"));
|
||||
|
||||
String sql =
|
||||
Query.format(
|
||||
"select i.cod_mdep, stb_activity.cod_jfas, stb_activity.activity_id\n" +
|
||||
"from dbo.steup_getRilevazioni(%s, %s, null) i\n" +
|
||||
"inner join stb_activity on i.activity_id = stb_activity.parent_activity_id\n" +
|
||||
"where stb_activity.activity_type_id = %s",
|
||||
dataIspezione, codMdep, tipoAttivitaRotturaStock);
|
||||
|
||||
List<HashMap<String, Object>> ispezioni = UtilityDB.executeSimpleQuery(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
if (ispezioni == null || ispezioni.isEmpty()) {
|
||||
throw new Exception("Nessuna ispezione trovata per la data e il punto vendita indicati.");
|
||||
}
|
||||
|
||||
Map<String, List<HashMap<String, Object>>> ispezioniDepo = ispezioni.stream().collect(groupingBy(x -> (String) x.get("cod_mdep")));
|
||||
|
||||
for (Map.Entry<String, List<HashMap<String, Object>>> entry : ispezioniDepo.entrySet()) {
|
||||
Map<String, List<HashMap<String, Object>>> reparti = entry.getValue().stream().collect(groupingBy(x -> (String) x.get("cod_jfas")));
|
||||
for (Map.Entry<String, List<HashMap<String, Object>>> reparto : reparti.entrySet()) {
|
||||
String codJfas = reparto.getKey();
|
||||
List<String> barcodes = new ArrayList<>();
|
||||
for ( HashMap<String, Object> r: reparto.getValue() ) {
|
||||
StbActivityFile stbActivityFile = new StbActivityFile()
|
||||
.setId((String) r.get("activity_id"))
|
||||
.setFileName("elenco_articoli.txt");
|
||||
stbActivityFile.setOperation(OperationType.SELECT_OBJECT);
|
||||
|
||||
entityProcessor.processEntity(stbActivityFile, multiDBTransactionManager);
|
||||
|
||||
byte[] contentB64 = stbActivityFile.getContent();
|
||||
if (contentB64 != null && contentB64.length > 0) {
|
||||
String content = new String(contentB64);
|
||||
barcodes.addAll(UtilityString.splitStringToMultipleLine(content, CommonConstants.A_CAPO));
|
||||
barcodes = Arrays.asList(("8001990030611\n" +
|
||||
"8003650000798\n" +
|
||||
"8054633830833\n" +
|
||||
"8410436393942\n" +
|
||||
"8002340012103\n" +
|
||||
"8007300004297\n" +
|
||||
"8002340012660\n" +
|
||||
"8033532102838\n" +
|
||||
"8052675290028\n" +
|
||||
"8000697001917\n" +
|
||||
"8055719541384\n" +
|
||||
"8055719541377\n" +
|
||||
"8018700037204\n" +
|
||||
"8001480720800\n" +
|
||||
"8001280070648\n" +
|
||||
"8054633831656\n" +
|
||||
"8720182641618\n" +
|
||||
"8011380002074\n" +
|
||||
"8230485606837\n" +
|
||||
"8033532107987\n" +
|
||||
"8033908800726\n" +
|
||||
"8021719130026\n" +
|
||||
"8051886470717\n" +
|
||||
"8700216772082\n" +
|
||||
"8033447586204\n" +
|
||||
"8006540891469\n" +
|
||||
"4012400502363\n" +
|
||||
"8051499395889\n" +
|
||||
"8051499393571\n" +
|
||||
"8051499395872\n" +
|
||||
"8034055535387\n" +
|
||||
"8056364996130\n" +
|
||||
"8056364993467\n" +
|
||||
"8007675733877").split("\n"));
|
||||
|
||||
}
|
||||
}
|
||||
if (barcodes.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
verificaRottura(entry.getKey(), codJfas, dataIspezione, repartiFreschi, tipiEsclusi, fornitori, barcodes);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<HashMap<String, Object>> verificaRottura(String codMdep, String codJfas,
|
||||
LocalDate dataCreation,
|
||||
List<String> repartiFreschi,
|
||||
List<String> tipiEsclusi,
|
||||
List<String> fornitori,
|
||||
List<String> barcode) throws Exception {
|
||||
|
||||
String tipoGriglia = setupGest.getSetupDet(multiDBTransactionManager.getPrimaryConnection(), "PVM", "RILEVAZIONI_STEUP", "TIPO_GRIGLIA", codJfas);
|
||||
|
||||
String profileDb = setupGest.getSetupDepo(multiDBTransactionManager.getPrimaryConnection(), "DATI_AZIENDA", "DATI_DEPOSITO", "PROFILE_DB", codMdep);
|
||||
|
||||
String sql = Query.format("SELECT cod_mgrp FROM jrl_fasi_mtb_grup WHERE cod_jfas = %s", codJfas);
|
||||
|
||||
List<String> gruppiMerc = UtilityDB.executeSimpleQueryOnlyFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
String queryAssortimento = "";
|
||||
switch (tipoGriglia) {
|
||||
case "A":
|
||||
queryAssortimento =
|
||||
"SELECT DISTINCT mtb_aart.cod_mart\n" +
|
||||
" FROM mvw_barcode INNER JOIN mtb_aart ON mtb_aart.cod_mart = mvw_barcode.cod_mart \n";
|
||||
break;
|
||||
case "V":
|
||||
queryAssortimento =
|
||||
"SELECT DISTINCT vtb_griglia_art.cod_mart\n" +
|
||||
"FROM vtb_griglia_art\n" +
|
||||
" INNER JOIN mvw_barcode ON vtb_griglia_art.cod_mart = mvw_barcode.cod_mart\n" +
|
||||
" INNER JOIN mtb_aart ON vtb_griglia_art.cod_mart = mtb_aart.cod_mart\n" +
|
||||
"WHERE cod_griglia = [COD_MDEP]\n" +
|
||||
" AND data_validita = [DATA_ISPEZIONE]\n" +
|
||||
" AND (SELECT MAX(data_validita)\n" +
|
||||
" FROM vtb_griglia_art\n" +
|
||||
" WHERE cod_griglia = [COD_MDEP]\n" +
|
||||
" AND data_validita <= [DATA_ISPEZIONE])";
|
||||
|
||||
queryAssortimento = queryAssortimento.replace("[COD_MDEP]", UtilityDB.valueToString(codMdep))
|
||||
.replace("[DATA_ISPEZIONE]", UtilityDB.valueToString(dataCreation));
|
||||
break;
|
||||
}
|
||||
|
||||
queryAssortimento = UtilityDB.addwhereCond(queryAssortimento, "mtb_aart.cod_mgrp IN (" + UtilityDB.listValueToString(gruppiMerc) + ")", false);
|
||||
String whereCondBarcode = "";
|
||||
if (repartiFreschi.contains(codJfas)) {
|
||||
whereCondBarcode = "mvw_barcode.cod_barre not in (" + UtilityDB.listValueToString(barcode) + ")";
|
||||
} else {
|
||||
whereCondBarcode = "mvw_barcode.cod_barre in (" + UtilityDB.listValueToString(barcode) + ")";
|
||||
}
|
||||
queryAssortimento = UtilityDB.addwhereCond(queryAssortimento, whereCondBarcode, false);
|
||||
|
||||
/*Nella query dei kit prendiamo componenti, composti, articoli sostitutivi ( cod_mart_stat) E componeni della distinta*/
|
||||
String queryKit =
|
||||
"SELECT mtb_aart.cod_mart, mtb_aart.cod_mart AS cod_mart_griglia\n" +
|
||||
"FROM mtb_aart\n" +
|
||||
"WHERE mtb_aart.articolo_composto = 'N'\n" +
|
||||
"UNION\n" +
|
||||
"SELECT mtb_aart.cod_mart, mtb_comp.cod_comp AS cod_mart_griglia\n" +
|
||||
"FROM mtb_aart\n" +
|
||||
" INNER JOIN mtb_comp ON mtb_aart.cod_mart = mtb_comp.cod_mart\n" +
|
||||
"WHERE mtb_aart.articolo_composto = 'S'\n" +
|
||||
"UNION\n" +
|
||||
"SELECT mtb_comp.cod_comp, mtb_comp.cod_mart\n" +
|
||||
"FROM mtb_aart\n" +
|
||||
" INNER JOIN mtb_comp ON mtb_aart.cod_mart = mtb_comp.cod_mart\n" +
|
||||
"WHERE mtb_aart.articolo_composto = 'S'\n" +
|
||||
"UNION\n" +
|
||||
"SELECT mtb_aart.cod_mart, mtb_aart.cod_mart_stat\n" +
|
||||
"FROM mtb_aart\n" +
|
||||
"WHERE mtb_aart.cod_mart_stat IS NOT NULL\n" +
|
||||
"UNION\n" +
|
||||
"SELECT cod_prod, cod_mart\n" +
|
||||
"FROM jtb_dist_mate\n" +
|
||||
"WHERE cod_mart IS NOT NULL";
|
||||
|
||||
List<HashMap<String, Object>> articoli = new ArrayList<>();
|
||||
try (MultiDBTransactionManager mdb = new MultiDBTransactionManager(profileDb)) {
|
||||
articoli = UtilityDB.executeSimpleQuery(mdb.getPrimaryConnection(), queryAssortimento);
|
||||
|
||||
//Eliminazione nuovi inserimenti in griglia
|
||||
String sqlGriglia =
|
||||
"WITH articoli AS ( \n" + queryKit + " ) \n" +
|
||||
"SELECT g.cod_mart\n" +
|
||||
"FROM dbo.getgrigliaacquisto([DATA_CREAZIONE], NULL, [COD_MDEP], NULL, NULL) g\n" +
|
||||
" INNER JOIN mtb_aart ON g.cod_mart = mtb_aart.cod_mart AND mtb_aart.cod_mgrp IN ([GRUPPI_MERC])\n" +
|
||||
" INNER JOIN articoli ON g.cod_mart = articoli.cod_mart_griglia\n" +
|
||||
"WHERE g.tipo_variazione = 'I'\n" +
|
||||
" AND g.data_validita >= DATEADD(DAY, -7, [DATA_CREAZIONE]) ";
|
||||
|
||||
sqlGriglia = sqlGriglia
|
||||
.replace("[DATA_CREAZIONE]", UtilityDB.valueToString(dataCreation))
|
||||
.replace("[COD_MDEP]", UtilityDB.valueToString(codMdep))
|
||||
.replace("[COD_JFAS]", UtilityDB.valueToString(codJfas))
|
||||
.replace("[GRUPPI_MERC]", UtilityDB.listValueToString(gruppiMerc));
|
||||
|
||||
if (!tipiEsclusi.isEmpty()) {
|
||||
sqlGriglia = UtilityDB.addwhereCond(sqlGriglia, "(mtb_aart.cod_mtip IS NULL OR mtb_aart.cod_mtip not in (" + UtilityDB.listValueToString(tipiEsclusi) + "))", true);
|
||||
}
|
||||
|
||||
List<String> nuoviInserimenti = UtilityDB.executeSimpleQueryOnlyFirstColumn(mdb.getPrimaryConnection(), sqlGriglia);
|
||||
|
||||
articoli = articoli.stream()
|
||||
.filter(x -> !nuoviInserimenti.contains(x.get("cod_mart").toString()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
//Verifica Inevasi
|
||||
String sqlInevasi =
|
||||
"WITH articoli AS (" + queryKit + ")\n" +
|
||||
"SELECT DISTINCT articoli.cod_mart\n" +
|
||||
"FROM dtb_ordt\n" +
|
||||
" INNER JOIN dtb_ordr ON dtb_ordt.gestione = dtb_ordr.gestione\n" +
|
||||
" AND dtb_ordt.data_ord = dtb_ordr.data_ord\n" +
|
||||
" AND dtb_ordt.num_ord = dtb_ordr.num_ord\n" +
|
||||
" INNER JOIN gtb_anag ON dtb_ordt.cod_anag = gtb_anag.cod_anag\n" +
|
||||
" INNER JOIN mtb_aart ON dtb_ordr.cod_mart = mtb_aart.cod_mart\n" +
|
||||
" INNER JOIN articoli ON mtb_aart.cod_mart = articoli.cod_mart_griglia\n" +
|
||||
"WHERE dtb_ordt.gestione = 'A'\n" +
|
||||
" AND dtb_ordt.flag_annulla = 'N'\n" +
|
||||
" AND gtb_anag.part_iva IN ([ELENCO_FORNITORI])\n" +
|
||||
" AND dtb_ordt.cod_mdep = [COD_MDEP]\n" +
|
||||
" AND dtb_ordt.data_esportazione IS NOT NULL\n" +
|
||||
" AND mtb_aart.cod_mgrp IN ( [GRUPPI_MERC] ) \n" +
|
||||
" AND dtb_ordr.qta_evasa = 0\n" +
|
||||
" AND dtb_ordr.data_cons BETWEEN DATEADD(DAY, -7, [DATA_ISPEZIONE]) AND [DATA_ISPEZIONE]\n";
|
||||
|
||||
sqlInevasi =
|
||||
sqlInevasi
|
||||
.replace("[DATA_ISPEZIONE]", UtilityDB.valueToString(dataCreation))
|
||||
.replace("[COD_MDEP]", UtilityDB.valueToString(codMdep))
|
||||
.replace("[GRUPPI_MERC]", UtilityDB.listValueToString(gruppiMerc))
|
||||
.replace("[ELENCO_FORNITORI]", UtilityDB.listValueToString(fornitori));
|
||||
|
||||
if (!tipiEsclusi.isEmpty()) {
|
||||
sqlInevasi = UtilityDB.addwhereCond(sqlInevasi, "(mtb_aart.cod_mtip IS NULL OR mtb_aart.cod_mtip not in (" + UtilityDB.listValueToString(tipiEsclusi) + "))", true);
|
||||
}
|
||||
|
||||
List<String> inevasi = UtilityDB.executeSimpleQueryOnlyFirstColumn(mdb.getPrimaryConnection(), sqlInevasi);
|
||||
|
||||
articoli = articoli.stream()
|
||||
.filter(x -> !inevasi.contains(x.get("cod_mart").toString()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return articoli;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user