From 599df1fc160b422a9d077e37862b94f0f0ddccd7 Mon Sep 17 00:00:00 2001 From: MinaR Date: Wed, 19 Jun 2024 17:29:14 +0200 Subject: [PATCH] sistemato controllo su inserimento promozione nello stesso periodo e controllato se i file di apulia sono vuoti --- .../ems/rules/completing/SalesRules.java | 29 ++++++++++--------- ...ListiniAcquistoApuliaCarrefourService.java | 16 ++++++---- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/ems-core/src/main/java/it/integry/ems/rules/completing/SalesRules.java b/ems-core/src/main/java/it/integry/ems/rules/completing/SalesRules.java index 114d12bfbe..d5efb66ddd 100644 --- a/ems-core/src/main/java/it/integry/ems/rules/completing/SalesRules.java +++ b/ems-core/src/main/java/it/integry/ems/rules/completing/SalesRules.java @@ -851,29 +851,30 @@ public class SalesRules extends QueryRules { public static Boolean checkArtPromoVendita(Connection conn, MtbLisvData entity) throws Exception { Boolean ret = false; String query = + Query.format( "SELECT TOP 1 cod_promo, " + "data_iniz, " + "data_fine, " + "versione " + - " FROM dbo.getPromozioneVendita(" + UtilityDB.valueDateToString(entity.getDataIniz(), CommonConstants.DATE_FORMAT_YMD) + ", " - + UtilityDB.valueDateToString(entity.getDataFine(), CommonConstants.DATE_FORMAT_YMD) + ", " - + UtilityDB.valueToString(entity.getCodVlis()) + ", null, " - + UtilityDB.valueToString(entity.getCodMart()) + ") " + + " FROM dbo.getPromozioneVendita( %s, %s, %s , null, %s) " + " WHERE tipo_variazione <> 'D' AND" + - " versione <> " + UtilityDB.valueToString(entity.getVersione()); + " versione <> %s", + entity.getDataIniz(), + entity.getDataFine(), + entity.getCodVlis(), + entity.getCodMart(), + entity.getVersione()==null?0:entity.getVersione() + ); - PreparedStatement ps = conn.prepareStatement(query); - ResultSet rs = ps.executeQuery(); - if (rs.next()) { + HashMap datiPromo = UtilityDB.executeSimpleQueryOnlyFirstRow(conn, query); + if (UtilityHashMap.isPresent(datiPromo)) { String errorMessage = "Impossibile salvare la promozione sul listino " + entity.getCodVlis() + ". " + "Articolo " + entity.getCodMart() + " già presente nella promozione " + - rs.getString(1) + - " valida dal " + new SimpleDateFormat(CommonConstants.DATE_FORMAT_DMY).format(rs.getDate(2)) + - " al " + new SimpleDateFormat(CommonConstants.DATE_FORMAT_DMY).format(rs.getDate(3)) + - " versione " + rs.getString(4); - rs.close(); - ps.close(); + datiPromo.get("cod_promo") + + " valida dal " + new SimpleDateFormat(CommonConstants.DATE_FORMAT_DMY).format(datiPromo.get("data_iniz")) + + " al " + new SimpleDateFormat(CommonConstants.DATE_FORMAT_DMY).format(datiPromo.get("data_fine")) + + " versione " + datiPromo.get("versione"); throw new Exception(errorMessage); } diff --git a/ems-engine/src/main/java/it/integry/ems/product/importaz/service/ImportListiniAcquistoApuliaCarrefourService.java b/ems-engine/src/main/java/it/integry/ems/product/importaz/service/ImportListiniAcquistoApuliaCarrefourService.java index 2e7130c7b4..32cf05a83c 100644 --- a/ems-engine/src/main/java/it/integry/ems/product/importaz/service/ImportListiniAcquistoApuliaCarrefourService.java +++ b/ems-engine/src/main/java/it/integry/ems/product/importaz/service/ImportListiniAcquistoApuliaCarrefourService.java @@ -27,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Service; +import java.io.File; import java.math.BigDecimal; import java.sql.Connection; import java.sql.PreparedStatement; @@ -424,10 +425,15 @@ public class ImportListiniAcquistoApuliaCarrefourService { String[] elencoFile = files.split("\\|"); //INSERIMENTO DATI IN TABELLE DI APPOGGIO - for (int i = 0; i < elencoFile.length; i++) { - String fileName = elencoFile[i]; + for (String fileName : elencoFile) { + //Controllo se il file esiste e se non è vuoto + File file = new File(pathFile + "/" + fileName + ".csv"); - String fileNamePart = UtilityString.left(elencoFile[i], 3).toUpperCase(); + if (!file.exists() || !file.isFile() || file.length() <= 0) { + throw new Exception("Il file è vuoto o non esiste."); + } + + String fileNamePart = UtilityString.left(fileName, 3).toUpperCase(); switch (fileNamePart) { case "LIS": @@ -503,8 +509,8 @@ public class ImportListiniAcquistoApuliaCarrefourService { ps.close(); } catch (SQLException e) { throw new Exception("Impossibile importare il file " + fileName + CommonConstants.A_CAPO + "." + - e.getMessage() + CommonConstants.A_CAPO + "." + - "Verificare il file, potrebbe essere corrotto o incompleto."); + e.getMessage() + CommonConstants.A_CAPO + "." + + "Verificare il file, potrebbe essere corrotto o incompleto."); } UtilityDB.trimTableColumn(conn, tableName, null);