diff --git a/pom.xml b/pom.xml index 2fd667a..fa81e24 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,19 @@ 1.8 + + + jaspersoft-third-party + https://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts/ + + true + + + true + + + + org.springframework.boot @@ -131,6 +144,18 @@ javase 2.2 + + + org.apache.poi + poi + 5.0.0 + + + org.apache.poi + poi-ooxml + 5.0.0 + + diff --git a/src/main/java/com/reporting/config/DbConfig.java b/src/main/java/com/reporting/config/DbConfig.java index b7f767d..49f732e 100644 --- a/src/main/java/com/reporting/config/DbConfig.java +++ b/src/main/java/com/reporting/config/DbConfig.java @@ -61,6 +61,28 @@ public class DbConfig { return null; } + @Bean(name = "thirdDataSource") + public DataSource dataSource3() { + try { + HikariConfig config = new HikariConfig(); + config.setPoolName("PoolReporting3"); + config.setDriverClassName("org.postgresql.Driver"); + config.setConnectionTestQuery("SELECT 1"); + config.setJdbcUrl("jdbc:postgresql://172.16.88.22:5432/gen2-development-sosialisasi"); + config.setUsername("simrs"); + config.setPassword("@S1mrs.3205@"); + 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 = {"jdbcTemplate"}) public JdbcTemplate jdbcTemplate1(@Qualifier("db") DataSource ds) { return new JdbcTemplate(ds); @@ -70,4 +92,9 @@ public class DbConfig { public JdbcTemplate jdbcTemplate2(@Qualifier("secondaryDataSource") DataSource ds) { return new JdbcTemplate(ds); } + + @Bean(name = "thirdJdbcTemplate") + public JdbcTemplate jdbcTemplate3(@Qualifier("thirdDataSource") DataSource ds) { + return new JdbcTemplate(ds); + } } diff --git a/src/main/java/com/reporting/controller/ReportingController.java b/src/main/java/com/reporting/controller/ReportingController.java index 523b541..3536821 100644 --- a/src/main/java/com/reporting/controller/ReportingController.java +++ b/src/main/java/com/reporting/controller/ReportingController.java @@ -7,6 +7,11 @@ import com.reporting.service.VerifikasiTagihanSupplierServices; import com.reporting.service.PostgresArrayService; import net.sf.jasperreports.engine.JasperExportManager; import net.sf.jasperreports.engine.JasperPrint; +import net.sf.jasperreports.engine.export.JRPdfExporter; +import net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter; +import net.sf.jasperreports.export.SimpleExporterInput; +import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput; +import net.sf.jasperreports.export.SimpleXlsxReportConfiguration; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; @@ -584,16 +589,6 @@ public class ReportingController { //sim2 -/* - @RequestMapping(value = {"/label-cetering/{noorder}"}, method = {RequestMethod.GET}) - public void exportPdfLabelKetring(@PathVariable("noorder") Integer noorder, - ModelAndView mv, HttpServletResponse response) throws Exception { - JasperPrint jasperPrint = this.reportingService.exportPdfLabelKetring(noorder); - response.setContentType("application/pdf"); - JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream()); - } -*/ - @RequestMapping(value = {"/label-cetering/{noorder}"}, method = {RequestMethod.GET}) public void exportPdfLabelKetring(@PathVariable("noorder") String noorder, ModelAndView mv, HttpServletResponse response) throws Exception { @@ -609,4 +604,201 @@ public class ReportingController { JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream()); } + // Ekport Excel + + @RequestMapping(value = {"/visit"}, method = {RequestMethod.GET}) + public void handleVisit(@RequestParam("tglAwal") String tglAwal, + @RequestParam("tglAkhir") String tglAkhir, + @RequestParam(value = "idDokter", required = false, defaultValue = "") Integer idDokter, + @RequestParam(value = "idRuangan", required = false, defaultValue = "") Integer idRuangan, + @RequestParam(value = "format", required = false, defaultValue = "pdf") String format, + @RequestParam(value = "mode", required = false, defaultValue = "download") String mode, + ModelAndView mv, HttpServletResponse response) throws Exception { + + // Generate report (common for both PDF/Excel) + JasperPrint jasperPrint = this.reportingService.exportVisit(tglAwal, tglAkhir, idDokter, idRuangan); + + if ("excel".equalsIgnoreCase(format)) { + // Handle Excel export + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setHeader("Content-Disposition", "attachment; filename=Visit.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=Visit.pdf"); + + JRPdfExporter exporter = new JRPdfExporter(); + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(response.getOutputStream())); + exporter.exportReport(); + } + } +/* + + @RequestMapping(value = {"/waktu-rawat-jalan"}, method = {RequestMethod.GET}) + public void exportExcelWaktuRawatJalan(@RequestParam("tglAwal") String tglAwal, + @RequestParam("tglAkhir") String tglAkhir, + ModelAndView mv, HttpServletResponse response) throws Exception { + // 1. Set content type untuk Excel + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setHeader("Content-Disposition", "attachment; filename=waktu_rawat_jalan.xlsx"); + // 2. Dapatkan JasperPrint dari service + JasperPrint jasperPrint = this.reportingService.exportExcelWaktuRawatJalan(tglAwal, tglAkhir); + // 3. Ekspor langsung ke output stream (tanpa menyimpan file sementara) + JRXlsxExporter exporter = new JRXlsxExporter(); + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(response.getOutputStream())); + SimpleXlsxReportConfiguration configuration = new SimpleXlsxReportConfiguration(); + configuration.setOnePagePerSheet(false); + configuration.setDetectCellType(true); + configuration.setCollapseRowSpan(false); + configuration.setRemoveEmptySpaceBetweenRows(true); + configuration.setWhitePageBackground(false); + exporter.setConfiguration(configuration); + exporter.exportReport(); + } +*/ + + @RequestMapping(value = {"/waktu-rawat-jalan"}, method = {RequestMethod.GET}) + public void handleWaktuRawatJalan( + @RequestParam("tglAwal") String tglAwal, + @RequestParam("tglAkhir") String tglAkhir, + @RequestParam(value = "idDokter", required = false, defaultValue = "") Integer idDokter, + @RequestParam(value = "idRuangan", required = false, defaultValue = "") Integer idRuangan, + @RequestParam(value = "format", required = false, defaultValue = "pdf") String format, + @RequestParam(value = "mode", required = false, defaultValue = "download") String mode, + HttpServletResponse response) throws Exception { + + // Generate report (common for both PDF/Excel) + JasperPrint jasperPrint = this.reportingService.exportWaktuRawatJalan(tglAwal, tglAkhir, idDokter, idRuangan); + + if ("excel".equalsIgnoreCase(format)) { + // Handle Excel export + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setHeader("Content-Disposition", "attachment; filename=waktu_rawat_jalan.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=waktu_rawat_jalan.pdf"); + + JRPdfExporter exporter = new JRPdfExporter(); + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(response.getOutputStream())); + exporter.exportReport(); + } + } + + @RequestMapping(value = {"/laporan-pendaftaran-online"}, method = {RequestMethod.GET}) + public void handleLpPendaftaranOnline( + @RequestParam("tglAwal") String tglAwal, + @RequestParam("tglAkhir") String tglAkhir, + @RequestParam(value = "idUnit", required = false, defaultValue = "") Integer idUnit, + @RequestParam(value = "idRuangan", required = false, defaultValue = "") Integer idRuangan, + @RequestParam(value = "format", required = false, defaultValue = "pdf") String format, + @RequestParam(value = "mode", required = false, defaultValue = "download") String mode, + HttpServletResponse response) throws Exception { + + // Generate report (common for both PDF/Excel) + JasperPrint jasperPrint = this.reportingService.exportLpPendaftaranOnline(tglAwal, tglAkhir, idUnit, idRuangan); + + if ("excel".equalsIgnoreCase(format)) { + // Handle Excel export + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setHeader("Content-Disposition", "attachment; filename=Laporan_Pendaftaran_Online.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_Pendaftaran_Online.pdf"); + + JRPdfExporter exporter = new JRPdfExporter(); + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(response.getOutputStream())); + exporter.exportReport(); + } + } + + @RequestMapping(value = {"/laporan-volume-tindakan"}, method = {RequestMethod.GET}) + public void handleLpVolumeTindakan( + @RequestParam("tglAwal") String tglAwal, + @RequestParam("tglAkhir") String tglAkhir, + @RequestParam(value = "idInstalasi", required = false, defaultValue = "") Integer idInstalasi, + @RequestParam(value = "idRuangan", required = false, defaultValue = "") Integer idRuangan, + @RequestParam(value = "idProduk", required = false, defaultValue = "") Integer idProduk, + @RequestParam(value = "idPegawai", required = false, defaultValue = "") Integer idPegawai, + @RequestParam(value = "idKp", required = false, defaultValue = "") Integer idKp, + @RequestParam(value = "format", required = false, defaultValue = "pdf") String format, + @RequestParam(value = "mode", required = false, defaultValue = "download") String mode, + HttpServletResponse response) throws Exception { + + // Generate report (common for both PDF/Excel) + JasperPrint jasperPrint = this.reportingService.exportLpVolumeTindakan(tglAwal, tglAkhir, idInstalasi, idRuangan, idProduk, idPegawai, idKp); + + if ("excel".equalsIgnoreCase(format)) { + // Handle Excel export + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setHeader("Content-Disposition", "attachment; filename=Laporan_Volume_Tindakan.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_Volume_Tindakan.pdf"); + + JRPdfExporter exporter = new JRPdfExporter(); + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(response.getOutputStream())); + exporter.exportReport(); + } + } + } diff --git a/src/main/java/com/reporting/dao/ReportingDao.java b/src/main/java/com/reporting/dao/ReportingDao.java index e7c181e..e20031f 100644 --- a/src/main/java/com/reporting/dao/ReportingDao.java +++ b/src/main/java/com/reporting/dao/ReportingDao.java @@ -3,9 +3,9 @@ package com.reporting.dao; import com.reporting.service.PostgresArrayService; import net.sf.jasperreports.engine.*; import net.sf.jasperreports.engine.export.JRPrintServiceExporter; +import net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter; import net.sf.jasperreports.engine.type.OrientationEnum; -import net.sf.jasperreports.export.SimpleExporterInput; -import net.sf.jasperreports.export.SimplePrintServiceExporterConfiguration; +import net.sf.jasperreports.export.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -23,7 +23,10 @@ import javax.print.attribute.standard.OrientationRequested; import javax.print.attribute.standard.PrinterName; import java.sql.Connection; import java.util.*; -import java.util.stream.Collectors; + +import net.sf.jasperreports.export.SimpleExporterInput; + +import java.io.File; @Transactional @Repository @@ -38,6 +41,10 @@ public class ReportingDao { @Autowired private JdbcTemplate jdbcTemplate2; + @Qualifier("thirdJdbcTemplate") + @Autowired + private JdbcTemplate jdbcTemplate3; + @Autowired private PostgresArrayService postgresArrayService; @@ -1064,33 +1071,77 @@ public class ReportingDao { return null; } -/* - public static String convertToPostgresArray(List idList) { - if (idList == null || idList.isEmpty()) { - return "{}"; // Mengembalikan array kosong - } - // Mengonversi ke format PostgreSQL array - return "{" + idList.stream() - .map(String::valueOf) - .collect(Collectors.joining(",")) + "}"; - } -*/ + //Export Excel -/* public JasperPrint exportPdfLabelKetring(Integer noorder) { - try (Connection conn = this.jdbcTemplate2.getDataSource().getConnection()) { - String path = jaspersim2DirPath + "label_catering.jrxml"; + public JasperPrint exportVisit(Date tglAwal, Date tglAkhir, Integer idDokter, Integer idRuangan) { + try (Connection conn = this.jdbcTemplate1.getDataSource().getConnection()) { + String path = jaspersim2DirPath + "visit.jrxml"; JasperReport jasperReport = JasperCompileManager.compileReport(path); Map parameters = new HashMap<>(); - parameters.put("noorderList", noorder); - - // Assuming you have a way to handle multiple noorder values in your report + parameters.put("tglAwal", tglAwal); + parameters.put("tglAkhir", tglAkhir); + parameters.put("idDokter", idDokter); + parameters.put("idRuangan", idRuangan); return JasperFillManager.fillReport(jasperReport, parameters, conn); } catch (Exception var15) { - LOG.error("Exception at exportPdfLabelKetring"); + LOG.error("Exception at exportVisit"); LOG.error(ReportingDao.class, var15); } return null; - }*/ + } + public JasperPrint exportWaktuRawatJalan(Date tglAwal, Date tglAkhir, Integer idDokter, Integer idRuangan) { + try (Connection conn = this.jdbcTemplate3.getDataSource().getConnection()) { + String path = jaspersim2DirPath + "waktu_rawat_jalan.jrxml"; + JasperReport jasperReport = JasperCompileManager.compileReport(path); + Map parameters = new HashMap<>(); + parameters.put("tglAwal", tglAwal); + parameters.put("tglAkhir", tglAkhir); + parameters.put("idDokter", idDokter); + parameters.put("idRuangan", idRuangan); + return JasperFillManager.fillReport(jasperReport, parameters, conn); + } catch (Exception var15) { + LOG.error("Exception at exportWaktuRawatJalan"); + LOG.error(ReportingDao.class, var15); + } + return null; + } + + public JasperPrint exportLpPendaftaranOnline(Date tglAwal, Date tglAkhir, Integer idUnit, Integer idRuangan) { + try (Connection conn = this.jdbcTemplate1.getDataSource().getConnection()) { + String path = jaspersim2DirPath + "Laporan_pemanfaatan_pendaftaran.jrxml"; + JasperReport jasperReport = JasperCompileManager.compileReport(path); + Map parameters = new HashMap<>(); + parameters.put("tglAwal", tglAwal); + parameters.put("tglAkhir", tglAkhir); + parameters.put("idUnit", idUnit); + parameters.put("idRuangan", idRuangan); + return JasperFillManager.fillReport(jasperReport, parameters, conn); + } catch (Exception var15) { + LOG.error("Exception at exportLpPendaftaranOnline"); + LOG.error(ReportingDao.class, var15); + } + return null; + } + + public JasperPrint exportLpVolumeTindakan(Date tglAwal, Date tglAkhir, Integer idInstalasi, Integer idRuangan, Integer idProduk, Integer idPegawai, Integer idKp) { + try (Connection conn = this.jdbcTemplate1.getDataSource().getConnection()) { + String path = jaspersim2DirPath + "laporan_volume_tindakan_pasien.jrxml"; + JasperReport jasperReport = JasperCompileManager.compileReport(path); + Map parameters = new HashMap<>(); + parameters.put("tglAwal", tglAwal); + parameters.put("tglAkhir", tglAkhir); + parameters.put("idUnit", idInstalasi); + parameters.put("idRuangan", idRuangan); + parameters.put("idProduk", idProduk); + parameters.put("idPegawai", idPegawai); + parameters.put("idKp", idKp); + return JasperFillManager.fillReport(jasperReport, parameters, conn); + } catch (Exception var15) { + LOG.error("Exception at exportLpVolumeTindakan"); + 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 95dda0c..5b9666f 100644 --- a/src/main/java/com/reporting/service/ReportingService.java +++ b/src/main/java/com/reporting/service/ReportingService.java @@ -305,14 +305,63 @@ public class ReportingService { //sim2 -/* - public JasperPrint exportPdfLabelKetring(Integer noorder) { - return this.reportingDao.exportPdfLabelKetring(noorder); - } -*/ - public JasperPrint exportPdfLabelKetring(List noorder) { return this.reportingDao.exportPdfLabelKetring(noorder); } + + // Export Excel + + public JasperPrint exportVisit(String tglAwal, String tglAkhir, Integer idDokter, Integer idRuangan) { + try { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); + Date parse = formatter.parse(tglAwal); + Date parse2 = formatter.parse(tglAkhir); + return this.reportingDao.exportVisit(parse, parse2, idDokter, idRuangan); + } catch (ParseException e) { + log.error(e.getMessage()); + + return null; + } + } + + public JasperPrint exportWaktuRawatJalan(String tglAwal, String tglAkhir, Integer idDokter, Integer idRuangan) { + try { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); + Date parse = formatter.parse(tglAwal); + Date parse2 = formatter.parse(tglAkhir); + return this.reportingDao.exportWaktuRawatJalan(parse, parse2, idDokter, idRuangan); + } catch (ParseException e) { + log.error(e.getMessage()); + + return null; + } + } + + public JasperPrint exportLpPendaftaranOnline(String tglAwal, String tglAkhir, Integer idUnit, Integer idRuangan) { + try { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); + Date parse = formatter.parse(tglAwal); + Date parse2 = formatter.parse(tglAkhir); + return this.reportingDao.exportLpPendaftaranOnline(parse, parse2, idUnit, idRuangan); + } catch (ParseException e) { + log.error(e.getMessage()); + + return null; + } + } + + public JasperPrint exportLpVolumeTindakan(String tglAwal, String tglAkhir, Integer idInstalasi, Integer idRuangan, Integer idProduk, Integer idPegawai, Integer idKp) { + try { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); + Date parse = formatter.parse(tglAwal); + Date parse2 = formatter.parse(tglAkhir); + return this.reportingDao.exportLpVolumeTindakan(parse, parse2, idInstalasi, idRuangan, idProduk, idPegawai, idKp); + } catch (ParseException e) { + log.error(e.getMessage()); + + return null; + } + } + } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 04f00b1..b497e06 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -13,6 +13,13 @@ spring.datasource.secondary.url=jdbc:postgresql://172.16.88.22:5432/order_gizi spring.datasource.secondary.username=simrs spring.datasource.secondary.password=@S1mrs.3205@ +# Konfigurasi untuk sumber data ketiga +spring.datasource.third.type=com.zaxxer.hikari.HikariDataSource +spring.datasource.third.driver-class-name=org.postgresql.Driver +spring.datasource.third.url=jdbc:postgresql://172.16.88.22:5432/gen2-development-sosialisasi +spring.datasource.third.username=simrs +spring.datasource.third.password=@S1mrs.3205@ + # Pengaturan lainnya spring.mvc.dispatch-trace-request=true spring.main.banner-mode=off