diff --git a/ems-core/src/main/java/it/integry/ems/service/ReportProcessor.java b/ems-core/src/main/java/it/integry/ems/service/ReportProcessor.java index eb66835ed2..c3e9f9d075 100644 --- a/ems-core/src/main/java/it/integry/ems/service/ReportProcessor.java +++ b/ems-core/src/main/java/it/integry/ems/service/ReportProcessor.java @@ -559,7 +559,7 @@ public class ReportProcessor { " AND ((:codAnag is null and cod_anag is null) OR (:codAnag is not null and ISNULL(cod_anag,:codAnag) = :codAnag)) " + " AND ((:codMdep is null and cod_mdep is null) OR (:codMdep is not null and ISNULL(cod_mdep,:codMdep) = :codMdep)) " + " AND ((:codDtip is null and cod_dtip is null) OR (:codDtip is not null and ISNULL(cod_dtip,:codDtip) = :codDtip)) " + - "order by cod_anag desc, cod_mdep desc"; + "order by cod_anag desc, cod_mdep desc, cod_dtip desc"; sql = sql .replace(":codAnag", UtilityDB.valueToString(reportTypeDTO.getCodAnag())) .replace(":codDtip", UtilityDB.valueToString(reportTypeDTO.getCodDtip())) diff --git a/ems-engine/src/main/java/it/integry/ems/document/export/DocumentiExporter.java b/ems-engine/src/main/java/it/integry/ems/document/export/DocumentiExporter.java index 9cbb2500b8..e6e3367fa1 100644 --- a/ems-engine/src/main/java/it/integry/ems/document/export/DocumentiExporter.java +++ b/ems-engine/src/main/java/it/integry/ems/document/export/DocumentiExporter.java @@ -117,7 +117,7 @@ public class DocumentiExporter extends BaseEntityExporter implements IEntityExpo break; case INTESA: DocumentiIntesaExportService intesaExportService = context.getBean(DocumentiIntesaExportService.class); - entityExportResponse = intesaExportService.export(username, type, format); + entityExportResponse = intesaExportService.export(whereCond, type, format, anomalie); break; case EXCEL: case CSV: diff --git a/ems-engine/src/main/java/it/integry/ems/document/export/service/DocumentiIntesaExportService.java b/ems-engine/src/main/java/it/integry/ems/document/export/service/DocumentiIntesaExportService.java index 70d548eded..b759007391 100644 --- a/ems-engine/src/main/java/it/integry/ems/document/export/service/DocumentiIntesaExportService.java +++ b/ems-engine/src/main/java/it/integry/ems/document/export/service/DocumentiIntesaExportService.java @@ -1,6 +1,8 @@ package it.integry.ems.document.export.service; +import com.mysql.cj.xdevapi.Warning; import it.integry.common.var.CommonConstants; +import it.integry.ems.Import.dto.AnomalieDTO; import it.integry.ems.export.base.EntityExportResponse; import it.integry.ems.response.FileItem; import it.integry.ems.service.EntityProcessor; @@ -20,6 +22,7 @@ import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Service; import java.util.*; +import java.util.stream.Collectors; @Service @Scope("request") @@ -37,22 +40,29 @@ public class DocumentiIntesaExportService { private final Logger logger = LogManager.getLogger(); - public EntityExportResponse> export(String userName, String type, String format) throws Exception { - EntityExportResponse> entityExportResponse = new EntityExportResponse<>(); + public EntityExportResponse> export(String whereCond, String type, String format, List anomalie) throws Exception { Connection conn = multiDBTransactionManager.getPrimaryConnection(); - Date dataDoc = UtilityDate.StringToDate("27/02/2025", CommonConstants.DATE_FORMAT_DMY); + EntityExportResponse> entityExportResponse = new EntityExportResponse<>(); + entityExportResponse.setAnomalie(anomalie); + char charSeparator = ';'; String fileName = "index"; String ext = "csv"; + String sql = UtilityDB.addwhereCond("SELECT * FROM dtb_doct ", whereCond, false); + List dtbDocts = UtilityDB.executeSimpleQueryDTO(conn, sql, DtbDoct.class); + if (dtbDocts == null || dtbDocts.isEmpty()) throw new Exception("Nessun documento trovato"); + + List dateDocumenti = dtbDocts.stream().map(DtbDoct::getDataDoc).collect(Collectors.toList()); + Map setup = setupGest.getExportSetupSection(conn, type, format); String piattaforma = setup.get("PIATTAFORMA"); String comunita = setup.get("COMUNITA"); String azienda = setup.get("AZIENDA"); String tipoDoc = setup.get("TIPO_DOC"); - String sql = Query.format( + sql = Query.format( "WITH RankedPDF AS (SELECT pdf.*,\n" + " ROW_NUMBER() OVER (\n" + " PARTITION BY pdf.data_doc, pdf.num_doc, pdf.ser_doc, pdf.cod_anag, pdf.cod_dtip\n" + @@ -87,11 +97,11 @@ public class DocumentiIntesaExportService { " ON doc.data_doc = pdf.data_doc AND doc.num_doc = pdf.num_doc AND doc.ser_doc = pdf.ser_doc\n" + " AND doc.cod_anag = pdf.cod_anag AND doc.cod_dtip = pdf.cod_dtip\n" + " CROSS APPLY azienda\n" + - "WHERE doc.data_doc = %s\n" + + "WHERE doc.data_doc IN (" + UtilityDB.listValueToString(dateDocumenti) + ")\n" + " AND doc.gestione = 'V'\n" + " AND dtb_tipi.tipo_emissione = 'DIRETTA'\n" + " AND pdf.rn = 1", - SIGNED_PREFIX, piattaforma, comunita, azienda, dataDoc + SIGNED_PREFIX, piattaforma, comunita, azienda ); byte[] csvContent = UtilityQuery.mapQueryToCSV(conn, sql, charSeparator, false, false).getBytes(); @@ -115,11 +125,11 @@ public class DocumentiIntesaExportService { " INNER JOIN RankedPDF pdf\n" + " ON doc.data_doc = pdf.data_doc AND doc.num_doc = pdf.num_doc AND doc.ser_doc = pdf.ser_doc\n" + " AND doc.cod_anag = pdf.cod_anag AND doc.cod_dtip = pdf.cod_dtip\n" + - "WHERE doc.data_doc = %s\n" + + "WHERE doc.data_doc = " + UtilityDB.listValueToString(dateDocumenti) + "\n" + " AND doc.gestione = 'V'\n" + " AND dtb_tipi.tipo_emissione = 'DIRETTA'\n" + " AND pdf.rn = 1", - SIGNED_PREFIX, dataDoc + SIGNED_PREFIX ); List> resultQuery = UtilityDB.executeSimpleQuery(conn, sql); List dtbDocPdfList = new ArrayList<>(); @@ -156,9 +166,11 @@ public class DocumentiIntesaExportService { entityProcessor.processEntityList(dtbDocPdfList, true); - if (dtbDocPdfList.isEmpty()) { - logger.info("[Esportazione Intesa del {}] nessun file inviato", new Date()); - return null; + if (logger.isInfoEnabled() && dtbDocPdfList.isEmpty()) { + String anomalia = "Nessun file firmato inviato"; + logger.error(anomalia); + anomalie.add(AnomalieDTO.warning(anomalia)); + return entityExportResponse; } List listFileToZip = new ArrayList<>();