-
Notifications
You must be signed in to change notification settings - Fork 0
feat(spring-jasper-example): implement bill report generation with Ja… #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ Includes loading `.jasper` templates, populating them with mock data, and export | |
|
|
||
| ## Profiles you can activate | ||
|
|
||
| - **client-list-dev** – Used in Docker, in the future, it will use pre-compiled `.jasper` files instead of `.jrxml`. Activates the internal module that generates a simple client report. | ||
| - **client-list-dev** – Used in Docker, Activates the internal module that generates a simple client report. | ||
| - **client-list-local** – Used locally, activates the internal module that generates a simple client report and use `.jrxml`. | ||
|
|
||
| - **bill-dev** – Used in Docker, Activates the internal module that generates a simple bill report. | ||
| - **bill-local** – Used locally, activates the internal module that generates a simple bill report and use `.jrxml`. | ||
|
Comment on lines
+22
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Fix casing/grammar in profile descriptions. Lowercase “activates” and use “uses” for JRXML. -- **client-list-dev** – Used in Docker, Activates the internal module that generates a simple client report.
+- **client-list-dev** – Used in Docker, activates the internal module that generates a simple client report.
- **client-list-local** – Used locally, activates the internal module that generates a simple client report and use `.jrxml`.
-- **bill-dev** – Used in Docker, Activates the internal module that generates a simple bill report.
-- **bill-local** – Used locally, activates the internal module that generates a simple bill report and use `.jrxml`.
+- **bill-dev** – Used in Docker, activates the internal module that generates a simple bill report.
+- **bill-local** – Used locally, activates the internal module that generates a simple bill report and uses `.jrxml`.
🧰 Tools🪛 LanguageTool[grammar] ~22-~22: There might be a mistake here. (QB_NEW_EN) [grammar] ~23-~23: Make sure you are using the right part of speech (QB_NEW_EN_OTHER_ERROR_IDS_21) [grammar] ~23-~23: There might be a mistake here. (QB_NEW_EN) [grammar] ~24-~24: There might be a mistake here. (QB_NEW_EN) [grammar] ~25-~25: Make sure you are using the right part of speech (QB_NEW_EN_OTHER_ERROR_IDS_21) [grammar] ~25-~25: There might be a mistake here. (QB_NEW_EN) 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,37 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| package com.io.example.base; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import net.sf.jasperreports.engine.*; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import net.sf.jasperreports.engine.util.JRLoader; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.core.io.ClassPathResource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.io.InputStream; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.Collection; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.HashMap; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+8
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Replace unused HashMap import; prefer Collections. We’ll switch to Collections.emptyMap() below; update imports accordingly. import java.io.InputStream;
import java.util.Collection;
-import java.util.HashMap;
+import java.util.Collections;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public class JasperReader { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+12
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Make utility class non-instantiable. Mark class final and add a private constructor. -public class JasperReader {
+public final class JasperReader {
+
+ private JasperReader() {}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static byte[] exportReportJrxmlToPdf(Collection<?> beanCollection, String path){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| InputStream stream = new ClassPathResource(path).getInputStream(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| JasperReport jasperReport = JasperCompileManager.compileReport(stream); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(beanCollection); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap<>(), dataSource); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return JasperExportManager.exportReportToPdf(jasperPrint); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (Exception e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new RuntimeException(e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+14
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Close JRXML InputStream; avoid resource leak and improve robustness. Use try-with-resources, guard null data, and avoid allocating a new HashMap on the hot path. - public static byte[] exportReportJrxmlToPdf(Collection<?> beanCollection, String path){
- try {
- InputStream stream = new ClassPathResource(path).getInputStream();
- JasperReport jasperReport = JasperCompileManager.compileReport(stream);
- JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(beanCollection);
- JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap<>(), dataSource);
- return JasperExportManager.exportReportToPdf(jasperPrint);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
+ public static byte[] exportReportJrxmlToPdf(Collection<?> beanCollection, String path){
+ try (InputStream stream = new ClassPathResource(path).getInputStream()) {
+ JasperReport jasperReport = JasperCompileManager.compileReport(stream);
+ Collection<?> data = (beanCollection == null) ? java.util.Collections.emptyList() : beanCollection;
+ JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(data);
+ JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, java.util.Collections.emptyMap(), dataSource);
+ return JasperExportManager.exportReportToPdf(jasperPrint);
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to export JRXML report to PDF: " + path, e);
+ }
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static byte[] exportReportJasperToPdf(Collection<?> beanCollection, String path){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try (InputStream stream = new ClassPathResource(path).getInputStream()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| JasperReport jasperReport = (JasperReport) JRLoader.loadObject(stream); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(beanCollection); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap<>(), dataSource); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return JasperExportManager.exportReportToPdf(jasperPrint); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (Exception e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new RuntimeException(e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+14
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Optional: de-duplicate fill/export logic. Consider a private helper that accepts a JasperReport and collection, returning the PDF; both public methods would prepare the JasperReport and delegate. 🤖 Prompt for AI Agents
Comment on lines
+26
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Harmonize map allocation and null-safety with the .jasper path. Use emptyMap(), add null guard, and include context in the exception message. public static byte[] exportReportJasperToPdf(Collection<?> beanCollection, String path){
try (InputStream stream = new ClassPathResource(path).getInputStream()) {
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(stream);
- JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(beanCollection);
- JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap<>(), dataSource);
+ Collection<?> data = (beanCollection == null) ? java.util.Collections.emptyList() : beanCollection;
+ JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(data);
+ JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, java.util.Collections.emptyMap(), dataSource);
return JasperExportManager.exportReportToPdf(jasperPrint);
} catch (Exception e) {
- throw new RuntimeException(e);
+ throw new RuntimeException("Failed to export compiled Jasper report to PDF: " + path, e);
}
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package com.io.example.clientList.service; | ||
|
|
||
| import com.io.example.clientList.dto.ClientDto; | ||
| import org.springframework.context.annotation.Profile; | ||
| import org.springframework.stereotype.Service; | ||
| import java.util.*; | ||
|
|
||
| import static com.io.example.base.JasperReader.exportReportJasperToPdf; | ||
|
|
||
| @Service | ||
| @Profile({"client-list-dev"}) | ||
| public class ClientsReportDevServiceImpl implements ClientsReportService { | ||
|
|
||
| private static final List<ClientDto> clients = Arrays.asList( | ||
| new ClientDto(1, "Alice", "Brazil"), | ||
| new ClientDto(2, "Bob", "USA"), | ||
| new ClientDto(3, "Carlos", "Spain") | ||
| ); | ||
|
|
||
| @Override | ||
| public byte[] generateClientsPdf() { | ||
| return exportReportJasperToPdf(clients, "reports/client-list-template.jasper"); | ||
| } | ||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package com.io.example.clientList.service; | ||
|
|
||
| import com.io.example.clientList.dto.ClientDto; | ||
| import org.springframework.context.annotation.Profile; | ||
| import org.springframework.stereotype.Service; | ||
| import java.util.*; | ||
|
|
||
| import static com.io.example.base.JasperReader.exportReportJrxmlToPdf; | ||
|
|
||
| @Service | ||
| @Profile({"client-list-local"}) | ||
| public class ClientsReportLocalServiceImpl implements ClientsReportService { | ||
|
|
||
| private static final List<ClientDto> clients = Arrays.asList( | ||
| new ClientDto(1, "Alice", "Brazil"), | ||
| new ClientDto(2, "Bob", "USA"), | ||
| new ClientDto(3, "Carlos", "Spain") | ||
| ); | ||
|
Comment on lines
+14
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Minor cleanup: use List.of and extract template path constant. Keeps the class immutable and avoids magic strings. Apply: - private static final List<ClientDto> clients = Arrays.asList(
+ private static final List<ClientDto> clients = List.of(
new ClientDto(1, "Alice", "Brazil"),
new ClientDto(2, "Bob", "USA"),
new ClientDto(3, "Carlos", "Spain")
);
+ private static final String TEMPLATE = "reports/client-list-template.jrxml";
@@
- return exportReportJrxmlToPdf(clients, "reports/client-list-template.jrxml");
+ return exportReportJrxmlToPdf(clients, TEMPLATE);Also applies to: 22-22 🤖 Prompt for AI Agents |
||
|
|
||
| @Override | ||
| public byte[] generateClientsPdf() { | ||
| return exportReportJrxmlToPdf(clients, "reports/client-list-template.jrxml"); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,5 @@ | ||||||||||||||
| package com.io.example.clientList.service; | ||||||||||||||
|
|
||||||||||||||
| public interface ClientsReportService { | ||||||||||||||
| byte[] generateClientsPdf(); | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+3
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Consider neutral method naming for reuse. Renaming to generatePdf() (or aligning with BillReportService) makes the interface reusable and reduces coupling to “clients”. -public interface ClientsReportService {
- byte[] generateClientsPdf();
+public interface ClientsReportService {
+ byte[] generatePdf();
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||||||
| package com.io.example.dataUsageBill.controller; | ||||||||||
|
|
||||||||||
| import com.io.example.clientList.service.ClientsReportService; | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Remove unused import. -import com.io.example.clientList.service.ClientsReportService;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| import com.io.example.dataUsageBill.service.BillReportService; | ||||||||||
| import lombok.RequiredArgsConstructor; | ||||||||||
| import org.springframework.context.annotation.Profile; | ||||||||||
| import org.springframework.http.HttpHeaders; | ||||||||||
| import org.springframework.http.MediaType; | ||||||||||
| import org.springframework.http.ResponseEntity; | ||||||||||
| import org.springframework.web.bind.annotation.GetMapping; | ||||||||||
| import org.springframework.web.bind.annotation.RestController; | ||||||||||
|
|
||||||||||
| @RestController | ||||||||||
| @Profile({"bill-dev", "bill-local"}) | ||||||||||
| @RequiredArgsConstructor | ||||||||||
| public class BillController { | ||||||||||
|
|
||||||||||
| private final BillReportService billReportService; | ||||||||||
|
|
||||||||||
| @GetMapping("/reports/bill") | ||||||||||
| public ResponseEntity<byte[]> getBillData() { | ||||||||||
|
Comment on lines
+20
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Declare produced media type on the mapping. Improves explicitness and content negotiation. - @GetMapping("/reports/bill")
+ @GetMapping(value = "/reports/bill", produces = MediaType.APPLICATION_PDF_VALUE)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| byte[] pdf = this.billReportService.generateBillPdf(); | ||||||||||
| return ResponseEntity.ok() | ||||||||||
| .header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=bill.pdf") | ||||||||||
| .contentType(MediaType.APPLICATION_PDF) | ||||||||||
| .body(pdf); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.io.example.dataUsageBill.dto; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Data | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class BillDto { | ||
|
Comment on lines
+8
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Adopt proper types and fix typo: BigDecimal for amounts, LocalDate for dates, totalAmount name. Prevents rounding errors and clarifies semantics. +import java.math.BigDecimal;
+import java.time.LocalDate;
@@
- private String dayStart;
- private String dayEnd;
+ private LocalDate dayStart;
+ private LocalDate dayEnd;
@@
- private Integer dtoOMamount;
- private Integer dtoONamount;
- private Integer dtoOLamount;
- private Integer dtoDLamount;
- private Integer dtoDNamount;
- private Integer dtoDamount;
+ private BigDecimal dtoOMamount;
+ private BigDecimal dtoONamount;
+ private BigDecimal dtoOLamount;
+ private BigDecimal dtoDLamount;
+ private BigDecimal dtoDNamount;
+ private BigDecimal dtoDamount;
@@
- private Integer totalHrs;
- private Integer toltalAm;
+ private Integer totalHrs;
+ private BigDecimal totalAmount;Note: update builders/usages and the JRXML field types/expressions accordingly. Also applies to: 27-35 🤖 Prompt for AI Agents |
||
| private String orgName; | ||
| private String depName; | ||
| private String devName; | ||
| private String groupName; | ||
| private String dayStart; | ||
| private String dayEnd; | ||
|
|
||
| private Integer dtoOM; | ||
| private Integer dtoON; | ||
| private Integer dtoOL; | ||
| private Integer dtoDL; | ||
| private Integer dtoDN; | ||
| private Integer dtoD; | ||
|
|
||
| private Integer dtoOMamount; | ||
| private Integer dtoONamount; | ||
| private Integer dtoOLamount; | ||
| private Integer dtoDLamount; | ||
| private Integer dtoDNamount; | ||
| private Integer dtoDamount; | ||
|
|
||
| private Integer totalHrs; | ||
| private Integer toltalAm; | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package com.io.example.dataUsageBill.service; | ||
|
|
||
| import com.io.example.dataUsageBill.dto.BillDto; | ||
| import org.springframework.context.annotation.Profile; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static com.io.example.base.JasperReader.exportReportJasperToPdf; | ||
|
|
||
| @Service | ||
| @Profile({"bill-dev"}) | ||
| public class BillReportDevServiceImpl implements BillReportService { | ||
|
|
||
| @Override | ||
| public byte[] generateBillPdf() { | ||
| return exportReportJasperToPdf(getBillDto(), "reports/bill-template.jasper"); | ||
| } | ||
|
|
||
| private List<BillDto> getBillDto(){ | ||
| BillDto bill = BillDto.builder() | ||
| .orgName("My Organization") | ||
| .depName("IT Department") | ||
| .devName("Development Team") | ||
| .groupName("Network Group") | ||
| .dayStart("2025-08-01") | ||
| .dayEnd("2025-08-31") | ||
| .dtoOM(10) | ||
| .dtoON(5) | ||
| .dtoOL(3) | ||
| .dtoDL(7) | ||
| .dtoDN(2) | ||
| .dtoD(1) | ||
| .dtoOMamount(100) | ||
| .dtoONamount(50) | ||
| .dtoOLamount(30) | ||
| .dtoDLamount(70) | ||
| .dtoDNamount(20) | ||
| .dtoDamount(10) | ||
| .totalHrs(28) | ||
| .toltalAm(280) | ||
| .build(); | ||
| return List.of(bill); | ||
| } | ||
|
Comment on lines
+20
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainTypo in field ‘toltalAm’ — rename to ‘totalAmount’ (align DTO/jrxml). Apply here (and update BillDto + templates accordingly): - .toltalAm(280)
+ .totalAmount(280)Also consider:
Verify resources/field consistency: 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Templates present?
fd -a 'bill-template.jasper' spring-jasper-example
fd -a 'bill-template.jrxml' spring-jasper-example
# Field usage consistency (expect either all 'toltalAm' today, or all 'totalAmount' after refactor)
rg -nS 'toltalAm|totalAmount' spring-jasper-example -C2Length of output: 3670 Fix typo ‘toltalAm’ → ‘totalAmount’ across DTO, builders, and JRXML templates
Consider also using BigDecimal for monetary fields and LocalDate for dayStart/dayEnd. |
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package com.io.example.dataUsageBill.service; | ||
|
|
||
| import com.io.example.dataUsageBill.dto.BillDto; | ||
| import org.springframework.context.annotation.Profile; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static com.io.example.base.JasperReader.exportReportJrxmlToPdf; | ||
|
|
||
| @Service | ||
| @Profile({"bill-local"}) | ||
| public class BillReportLocalServiceImpl implements BillReportService { | ||
|
|
||
| @Override | ||
| public byte[] generateBillPdf() { | ||
| return exportReportJrxmlToPdf(getBillDto(), "reports/bill-template.jrxml"); | ||
| } | ||
|
|
||
| private List<BillDto> getBillDto(){ | ||
| BillDto bill = BillDto.builder() | ||
| .orgName("My Organization") | ||
| .depName("IT Department") | ||
| .devName("Development Team") | ||
| .groupName("Network Group") | ||
| .dayStart("2025-08-01") | ||
| .dayEnd("2025-08-31") | ||
| .dtoOM(10) | ||
| .dtoON(5) | ||
| .dtoOL(3) | ||
| .dtoDL(7) | ||
| .dtoDN(2) | ||
| .dtoD(1) | ||
| .dtoOMamount(100) | ||
| .dtoONamount(50) | ||
| .dtoOLamount(30) | ||
| .dtoDLamount(70) | ||
| .dtoDNamount(20) | ||
| .dtoDamount(10) | ||
| .totalHrs(28) | ||
| .toltalAm(280) | ||
| .build(); | ||
|
Comment on lines
+20
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Fix naming and money types: rename toltalAm; use BigDecimal for amounts. “toltalAm” is a typo and all monetary fields should be BigDecimal to avoid precision issues. Consider LocalDate for dayStart/dayEnd. Minimal change here (requires coordinated updates to DTO and JRXML): - .toltalAm(280)
+ .totalAmount(new java.math.BigDecimal("280.00"))Follow-up (outside this file): rename field in BillDto and bill-template.jrxml, and change all dto*amount fields to BigDecimal.
🤖 Prompt for AI Agents |
||
| return List.of(bill); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package com.io.example.dataUsageBill.service; | ||
|
|
||
| public interface BillReportService { | ||
| byte[] generateBillPdf(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Grammar nit: “uses” (not “use”).
Keep it consistent with the bill-local entry.
📝 Committable suggestion
🧰 Tools
🪛 LanguageTool
[grammar] ~23-~23: Make sure you are using the right part of speech
Context: ...at generates a simple client report and use
.jrxml. - bill-dev – Used in Dock...(QB_NEW_EN_OTHER_ERROR_IDS_21)
[grammar] ~23-~23: There might be a mistake here.
Context: ...a simple client report and use
.jrxml. - bill-dev – Used in Docker, Activates t...(QB_NEW_EN)
🤖 Prompt for AI Agents