From 7536117c7a4d2d8fc4a17f90e62f2462b3bd879f Mon Sep 17 00:00:00 2001 From: ridwan Date: Mon, 29 Jun 2026 16:06:01 +0700 Subject: [PATCH] update reporting akbar dan fahmi --- .../java/com/reporting/config/DbConfig.java | 64 ++++---- .../controller/ReportingController.java | 138 ++++++++++++++++++ .../java/com/reporting/dao/ReportingDao.java | 56 ++++++- .../reporting/service/ReportingService.java | 17 ++- 4 files changed, 241 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/reporting/config/DbConfig.java b/src/main/java/com/reporting/config/DbConfig.java index 355fd2f..9ee3b79 100644 --- a/src/main/java/com/reporting/config/DbConfig.java +++ b/src/main/java/com/reporting/config/DbConfig.java @@ -13,6 +13,7 @@ import javax.sql.DataSource; @Configuration public class DbConfig { + public DbConfig() { } @@ -34,7 +35,7 @@ public class DbConfig { config.setAutoCommit(ConnDb1.autoCommit); return new HikariDataSource(config); } catch (Exception var3) { - System.out.println(var3.getMessage()); + System.out.println("Error DataSource 1: " + var3.getMessage()); } return null; } @@ -56,7 +57,7 @@ public class DbConfig { config.setAutoCommit(ConnDb1.autoCommit); return new HikariDataSource(config); } catch (Exception var3) { - System.out.println(var3.getMessage()); + System.out.println("Error DataSource 2: " + var3.getMessage()); } return null; } @@ -78,32 +79,37 @@ public class DbConfig { config.setAutoCommit(ConnDb1.autoCommit); return new HikariDataSource(config); } catch (Exception var3) { - System.out.println(var3.getMessage()); + System.out.println("Error DataSource 3: " + var3.getMessage()); } return null; } -// @Bean(name = "fourDataSource") -// public DataSource dataSource4() { -// try { -// HikariConfig config = new HikariConfig(); -// config.setPoolName("PoolReporting3"); -// config.setDriverClassName("org.postgresql.Driver"); -// config.setConnectionTestQuery("SELECT 1"); -// config.setJdbcUrl("jdbc:postgresql://192.168.12.3:5432/rsab_hk_25_01_14"); -// config.setUsername("postgres"); -// config.setPassword("postgres"); -// config.setMinimumIdle(5); -// config.setIdleTimeout(300000L); -// config.setMaximumPoolSize(20); -// config.setConnectionTimeout(100000L); -// config.setAutoCommit(ConnDb1.autoCommit); -// return new HikariDataSource(config); -// } catch (Exception var3) { -// System.out.println(var3.getMessage()); -// } -// return null; -// } + @Bean(name = "fourDataSource") + public DataSource dataSource4() { + try { + HikariConfig config = new HikariConfig(); + config.setPoolName("PoolReporting4"); // Perbaikan typo nama pool agar tidak bentrok dengan Pool 3 + config.setDriverClassName("org.postgresql.Driver"); + config.setConnectionTestQuery("SELECT 1"); + config.setJdbcUrl("jdbc:postgresql://192.168.12.3:5432/rsab_hk_25_01_14"); + config.setUsername("postgres"); + config.setPassword("postgres"); + config.setIdleTimeout(300000L); + config.setMaximumPoolSize(20); + config.setAutoCommit(ConnDb1.autoCommit); + + /* PENGATURAN AGAR TIDAK MENGGANGGU RESTART/STARTUP APLIKASI SAAT MATI LAMPU: + */ + config.setMinimumIdle(0); // Jangan paksa alokasi koneksi di awal saat menyala + config.setConnectionTimeout(3000L); // Jika database mati saat diakses, timeout cepat dalam 3 detik (tidak hang sampai 100 detik) + config.setInitializationFailTimeout(-1L); // JANGAN GAGALKAN STARTUP jika database offline/mati + + return new HikariDataSource(config); + } catch (Exception var3) { + System.out.println("Error DataSource 4 (Aplikasi tetap berjalan): " + var3.getMessage()); + } + return null; + } @Bean(name = {"jdbcTemplate"}) public JdbcTemplate jdbcTemplate1(@Qualifier("db") DataSource ds) { @@ -120,8 +126,8 @@ public class DbConfig { return new JdbcTemplate(ds); } -// @Bean(name = "fourJdbcTemplate") -// public JdbcTemplate jdbcTemplate4(@Qualifier("fourDataSource") DataSource ds) { -// return new JdbcTemplate(ds); -// } -} + @Bean(name = "fourJdbcTemplate") + public JdbcTemplate jdbcTemplate4(@Qualifier("fourDataSource") DataSource ds) { + return new JdbcTemplate(ds); + } +} \ No newline at end of file diff --git a/src/main/java/com/reporting/controller/ReportingController.java b/src/main/java/com/reporting/controller/ReportingController.java index e3d9e73..53dc84b 100644 --- a/src/main/java/com/reporting/controller/ReportingController.java +++ b/src/main/java/com/reporting/controller/ReportingController.java @@ -2636,4 +2636,142 @@ public class ReportingController { } } + @RequestMapping(value = {"/laporan-detail-ppra"}, method = {RequestMethod.GET}) + public void handleLpDetailPPRA( + @RequestParam("tglAwal") Timestamp tglAwal, + @RequestParam("tglAkhir") Timestamp tglAkhir, + @RequestParam(value = "format", required = false, defaultValue = "pdf") String format, + @RequestParam(value = "mode", required = false, defaultValue = "download") String mode, + @RequestParam(value = "printBy", required = false, defaultValue = "") String printBy, + HttpServletResponse response) throws Exception { + + JasperPrint jasperPrint = null; + try { + // Generate report (common for both PDF/Excel) + jasperPrint = this.reportingService.exportLpDetailPPRA(tglAwal, tglAkhir, printBy); + + if ("excel".equalsIgnoreCase(format)) { + // Handle Excel export + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setHeader("Content-Disposition", "attachment; filename=Laporan_Detail_PPRA.xlsx"); + + JRXlsxExporter exporter = new JRXlsxExporter(); + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(response.getOutputStream())); + SimpleXlsxReportConfiguration config = new SimpleXlsxReportConfiguration(); + config.setOnePagePerSheet(false); + config.setDetectCellType(true); + config.setCollapseRowSpan(false); + config.setRemoveEmptySpaceBetweenRows(true); + config.setWhitePageBackground(false); + exporter.setConfiguration(config); + exporter.exportReport(); + + } else { + // Handle PDF preview + response.setContentType("application/pdf"); + response.setHeader("Content-Disposition", "inline; filename=Laporan_Detail_PPRA.pdf"); + + JRPdfExporter exporter = new JRPdfExporter(); + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(response.getOutputStream())); + exporter.exportReport(); + } + } finally { + jasperPrint = null; + } + } + + @RequestMapping(value = {"/laporan-rekap-pasien-baru-pertahun"}, method = {RequestMethod.GET}) + public void handleLpRekapPasienBaru( + @RequestParam("tglAwal") Timestamp tglAwal, + @RequestParam("tglAkhir") Timestamp tglAkhir, + @RequestParam(value = "format", required = false, defaultValue = "pdf") String format, + @RequestParam(value = "mode", required = false, defaultValue = "download") String mode, + @RequestParam(value = "printBy", required = false, defaultValue = "") String printBy, + HttpServletResponse response) throws Exception { + + JasperPrint jasperPrint = null; + try { + // Generate report (common for both PDF/Excel) + jasperPrint = this.reportingService.exportLpRekapPasienBaru(tglAwal, tglAkhir, printBy); + + if ("excel".equalsIgnoreCase(format)) { + // Handle Excel export + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setHeader("Content-Disposition", "attachment; filename=Laporan_Rekap_Pasien_Baru.xlsx"); + + JRXlsxExporter exporter = new JRXlsxExporter(); + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(response.getOutputStream())); + SimpleXlsxReportConfiguration config = new SimpleXlsxReportConfiguration(); + config.setOnePagePerSheet(false); + config.setDetectCellType(true); + config.setCollapseRowSpan(false); + config.setRemoveEmptySpaceBetweenRows(true); + config.setWhitePageBackground(false); + exporter.setConfiguration(config); + exporter.exportReport(); + + } else { + // Handle PDF preview + response.setContentType("application/pdf"); + response.setHeader("Content-Disposition", "inline; filename=Laporan_Rekap_Pasien_Baru.pdf"); + + JRPdfExporter exporter = new JRPdfExporter(); + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(response.getOutputStream())); + exporter.exportReport(); + } + } finally { + jasperPrint = null; + } + } + + @RequestMapping(value = {"/laporan-log-radiologi"}, method = {RequestMethod.GET}) + public void handleLpLogRadiologi( + @RequestParam("tglAwal") Timestamp tglAwal, + @RequestParam("tglAkhir") Timestamp tglAkhir, + @RequestParam(value = "format", required = false, defaultValue = "pdf") String format, + @RequestParam(value = "mode", required = false, defaultValue = "download") String mode, + @RequestParam(value = "printBy", required = false, defaultValue = "") String printBy, + HttpServletResponse response) throws Exception { + + JasperPrint jasperPrint = null; + try { + // Generate report (common for both PDF/Excel) + jasperPrint = this.reportingService.exportLpLogRadiologi(tglAwal, tglAkhir, printBy); + + if ("excel".equalsIgnoreCase(format)) { + // Handle Excel export + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setHeader("Content-Disposition", "attachment; filename=Laporan_Log_Radiologi.xlsx"); + + JRXlsxExporter exporter = new JRXlsxExporter(); + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(response.getOutputStream())); + SimpleXlsxReportConfiguration config = new SimpleXlsxReportConfiguration(); + config.setOnePagePerSheet(false); + config.setDetectCellType(true); + config.setCollapseRowSpan(false); + config.setRemoveEmptySpaceBetweenRows(true); + config.setWhitePageBackground(false); + exporter.setConfiguration(config); + exporter.exportReport(); + + } else { + // Handle PDF preview + response.setContentType("application/pdf"); + response.setHeader("Content-Disposition", "inline; filename=Laporan_Log_Radiologi.pdf"); + + JRPdfExporter exporter = new JRPdfExporter(); + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(response.getOutputStream())); + exporter.exportReport(); + } + } finally { + jasperPrint = null; + } + } + } diff --git a/src/main/java/com/reporting/dao/ReportingDao.java b/src/main/java/com/reporting/dao/ReportingDao.java index 561d1db..9001550 100644 --- a/src/main/java/com/reporting/dao/ReportingDao.java +++ b/src/main/java/com/reporting/dao/ReportingDao.java @@ -46,9 +46,9 @@ public class ReportingDao { @Autowired private JdbcTemplate jdbcTemplate3; -// @Qualifier("fourJdbcTemplate") -// @Autowired -// private JdbcTemplate jdbcTemplate4; + @Qualifier("fourJdbcTemplate") + @Autowired + private JdbcTemplate jdbcTemplate4; @Autowired private PostgresArrayService postgresArrayService; @@ -1573,7 +1573,7 @@ public class ReportingDao { } public JasperPrint exportLpTreaseHasil(String norec) { - try (Connection conn = this.jdbcTemplate1.getDataSource().getConnection()) { + try (Connection conn = this.jdbcTemplate4.getDataSource().getConnection()) { String path = jasperDirPath + "trease_hasil.jrxml"; JasperReport jasperReport = JasperCompileManager.compileReport(path); Map parameters = new HashMap<>(); @@ -1762,4 +1762,52 @@ public class ReportingDao { return null; } + public JasperPrint exportLpDetailPPRA(Timestamp tglAwal, Timestamp tglAkhir, String printBy) { + try (Connection conn = this.jdbcTemplate1.getDataSource().getConnection()) { + String path = jasperDirPath + "laporan_detail_PPRA.jrxml"; + JasperReport jasperReport = JasperCompileManager.compileReport(path); + Map parameters = new HashMap<>(); + parameters.put("tglAwal", tglAwal); + parameters.put("tglAkhir", tglAkhir); + parameters.put("printBy", printBy); + return JasperFillManager.fillReport(jasperReport, parameters, conn); + } catch (Exception var15) { + LOG.error("Exception at exportLpDetailPPRA"); + LOG.error(ReportingDao.class, var15); + } + return null; + } + + public JasperPrint exportLpRekapPasienBaru(Timestamp tglAwal, Timestamp tglAkhir, String printBy) { + try (Connection conn = this.jdbcTemplate1.getDataSource().getConnection()) { + String path = jaspersim2DirPath + "pasien_baru.jrxml"; + JasperReport jasperReport = JasperCompileManager.compileReport(path); + Map parameters = new HashMap<>(); + parameters.put("tglAwal", tglAwal); + parameters.put("tglAkhir", tglAkhir); + parameters.put("printBy", printBy); + return JasperFillManager.fillReport(jasperReport, parameters, conn); + } catch (Exception var15) { + LOG.error("Exception at exportLpRekapPasienBaru"); + LOG.error(ReportingDao.class, var15); + } + return null; + } + + public JasperPrint exportLpLogRadiologi(Timestamp tglAwal, Timestamp tglAkhir, String printBy) { + try (Connection conn = this.jdbcTemplate1.getDataSource().getConnection()) { + String path = jaspersim2DirPath + "log_radiologi.jrxml"; + JasperReport jasperReport = JasperCompileManager.compileReport(path); + Map parameters = new HashMap<>(); + parameters.put("tglAwal", tglAwal); + parameters.put("tglAkhir", tglAkhir); + parameters.put("printBy", printBy); + return JasperFillManager.fillReport(jasperReport, parameters, conn); + } catch (Exception var15) { + LOG.error("Exception at exportLpLogRadiologi"); + LOG.error(ReportingDao.class, var15); + } + return null; + } + } diff --git a/src/main/java/com/reporting/service/ReportingService.java b/src/main/java/com/reporting/service/ReportingService.java index 11d93f9..5021879 100644 --- a/src/main/java/com/reporting/service/ReportingService.java +++ b/src/main/java/com/reporting/service/ReportingService.java @@ -669,8 +669,23 @@ public class ReportingService { } public JasperPrint exportLpRekapPasienLama(Timestamp tglAwal, Timestamp tglAkhir, String printBy) { - log.info("Starting exportKunjunganPasienPerRuangan with tglAwal: {}, tglAkhir: {}, printBy: {}", tglAwal, tglAkhir, printBy); + log.info("Starting exportLpRekapPasienLama with tglAwal: {}, tglAkhir: {}, printBy: {}", tglAwal, tglAkhir, printBy); return this.reportingDao.exportLpRekapPasienLama(tglAwal, tglAkhir, printBy); } + public JasperPrint exportLpDetailPPRA(Timestamp tglAwal, Timestamp tglAkhir, String printBy) { + log.info("Starting exportLpDetailPPRA with tglAwal: {}, tglAkhir: {}, printBy: {}", tglAwal, tglAkhir, printBy); + return this.reportingDao.exportLpDetailPPRA(tglAwal, tglAkhir, printBy); + } + + public JasperPrint exportLpRekapPasienBaru(Timestamp tglAwal, Timestamp tglAkhir, String printBy) { + log.info("Starting exportLpRekapPasienBaru with tglAwal: {}, tglAkhir: {}, printBy: {}", tglAwal, tglAkhir, printBy); + return this.reportingDao.exportLpRekapPasienBaru(tglAwal, tglAkhir, printBy); + } + + public JasperPrint exportLpLogRadiologi(Timestamp tglAwal, Timestamp tglAkhir, String printBy) { + log.info("Starting exportLpLogRadiologi with tglAwal: {}, tglAkhir: {}, printBy: {}", tglAwal, tglAkhir, printBy); + return this.reportingDao.exportLpLogRadiologi(tglAwal, tglAkhir, printBy); + } + }