diff --git a/src/main/java/com/reporting/config/DbConfig.java b/src/main/java/com/reporting/config/DbConfig.java index 64585df..b7f767d 100644 --- a/src/main/java/com/reporting/config/DbConfig.java +++ b/src/main/java/com/reporting/config/DbConfig.java @@ -39,8 +39,35 @@ public class DbConfig { return null; } + @Bean(name = "secondaryDataSource") + public DataSource dataSource2() { + try { + HikariConfig config = new HikariConfig(); + config.setPoolName("PoolReporting2"); + config.setDriverClassName("org.postgresql.Driver"); + config.setConnectionTestQuery("SELECT 1"); + config.setJdbcUrl("jdbc:postgresql://172.16.88.22:5432/order_gizi"); + 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); } + + @Bean(name = "secondaryJdbcTemplate") + public JdbcTemplate jdbcTemplate2(@Qualifier("secondaryDataSource") 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 9e034da..523b541 100644 --- a/src/main/java/com/reporting/controller/ReportingController.java +++ b/src/main/java/com/reporting/controller/ReportingController.java @@ -4,6 +4,7 @@ import com.reporting.model.Pasien; import com.reporting.service.ReportingService; import com.reporting.service.ResepService; import com.reporting.service.VerifikasiTagihanSupplierServices; +import com.reporting.service.PostgresArrayService; import net.sf.jasperreports.engine.JasperExportManager; import net.sf.jasperreports.engine.JasperPrint; import org.springframework.beans.factory.annotation.Autowired; @@ -17,8 +18,8 @@ import java.io.File; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.NoSuchFileException; -import java.util.HashMap; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; @RestController @RequestMapping({"/service-reporting"}) @@ -581,4 +582,31 @@ public class ReportingController { JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream()); } + //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 { + List noorderList = (ArrayList) Arrays.stream(noorder.split(",")) + .map(Integer::parseInt) + .collect(Collectors.toList()); +/* // Print out a message indicating the report is being exported + System.out.println("Exporting PDF for order numbers: " + noorderList);*/ + // Set the content type for the response + response.setContentType("application/pdf"); + JasperPrint jasperPrint = this.reportingService.exportPdfLabelKetring(noorderList); + // Export each JasperPrint to the response output stream + JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream()); + } + } diff --git a/src/main/java/com/reporting/dao/ReportingDao.java b/src/main/java/com/reporting/dao/ReportingDao.java index a3e687f..e7c181e 100644 --- a/src/main/java/com/reporting/dao/ReportingDao.java +++ b/src/main/java/com/reporting/dao/ReportingDao.java @@ -1,6 +1,6 @@ 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.type.OrientationEnum; @@ -22,9 +22,8 @@ import javax.print.attribute.standard.MediaSizeName; import javax.print.attribute.standard.OrientationRequested; import javax.print.attribute.standard.PrinterName; import java.sql.Connection; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; @Transactional @Repository @@ -35,12 +34,22 @@ public class ReportingDao { @Autowired private JdbcTemplate jdbcTemplate1; + @Qualifier("secondaryJdbcTemplate") + @Autowired + private JdbcTemplate jdbcTemplate2; + + @Autowired + private PostgresArrayService postgresArrayService; + @Value("${application.jasper-xml.dir-path}") String jasperDirPath; @Value("${application.jasper-xml.dir-bintaro-path}") String jasperBintaroDirPath; + @Value("${application.jasper-xml.dir-sim2-path}") + String jaspersim2DirPath; + public ReportingDao() { } @@ -1037,4 +1046,51 @@ public class ReportingDao { return null; } + //sim2 + + public JasperPrint exportPdfLabelKetring(List noorder) { + + try (Connection conn = this.jdbcTemplate2.getDataSource().getConnection()) { + String path = jaspersim2DirPath + "label_catering_new.jrxml"; + JasperReport jasperReport = JasperCompileManager.compileReport(path); + Map parameters = new HashMap<>(); + String pgArray = PostgresArrayService.convertToPostgresArray(noorder); // Hasil: {1,2,3,4} + parameters.put("noorder", pgArray); + return JasperFillManager.fillReport(jasperReport, parameters, conn); + } catch (Exception var15) { + LOG.error("Exception at exportPdfLabelKetring"); + LOG.error(ReportingDao.class, var15); + } + 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(",")) + "}"; + } + +*/ + +/* public JasperPrint exportPdfLabelKetring(Integer noorder) { + try (Connection conn = this.jdbcTemplate2.getDataSource().getConnection()) { + String path = jaspersim2DirPath + "label_catering.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 + return JasperFillManager.fillReport(jasperReport, parameters, conn); + } catch (Exception var15) { + LOG.error("Exception at exportPdfLabelKetring"); + LOG.error(ReportingDao.class, var15); + } + return null; + }*/ + } diff --git a/src/main/java/com/reporting/service/PostgresArrayService.java b/src/main/java/com/reporting/service/PostgresArrayService.java new file mode 100644 index 0000000..87527da --- /dev/null +++ b/src/main/java/com/reporting/service/PostgresArrayService.java @@ -0,0 +1,16 @@ +package com.reporting.service; +import org.springframework.stereotype.Service; // Pastikan untuk mengimpor ini +import java.util.List; +import java.util.stream.Collectors; +@Service // Tambahkan anotasi ini +public class PostgresArrayService { + 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(",")) + "}"; + } +} \ No newline at end of file diff --git a/src/main/java/com/reporting/service/ReportingService.java b/src/main/java/com/reporting/service/ReportingService.java index afd559a..95dda0c 100644 --- a/src/main/java/com/reporting/service/ReportingService.java +++ b/src/main/java/com/reporting/service/ReportingService.java @@ -11,6 +11,7 @@ import org.springframework.stereotype.Service; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.List; import java.util.Objects; @Service @@ -302,4 +303,16 @@ public class ReportingService { return this.reportingDao.exportPdfLabelFarmasiBintaro(norec); } + //sim2 + +/* + public JasperPrint exportPdfLabelKetring(Integer noorder) { + return this.reportingDao.exportPdfLabelKetring(noorder); + } +*/ + + public JasperPrint exportPdfLabelKetring(List noorder) { + return this.reportingDao.exportPdfLabelKetring(noorder); + } + } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 55d3ca7..04f00b1 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,13 +1,23 @@ server.port=7777 -spring.datasource.type=com.zaxxer.hikari.HikariDataSource -spring.datasource.driver-class-name=org.postgresql.Driver -spring.datasource.url=jdbc:postgresql://ds.rsabhk.lan:5432/rsab_hk_production -#spring.datasource.url=jdbc:postgresql://172.16.44.35:5432/rsab_hk_production -spring.datasource.username=postgres -spring.datasource.password=root +# Konfigurasi untuk sumber data pertama +spring.datasource.primary.type=com.zaxxer.hikari.HikariDataSource +spring.datasource.primary.driver-class-name=org.postgresql.Driver +spring.datasource.primary.url=jdbc:postgresql://ds.rsabhk.lan:5432/rsab_hk_production +spring.datasource.primary.username=postgres +spring.datasource.primary.password=root + +# Konfigurasi untuk sumber data kedua +spring.datasource.secondary.type=com.zaxxer.hikari.HikariDataSource +spring.datasource.secondary.driver-class-name=org.postgresql.Driver +spring.datasource.secondary.url=jdbc:postgresql://172.16.88.22:5432/order_gizi +spring.datasource.secondary.username=simrs +spring.datasource.secondary.password=@S1mrs.3205@ + +# Pengaturan lainnya spring.mvc.dispatch-trace-request=true spring.main.banner-mode=off application.jasper-xml.dir-path=/mnt/files/jasper-xml/ application.jasper-xml.dir-bintaro-path=/mnt/files/jasper-xml-bintaro/ +application.jasper-xml.dir-sim2-path=/mnt/files/jasper-xml-sim2/ application.pdf.dir-sep=/mnt/files/sep/ application.pdf.dir-lis=/mnt/lis/ \ No newline at end of file